@@ -506,9 +506,20 @@ struct TargetMethodDescriptor {
506506 MethodDescriptorFlags Flags;
507507
508508 // / The method implementation.
509- TargetRelativeDirectPointer<Runtime, void > Impl;
509+ union {
510+ TargetCompactFunctionPointer<Runtime, void > Impl;
511+ TargetRelativeDirectPointer<Runtime, void > AsyncImpl;
512+ };
510513
511514 // TODO: add method types or anything else needed for reflection.
515+
516+ void *getImpl () const {
517+ if (Flags.isAsync ()) {
518+ return AsyncImpl.get ();
519+ } else {
520+ return Impl.get ();
521+ }
522+ }
512523};
513524
514525using MethodDescriptor = TargetMethodDescriptor<InProcess>;
@@ -578,7 +589,20 @@ struct TargetMethodOverrideDescriptor {
578589 TargetRelativeMethodDescriptorPointer<Runtime> Method;
579590
580591 // / The implementation of the override.
581- TargetRelativeDirectPointer<Runtime, void , /* nullable*/ true > Impl;
592+ union {
593+ TargetCompactFunctionPointer<Runtime, void , /* nullable*/ true > Impl;
594+ TargetRelativeDirectPointer<Runtime, void , /* nullable*/ true > AsyncImpl;
595+ };
596+
597+ void *getImpl () const {
598+ auto *baseMethod = Method.get ();
599+ assert (baseMethod && " no base method" );
600+ if (baseMethod->Flags .isAsync ()) {
601+ return AsyncImpl.get ();
602+ } else {
603+ return Impl.get ();
604+ }
605+ }
582606};
583607
584608// / Header for a class vtable override descriptor. This is a variable-sized
@@ -1523,7 +1547,18 @@ struct TargetProtocolRequirement {
15231547 // TODO: name, type
15241548
15251549 // / The optional default implementation of the protocol.
1526- RelativeDirectPointer<void , /* nullable*/ true > DefaultImplementation;
1550+ union {
1551+ TargetCompactFunctionPointer<Runtime, void , /* nullable*/ true > DefaultFuncImplementation;
1552+ TargetRelativeDirectPointer<Runtime, void , /* nullable*/ true > DefaultImplementation;
1553+ };
1554+
1555+ void *getDefaultImplementation () const {
1556+ if (Flags.isFunctionImpl ()) {
1557+ return DefaultFuncImplementation.get ();
1558+ } else {
1559+ return DefaultImplementation.get ();
1560+ }
1561+ }
15271562};
15281563
15291564using ProtocolRequirement = TargetProtocolRequirement<InProcess>;
@@ -2170,7 +2205,18 @@ using GenericBoxHeapMetadata = TargetGenericBoxHeapMetadata<InProcess>;
21702205template <typename Runtime>
21712206struct TargetResilientWitness {
21722207 TargetRelativeProtocolRequirementPointer<Runtime> Requirement;
2173- RelativeDirectPointer<void > Witness;
2208+ union {
2209+ TargetRelativeDirectPointer<Runtime, void > Impl;
2210+ TargetCompactFunctionPointer<Runtime, void > FuncImpl;
2211+ };
2212+
2213+ void *getWitness (ProtocolRequirementFlags flags) const {
2214+ if (flags.isFunctionImpl ()) {
2215+ return FuncImpl.get ();
2216+ } else {
2217+ return Impl.get ();
2218+ }
2219+ }
21742220};
21752221using ResilientWitness = TargetResilientWitness<InProcess>;
21762222
@@ -2233,10 +2279,13 @@ struct TargetGenericWitnessTable {
22332279 uint16_t WitnessTablePrivateSizeInWordsAndRequiresInstantiation;
22342280
22352281 // / The instantiation function, which is called after the template is copied.
2236- RelativeDirectPointer<void (TargetWitnessTable<Runtime> *instantiatedTable,
2237- const TargetMetadata<Runtime> *type,
2238- const void * const *instantiationArgs),
2239- /* nullable*/ true > Instantiator;
2282+ TargetCompactFunctionPointer<
2283+ Runtime,
2284+ void (TargetWitnessTable<Runtime> *instantiatedTable,
2285+ const TargetMetadata<Runtime> *type,
2286+ const void *const *instantiationArgs),
2287+ /* nullable*/ true >
2288+ Instantiator;
22402289
22412290 using PrivateDataType = void *[swift::NumGenericMetadataPrivateDataWords];
22422291
@@ -2968,12 +3017,12 @@ using MetadataCompleter =
29683017template <typename Runtime>
29693018struct TargetGenericMetadataPattern {
29703019 // / The function to call to instantiate the template.
2971- TargetRelativeDirectPointer <Runtime, MetadataInstantiator>
3020+ TargetCompactFunctionPointer <Runtime, MetadataInstantiator>
29723021 InstantiationFunction;
29733022
29743023 // / The function to call to complete the instantiation. If this is null,
29753024 // / the instantiation function must always generate complete metadata.
2976- TargetRelativeDirectPointer <Runtime, MetadataCompleter, /* nullable*/ true >
3025+ TargetCompactFunctionPointer <Runtime, MetadataCompleter, /* nullable*/ true >
29773026 CompletionFunction;
29783027
29793028 // / Flags describing the layout of this instantiation pattern.
@@ -3080,10 +3129,10 @@ struct TargetGenericClassMetadataPattern final :
30803129 using TargetGenericMetadataPattern<Runtime>::PatternFlags;
30813130
30823131 // / The heap-destructor function.
3083- TargetRelativeDirectPointer <Runtime, HeapObjectDestroyer> Destroy;
3132+ TargetCompactFunctionPointer <Runtime, HeapObjectDestroyer> Destroy;
30843133
30853134 // / The ivar-destructor function.
3086- TargetRelativeDirectPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
3135+ TargetCompactFunctionPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
30873136 IVarDestroyer;
30883137
30893138 // / The class flags.
@@ -3284,7 +3333,7 @@ class MetadataAccessFunction {
32843333template <typename Runtime>
32853334struct TargetForeignMetadataInitialization {
32863335 // / The completion function. The pattern will always be null.
3287- TargetRelativeDirectPointer <Runtime, MetadataCompleter, /* nullable*/ true >
3336+ TargetCompactFunctionPointer <Runtime, MetadataCompleter, /* nullable*/ true >
32883337 CompletionFunction;
32893338};
32903339
@@ -3329,14 +3378,14 @@ struct TargetResilientClassMetadataPattern {
33293378 // /
33303379 // / If this is null, the runtime instead calls swift_relocateClassMetadata(),
33313380 // / passing in the class descriptor and this pattern.
3332- TargetRelativeDirectPointer <Runtime, MetadataRelocator, /* nullable*/ true >
3381+ TargetCompactFunctionPointer <Runtime, MetadataRelocator, /* nullable*/ true >
33333382 RelocationFunction;
33343383
33353384 // / The heap-destructor function.
3336- TargetRelativeDirectPointer <Runtime, HeapObjectDestroyer> Destroy;
3385+ TargetCompactFunctionPointer <Runtime, HeapObjectDestroyer> Destroy;
33373386
33383387 // / The ivar-destructor function.
3339- TargetRelativeDirectPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
3388+ TargetCompactFunctionPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
33403389 IVarDestroyer;
33413390
33423391 // / The class flags.
@@ -3380,7 +3429,7 @@ struct TargetSingletonMetadataInitialization {
33803429
33813430 // / The completion function. The pattern will always be null, even
33823431 // / for a resilient class.
3383- TargetRelativeDirectPointer <Runtime, MetadataCompleter>
3432+ TargetCompactFunctionPointer <Runtime, MetadataCompleter>
33843433 CompletionFunction;
33853434
33863435 bool hasResilientClassPattern (
@@ -3409,7 +3458,7 @@ struct TargetCanonicalSpecializedMetadatasListEntry {
34093458
34103459template <typename Runtime>
34113460struct TargetCanonicalSpecializedMetadataAccessorsListEntry {
3412- TargetRelativeDirectPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false > accessor;
3461+ TargetCompactFunctionPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false > accessor;
34133462};
34143463
34153464template <typename Runtime>
@@ -3429,7 +3478,7 @@ class TargetTypeContextDescriptor
34293478 // / The function type here is a stand-in. You should use getAccessFunction()
34303479 // / to wrap the function pointer in an accessor that uses the proper calling
34313480 // / convention for a given number of arguments.
3432- TargetRelativeDirectPointer <Runtime, MetadataResponse(...),
3481+ TargetCompactFunctionPointer <Runtime, MetadataResponse(...),
34333482 /* Nullable*/ true > AccessFunctionPtr;
34343483
34353484 // / A pointer to the field descriptor for the type, if any.
@@ -3694,7 +3743,7 @@ class TargetClassDescriptor final
36943743 using MetadataListEntry =
36953744 TargetCanonicalSpecializedMetadatasListEntry<Runtime>;
36963745 using MetadataAccessor =
3697- TargetRelativeDirectPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false >;
3746+ TargetCompactFunctionPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false >;
36983747 using MetadataAccessorListEntry =
36993748 TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>;
37003749 using MetadataCachingOnceToken =
@@ -4495,12 +4544,23 @@ class DynamicReplacementDescriptor {
44954544 DynamicReplacementKey *
44964545 __ptrauth_swift_dynamic_replacement_key>>
44974546 replacedFunctionKey;
4498- RelativeDirectPointer<void , false > replacementFunction;
4547+ union {
4548+ TargetCompactFunctionPointer<InProcess, void , false > replacementFunction;
4549+ TargetRelativeDirectPointer<InProcess, void , false > replacementAsyncFunction;
4550+ };
44994551 RelativeDirectPointer<DynamicReplacementChainEntry, false > chainEntry;
45004552 uint32_t flags;
45014553
45024554 enum : uint32_t { EnableChainingMask = 0x1 };
45034555
4556+ void *getReplacementFunction () const {
4557+ if (replacedFunctionKey->isAsync ()) {
4558+ return replacementAsyncFunction.get ();
4559+ } else {
4560+ return replacementFunction.get ();
4561+ }
4562+ }
4563+
45044564public:
45054565 // / Enable this replacement by changing the function's replacement chain's
45064566 // / root entry.
0 commit comments