@@ -189,6 +189,31 @@ class WeakReference;
189
189
template <typename Runtime> struct TargetMetadata ;
190
190
using Metadata = TargetMetadata<InProcess>;
191
191
192
+ // / The result of requesting type metadata. Generally the return value of
193
+ // / a function.
194
+ // /
195
+ // / For performance, functions returning this type should use SWIFT_CC so
196
+ // / that the components are returned as separate values.
197
+ struct MetadataResponse {
198
+ // / For metadata access functions, this is the requested metadata.
199
+ // /
200
+ // / For metadata initialization functions, this is either null,
201
+ // / indicating that initialization was successful, or a metadata on
202
+ // / which initialization depends for further progress.
203
+ const Metadata *Value;
204
+
205
+ // / For metadata access functions, this is the current state of the
206
+ // / metadata returned. Always use this instead of trying to inspect
207
+ // / the metadata directly; an incomplete metadata may be getting
208
+ // / initialized concurrently. This can generally be ignored if the
209
+ // / metadata request was for abstract metadata or if the request is
210
+ // / blocking.
211
+ // /
212
+ // / For metadata initialization functions, this is the state that the
213
+ // / given metadata needs to be in before initialization can continue.
214
+ MetadataRequest::BasicKind State;
215
+ };
216
+
192
217
template <typename Runtime> struct TargetProtocolConformanceDescriptor ;
193
218
194
219
// / Storage for an arbitrary value. In C/C++ terms, this is an
@@ -1983,6 +2008,16 @@ using TargetWitnessTablePointer =
1983
2008
1984
2009
using WitnessTablePointer = TargetWitnessTablePointer<InProcess>;
1985
2010
2011
+ using AssociatedTypeAccessFunction =
2012
+ SWIFT_CC (swift) MetadataResponse(MetadataRequest request,
2013
+ const Metadata *self,
2014
+ const WitnessTable *selfConformance);
2015
+
2016
+ using AssociatedWitnessTableAccessFunction =
2017
+ SWIFT_CC (swift) WitnessTable *(const Metadata *associatedType,
2018
+ const Metadata *self,
2019
+ const WitnessTable *selfConformance);
2020
+
1986
2021
// / The possible physical representations of existential types.
1987
2022
enum class ExistentialTypeRepresentation {
1988
2023
// / The type uses an opaque existential representation.
@@ -3008,9 +3043,10 @@ struct MetadataCompletionContext {
3008
3043
// / pointer to indicate that completion is blocked on the completion of
3009
3044
// / some other type
3010
3045
using MetadataCompleter =
3011
- Metadata *(const Metadata *type,
3012
- MetadataCompletionContext *context,
3013
- const TargetGenericMetadataPattern<InProcess> *pattern);
3046
+ SWIFT_CC (swift)
3047
+ MetadataResponse(const Metadata *type,
3048
+ MetadataCompletionContext *context,
3049
+ const TargetGenericMetadataPattern<InProcess> *pattern);
3014
3050
3015
3051
// / An instantiation pattern for type metadata.
3016
3052
template <typename Runtime>
@@ -3229,98 +3265,92 @@ using TypeGenericContextDescriptorHeader =
3229
3265
// / Wrapper class for the pointer to a metadata access function that provides
3230
3266
// / operator() overloads to call it with the right calling convention.
3231
3267
class MetadataAccessFunction {
3232
- const Metadata * (*Function)(...);
3268
+ MetadataResponse (*Function)(...);
3233
3269
3234
3270
static_assert (NumDirectGenericTypeMetadataAccessFunctionArgs == 3 ,
3235
3271
" Need to account for change in number of direct arguments" );
3236
3272
3237
- template <typename T>
3238
- const Metadata *applyN (const void *arg0,
3239
- const void *arg1,
3240
- const void *arg2,
3241
- llvm::ArrayRef<T *> argRest) const {
3242
- using FnN = const Metadata *(const void *,
3243
- const void *,
3244
- const void *,
3245
- const void *);
3246
- return reinterpret_cast <FnN*>(Function)(arg0, arg1, arg2, argRest.data ());
3247
- }
3248
-
3249
- template <typename ...Args>
3250
- const Metadata *variadic_apply (const void *arg0,
3251
- const void *arg1,
3252
- const void *arg2,
3253
- llvm::MutableArrayRef<const void *> argRest,
3254
- unsigned n,
3255
- const void *arg3,
3256
- Args...argN) const {
3257
- argRest[n] = arg3;
3258
- return variadic_apply (arg0, arg1, arg2, argRest, n+1 , argN...);
3259
- }
3260
-
3261
- const Metadata *variadic_apply (const void *arg0,
3262
- const void *arg1,
3263
- const void *arg2,
3264
- llvm::MutableArrayRef<const void *> argRest,
3265
- unsigned n) const {
3266
- return applyN (arg0, arg1, arg2, argRest);
3267
- }
3268
-
3269
3273
public:
3270
- explicit MetadataAccessFunction (const Metadata * (*Function)(...))
3274
+ explicit MetadataAccessFunction (MetadataResponse (*Function)(...))
3271
3275
: Function(Function)
3272
3276
{}
3273
3277
3274
3278
explicit operator bool () const {
3275
3279
return Function != nullptr ;
3276
3280
}
3277
3281
3278
- // Invoke with an array of arguments.
3279
- template < typename T>
3280
- const Metadata * operator ()( llvm::ArrayRef<T *> args) const {
3282
+ // / Invoke with an array of arguments of dynamic size .
3283
+ MetadataResponse operator ()(MetadataRequest request,
3284
+ llvm::ArrayRef<const void *> args) const {
3281
3285
switch (args.size ()) {
3282
3286
case 0 :
3283
- return (* this )( );
3287
+ return operator ()(request );
3284
3288
case 1 :
3285
- return (* this )( args[0 ]);
3289
+ return operator ()(request, args[0 ]);
3286
3290
case 2 :
3287
- return (* this )( args[0 ], args[1 ]);
3291
+ return operator ()(request, args[0 ], args[1 ]);
3288
3292
case 3 :
3289
- return (* this )( args[0 ], args[1 ], args[2 ]);
3293
+ return operator ()(request, args[0 ], args[1 ], args[2 ]);
3290
3294
default :
3291
- return applyN (args[ 0 ] , args[ 1 ], args[ 2 ], args );
3295
+ return applyMany (request , args. data () );
3292
3296
}
3293
3297
}
3294
3298
3295
- // Invoke with n arguments.
3296
- const Metadata *operator ()() const {
3297
- using Fn0 = const Metadata *();
3298
- return reinterpret_cast <Fn0*>(Function)();
3299
- }
3300
- const Metadata *operator ()(const void *arg0) const {
3301
- using Fn1 = const Metadata *(const void *);
3302
- return reinterpret_cast <Fn1*>(Function)(arg0);
3303
-
3304
- }
3305
- const Metadata *operator ()(const void *arg0,
3306
- const void *arg1) const {
3307
- using Fn2 = const Metadata *(const void *, const void *);
3308
- return reinterpret_cast <Fn2*>(Function)(arg0, arg1);
3309
- }
3310
- const Metadata *operator ()(const void *arg0,
3311
- const void *arg1,
3312
- const void *arg2) const {
3313
- using Fn3 = const Metadata *(const void *, const void *, const void *);
3314
- return reinterpret_cast <Fn3*>(Function)(arg0, arg1, arg2);
3299
+ // / Invoke with exactly 0 arguments.
3300
+ MetadataResponse operator ()(MetadataRequest request) const {
3301
+ using Fn0 = SWIFT_CC (swift) MetadataResponse (MetadataRequest request);
3302
+ return reinterpret_cast <Fn0*>(Function)(request);
3303
+ }
3304
+
3305
+ // / Invoke with exactly 1 argument.
3306
+ MetadataResponse operator ()(MetadataRequest request,
3307
+ const void *arg0) const {
3308
+ using Fn1 = SWIFT_CC (swift) MetadataResponse (MetadataRequest request,
3309
+ const void *arg0);
3310
+ return reinterpret_cast <Fn1*>(Function)(request, arg0);
3311
+
3312
+ }
3313
+
3314
+ // / Invoke with exactly 2 arguments.
3315
+ MetadataResponse operator ()(MetadataRequest request,
3316
+ const void *arg0,
3317
+ const void *arg1) const {
3318
+ using Fn2 = SWIFT_CC (swift) MetadataResponse (MetadataRequest request,
3319
+ const void *arg0,
3320
+ const void *arg1);
3321
+ return reinterpret_cast <Fn2*>(Function)(request, arg0, arg1);
3322
+ }
3323
+
3324
+ // / Invoke with exactly 3 arguments.
3325
+ MetadataResponse operator ()(MetadataRequest request,
3326
+ const void *arg0,
3327
+ const void *arg1,
3328
+ const void *arg2) const {
3329
+ using Fn3 = SWIFT_CC (swift) MetadataResponse (MetadataRequest request,
3330
+ const void *arg0,
3331
+ const void *arg1,
3332
+ const void *arg2);
3333
+ return reinterpret_cast <Fn3*>(Function)(request, arg0, arg1, arg2);
3315
3334
}
3316
3335
3336
+ // / Invoke with more than 3 arguments.
3317
3337
template <typename ...Args>
3318
- const Metadata *operator ()(const void *arg0,
3319
- const void *arg1,
3320
- const void *arg2,
3321
- Args...argN) const {
3322
- const void *args[3 + sizeof ...(Args)];
3323
- return variadic_apply (arg0, arg1, arg2, args, 3 , argN...);
3338
+ MetadataResponse operator ()(MetadataRequest request,
3339
+ const void *arg0,
3340
+ const void *arg1,
3341
+ const void *arg2,
3342
+ Args... argN) const {
3343
+ const void *args[] = { arg0, arg1, arg2, argN... };
3344
+ return applyMany (request, args);
3345
+ }
3346
+
3347
+ private:
3348
+ // / In the more-then-max case, just pass all the arguments as an array.
3349
+ MetadataResponse applyMany (MetadataRequest request,
3350
+ const void * const *args) const {
3351
+ using FnN = SWIFT_CC (swift) MetadataResponse (MetadataRequest request,
3352
+ const void * const *args);
3353
+ return reinterpret_cast <FnN*>(Function)(request, args);
3324
3354
}
3325
3355
};
3326
3356
@@ -3336,7 +3366,7 @@ class TargetTypeContextDescriptor
3336
3366
// / The function type here is a stand-in. You should use getAccessFunction()
3337
3367
// / to wrap the function pointer in an accessor that uses the proper calling
3338
3368
// / convention for a given number of arguments.
3339
- TargetRelativeDirectPointer<Runtime, const Metadata * (...),
3369
+ TargetRelativeDirectPointer<Runtime, MetadataResponse (...),
3340
3370
/* Nullable*/ true > AccessFunctionPtr;
3341
3371
3342
3372
MetadataAccessFunction getAccessFunction () const {
@@ -3855,27 +3885,11 @@ TargetTypeContextDescriptor<Runtime>::getFullGenericContextHeader() const {
3855
3885
}
3856
3886
3857
3887
// / \brief Fetch a uniqued metadata object for a generic nominal type.
3858
- // /
3859
- // / The basic algorithm for fetching a metadata object is:
3860
- // / func swift_getGenericMetadata(header, arguments) {
3861
- // / if (metadata = getExistingMetadata(&header.PrivateData,
3862
- // / arguments[0..header.NumArguments]))
3863
- // / return metadata
3864
- // / metadata = malloc(superclass.MetadataSize +
3865
- // / numImmediateMembers * sizeof(void *))
3866
- // / memcpy(metadata, header.MetadataTemplate, header.TemplateSize)
3867
- // / for (i in 0..header.NumFillInstructions)
3868
- // / metadata[header.FillInstructions[i].ToIndex]
3869
- // / = arguments[header.FillInstructions[i].FromIndex]
3870
- // / setExistingMetadata(&header.PrivateData,
3871
- // / arguments[0..header.NumArguments],
3872
- // / metadata)
3873
- // / return metadata
3874
- // / }
3875
- SWIFT_RUNTIME_EXPORT
3876
- const Metadata *
3877
- swift_getGenericMetadata (const TypeContextDescriptor *description,
3878
- const void *arguments);
3888
+ SWIFT_RUNTIME_EXPORT SWIFT_CC (swift)
3889
+ MetadataResponse
3890
+ swift_getGenericMetadata(MetadataRequest request,
3891
+ const void * const *arguments,
3892
+ const TypeContextDescriptor *description);
3879
3893
3880
3894
// / Allocate a generic class metadata object. This is intended to be
3881
3895
// / called by the metadata instantiation function of a generic class.
0 commit comments