Skip to content

Commit 864f5f0

Browse files
committed
Runtime: GenericParamPackShapeDescriptor => GenericPackShapeDescriptor
We also need to track witness table packs, and store an index here for convenient access from the metadata caching key comparison logic.
1 parent 5215406 commit 864f5f0

File tree

2 files changed

+62
-42
lines changed

2 files changed

+62
-42
lines changed

include/swift/ABI/GenericContext.h

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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,39 @@ class TargetGenericRequirementDescriptor {
245245
using 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+
struct GenericPackShapeDescriptor {
269+
GenericPackKind Kind;
270+
271+
/// The index of this metadata pack or witness table pack in the
272+
/// generic arguments array.
273+
uint16_t Index;
274+
275+
/// The equivalence class of this pack under the same-shape relation.
262276
///
263-
/// Must be less than GenericParamPackShapeHeader::NumShapeClasses.
277+
/// Must be less than GenericPackShapeHeader::NumShapeClasses.
264278
uint16_t ShapeClass;
279+
280+
uint16_t Unused;
265281
};
266282

267283
/// An array of generic parameter descriptors, all
@@ -299,8 +315,8 @@ class RuntimeGenericSignature {
299315
TargetGenericContextDescriptorHeader<Runtime> Header;
300316
const GenericParamDescriptor *Params;
301317
const TargetGenericRequirementDescriptor<Runtime> *Requirements;
302-
GenericParamPackShapeHeader PackShapeHeader;
303-
const GenericParamPackShapeDescriptor *PackShapeDescriptors;
318+
GenericPackShapeHeader PackShapeHeader;
319+
const GenericPackShapeDescriptor *PackShapeDescriptors;
304320

305321
public:
306322
RuntimeGenericSignature()
@@ -310,8 +326,8 @@ class RuntimeGenericSignature {
310326
RuntimeGenericSignature(const TargetGenericContextDescriptorHeader<Runtime> &header,
311327
const GenericParamDescriptor *params,
312328
const TargetGenericRequirementDescriptor<Runtime> *requirements,
313-
const GenericParamPackShapeHeader &packShapeHeader,
314-
const GenericParamPackShapeDescriptor *packShapeDescriptors)
329+
const GenericPackShapeHeader &packShapeHeader,
330+
const GenericPackShapeDescriptor *packShapeDescriptors)
315331
: Header(header), Params(params), Requirements(requirements),
316332
PackShapeHeader(packShapeHeader), PackShapeDescriptors(packShapeDescriptors) {}
317333

@@ -323,8 +339,12 @@ class RuntimeGenericSignature {
323339
return llvm::makeArrayRef(Requirements, Header.NumRequirements);
324340
}
325341

326-
llvm::ArrayRef<GenericParamPackShapeDescriptor> getPackShapeDescriptors() const {
327-
return llvm::makeArrayRef(PackShapeDescriptors, PackShapeHeader.NumTypePacks);
342+
const GenericPackShapeHeader &getGenericPackShapeHeader() const {
343+
return PackShapeHeader;
344+
}
345+
346+
llvm::ArrayRef<GenericPackShapeDescriptor> getGenericPackShapeDescriptors() const {
347+
return llvm::makeArrayRef(PackShapeDescriptors, PackShapeHeader.NumPacks);
328348
}
329349

330350
size_t getArgumentLayoutSizeInWords() const {
@@ -417,8 +437,8 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
417437
TargetGenericContextHeaderType<Runtime>,
418438
GenericParamDescriptor,
419439
TargetGenericRequirementDescriptor<Runtime>,
420-
GenericParamPackShapeHeader,
421-
GenericParamPackShapeDescriptor,
440+
GenericPackShapeHeader,
441+
GenericPackShapeDescriptor,
422442
FollowingTrailingObjects...>
423443
{
424444
protected:
@@ -431,8 +451,8 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
431451
GenericContextHeaderType,
432452
GenericParamDescriptor,
433453
GenericRequirementDescriptor,
434-
GenericParamPackShapeHeader,
435-
GenericParamPackShapeDescriptor,
454+
GenericPackShapeHeader,
455+
GenericPackShapeDescriptor,
436456
FollowingTrailingObjects...>;
437457
friend TrailingObjects;
438458

@@ -487,21 +507,21 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
487507
getGenericContextHeader().NumRequirements};
488508
}
489509

490-
GenericParamPackShapeHeader getGenericParamPackShapeHeader() const {
510+
GenericPackShapeHeader getGenericPackShapeHeader() const {
491511
if (!asSelf()->isGeneric())
492512
return {0, 0};
493513
if (!getGenericContextHeader().Flags.hasTypePacks())
494514
return {0, 0};
495-
return *this->template getTrailingObjects<GenericParamPackShapeHeader>();
515+
return *this->template getTrailingObjects<GenericPackShapeHeader>();
496516
}
497517

498-
llvm::ArrayRef<GenericParamPackShapeDescriptor> getGenericParamPackShapeDescriptors() const {
499-
auto header = getGenericParamPackShapeHeader();
500-
if (header.NumTypePacks == 0)
518+
llvm::ArrayRef<GenericPackShapeDescriptor> getGenericPackShapeDescriptors() const {
519+
auto header = getGenericPackShapeHeader();
520+
if (header.NumPacks == 0)
501521
return {};
502522

503-
return {this->template getTrailingObjects<GenericParamPackShapeDescriptor>(),
504-
header.NumTypePacks};
523+
return {this->template getTrailingObjects<GenericPackShapeDescriptor>(),
524+
header.NumPacks};
505525
}
506526

507527
/// Return the amount of space that the generic arguments take up in
@@ -516,8 +536,8 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
516536
return {getGenericContextHeader(),
517537
getGenericParams().data(),
518538
getGenericRequirements().data(),
519-
getGenericParamPackShapeHeader(),
520-
getGenericParamPackShapeDescriptors().data()};
539+
getGenericPackShapeHeader(),
540+
getGenericPackShapeDescriptors().data()};
521541
}
522542

523543
protected:
@@ -533,21 +553,21 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
533553
return asSelf()->isGeneric() ? getGenericContextHeader().NumRequirements : 0;
534554
}
535555

536-
size_t numTrailingObjects(OverloadToken<GenericParamPackShapeHeader>) const {
556+
size_t numTrailingObjects(OverloadToken<GenericPackShapeHeader>) const {
537557
if (!asSelf()->isGeneric())
538558
return 0;
539559

540560
return getGenericContextHeader().Flags.hasTypePacks() ? 1 : 0;
541561
}
542562

543-
size_t numTrailingObjects(OverloadToken<GenericParamPackShapeDescriptor>) const {
563+
size_t numTrailingObjects(OverloadToken<GenericPackShapeDescriptor>) const {
544564
if (!asSelf()->isGeneric())
545565
return 0;
546566

547567
if (!getGenericContextHeader().Flags.hasTypePacks())
548568
return 0;
549569

550-
return getGenericParamPackShapeHeader().NumTypePacks;
570+
return getGenericPackShapeHeader().NumPacks;
551571
}
552572

553573
#if defined(_MSC_VER) && _MSC_VER < 1920

include/swift/ABI/Metadata.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,10 +1932,10 @@ struct TargetExtendedExistentialTypeShape
19321932
TargetGenericRequirementDescriptor<Runtime>,
19331933
// Optional header describing any type packs in the generalization
19341934
// signature.
1935-
GenericParamPackShapeHeader,
1935+
GenericPackShapeHeader,
19361936
// For each type pack in the generalization signature, a descriptor
19371937
// storing the shape class.
1938-
GenericParamPackShapeDescriptor> {
1938+
GenericPackShapeDescriptor> {
19391939
private:
19401940
using RelativeValueWitnessTablePointer =
19411941
TargetRelativeIndirectablePointer<Runtime,
@@ -1949,8 +1949,8 @@ struct TargetExtendedExistentialTypeShape
19491949
RelativeValueWitnessTablePointer,
19501950
GenericParamDescriptor,
19511951
TargetGenericRequirementDescriptor<Runtime>,
1952-
GenericParamPackShapeHeader,
1953-
GenericParamPackShapeDescriptor>;
1952+
GenericPackShapeHeader,
1953+
GenericPackShapeDescriptor>;
19541954
friend TrailingObjects;
19551955

19561956
template<typename T>
@@ -1977,11 +1977,11 @@ struct TargetExtendedExistentialTypeShape
19771977
return getNumGenSigRequirements() + getNumReqSigRequirements();
19781978
}
19791979

1980-
size_t numTrailingObjects(OverloadToken<GenericParamPackShapeHeader>) const {
1980+
size_t numTrailingObjects(OverloadToken<GenericPackShapeHeader>) const {
19811981
return (Flags.hasTypePacks() ? 1 : 0);
19821982
}
19831983

1984-
size_t numTrailingObjects(OverloadToken<GenericParamPackShapeDescriptor>) const {
1984+
size_t numTrailingObjects(OverloadToken<GenericPackShapeDescriptor>) const {
19851985
if (!Flags.hasTypePacks())
19861986
return 0;
19871987

@@ -2142,18 +2142,18 @@ struct TargetExtendedExistentialTypeShape
21422142
return getReqSigRequirements() + ReqSigHeader.NumRequirements;
21432143
}
21442144

2145-
GenericParamPackShapeHeader getGenSigPackShapeHeader() const {
2145+
GenericPackShapeHeader getGenSigPackShapeHeader() const {
21462146
assert(hasGeneralizationSignature());
21472147
if (!Flags.hasTypePacks())
21482148
return {0, 0};
2149-
return *this->template getTrailingObjects<GenericParamPackShapeHeader>();
2149+
return *this->template getTrailingObjects<GenericPackShapeHeader>();
21502150
}
21512151

2152-
const GenericParamPackShapeDescriptor *getGenSigPackShapeDescriptors() const {
2152+
const GenericPackShapeDescriptor *getGenSigPackShapeDescriptors() const {
21532153
assert(hasGeneralizationSignature());
21542154
if (!Flags.hasTypePacks())
21552155
return nullptr;
2156-
return this->template getTrailingObjects<GenericParamPackShapeDescriptor>();
2156+
return this->template getTrailingObjects<GenericPackShapeDescriptor>();
21572157
}
21582158

21592159
/// Return the amount of space used in ExtendedExistentialTypeMetadata

0 commit comments

Comments
 (0)