Skip to content

Commit 4b71d67

Browse files
committed
[ABI] Introduce MetadataKind TypeRef
1 parent f21a306 commit 4b71d67

File tree

6 files changed

+46
-7
lines changed

6 files changed

+46
-7
lines changed

include/swift/ABI/Metadata.h

Lines changed: 20 additions & 1 deletion
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
@@ -2325,6 +2325,7 @@ struct TargetTypeMetadataRecord {
23252325
// in the future) are just never used in these lists.
23262326
case TypeReferenceKind::DirectObjCClassName:
23272327
case TypeReferenceKind::IndirectObjCClass:
2328+
case TypeReferenceKind::MetadataKind:
23282329
return nullptr;
23292330
}
23302331

@@ -2415,6 +2416,9 @@ struct TargetTypeReference {
24152416
/// A direct reference to an Objective-C class name.
24162417
RelativeDirectPointer<const char>
24172418
DirectObjCClassName;
2419+
2420+
/// A "reference" to some metadata kind, e.g. tuple.
2421+
MetadataKind MetadataKind;
24182422
};
24192423

24202424
const TargetContextDescriptor<Runtime> *
@@ -2428,12 +2432,18 @@ struct TargetTypeReference {
24282432

24292433
case TypeReferenceKind::DirectObjCClassName:
24302434
case TypeReferenceKind::IndirectObjCClass:
2435+
case TypeReferenceKind::MetadataKind:
24312436
return nullptr;
24322437
}
24332438

24342439
return nullptr;
24352440
}
24362441

2442+
enum MetadataKind getMetadataKind(TypeReferenceKind kind) const {
2443+
assert(kind == TypeReferenceKind::MetadataKind);
2444+
return MetadataKind;
2445+
}
2446+
24372447
#if SWIFT_OBJC_INTEROP
24382448
/// If this type reference is one of the kinds that supports ObjC
24392449
/// references,
@@ -2519,6 +2529,10 @@ struct TargetProtocolConformanceDescriptor final
25192529
return Flags.getTypeReferenceKind();
25202530
}
25212531

2532+
enum MetadataKind getMetadataKind() const {
2533+
return TypeRef.getMetadataKind(getTypeKind());
2534+
}
2535+
25222536
const char *getDirectObjCClassName() const {
25232537
return TypeRef.getDirectObjCClassName(getTypeKind());
25242538
}
@@ -2546,6 +2560,11 @@ struct TargetProtocolConformanceDescriptor final
25462560
TargetRelativeContextPointer<Runtime>>();
25472561
}
25482562

2563+
/// Whether this conformance is builtin by the compiler + runtime.
2564+
bool isBuiltin() const {
2565+
return getTypeKind() == TypeReferenceKind::MetadataKind;
2566+
}
2567+
25492568
/// Whether this conformance is non-unique because it has been synthesized
25502569
/// for a foreign type.
25512570
bool isSynthesizedNonUnique() const {

include/swift/ABI/MetadataValues.h

Lines changed: 6 additions & 2 deletions
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
@@ -384,10 +384,14 @@ enum class TypeReferenceKind : unsigned {
384384
/// unused.
385385
IndirectObjCClass = 0x03,
386386

387+
/// The conformance is for a non-nominal type whose metadata kind we recorded;
388+
/// getMetadataKind() returns the kind.
389+
MetadataKind = 0x04,
390+
387391
// We only reserve three bits for this in the various places we store it.
388392

389393
First_Kind = DirectTypeDescriptor,
390-
Last_Kind = IndirectObjCClass,
394+
Last_Kind = MetadataKind,
391395
};
392396

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

include/swift/Remote/MetadataReader.h

Lines changed: 4 additions & 1 deletion
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
@@ -1414,6 +1414,9 @@ class MetadataReader {
14141414

14151415
return metadataFn(metadata);
14161416
}
1417+
case TypeReferenceKind::MetadataKind: {
1418+
return None;
1419+
}
14171420
}
14181421

14191422
return None;

stdlib/public/runtime/Metadata.cpp

Lines changed: 4 additions & 1 deletion
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
@@ -193,6 +193,9 @@ computeMetadataBoundsForSuperclass(const void *ref,
193193
break;
194194
#endif
195195
}
196+
// Type metadata type ref is unsupported here.
197+
case TypeReferenceKind::MetadataKind:
198+
break;
196199
}
197200
swift_unreachable("unsupported superclass reference kind");
198201
}

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 9 additions & 2 deletions
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
@@ -83,11 +83,14 @@ template<> void ProtocolConformanceDescriptor::dump() const {
8383
case TypeReferenceKind::IndirectTypeDescriptor:
8484
printf("unique nominal type descriptor %s", symbolName(getTypeDescriptor()));
8585
break;
86+
case TypeReferenceKind::MetadataKind:
87+
printf("metadata kind %i", getMetadataKind());
88+
break;
8689
}
8790

8891
printf(" => ");
8992

90-
printf("witness table %pattern s\n", symbolName(getWitnessTablePattern()));
93+
printf("witness table pattern %p\n", symbolName(getWitnessTablePattern()));
9194
}
9295
#endif
9396

@@ -113,6 +116,7 @@ const ClassMetadata *TypeReference::getObjCClass(TypeReferenceKind kind) const {
113116

114117
case TypeReferenceKind::DirectTypeDescriptor:
115118
case TypeReferenceKind::IndirectTypeDescriptor:
119+
case TypeReferenceKind::MetadataKind:
116120
return nullptr;
117121
}
118122

@@ -153,6 +157,9 @@ ProtocolConformanceDescriptor::getCanonicalTypeMetadata() const {
153157

154158
return nullptr;
155159
}
160+
case TypeReferenceKind::MetadataKind: {
161+
return nullptr;
162+
}
156163
}
157164

158165
swift_unreachable("Unhandled TypeReferenceKind in switch.");

stdlib/toolchain/Compatibility51/ProtocolConformance.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ override_getCanonicalTypeMetadata(const ProtocolConformanceDescriptor *conf) {
229229

230230
return nullptr;
231231
}
232+
case TypeReferenceKind::MetadataKind: {
233+
return nullptr;
234+
}
232235
}
233236

234237
swift_unreachable("Unhandled TypeReferenceKind in switch.");

0 commit comments

Comments
 (0)