Skip to content

Commit 6385934

Browse files
committed
Metadata emission for extended existential type shapes
1 parent f7290c9 commit 6385934

File tree

11 files changed

+705
-97
lines changed

11 files changed

+705
-97
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ class ExtendedExistentialTypeShapeFlags {
865865
(Data & ~SpecialKindMask) | (int_type(kind) << SpecialKindShift));
866866
}
867867
constexpr ExtendedExistentialTypeShapeFlags
868-
withHasTypeExpresssion(bool hasTypeExpression) const {
868+
withHasTypeExpression(bool hasTypeExpression) const {
869869
return ExtendedExistentialTypeShapeFlags(
870870
hasTypeExpression ? (Data | HasTypeExpression)
871871
: (Data & ~HasTypeExpression));

include/swift/AST/IRGenOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ struct PointerAuthOptions : clang::PointerAuthOptions {
189189

190190
/// The swift async context entry in the extended frame info.
191191
PointerAuthSchema AsyncContextExtendedFrameEntry;
192+
193+
/// Extended existential type shapes in flight.
194+
PointerAuthSchema ExtendedExistentialTypeShape;
195+
196+
/// Non-unique extended existential type shapes in flight.
197+
PointerAuthSchema NonUniqueExtendedExistentialTypeShape;
192198
};
193199

194200
enum class JITDebugArtifact : unsigned {

include/swift/IRGen/Linking.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ class LinkEntity {
119119
// This field appears in SILFunction.
120120
IsDynamicallyReplaceableImplShift = 8,
121121
IsDynamicallyReplaceableImplMask = ~KindMask,
122+
123+
// These fields appear in ExtendedExistentialTypeShape.
124+
ExtendedExistentialIsUniqueShift = 8,
125+
ExtendedExistentialIsUniqueMask = 0x100,
126+
ExtendedExistentialIsSharedShift = 9,
127+
ExtendedExistentialIsSharedMask = 0x200,
128+
ExtendedExistentialMetatypeDepthShift = 10,
129+
ExtendedExistentialMetatypeDepthMask =
130+
~(KindMask | ExtendedExistentialIsUniqueMask |
131+
ExtendedExistentialIsSharedMask),
122132
};
123133
#define LINKENTITY_SET_FIELD(field, value) (value << field##Shift)
124134
#define LINKENTITY_GET_FIELD(value, field) ((value & field##Mask) >> field##Shift)
@@ -493,6 +503,11 @@ class LinkEntity {
493503
/// Accessible function record, which describes a function that can be
494504
/// looked up by name by the runtime.
495505
AccessibleFunctionRecord,
506+
507+
/// Extended existential type shape.
508+
/// Pointer is the (generalized) existential type.
509+
/// SecondaryPointer is the GenericSignatureImpl*.
510+
ExtendedExistentialTypeShape,
496511
};
497512
friend struct llvm::DenseMapInfo<LinkEntity>;
498513

@@ -1352,6 +1367,24 @@ class LinkEntity {
13521367
return entity;
13531368
}
13541369

1370+
static LinkEntity forExtendedExistentialTypeShape(CanGenericSignature genSig,
1371+
CanExistentialType
1372+
existentialType,
1373+
unsigned metatypeDepth,
1374+
bool isUnique,
1375+
bool isShared) {
1376+
LinkEntity entity;
1377+
entity.Pointer = existentialType.getPointer();
1378+
entity.SecondaryPointer =
1379+
const_cast<GenericSignatureImpl*>(genSig.getPointer());
1380+
entity.Data =
1381+
LINKENTITY_SET_FIELD(Kind, unsigned(Kind::ExtendedExistentialTypeShape))
1382+
| LINKENTITY_SET_FIELD(ExtendedExistentialIsUnique, unsigned(isUnique))
1383+
| LINKENTITY_SET_FIELD(ExtendedExistentialIsShared, unsigned(isShared))
1384+
| LINKENTITY_SET_FIELD(ExtendedExistentialMetatypeDepth, metatypeDepth);
1385+
return entity;
1386+
}
1387+
13551388
void mangle(llvm::raw_ostream &out) const;
13561389
void mangle(SmallVectorImpl<char> &buffer) const;
13571390
std::string mangleAsString() const;
@@ -1445,6 +1478,32 @@ class LinkEntity {
14451478
SecondaryPointer);
14461479
}
14471480

1481+
CanGenericSignature getExtendedExistentialTypeShapeGenSig() const {
1482+
assert(getKind() == Kind::ExtendedExistentialTypeShape);
1483+
return CanGenericSignature(
1484+
reinterpret_cast<const GenericSignatureImpl*>(SecondaryPointer));
1485+
}
1486+
1487+
CanExistentialType getExtendedExistentialTypeShapeType() const {
1488+
assert(getKind() == Kind::ExtendedExistentialTypeShape);
1489+
return cast<ExistentialType>(CanType(reinterpret_cast<TypeBase*>(Pointer)));
1490+
}
1491+
1492+
bool isExtendedExistentialTypeShapeUnique() const {
1493+
assert(getKind() == Kind::ExtendedExistentialTypeShape);
1494+
return LINKENTITY_GET_FIELD(Data, ExtendedExistentialIsUnique);
1495+
}
1496+
1497+
bool isExtendedExistentialTypeShapeShared() const {
1498+
assert(getKind() == Kind::ExtendedExistentialTypeShape);
1499+
return LINKENTITY_GET_FIELD(Data, ExtendedExistentialIsShared);
1500+
}
1501+
1502+
unsigned getExtendedExistentialTypeShapeMetatypeDepth() const {
1503+
assert(getKind() == Kind::ExtendedExistentialTypeShape);
1504+
return LINKENTITY_GET_FIELD(Data, ExtendedExistentialMetatypeDepth);
1505+
}
1506+
14481507
bool isDynamicallyReplaceable() const {
14491508
assert(getKind() == Kind::SILFunction);
14501509
return LINKENTITY_GET_FIELD(Data, IsDynamicallyReplaceableImpl);

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,36 @@ FUNCTION(GetExistentialMetadata,
10761076
ATTRS(NoUnwind, ReadOnly, WillReturn),
10771077
EFFECT(MetaData)) // ?
10781078

1079+
// const ExtendedExistentialTypeShape *
1080+
// swift_getExtendedExistentialTypeShape(
1081+
// const NonUniqueExtendedExistentialTypeShape *nonUnique);
1082+
FUNCTION(GetExtendedExistentialTypeShape,
1083+
swift_getExtendedExistentialTypeShape, C_CC, AlwaysAvailable,
1084+
RETURNS(TypeMetadataPtrTy),
1085+
ARGS(Int8PtrTy, Int8PtrPtrTy),
1086+
ATTRS(NoUnwind, ArgMemOnly, WillReturn),
1087+
EFFECT(MetaData)) // ?
1088+
1089+
// Metadata *swift_getExtendedExistentialTypeMetadata(
1090+
// const NonUniqueExtendedExistentialTypeShape *shape,
1091+
// const void * const *generalizationArgs);
1092+
FUNCTION(GetExtendedExistentialTypeMetadata,
1093+
swift_getExtendedExistentialTypeMetadata, C_CC, AlwaysAvailable,
1094+
RETURNS(TypeMetadataPtrTy),
1095+
ARGS(Int8PtrTy, Int8PtrPtrTy),
1096+
ATTRS(NoUnwind, ArgMemOnly, WillReturn),
1097+
EFFECT(MetaData)) // ?
1098+
1099+
// Metadata *swift_getExtendedExistentialTypeMetadata_unique(
1100+
// const ExtendedExistentialTypeShape *shape,
1101+
// const void * const *generalizationArgs);
1102+
FUNCTION(GetExtendedExistentialTypeMetadataUnique,
1103+
swift_getExtendedExistentialTypeMetadata_unique, C_CC, AlwaysAvailable,
1104+
RETURNS(TypeMetadataPtrTy),
1105+
ARGS(Int8PtrTy, Int8PtrPtrTy),
1106+
ATTRS(NoUnwind, ArgMemOnly, WillReturn),
1107+
EFFECT(MetaData)) // ?
1108+
10791109
// Metadata *swift_relocateClassMetadata(TypeContextDescriptor *descriptor,
10801110
// const void *pattern);
10811111
FUNCTION(RelocateClassMetadata,

0 commit comments

Comments
 (0)