@@ -502,9 +502,20 @@ struct TargetMethodDescriptor {
502502 MethodDescriptorFlags Flags;
503503
504504 // / The method implementation.
505- TargetRelativeDirectPointer<Runtime, void > Impl;
505+ union {
506+ TargetCompactFunctionPointer<Runtime, void > Impl;
507+ TargetRelativeDirectPointer<Runtime, void > AsyncImpl;
508+ };
506509
507510 // TODO: add method types or anything else needed for reflection.
511+
512+ void *getImpl () const {
513+ if (Flags.isAsync ()) {
514+ return AsyncImpl.get ();
515+ } else {
516+ return Impl.get ();
517+ }
518+ }
508519};
509520
510521using MethodDescriptor = TargetMethodDescriptor<InProcess>;
@@ -574,7 +585,20 @@ struct TargetMethodOverrideDescriptor {
574585 TargetRelativeMethodDescriptorPointer<Runtime> Method;
575586
576587 // / The implementation of the override.
577- TargetRelativeDirectPointer<Runtime, void , /* nullable*/ true > Impl;
588+ union {
589+ TargetCompactFunctionPointer<Runtime, void , /* nullable*/ true > Impl;
590+ TargetRelativeDirectPointer<Runtime, void , /* nullable*/ true > AsyncImpl;
591+ };
592+
593+ void *getImpl () const {
594+ auto *baseMethod = Method.get ();
595+ assert (baseMethod && " no base method" );
596+ if (baseMethod->Flags .isAsync ()) {
597+ return AsyncImpl.get ();
598+ } else {
599+ return Impl.get ();
600+ }
601+ }
578602};
579603
580604// / Header for a class vtable override descriptor. This is a variable-sized
@@ -1519,7 +1543,18 @@ struct TargetProtocolRequirement {
15191543 // TODO: name, type
15201544
15211545 // / The optional default implementation of the protocol.
1522- RelativeDirectPointer<void , /* nullable*/ true > DefaultImplementation;
1546+ union {
1547+ TargetCompactFunctionPointer<Runtime, void , /* nullable*/ true > DefaultFuncImplementation;
1548+ TargetRelativeDirectPointer<Runtime, void , /* nullable*/ true > DefaultImplementation;
1549+ };
1550+
1551+ void *getDefaultImplementation () const {
1552+ if (Flags.isFunctionImpl ()) {
1553+ return DefaultFuncImplementation.get ();
1554+ } else {
1555+ return DefaultImplementation.get ();
1556+ }
1557+ }
15231558};
15241559
15251560using ProtocolRequirement = TargetProtocolRequirement<InProcess>;
@@ -1808,7 +1843,18 @@ using GenericBoxHeapMetadata = TargetGenericBoxHeapMetadata<InProcess>;
18081843template <typename Runtime>
18091844struct TargetResilientWitness {
18101845 TargetRelativeProtocolRequirementPointer<Runtime> Requirement;
1811- RelativeDirectPointer<void > Witness;
1846+ union {
1847+ TargetRelativeDirectPointer<Runtime, void > Impl;
1848+ TargetCompactFunctionPointer<Runtime, void > FuncImpl;
1849+ };
1850+
1851+ void *getWitness (ProtocolRequirementFlags flags) const {
1852+ if (flags.isFunctionImpl ()) {
1853+ return FuncImpl.get ();
1854+ } else {
1855+ return Impl.get ();
1856+ }
1857+ }
18121858};
18131859using ResilientWitness = TargetResilientWitness<InProcess>;
18141860
@@ -1871,10 +1917,13 @@ struct TargetGenericWitnessTable {
18711917 uint16_t WitnessTablePrivateSizeInWordsAndRequiresInstantiation;
18721918
18731919 // / The instantiation function, which is called after the template is copied.
1874- RelativeDirectPointer<void (TargetWitnessTable<Runtime> *instantiatedTable,
1875- const TargetMetadata<Runtime> *type,
1876- const void * const *instantiationArgs),
1877- /* nullable*/ true > Instantiator;
1920+ TargetCompactFunctionPointer<
1921+ Runtime,
1922+ void (TargetWitnessTable<Runtime> *instantiatedTable,
1923+ const TargetMetadata<Runtime> *type,
1924+ const void *const *instantiationArgs),
1925+ /* nullable*/ true >
1926+ Instantiator;
18781927
18791928 using PrivateDataType = void *[swift::NumGenericMetadataPrivateDataWords];
18801929
@@ -2606,12 +2655,12 @@ using MetadataCompleter =
26062655template <typename Runtime>
26072656struct TargetGenericMetadataPattern {
26082657 // / The function to call to instantiate the template.
2609- TargetRelativeDirectPointer <Runtime, MetadataInstantiator>
2658+ TargetCompactFunctionPointer <Runtime, MetadataInstantiator>
26102659 InstantiationFunction;
26112660
26122661 // / The function to call to complete the instantiation. If this is null,
26132662 // / the instantiation function must always generate complete metadata.
2614- TargetRelativeDirectPointer <Runtime, MetadataCompleter, /* nullable*/ true >
2663+ TargetCompactFunctionPointer <Runtime, MetadataCompleter, /* nullable*/ true >
26152664 CompletionFunction;
26162665
26172666 // / Flags describing the layout of this instantiation pattern.
@@ -2718,10 +2767,10 @@ struct TargetGenericClassMetadataPattern final :
27182767 using TargetGenericMetadataPattern<Runtime>::PatternFlags;
27192768
27202769 // / The heap-destructor function.
2721- TargetRelativeDirectPointer <Runtime, HeapObjectDestroyer> Destroy;
2770+ TargetCompactFunctionPointer <Runtime, HeapObjectDestroyer> Destroy;
27222771
27232772 // / The ivar-destructor function.
2724- TargetRelativeDirectPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
2773+ TargetCompactFunctionPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
27252774 IVarDestroyer;
27262775
27272776 // / The class flags.
@@ -2922,7 +2971,7 @@ class MetadataAccessFunction {
29222971template <typename Runtime>
29232972struct TargetForeignMetadataInitialization {
29242973 // / The completion function. The pattern will always be null.
2925- TargetRelativeDirectPointer <Runtime, MetadataCompleter, /* nullable*/ true >
2974+ TargetCompactFunctionPointer <Runtime, MetadataCompleter, /* nullable*/ true >
29262975 CompletionFunction;
29272976};
29282977
@@ -2967,14 +3016,14 @@ struct TargetResilientClassMetadataPattern {
29673016 // /
29683017 // / If this is null, the runtime instead calls swift_relocateClassMetadata(),
29693018 // / passing in the class descriptor and this pattern.
2970- TargetRelativeDirectPointer <Runtime, MetadataRelocator, /* nullable*/ true >
3019+ TargetCompactFunctionPointer <Runtime, MetadataRelocator, /* nullable*/ true >
29713020 RelocationFunction;
29723021
29733022 // / The heap-destructor function.
2974- TargetRelativeDirectPointer <Runtime, HeapObjectDestroyer> Destroy;
3023+ TargetCompactFunctionPointer <Runtime, HeapObjectDestroyer> Destroy;
29753024
29763025 // / The ivar-destructor function.
2977- TargetRelativeDirectPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
3026+ TargetCompactFunctionPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
29783027 IVarDestroyer;
29793028
29803029 // / The class flags.
@@ -3018,7 +3067,7 @@ struct TargetSingletonMetadataInitialization {
30183067
30193068 // / The completion function. The pattern will always be null, even
30203069 // / for a resilient class.
3021- TargetRelativeDirectPointer <Runtime, MetadataCompleter>
3070+ TargetCompactFunctionPointer <Runtime, MetadataCompleter>
30223071 CompletionFunction;
30233072
30243073 bool hasResilientClassPattern (
@@ -3047,7 +3096,7 @@ struct TargetCanonicalSpecializedMetadatasListEntry {
30473096
30483097template <typename Runtime>
30493098struct TargetCanonicalSpecializedMetadataAccessorsListEntry {
3050- TargetRelativeDirectPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false > accessor;
3099+ TargetCompactFunctionPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false > accessor;
30513100};
30523101
30533102template <typename Runtime>
@@ -3067,7 +3116,7 @@ class TargetTypeContextDescriptor
30673116 // / The function type here is a stand-in. You should use getAccessFunction()
30683117 // / to wrap the function pointer in an accessor that uses the proper calling
30693118 // / convention for a given number of arguments.
3070- TargetRelativeDirectPointer <Runtime, MetadataResponse(...),
3119+ TargetCompactFunctionPointer <Runtime, MetadataResponse(...),
30713120 /* Nullable*/ true > AccessFunctionPtr;
30723121
30733122 // / A pointer to the field descriptor for the type, if any.
@@ -3332,7 +3381,7 @@ class TargetClassDescriptor final
33323381 using MetadataListEntry =
33333382 TargetCanonicalSpecializedMetadatasListEntry<Runtime>;
33343383 using MetadataAccessor =
3335- TargetRelativeDirectPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false >;
3384+ TargetCompactFunctionPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false >;
33363385 using MetadataAccessorListEntry =
33373386 TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>;
33383387 using MetadataCachingOnceToken =
@@ -4133,12 +4182,23 @@ class DynamicReplacementDescriptor {
41334182 DynamicReplacementKey *
41344183 __ptrauth_swift_dynamic_replacement_key>>
41354184 replacedFunctionKey;
4136- RelativeDirectPointer<void , false > replacementFunction;
4185+ union {
4186+ TargetCompactFunctionPointer<InProcess, void , false > replacementFunction;
4187+ TargetRelativeDirectPointer<InProcess, void , false > replacementAsyncFunction;
4188+ };
41374189 RelativeDirectPointer<DynamicReplacementChainEntry, false > chainEntry;
41384190 uint32_t flags;
41394191
41404192 enum : uint32_t { EnableChainingMask = 0x1 };
41414193
4194+ void *getReplacementFunction () const {
4195+ if (replacedFunctionKey->isAsync ()) {
4196+ return replacementAsyncFunction.get ();
4197+ } else {
4198+ return replacementFunction.get ();
4199+ }
4200+ }
4201+
41424202public:
41434203 // / Enable this replacement by changing the function's replacement chain's
41444204 // / root entry.
0 commit comments