Skip to content

Commit 62e3c93

Browse files
Merge remote-tracking branch 'apple/main' into katei/merge-main-2020-10-27
2 parents 0530639 + 96c1e47 commit 62e3c93

File tree

156 files changed

+3871
-539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+3871
-539
lines changed

CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ if(POLICY CMP0076)
1717
cmake_policy(SET CMP0076 NEW)
1818
endif()
1919

20+
# Don't clobber existing variable values when evaluating `option()` declarations.
21+
if(POLICY CMP0077)
22+
cmake_policy(SET CMP0077 NEW)
23+
endif()
24+
2025
# Add path for custom CMake modules.
2126
list(APPEND CMAKE_MODULE_PATH
2227
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

include/swift/ABI/Metadata.h

+24-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -2295,37 +2295,28 @@ struct TargetTypeMetadataRecord {
22952295
union {
22962296
/// A direct reference to a nominal type descriptor.
22972297
RelativeDirectPointerIntPair<TargetContextDescriptor<Runtime>,
2298-
TypeReferenceKind>
2298+
TypeMetadataRecordKind>
22992299
DirectNominalTypeDescriptor;
23002300

23012301
/// An indirect reference to a nominal type descriptor.
23022302
RelativeDirectPointerIntPair<TargetSignedPointer<Runtime, TargetContextDescriptor<Runtime> * __ptrauth_swift_type_descriptor>,
2303-
TypeReferenceKind>
2303+
TypeMetadataRecordKind>
23042304
IndirectNominalTypeDescriptor;
2305-
2306-
// We only allow a subset of the TypeReferenceKinds here.
2307-
// Should we just acknowledge that this is a different enum?
23082305
};
23092306

23102307
public:
2311-
TypeReferenceKind getTypeKind() const {
2308+
TypeMetadataRecordKind getTypeKind() const {
23122309
return DirectNominalTypeDescriptor.getInt();
23132310
}
23142311

23152312
const TargetContextDescriptor<Runtime> *
23162313
getContextDescriptor() const {
23172314
switch (getTypeKind()) {
2318-
case TypeReferenceKind::DirectTypeDescriptor:
2315+
case TypeMetadataRecordKind::DirectTypeDescriptor:
23192316
return DirectNominalTypeDescriptor.getPointer();
23202317

2321-
case TypeReferenceKind::IndirectTypeDescriptor:
2318+
case TypeMetadataRecordKind::IndirectTypeDescriptor:
23222319
return *IndirectNominalTypeDescriptor.getPointer();
2323-
2324-
// These types (and any others we might add to TypeReferenceKind
2325-
// in the future) are just never used in these lists.
2326-
case TypeReferenceKind::DirectObjCClassName:
2327-
case TypeReferenceKind::IndirectObjCClass:
2328-
return nullptr;
23292320
}
23302321

23312322
return nullptr;
@@ -2415,6 +2406,9 @@ struct TargetTypeReference {
24152406
/// A direct reference to an Objective-C class name.
24162407
RelativeDirectPointer<const char>
24172408
DirectObjCClassName;
2409+
2410+
/// A "reference" to some metadata kind, e.g. tuple.
2411+
MetadataKind MetadataKind;
24182412
};
24192413

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

24292423
case TypeReferenceKind::DirectObjCClassName:
24302424
case TypeReferenceKind::IndirectObjCClass:
2425+
case TypeReferenceKind::MetadataKind:
24312426
return nullptr;
24322427
}
24332428

24342429
return nullptr;
24352430
}
24362431

2432+
enum MetadataKind getMetadataKind(TypeReferenceKind kind) const {
2433+
assert(kind == TypeReferenceKind::MetadataKind);
2434+
return MetadataKind;
2435+
}
2436+
24372437
#if SWIFT_OBJC_INTEROP
24382438
/// If this type reference is one of the kinds that supports ObjC
24392439
/// references,
@@ -2519,6 +2519,10 @@ struct TargetProtocolConformanceDescriptor final
25192519
return Flags.getTypeReferenceKind();
25202520
}
25212521

2522+
enum MetadataKind getMetadataKind() const {
2523+
return TypeRef.getMetadataKind(getTypeKind());
2524+
}
2525+
25222526
const char *getDirectObjCClassName() const {
25232527
return TypeRef.getDirectObjCClassName(getTypeKind());
25242528
}
@@ -2546,6 +2550,11 @@ struct TargetProtocolConformanceDescriptor final
25462550
TargetRelativeContextPointer<Runtime>>();
25472551
}
25482552

2553+
/// Whether this conformance is builtin by the compiler + runtime.
2554+
bool isBuiltin() const {
2555+
return getTypeKind() == TypeReferenceKind::MetadataKind;
2556+
}
2557+
25492558
/// Whether this conformance is non-unique because it has been synthesized
25502559
/// for a foreign type.
25512560
bool isSynthesizedNonUnique() const {

include/swift/ABI/MetadataValues.h

+19-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -361,7 +361,19 @@ enum : unsigned {
361361
NumGenericMetadataPrivateDataWords = 16,
362362
};
363363

364-
/// Kinds of type metadata/protocol conformance records.
364+
/// Kinds of type metadata reocrds.
365+
enum class TypeMetadataRecordKind : unsigned {
366+
/// A direct reference to a nominal type descriptor.
367+
DirectTypeDescriptor = 0x00,
368+
369+
/// An indirect reference to a nominal type descriptor.
370+
IndirectTypeDescriptor = 0x01,
371+
372+
First_Kind = DirectTypeDescriptor,
373+
Last_Kind = IndirectTypeDescriptor,
374+
};
375+
376+
/// Kinds of references to type metadata.
365377
enum class TypeReferenceKind : unsigned {
366378
/// The conformance is for a nominal type referenced directly;
367379
/// getTypeDescriptor() points to the type context descriptor.
@@ -384,10 +396,14 @@ enum class TypeReferenceKind : unsigned {
384396
/// unused.
385397
IndirectObjCClass = 0x03,
386398

399+
/// The conformance is for a non-nominal type whose metadata kind we recorded;
400+
/// getMetadataKind() returns the kind.
401+
MetadataKind = 0x04,
402+
387403
// We only reserve three bits for this in the various places we store it.
388404

389405
First_Kind = DirectTypeDescriptor,
390-
Last_Kind = IndirectObjCClass,
406+
Last_Kind = MetadataKind,
391407
};
392408

393409
/// Flag that indicates whether an existential type is class-constrained or not.

include/swift/AST/ASTContext.h

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ namespace swift {
103103
class InheritedProtocolConformance;
104104
class SelfProtocolConformance;
105105
class SpecializedProtocolConformance;
106+
class BuiltinProtocolConformance;
106107
enum class ProtocolConformanceState;
107108
class Pattern;
108109
enum PointerTypeKind : unsigned;
@@ -948,6 +949,11 @@ class ASTContext final {
948949
SelfProtocolConformance *
949950
getSelfConformance(ProtocolDecl *protocol);
950951

952+
/// Produce the builtin conformance for some structural type to some protocol.
953+
BuiltinProtocolConformance *
954+
getBuiltinConformance(Type type, ProtocolDecl *protocol,
955+
ArrayRef<ProtocolConformanceRef> conformances);
956+
951957
/// A callback used to produce a diagnostic for an ill-formed protocol
952958
/// conformance that was type-checked before we're actually walking the
953959
/// conformance itself, along with a bit indicating whether this diagnostic

include/swift/AST/Module.h

+3-29
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
593593
Default = 1 << 1,
594594
/// Include imports declared with `@_implementationOnly`.
595595
ImplementationOnly = 1 << 2,
596-
/// Include imports of SPIs declared with `@_spi`. Non-SPI imports are
597-
/// included whether or not this flag is specified.
596+
/// Include imports of SPIs declared with `@_spi`
598597
SPIAccessControl = 1 << 3,
599598
/// Include imports shadowed by a cross-import overlay. Unshadowed imports
600599
/// are included whether or not this flag is specified.
@@ -605,33 +604,8 @@ class ModuleDecl : public DeclContext, public TypeDecl {
605604

606605
/// Looks up which modules are imported by this module.
607606
///
608-
/// \p filter controls which imports are included in the list.
609-
///
610-
/// There are three axes for categorizing imports:
611-
/// 1. Privacy: Exported/Private/ImplementationOnly (mutually exclusive).
612-
/// 2. SPI/non-SPI: An import of any privacy level may be @_spi("SPIName").
613-
/// 3. Shadowed/Non-shadowed: An import of any privacy level may be shadowed
614-
/// by a cross-import overlay.
615-
///
616-
/// It is also possible for SPI imports to be shadowed by a cross-import
617-
/// overlay.
618-
///
619-
/// If \p filter contains multiple privacy levels, modules at all the privacy
620-
/// levels are included.
621-
///
622-
/// If \p filter contains \c ImportFilterKind::SPIAccessControl, then both
623-
/// SPI and non-SPI imports are included. Otherwise, only non-SPI imports are
624-
/// included.
625-
///
626-
/// If \p filter contains \c ImportFilterKind::ShadowedByCrossImportOverlay,
627-
/// both shadowed and non-shadowed imports are included. Otherwise, only
628-
/// non-shadowed imports are included.
629-
///
630-
/// Clang modules have some additional complexities; see the implementation of
631-
/// \c ClangModuleUnit::getImportedModules for details.
632-
///
633-
/// \pre \p filter must contain at least one privacy level, i.e. one of
634-
/// \c Exported or \c Private or \c ImplementationOnly.
607+
/// \p filter controls whether public, private, or any imports are included
608+
/// in this list.
635609
void getImportedModules(SmallVectorImpl<ImportedModule> &imports,
636610
ImportFilter filter = ImportFilterKind::Exported) const;
637611

include/swift/AST/ProtocolConformance.h

+114-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -66,7 +66,10 @@ enum class ProtocolConformanceKind {
6666
Specialized,
6767
/// Conformance of a generic class type projected through one of its
6868
/// superclass's conformances.
69-
Inherited
69+
Inherited,
70+
/// Builtin conformances are special conformaces that the runtime handles
71+
/// and isn't implemented directly in Swift.
72+
Builtin
7073
};
7174

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

381386
static bool classof(const ProtocolConformance *conformance) {
382387
return conformance->getKind() == ProtocolConformanceKind::Normal ||
383-
conformance->getKind() == ProtocolConformanceKind::Self;
388+
conformance->getKind() == ProtocolConformanceKind::Self ||
389+
conformance->getKind() == ProtocolConformanceKind::Builtin;
384390
}
385391
};
386392

@@ -1014,6 +1020,110 @@ class InheritedProtocolConformance : public ProtocolConformance,
10141020
}
10151021
};
10161022

1023+
/// A builtin conformance appears when a special non-nominal type has a runtime
1024+
/// declared conformance. E.g. the runtime implements Equatable for tuples.
1025+
class BuiltinProtocolConformance final : public RootProtocolConformance,
1026+
private llvm::TrailingObjects<BuiltinProtocolConformance,
1027+
ProtocolConformanceRef> {
1028+
friend ASTContext;
1029+
friend TrailingObjects;
1030+
1031+
ProtocolDecl *protocol = nullptr;
1032+
size_t numConformances;
1033+
1034+
mutable Optional<ArrayRef<Requirement>> conditionalConformances = None;
1035+
1036+
BuiltinProtocolConformance(Type conformingType, ProtocolDecl *protocol,
1037+
ArrayRef<ProtocolConformanceRef> conformances);
1038+
1039+
size_t numTrailingObjects(OverloadToken<ProtocolConformanceRef>) const {
1040+
return numConformances;
1041+
}
1042+
1043+
public:
1044+
/// Get the protocol being conformed to.
1045+
ProtocolDecl *getProtocol() const {
1046+
return protocol;
1047+
}
1048+
1049+
/// Get the trailing conformances that this builtin conformance needs.
1050+
MutableArrayRef<ProtocolConformanceRef> getConformances() {
1051+
return {getTrailingObjects<ProtocolConformanceRef>(), numConformances};
1052+
}
1053+
1054+
/// Get the trailing conformances that this builtin conformance needs.
1055+
ArrayRef<ProtocolConformanceRef> getConformances() const {
1056+
return {getTrailingObjects<ProtocolConformanceRef>(), numConformances};
1057+
}
1058+
1059+
/// Get any requirements that must be satisfied for this conformance to apply.
1060+
Optional<ArrayRef<Requirement>>
1061+
getConditionalRequirementsIfAvailable() const {
1062+
return ArrayRef<Requirement>();
1063+
}
1064+
1065+
/// Get any requirements that must be satisfied for this conformance to apply.
1066+
ArrayRef<Requirement> getConditionalRequirements() const;
1067+
1068+
/// Get the declaration context that contains the nominal type declaration.
1069+
DeclContext *getDeclContext() const {
1070+
return getProtocol();
1071+
}
1072+
1073+
/// Retrieve the state of this conformance.
1074+
ProtocolConformanceState getState() const {
1075+
return ProtocolConformanceState::Complete;
1076+
}
1077+
1078+
/// Get the kind of source from which this conformance comes.
1079+
ConformanceEntryKind getSourceKind() const {
1080+
return ConformanceEntryKind::Synthesized;
1081+
}
1082+
/// Get the protocol conformance which implied this implied conformance.
1083+
NormalProtocolConformance *getImplyingConformance() const {
1084+
return nullptr;
1085+
}
1086+
1087+
bool hasTypeWitness(AssociatedTypeDecl *assocType) const {
1088+
llvm_unreachable("builtin-conformances currently don't have associated \
1089+
types");
1090+
}
1091+
1092+
/// Retrieve the type witness and type decl (if one exists)
1093+
/// for the given associated type.
1094+
TypeWitnessAndDecl
1095+
getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
1096+
SubstOptions options=None) const {
1097+
llvm_unreachable("builtin-conformances currently don't have associated \
1098+
types");
1099+
}
1100+
1101+
/// Given that the requirement signature of the protocol directly states
1102+
/// that the given dependent type must conform to the given protocol,
1103+
/// return its associated conformance.
1104+
ProtocolConformanceRef
1105+
getAssociatedConformance(Type assocType, ProtocolDecl *protocol) const {
1106+
llvm_unreachable("builtin-conformances currently don't have associated \
1107+
types");
1108+
}
1109+
1110+
/// Retrieve the witness corresponding to the given value requirement.
1111+
ConcreteDeclRef getWitnessDeclRef(ValueDecl *requirement) const {
1112+
return ConcreteDeclRef(requirement);
1113+
}
1114+
1115+
/// Determine whether the witness for the given requirement
1116+
/// is either the default definition or was otherwise deduced.
1117+
bool usesDefaultDefinition(AssociatedTypeDecl *requirement) const {
1118+
llvm_unreachable("builtin-conformances currently don't have associated \
1119+
types");
1120+
}
1121+
1122+
static bool classof(const ProtocolConformance *conformance) {
1123+
return conformance->getKind() == ProtocolConformanceKind::Builtin;
1124+
}
1125+
};
1126+
10171127
inline bool ProtocolConformance::isInvalid() const {
10181128
return getRootConformance()->isInvalid();
10191129
}

0 commit comments

Comments
 (0)