@@ -46,7 +46,7 @@ class GenericContextDescriptorFlags {
46
46
47
47
// / Whether this generic context has at least one type parameter
48
48
// / pack, in which case the generic context will have a trailing
49
- // / GenericParamPackShapeHeader .
49
+ // / GenericPackShapeHeader .
50
50
constexpr bool hasTypePacks () const {
51
51
return (Value & 0x1 ) != 0 ;
52
52
}
@@ -245,23 +245,51 @@ class TargetGenericRequirementDescriptor {
245
245
using GenericRequirementDescriptor =
246
246
TargetGenericRequirementDescriptor<InProcess>;
247
247
248
- struct GenericParamPackShapeHeader {
249
- // / The number of generic parameters which are packs.
248
+ struct GenericPackShapeHeader {
249
+ // / The number of generic parameters and conformance requirements
250
+ // / which are packs.
250
251
// /
251
- // / Must equal the number of GenericParamDescriptors whose kind is
252
- // / GenericParamKind::TypePack.
253
- uint16_t NumTypePacks;
252
+ // / Must equal the sum of:
253
+ // / - the number of GenericParamDescriptors whose kind is
254
+ // / GenericParamKind::TypePack and isKeyArgument bits set;
255
+ // / - the number of GenericRequirementDescriptors with the
256
+ // / isPackRequirement and isKeyArgument bits set
257
+ uint16_t NumPacks;
254
258
255
259
// / The number of equivalence classes in the same-shape relation.
256
260
uint16_t NumShapeClasses;
257
261
};
258
262
259
- struct GenericParamPackShapeDescriptor {
260
- // / The equivalence class of this generic parameter pack under
261
- // / the same-shape relation.
263
+ enum class GenericPackKind : uint16_t {
264
+ Metadata = 0 ,
265
+ WitnessTable = 1
266
+ };
267
+
268
+ // / The GenericPackShapeHeader is followed by an array of these descriptors,
269
+ // / whose length is given by the header's NumPacks field.
270
+ // /
271
+ // / The invariant is that all pack descriptors with GenericPackKind::Metadata
272
+ // / must precede those with GenericPackKind::WitnessTable, and for each kind,
273
+ // / the pack descriptors are ordered by their Index.
274
+ // /
275
+ // / This allows us to iterate over the generic arguments array in parallel
276
+ // / with the array of pack shape descriptors. We know we have a metadata
277
+ // / or witness table when we reach the generic argument whose index is
278
+ // / stored in the next descriptor; we increment the descriptor pointer in
279
+ // / this case.
280
+ struct GenericPackShapeDescriptor {
281
+ GenericPackKind Kind;
282
+
283
+ // / The index of this metadata pack or witness table pack in the
284
+ // / generic arguments array.
285
+ uint16_t Index;
286
+
287
+ // / The equivalence class of this pack under the same-shape relation.
262
288
// /
263
- // / Must be less than GenericParamPackShapeHeader ::NumShapeClasses.
289
+ // / Must be less than GenericPackShapeHeader ::NumShapeClasses.
264
290
uint16_t ShapeClass;
291
+
292
+ uint16_t Unused;
265
293
};
266
294
267
295
// / An array of generic parameter descriptors, all
@@ -299,8 +327,8 @@ class RuntimeGenericSignature {
299
327
TargetGenericContextDescriptorHeader<Runtime> Header;
300
328
const GenericParamDescriptor *Params;
301
329
const TargetGenericRequirementDescriptor<Runtime> *Requirements;
302
- GenericParamPackShapeHeader PackShapeHeader;
303
- const GenericParamPackShapeDescriptor *PackShapeDescriptors;
330
+ GenericPackShapeHeader PackShapeHeader;
331
+ const GenericPackShapeDescriptor *PackShapeDescriptors;
304
332
305
333
public:
306
334
RuntimeGenericSignature ()
@@ -310,8 +338,8 @@ class RuntimeGenericSignature {
310
338
RuntimeGenericSignature (const TargetGenericContextDescriptorHeader<Runtime> &header,
311
339
const GenericParamDescriptor *params,
312
340
const TargetGenericRequirementDescriptor<Runtime> *requirements,
313
- const GenericParamPackShapeHeader &packShapeHeader,
314
- const GenericParamPackShapeDescriptor *packShapeDescriptors)
341
+ const GenericPackShapeHeader &packShapeHeader,
342
+ const GenericPackShapeDescriptor *packShapeDescriptors)
315
343
: Header(header), Params(params), Requirements(requirements),
316
344
PackShapeHeader (packShapeHeader), PackShapeDescriptors(packShapeDescriptors) {}
317
345
@@ -323,8 +351,12 @@ class RuntimeGenericSignature {
323
351
return llvm::makeArrayRef (Requirements, Header.NumRequirements );
324
352
}
325
353
326
- llvm::ArrayRef<GenericParamPackShapeDescriptor> getPackShapeDescriptors () const {
327
- return llvm::makeArrayRef (PackShapeDescriptors, PackShapeHeader.NumTypePacks );
354
+ const GenericPackShapeHeader &getGenericPackShapeHeader () const {
355
+ return PackShapeHeader;
356
+ }
357
+
358
+ llvm::ArrayRef<GenericPackShapeDescriptor> getGenericPackShapeDescriptors () const {
359
+ return llvm::makeArrayRef (PackShapeDescriptors, PackShapeHeader.NumPacks );
328
360
}
329
361
330
362
size_t getArgumentLayoutSizeInWords () const {
@@ -417,8 +449,8 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
417
449
TargetGenericContextHeaderType<Runtime>,
418
450
GenericParamDescriptor,
419
451
TargetGenericRequirementDescriptor<Runtime>,
420
- GenericParamPackShapeHeader ,
421
- GenericParamPackShapeDescriptor ,
452
+ GenericPackShapeHeader ,
453
+ GenericPackShapeDescriptor ,
422
454
FollowingTrailingObjects...>
423
455
{
424
456
protected:
@@ -431,8 +463,8 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
431
463
GenericContextHeaderType,
432
464
GenericParamDescriptor,
433
465
GenericRequirementDescriptor,
434
- GenericParamPackShapeHeader ,
435
- GenericParamPackShapeDescriptor ,
466
+ GenericPackShapeHeader ,
467
+ GenericPackShapeDescriptor ,
436
468
FollowingTrailingObjects...>;
437
469
friend TrailingObjects;
438
470
@@ -487,21 +519,21 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
487
519
getGenericContextHeader ().NumRequirements };
488
520
}
489
521
490
- GenericParamPackShapeHeader getGenericParamPackShapeHeader () const {
522
+ GenericPackShapeHeader getGenericPackShapeHeader () const {
491
523
if (!asSelf ()->isGeneric ())
492
524
return {0 , 0 };
493
525
if (!getGenericContextHeader ().Flags .hasTypePacks ())
494
526
return {0 , 0 };
495
- return *this ->template getTrailingObjects <GenericParamPackShapeHeader >();
527
+ return *this ->template getTrailingObjects <GenericPackShapeHeader >();
496
528
}
497
529
498
- llvm::ArrayRef<GenericParamPackShapeDescriptor> getGenericParamPackShapeDescriptors () const {
499
- auto header = getGenericParamPackShapeHeader ();
500
- if (header.NumTypePacks == 0 )
530
+ llvm::ArrayRef<GenericPackShapeDescriptor> getGenericPackShapeDescriptors () const {
531
+ auto header = getGenericPackShapeHeader ();
532
+ if (header.NumPacks == 0 )
501
533
return {};
502
534
503
- return {this ->template getTrailingObjects <GenericParamPackShapeDescriptor >(),
504
- header.NumTypePacks };
535
+ return {this ->template getTrailingObjects <GenericPackShapeDescriptor >(),
536
+ header.NumPacks };
505
537
}
506
538
507
539
// / Return the amount of space that the generic arguments take up in
@@ -516,8 +548,8 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
516
548
return {getGenericContextHeader (),
517
549
getGenericParams ().data (),
518
550
getGenericRequirements ().data (),
519
- getGenericParamPackShapeHeader (),
520
- getGenericParamPackShapeDescriptors ().data ()};
551
+ getGenericPackShapeHeader (),
552
+ getGenericPackShapeDescriptors ().data ()};
521
553
}
522
554
523
555
protected:
@@ -533,21 +565,21 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
533
565
return asSelf ()->isGeneric () ? getGenericContextHeader ().NumRequirements : 0 ;
534
566
}
535
567
536
- size_t numTrailingObjects (OverloadToken<GenericParamPackShapeHeader >) const {
568
+ size_t numTrailingObjects (OverloadToken<GenericPackShapeHeader >) const {
537
569
if (!asSelf ()->isGeneric ())
538
570
return 0 ;
539
571
540
572
return getGenericContextHeader ().Flags .hasTypePacks () ? 1 : 0 ;
541
573
}
542
574
543
- size_t numTrailingObjects (OverloadToken<GenericParamPackShapeDescriptor >) const {
575
+ size_t numTrailingObjects (OverloadToken<GenericPackShapeDescriptor >) const {
544
576
if (!asSelf ()->isGeneric ())
545
577
return 0 ;
546
578
547
579
if (!getGenericContextHeader ().Flags .hasTypePacks ())
548
580
return 0 ;
549
581
550
- return getGenericParamPackShapeHeader ().NumTypePacks ;
582
+ return getGenericPackShapeHeader ().NumPacks ;
551
583
}
552
584
553
585
#if defined(_MSC_VER) && _MSC_VER < 1920
0 commit comments