Skip to content

Commit

Permalink
Revert SE-0283 (#34492)
Browse files Browse the repository at this point in the history
Reverted despite build failures.
  • Loading branch information
Azoy committed Oct 30, 2020
1 parent 142b726 commit 424802f
Show file tree
Hide file tree
Showing 55 changed files with 100 additions and 3,033 deletions.
39 changes: 15 additions & 24 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -2295,28 +2295,37 @@ struct TargetTypeMetadataRecord {
union {
/// A direct reference to a nominal type descriptor.
RelativeDirectPointerIntPair<TargetContextDescriptor<Runtime>,
TypeMetadataRecordKind>
TypeReferenceKind>
DirectNominalTypeDescriptor;

/// An indirect reference to a nominal type descriptor.
RelativeDirectPointerIntPair<TargetSignedPointer<Runtime, TargetContextDescriptor<Runtime> * __ptrauth_swift_type_descriptor>,
TypeMetadataRecordKind>
TypeReferenceKind>
IndirectNominalTypeDescriptor;

// We only allow a subset of the TypeReferenceKinds here.
// Should we just acknowledge that this is a different enum?
};

public:
TypeMetadataRecordKind getTypeKind() const {
TypeReferenceKind getTypeKind() const {
return DirectNominalTypeDescriptor.getInt();
}

const TargetContextDescriptor<Runtime> *
getContextDescriptor() const {
switch (getTypeKind()) {
case TypeMetadataRecordKind::DirectTypeDescriptor:
case TypeReferenceKind::DirectTypeDescriptor:
return DirectNominalTypeDescriptor.getPointer();

case TypeMetadataRecordKind::IndirectTypeDescriptor:
case TypeReferenceKind::IndirectTypeDescriptor:
return *IndirectNominalTypeDescriptor.getPointer();

// These types (and any others we might add to TypeReferenceKind
// in the future) are just never used in these lists.
case TypeReferenceKind::DirectObjCClassName:
case TypeReferenceKind::IndirectObjCClass:
return nullptr;
}

return nullptr;
Expand Down Expand Up @@ -2406,9 +2415,6 @@ struct TargetTypeReference {
/// A direct reference to an Objective-C class name.
RelativeDirectPointer<const char>
DirectObjCClassName;

/// A "reference" to some metadata kind, e.g. tuple.
MetadataKind MetadataKind;
};

const TargetContextDescriptor<Runtime> *
Expand All @@ -2422,18 +2428,12 @@ struct TargetTypeReference {

case TypeReferenceKind::DirectObjCClassName:
case TypeReferenceKind::IndirectObjCClass:
case TypeReferenceKind::MetadataKind:
return nullptr;
}

return nullptr;
}

enum MetadataKind getMetadataKind(TypeReferenceKind kind) const {
assert(kind == TypeReferenceKind::MetadataKind);
return MetadataKind;
}

#if SWIFT_OBJC_INTEROP
/// If this type reference is one of the kinds that supports ObjC
/// references,
Expand Down Expand Up @@ -2519,10 +2519,6 @@ struct TargetProtocolConformanceDescriptor final
return Flags.getTypeReferenceKind();
}

enum MetadataKind getMetadataKind() const {
return TypeRef.getMetadataKind(getTypeKind());
}

const char *getDirectObjCClassName() const {
return TypeRef.getDirectObjCClassName(getTypeKind());
}
Expand Down Expand Up @@ -2550,11 +2546,6 @@ struct TargetProtocolConformanceDescriptor final
TargetRelativeContextPointer<Runtime>>();
}

/// Whether this conformance is builtin by the compiler + runtime.
bool isBuiltin() const {
return getTypeKind() == TypeReferenceKind::MetadataKind;
}

/// Whether this conformance is non-unique because it has been synthesized
/// for a foreign type.
bool isSynthesizedNonUnique() const {
Expand Down
22 changes: 3 additions & 19 deletions include/swift/ABI/MetadataValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -361,19 +361,7 @@ enum : unsigned {
NumGenericMetadataPrivateDataWords = 16,
};

/// Kinds of type metadata reocrds.
enum class TypeMetadataRecordKind : unsigned {
/// A direct reference to a nominal type descriptor.
DirectTypeDescriptor = 0x00,

/// An indirect reference to a nominal type descriptor.
IndirectTypeDescriptor = 0x01,

First_Kind = DirectTypeDescriptor,
Last_Kind = IndirectTypeDescriptor,
};

/// Kinds of references to type metadata.
/// Kinds of type metadata/protocol conformance records.
enum class TypeReferenceKind : unsigned {
/// The conformance is for a nominal type referenced directly;
/// getTypeDescriptor() points to the type context descriptor.
Expand All @@ -396,14 +384,10 @@ enum class TypeReferenceKind : unsigned {
/// unused.
IndirectObjCClass = 0x03,

/// The conformance is for a non-nominal type whose metadata kind we recorded;
/// getMetadataKind() returns the kind.
MetadataKind = 0x04,

// We only reserve three bits for this in the various places we store it.

First_Kind = DirectTypeDescriptor,
Last_Kind = MetadataKind,
Last_Kind = IndirectObjCClass,
};

/// Flag that indicates whether an existential type is class-constrained or not.
Expand Down
6 changes: 0 additions & 6 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ namespace swift {
class InheritedProtocolConformance;
class SelfProtocolConformance;
class SpecializedProtocolConformance;
class BuiltinProtocolConformance;
enum class ProtocolConformanceState;
class Pattern;
enum PointerTypeKind : unsigned;
Expand Down Expand Up @@ -949,11 +948,6 @@ class ASTContext final {
SelfProtocolConformance *
getSelfConformance(ProtocolDecl *protocol);

/// Produce the builtin conformance for some structural type to some protocol.
BuiltinProtocolConformance *
getBuiltinConformance(Type type, ProtocolDecl *protocol,
ArrayRef<ProtocolConformanceRef> conformances);

/// A callback used to produce a diagnostic for an ill-formed protocol
/// conformance that was type-checked before we're actually walking the
/// conformance itself, along with a bit indicating whether this diagnostic
Expand Down
118 changes: 4 additions & 114 deletions include/swift/AST/ProtocolConformance.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -66,10 +66,7 @@ enum class ProtocolConformanceKind {
Specialized,
/// Conformance of a generic class type projected through one of its
/// superclass's conformances.
Inherited,
/// Builtin conformances are special conformaces that the runtime handles
/// and isn't implemented directly in Swift.
Builtin
Inherited
};

/// Describes the state of a protocol conformance, which may be complete,
Expand Down Expand Up @@ -332,9 +329,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
/// - the type is directly declared to conform to the protocol (a
/// normal conformance) or
/// - the protocol's existential type is known to conform to itself (a
/// self-conformance) or
/// - the type's conformance is declared within the runtime (a builtin
/// conformance).
/// self-conformance).
class RootProtocolConformance : public ProtocolConformance {
protected:
RootProtocolConformance(ProtocolConformanceKind kind, Type conformingType)
Expand Down Expand Up @@ -385,8 +380,7 @@ class RootProtocolConformance : public ProtocolConformance {

static bool classof(const ProtocolConformance *conformance) {
return conformance->getKind() == ProtocolConformanceKind::Normal ||
conformance->getKind() == ProtocolConformanceKind::Self ||
conformance->getKind() == ProtocolConformanceKind::Builtin;
conformance->getKind() == ProtocolConformanceKind::Self;
}
};

Expand Down Expand Up @@ -1020,110 +1014,6 @@ class InheritedProtocolConformance : public ProtocolConformance,
}
};

/// A builtin conformance appears when a special non-nominal type has a runtime
/// declared conformance. E.g. the runtime implements Equatable for tuples.
class BuiltinProtocolConformance final : public RootProtocolConformance,
private llvm::TrailingObjects<BuiltinProtocolConformance,
ProtocolConformanceRef> {
friend ASTContext;
friend TrailingObjects;

ProtocolDecl *protocol = nullptr;
size_t numConformances;

mutable Optional<ArrayRef<Requirement>> conditionalConformances = None;

BuiltinProtocolConformance(Type conformingType, ProtocolDecl *protocol,
ArrayRef<ProtocolConformanceRef> conformances);

size_t numTrailingObjects(OverloadToken<ProtocolConformanceRef>) const {
return numConformances;
}

public:
/// Get the protocol being conformed to.
ProtocolDecl *getProtocol() const {
return protocol;
}

/// Get the trailing conformances that this builtin conformance needs.
MutableArrayRef<ProtocolConformanceRef> getConformances() {
return {getTrailingObjects<ProtocolConformanceRef>(), numConformances};
}

/// Get the trailing conformances that this builtin conformance needs.
ArrayRef<ProtocolConformanceRef> getConformances() const {
return {getTrailingObjects<ProtocolConformanceRef>(), numConformances};
}

/// Get any requirements that must be satisfied for this conformance to apply.
Optional<ArrayRef<Requirement>>
getConditionalRequirementsIfAvailable() const {
return ArrayRef<Requirement>();
}

/// Get any requirements that must be satisfied for this conformance to apply.
ArrayRef<Requirement> getConditionalRequirements() const;

/// Get the declaration context that contains the nominal type declaration.
DeclContext *getDeclContext() const {
return getProtocol();
}

/// Retrieve the state of this conformance.
ProtocolConformanceState getState() const {
return ProtocolConformanceState::Complete;
}

/// Get the kind of source from which this conformance comes.
ConformanceEntryKind getSourceKind() const {
return ConformanceEntryKind::Synthesized;
}
/// Get the protocol conformance which implied this implied conformance.
NormalProtocolConformance *getImplyingConformance() const {
return nullptr;
}

bool hasTypeWitness(AssociatedTypeDecl *assocType) const {
llvm_unreachable("builtin-conformances currently don't have associated \
types");
}

/// Retrieve the type witness and type decl (if one exists)
/// for the given associated type.
TypeWitnessAndDecl
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
SubstOptions options=None) const {
llvm_unreachable("builtin-conformances currently don't have associated \
types");
}

/// Given that the requirement signature of the protocol directly states
/// that the given dependent type must conform to the given protocol,
/// return its associated conformance.
ProtocolConformanceRef
getAssociatedConformance(Type assocType, ProtocolDecl *protocol) const {
llvm_unreachable("builtin-conformances currently don't have associated \
types");
}

/// Retrieve the witness corresponding to the given value requirement.
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement) const {
return ConcreteDeclRef(requirement);
}

/// Determine whether the witness for the given requirement
/// is either the default definition or was otherwise deduced.
bool usesDefaultDefinition(AssociatedTypeDecl *requirement) const {
llvm_unreachable("builtin-conformances currently don't have associated \
types");
}

static bool classof(const ProtocolConformance *conformance) {
return conformance->getKind() == ProtocolConformanceKind::Builtin;
}
};

inline bool ProtocolConformance::isInvalid() const {
return getRootConformance()->isInvalid();
}
Expand Down
1 change: 0 additions & 1 deletion include/swift/Frontend/BackDeploymentLibs.def
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50")
BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51")
BACK_DEPLOYMENT_LIB((5, 3), all, "swiftCompatibility53")
BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements")

#undef BACK_DEPLOYMENT_LIB
5 changes: 1 addition & 4 deletions include/swift/Remote/MetadataReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -1414,9 +1414,6 @@ class MetadataReader {

return metadataFn(metadata);
}
case TypeReferenceKind::MetadataKind: {
return None;
}
}

return None;
Expand Down

0 comments on commit 424802f

Please sign in to comment.