@@ -46,7 +46,7 @@ class GenericContextDescriptorFlags {
4646
4747 // / Whether this generic context has at least one type parameter
4848 // / pack, in which case the generic context will have a trailing
49- // / GenericParamPackShapeHeader .
49+ // / GenericPackShapeHeader .
5050 constexpr bool hasTypePacks () const {
5151 return (Value & 0x1 ) != 0 ;
5252 }
@@ -245,23 +245,51 @@ class TargetGenericRequirementDescriptor {
245245using GenericRequirementDescriptor =
246246 TargetGenericRequirementDescriptor<InProcess>;
247247
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.
250251 // /
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;
254258
255259 // / The number of equivalence classes in the same-shape relation.
256260 uint16_t NumShapeClasses;
257261};
258262
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.
262288 // /
263- // / Must be less than GenericParamPackShapeHeader ::NumShapeClasses.
289+ // / Must be less than GenericPackShapeHeader ::NumShapeClasses.
264290 uint16_t ShapeClass;
291+
292+ uint16_t Unused;
265293};
266294
267295// / An array of generic parameter descriptors, all
@@ -299,8 +327,8 @@ class RuntimeGenericSignature {
299327 TargetGenericContextDescriptorHeader<Runtime> Header;
300328 const GenericParamDescriptor *Params;
301329 const TargetGenericRequirementDescriptor<Runtime> *Requirements;
302- GenericParamPackShapeHeader PackShapeHeader;
303- const GenericParamPackShapeDescriptor *PackShapeDescriptors;
330+ GenericPackShapeHeader PackShapeHeader;
331+ const GenericPackShapeDescriptor *PackShapeDescriptors;
304332
305333public:
306334 RuntimeGenericSignature ()
@@ -310,8 +338,8 @@ class RuntimeGenericSignature {
310338 RuntimeGenericSignature (const TargetGenericContextDescriptorHeader<Runtime> &header,
311339 const GenericParamDescriptor *params,
312340 const TargetGenericRequirementDescriptor<Runtime> *requirements,
313- const GenericParamPackShapeHeader &packShapeHeader,
314- const GenericParamPackShapeDescriptor *packShapeDescriptors)
341+ const GenericPackShapeHeader &packShapeHeader,
342+ const GenericPackShapeDescriptor *packShapeDescriptors)
315343 : Header(header), Params(params), Requirements(requirements),
316344 PackShapeHeader (packShapeHeader), PackShapeDescriptors(packShapeDescriptors) {}
317345
@@ -323,8 +351,12 @@ class RuntimeGenericSignature {
323351 return llvm::makeArrayRef (Requirements, Header.NumRequirements );
324352 }
325353
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 );
328360 }
329361
330362 size_t getArgumentLayoutSizeInWords () const {
@@ -417,8 +449,8 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
417449 TargetGenericContextHeaderType<Runtime>,
418450 GenericParamDescriptor,
419451 TargetGenericRequirementDescriptor<Runtime>,
420- GenericParamPackShapeHeader ,
421- GenericParamPackShapeDescriptor ,
452+ GenericPackShapeHeader ,
453+ GenericPackShapeDescriptor ,
422454 FollowingTrailingObjects...>
423455{
424456protected:
@@ -431,8 +463,8 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
431463 GenericContextHeaderType,
432464 GenericParamDescriptor,
433465 GenericRequirementDescriptor,
434- GenericParamPackShapeHeader ,
435- GenericParamPackShapeDescriptor ,
466+ GenericPackShapeHeader ,
467+ GenericPackShapeDescriptor ,
436468 FollowingTrailingObjects...>;
437469 friend TrailingObjects;
438470
@@ -487,21 +519,21 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
487519 getGenericContextHeader ().NumRequirements };
488520 }
489521
490- GenericParamPackShapeHeader getGenericParamPackShapeHeader () const {
522+ GenericPackShapeHeader getGenericPackShapeHeader () const {
491523 if (!asSelf ()->isGeneric ())
492524 return {0 , 0 };
493525 if (!getGenericContextHeader ().Flags .hasTypePacks ())
494526 return {0 , 0 };
495- return *this ->template getTrailingObjects <GenericParamPackShapeHeader >();
527+ return *this ->template getTrailingObjects <GenericPackShapeHeader >();
496528 }
497529
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 )
501533 return {};
502534
503- return {this ->template getTrailingObjects <GenericParamPackShapeDescriptor >(),
504- header.NumTypePacks };
535+ return {this ->template getTrailingObjects <GenericPackShapeDescriptor >(),
536+ header.NumPacks };
505537 }
506538
507539 // / Return the amount of space that the generic arguments take up in
@@ -516,8 +548,8 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
516548 return {getGenericContextHeader (),
517549 getGenericParams ().data (),
518550 getGenericRequirements ().data (),
519- getGenericParamPackShapeHeader (),
520- getGenericParamPackShapeDescriptors ().data ()};
551+ getGenericPackShapeHeader (),
552+ getGenericPackShapeDescriptors ().data ()};
521553 }
522554
523555protected:
@@ -533,21 +565,21 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
533565 return asSelf ()->isGeneric () ? getGenericContextHeader ().NumRequirements : 0 ;
534566 }
535567
536- size_t numTrailingObjects (OverloadToken<GenericParamPackShapeHeader >) const {
568+ size_t numTrailingObjects (OverloadToken<GenericPackShapeHeader >) const {
537569 if (!asSelf ()->isGeneric ())
538570 return 0 ;
539571
540572 return getGenericContextHeader ().Flags .hasTypePacks () ? 1 : 0 ;
541573 }
542574
543- size_t numTrailingObjects (OverloadToken<GenericParamPackShapeDescriptor >) const {
575+ size_t numTrailingObjects (OverloadToken<GenericPackShapeDescriptor >) const {
544576 if (!asSelf ()->isGeneric ())
545577 return 0 ;
546578
547579 if (!getGenericContextHeader ().Flags .hasTypePacks ())
548580 return 0 ;
549581
550- return getGenericParamPackShapeHeader ().NumTypePacks ;
582+ return getGenericPackShapeHeader ().NumPacks ;
551583 }
552584
553585#if defined(_MSC_VER) && _MSC_VER < 1920
0 commit comments