@@ -506,9 +506,20 @@ struct TargetMethodDescriptor {
506
506
MethodDescriptorFlags Flags;
507
507
508
508
// / The method implementation.
509
- TargetRelativeDirectPointer<Runtime, void > Impl;
509
+ union {
510
+ TargetCompactFunctionPointer<Runtime, void > Impl;
511
+ TargetRelativeDirectPointer<Runtime, void > AsyncImpl;
512
+ };
510
513
511
514
// 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
+ }
512
523
};
513
524
514
525
using MethodDescriptor = TargetMethodDescriptor<InProcess>;
@@ -578,7 +589,20 @@ struct TargetMethodOverrideDescriptor {
578
589
TargetRelativeMethodDescriptorPointer<Runtime> Method;
579
590
580
591
// / 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
+ }
582
606
};
583
607
584
608
// / Header for a class vtable override descriptor. This is a variable-sized
@@ -1523,7 +1547,18 @@ struct TargetProtocolRequirement {
1523
1547
// TODO: name, type
1524
1548
1525
1549
// / 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
+ }
1527
1562
};
1528
1563
1529
1564
using ProtocolRequirement = TargetProtocolRequirement<InProcess>;
@@ -2170,7 +2205,18 @@ using GenericBoxHeapMetadata = TargetGenericBoxHeapMetadata<InProcess>;
2170
2205
template <typename Runtime>
2171
2206
struct TargetResilientWitness {
2172
2207
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
+ }
2174
2220
};
2175
2221
using ResilientWitness = TargetResilientWitness<InProcess>;
2176
2222
@@ -2233,10 +2279,13 @@ struct TargetGenericWitnessTable {
2233
2279
uint16_t WitnessTablePrivateSizeInWordsAndRequiresInstantiation;
2234
2280
2235
2281
// / 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;
2240
2289
2241
2290
using PrivateDataType = void *[swift::NumGenericMetadataPrivateDataWords];
2242
2291
@@ -2968,12 +3017,12 @@ using MetadataCompleter =
2968
3017
template <typename Runtime>
2969
3018
struct TargetGenericMetadataPattern {
2970
3019
// / The function to call to instantiate the template.
2971
- TargetRelativeDirectPointer <Runtime, MetadataInstantiator>
3020
+ TargetCompactFunctionPointer <Runtime, MetadataInstantiator>
2972
3021
InstantiationFunction;
2973
3022
2974
3023
// / The function to call to complete the instantiation. If this is null,
2975
3024
// / the instantiation function must always generate complete metadata.
2976
- TargetRelativeDirectPointer <Runtime, MetadataCompleter, /* nullable*/ true >
3025
+ TargetCompactFunctionPointer <Runtime, MetadataCompleter, /* nullable*/ true >
2977
3026
CompletionFunction;
2978
3027
2979
3028
// / Flags describing the layout of this instantiation pattern.
@@ -3080,10 +3129,10 @@ struct TargetGenericClassMetadataPattern final :
3080
3129
using TargetGenericMetadataPattern<Runtime>::PatternFlags;
3081
3130
3082
3131
// / The heap-destructor function.
3083
- TargetRelativeDirectPointer <Runtime, HeapObjectDestroyer> Destroy;
3132
+ TargetCompactFunctionPointer <Runtime, HeapObjectDestroyer> Destroy;
3084
3133
3085
3134
// / The ivar-destructor function.
3086
- TargetRelativeDirectPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
3135
+ TargetCompactFunctionPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
3087
3136
IVarDestroyer;
3088
3137
3089
3138
// / The class flags.
@@ -3284,7 +3333,7 @@ class MetadataAccessFunction {
3284
3333
template <typename Runtime>
3285
3334
struct TargetForeignMetadataInitialization {
3286
3335
// / The completion function. The pattern will always be null.
3287
- TargetRelativeDirectPointer <Runtime, MetadataCompleter, /* nullable*/ true >
3336
+ TargetCompactFunctionPointer <Runtime, MetadataCompleter, /* nullable*/ true >
3288
3337
CompletionFunction;
3289
3338
};
3290
3339
@@ -3329,14 +3378,14 @@ struct TargetResilientClassMetadataPattern {
3329
3378
// /
3330
3379
// / If this is null, the runtime instead calls swift_relocateClassMetadata(),
3331
3380
// / passing in the class descriptor and this pattern.
3332
- TargetRelativeDirectPointer <Runtime, MetadataRelocator, /* nullable*/ true >
3381
+ TargetCompactFunctionPointer <Runtime, MetadataRelocator, /* nullable*/ true >
3333
3382
RelocationFunction;
3334
3383
3335
3384
// / The heap-destructor function.
3336
- TargetRelativeDirectPointer <Runtime, HeapObjectDestroyer> Destroy;
3385
+ TargetCompactFunctionPointer <Runtime, HeapObjectDestroyer> Destroy;
3337
3386
3338
3387
// / The ivar-destructor function.
3339
- TargetRelativeDirectPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
3388
+ TargetCompactFunctionPointer <Runtime, ClassIVarDestroyer, /* nullable*/ true >
3340
3389
IVarDestroyer;
3341
3390
3342
3391
// / The class flags.
@@ -3380,7 +3429,7 @@ struct TargetSingletonMetadataInitialization {
3380
3429
3381
3430
// / The completion function. The pattern will always be null, even
3382
3431
// / for a resilient class.
3383
- TargetRelativeDirectPointer <Runtime, MetadataCompleter>
3432
+ TargetCompactFunctionPointer <Runtime, MetadataCompleter>
3384
3433
CompletionFunction;
3385
3434
3386
3435
bool hasResilientClassPattern (
@@ -3409,7 +3458,7 @@ struct TargetCanonicalSpecializedMetadatasListEntry {
3409
3458
3410
3459
template <typename Runtime>
3411
3460
struct TargetCanonicalSpecializedMetadataAccessorsListEntry {
3412
- TargetRelativeDirectPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false > accessor;
3461
+ TargetCompactFunctionPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false > accessor;
3413
3462
};
3414
3463
3415
3464
template <typename Runtime>
@@ -3429,7 +3478,7 @@ class TargetTypeContextDescriptor
3429
3478
// / The function type here is a stand-in. You should use getAccessFunction()
3430
3479
// / to wrap the function pointer in an accessor that uses the proper calling
3431
3480
// / convention for a given number of arguments.
3432
- TargetRelativeDirectPointer <Runtime, MetadataResponse(...),
3481
+ TargetCompactFunctionPointer <Runtime, MetadataResponse(...),
3433
3482
/* Nullable*/ true > AccessFunctionPtr;
3434
3483
3435
3484
// / A pointer to the field descriptor for the type, if any.
@@ -3694,7 +3743,7 @@ class TargetClassDescriptor final
3694
3743
using MetadataListEntry =
3695
3744
TargetCanonicalSpecializedMetadatasListEntry<Runtime>;
3696
3745
using MetadataAccessor =
3697
- TargetRelativeDirectPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false >;
3746
+ TargetCompactFunctionPointer <Runtime, MetadataResponse(MetadataRequest), /* Nullable*/ false >;
3698
3747
using MetadataAccessorListEntry =
3699
3748
TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>;
3700
3749
using MetadataCachingOnceToken =
@@ -4495,12 +4544,23 @@ class DynamicReplacementDescriptor {
4495
4544
DynamicReplacementKey *
4496
4545
__ptrauth_swift_dynamic_replacement_key>>
4497
4546
replacedFunctionKey;
4498
- RelativeDirectPointer<void , false > replacementFunction;
4547
+ union {
4548
+ TargetCompactFunctionPointer<InProcess, void , false > replacementFunction;
4549
+ TargetRelativeDirectPointer<InProcess, void , false > replacementAsyncFunction;
4550
+ };
4499
4551
RelativeDirectPointer<DynamicReplacementChainEntry, false > chainEntry;
4500
4552
uint32_t flags;
4501
4553
4502
4554
enum : uint32_t { EnableChainingMask = 0x1 };
4503
4555
4556
+ void *getReplacementFunction () const {
4557
+ if (replacedFunctionKey->isAsync ()) {
4558
+ return replacementAsyncFunction.get ();
4559
+ } else {
4560
+ return replacementFunction.get ();
4561
+ }
4562
+ }
4563
+
4504
4564
public:
4505
4565
// / Enable this replacement by changing the function's replacement chain's
4506
4566
// / root entry.
0 commit comments