@@ -502,9 +502,20 @@ struct TargetMethodDescriptor {
502
502
MethodDescriptorFlags Flags;
503
503
504
504
// / The method implementation.
505
- TargetRelativeDirectPointer<Runtime, void > Impl;
505
+ union {
506
+ TargetCompactFunctionPointer<Runtime, void > Impl;
507
+ TargetRelativeDirectPointer<Runtime, void > AsyncImpl;
508
+ };
506
509
507
510
// 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
+ }
508
519
};
509
520
510
521
using MethodDescriptor = TargetMethodDescriptor<InProcess>;
@@ -574,7 +585,20 @@ struct TargetMethodOverrideDescriptor {
574
585
TargetRelativeMethodDescriptorPointer<Runtime> Method;
575
586
576
587
// / 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
+ }
578
602
};
579
603
580
604
// / Header for a class vtable override descriptor. This is a variable-sized
@@ -1519,7 +1543,18 @@ struct TargetProtocolRequirement {
1519
1543
// TODO: name, type
1520
1544
1521
1545
// / 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
+ }
1523
1558
};
1524
1559
1525
1560
using ProtocolRequirement = TargetProtocolRequirement<InProcess>;
@@ -1808,7 +1843,18 @@ using GenericBoxHeapMetadata = TargetGenericBoxHeapMetadata<InProcess>;
1808
1843
template <typename Runtime>
1809
1844
struct TargetResilientWitness {
1810
1845
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
+ }
1812
1858
};
1813
1859
using ResilientWitness = TargetResilientWitness<InProcess>;
1814
1860
@@ -1871,10 +1917,13 @@ struct TargetGenericWitnessTable {
1871
1917
uint16_t WitnessTablePrivateSizeInWordsAndRequiresInstantiation;
1872
1918
1873
1919
// / 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;
1878
1927
1879
1928
using PrivateDataType = void *[swift::NumGenericMetadataPrivateDataWords];
1880
1929
@@ -2606,12 +2655,12 @@ using MetadataCompleter =
2606
2655
template <typename Runtime>
2607
2656
struct TargetGenericMetadataPattern {
2608
2657
// / The function to call to instantiate the template.
2609
- TargetRelativeDirectPointer <Runtime, MetadataInstantiator>
2658
+ TargetCompactFunctionPointer <Runtime, MetadataInstantiator>
2610
2659
InstantiationFunction;
2611
2660
2612
2661
// / The function to call to complete the instantiation. If this is null,
2613
2662
// / the instantiation function must always generate complete metadata.
2614
- TargetRelativeDirectPointer <Runtime, MetadataCompleter, /* nullable*/ true >
2663
+ TargetCompactFunctionPointer <Runtime, MetadataCompleter, /* nullable*/ true >
2615
2664
CompletionFunction;
2616
2665
2617
2666
// / Flags describing the layout of this instantiation pattern.
@@ -2718,10 +2767,10 @@ struct TargetGenericClassMetadataPattern final :
2718
2767
using TargetGenericMetadataPattern<Runtime>::PatternFlags;
2719
2768
2720
2769
// / The heap-destructor function.
2721
- TargetRelativeDirectPointer <Runtime, HeapObjectDestroyer> Destroy;
2770
+ TargetCompactFunctionPointer <Runtime, HeapObjectDestroyer> Destroy;
2722
2771
2723
2772
// / The ivar-destructor function.
2724
- TargetRelativeDirectPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
2773
+ TargetCompactFunctionPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
2725
2774
IVarDestroyer;
2726
2775
2727
2776
// / The class flags.
@@ -2922,7 +2971,7 @@ class MetadataAccessFunction {
2922
2971
template <typename Runtime>
2923
2972
struct TargetForeignMetadataInitialization {
2924
2973
// / The completion function. The pattern will always be null.
2925
- TargetRelativeDirectPointer <Runtime, MetadataCompleter, /* nullable*/ true >
2974
+ TargetCompactFunctionPointer <Runtime, MetadataCompleter, /* nullable*/ true >
2926
2975
CompletionFunction;
2927
2976
};
2928
2977
@@ -2967,14 +3016,14 @@ struct TargetResilientClassMetadataPattern {
2967
3016
// /
2968
3017
// / If this is null, the runtime instead calls swift_relocateClassMetadata(),
2969
3018
// / passing in the class descriptor and this pattern.
2970
- TargetRelativeDirectPointer <Runtime, MetadataRelocator, /* nullable*/ true >
3019
+ TargetCompactFunctionPointer <Runtime, MetadataRelocator, /* nullable*/ true >
2971
3020
RelocationFunction;
2972
3021
2973
3022
// / The heap-destructor function.
2974
- TargetRelativeDirectPointer <Runtime, HeapObjectDestroyer> Destroy;
3023
+ TargetCompactFunctionPointer <Runtime, HeapObjectDestroyer> Destroy;
2975
3024
2976
3025
// / The ivar-destructor function.
2977
- TargetRelativeDirectPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
3026
+ TargetCompactFunctionPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
2978
3027
IVarDestroyer;
2979
3028
2980
3029
// / The class flags.
@@ -3018,7 +3067,7 @@ struct TargetSingletonMetadataInitialization {
3018
3067
3019
3068
// / The completion function. The pattern will always be null, even
3020
3069
// / for a resilient class.
3021
- TargetRelativeDirectPointer <Runtime, MetadataCompleter>
3070
+ TargetCompactFunctionPointer <Runtime, MetadataCompleter>
3022
3071
CompletionFunction;
3023
3072
3024
3073
bool hasResilientClassPattern (
@@ -3047,7 +3096,7 @@ struct TargetCanonicalSpecializedMetadatasListEntry {
3047
3096
3048
3097
template <typename Runtime>
3049
3098
struct TargetCanonicalSpecializedMetadataAccessorsListEntry {
3050
- TargetRelativeDirectPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false > accessor;
3099
+ TargetCompactFunctionPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false > accessor;
3051
3100
};
3052
3101
3053
3102
template <typename Runtime>
@@ -3067,7 +3116,7 @@ class TargetTypeContextDescriptor
3067
3116
// / The function type here is a stand-in. You should use getAccessFunction()
3068
3117
// / to wrap the function pointer in an accessor that uses the proper calling
3069
3118
// / convention for a given number of arguments.
3070
- TargetRelativeDirectPointer <Runtime, MetadataResponse(...),
3119
+ TargetCompactFunctionPointer <Runtime, MetadataResponse(...),
3071
3120
/* Nullable*/ true > AccessFunctionPtr;
3072
3121
3073
3122
// / A pointer to the field descriptor for the type, if any.
@@ -3332,7 +3381,7 @@ class TargetClassDescriptor final
3332
3381
using MetadataListEntry =
3333
3382
TargetCanonicalSpecializedMetadatasListEntry<Runtime>;
3334
3383
using MetadataAccessor =
3335
- TargetRelativeDirectPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false >;
3384
+ TargetCompactFunctionPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false >;
3336
3385
using MetadataAccessorListEntry =
3337
3386
TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>;
3338
3387
using MetadataCachingOnceToken =
@@ -4133,12 +4182,23 @@ class DynamicReplacementDescriptor {
4133
4182
DynamicReplacementKey *
4134
4183
__ptrauth_swift_dynamic_replacement_key>>
4135
4184
replacedFunctionKey;
4136
- RelativeDirectPointer<void , false > replacementFunction;
4185
+ union {
4186
+ TargetCompactFunctionPointer<InProcess, void , false > replacementFunction;
4187
+ TargetRelativeDirectPointer<InProcess, void , false > replacementAsyncFunction;
4188
+ };
4137
4189
RelativeDirectPointer<DynamicReplacementChainEntry, false > chainEntry;
4138
4190
uint32_t flags;
4139
4191
4140
4192
enum : uint32_t { EnableChainingMask = 0x1 };
4141
4193
4194
+ void *getReplacementFunction () const {
4195
+ if (replacedFunctionKey->isAsync ()) {
4196
+ return replacementAsyncFunction.get ();
4197
+ } else {
4198
+ return replacementFunction.get ();
4199
+ }
4200
+ }
4201
+
4142
4202
public:
4143
4203
// / Enable this replacement by changing the function's replacement chain's
4144
4204
// / root entry.
0 commit comments