Skip to content

Commit 5215406

Browse files
committed
Runtime: Plumb through the pack shape stuff in more places
1 parent 70c56de commit 5215406

File tree

3 files changed

+79
-16
lines changed

3 files changed

+79
-16
lines changed

include/swift/ABI/GenericContext.h

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,21 @@ class RuntimeGenericSignature {
299299
TargetGenericContextDescriptorHeader<Runtime> Header;
300300
const GenericParamDescriptor *Params;
301301
const TargetGenericRequirementDescriptor<Runtime> *Requirements;
302+
GenericParamPackShapeHeader PackShapeHeader;
303+
const GenericParamPackShapeDescriptor *PackShapeDescriptors;
304+
302305
public:
303306
RuntimeGenericSignature()
304-
: Header{0, 0, 0, 0}, Params(nullptr), Requirements(nullptr) {}
307+
: Header{0, 0, 0, 0}, Params(nullptr), Requirements(nullptr),
308+
PackShapeHeader{0, 0}, PackShapeDescriptors(nullptr) {}
305309

306310
RuntimeGenericSignature(const TargetGenericContextDescriptorHeader<Runtime> &header,
307311
const GenericParamDescriptor *params,
308-
const TargetGenericRequirementDescriptor<Runtime> *requirements)
309-
: Header(header), Params(params), Requirements(requirements) {}
312+
const TargetGenericRequirementDescriptor<Runtime> *requirements,
313+
const GenericParamPackShapeHeader &packShapeHeader,
314+
const GenericParamPackShapeDescriptor *packShapeDescriptors)
315+
: Header(header), Params(params), Requirements(requirements),
316+
PackShapeHeader(packShapeHeader), PackShapeDescriptors(packShapeDescriptors) {}
310317

311318
llvm::ArrayRef<GenericParamDescriptor> getParams() const {
312319
return llvm::makeArrayRef(Params, Header.NumParams);
@@ -316,6 +323,10 @@ class RuntimeGenericSignature {
316323
return llvm::makeArrayRef(Requirements, Header.NumRequirements);
317324
}
318325

326+
llvm::ArrayRef<GenericParamPackShapeDescriptor> getPackShapeDescriptors() const {
327+
return llvm::makeArrayRef(PackShapeDescriptors, PackShapeHeader.NumTypePacks);
328+
}
329+
319330
size_t getArgumentLayoutSizeInWords() const {
320331
return Header.getArgumentLayoutSizeInWords();
321332
}
@@ -476,21 +487,21 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
476487
getGenericContextHeader().NumRequirements};
477488
}
478489

479-
const GenericParamPackShapeHeader *getGenericParamPackShapeHeader() const {
490+
GenericParamPackShapeHeader getGenericParamPackShapeHeader() const {
480491
if (!asSelf()->isGeneric())
481-
return nullptr;
492+
return {0, 0};
482493
if (!getGenericContextHeader().Flags.hasTypePacks())
483-
return nullptr;
484-
return this->template getTrailingObjects<GenericParamPackShapeHeader>();
494+
return {0, 0};
495+
return *this->template getTrailingObjects<GenericParamPackShapeHeader>();
485496
}
486497

487498
llvm::ArrayRef<GenericParamPackShapeDescriptor> getGenericParamPackShapeDescriptors() const {
488-
auto *header = getGenericParamPackShapeHeader();
489-
if (header == nullptr)
499+
auto header = getGenericParamPackShapeHeader();
500+
if (header.NumTypePacks == 0)
490501
return {};
491502

492503
return {this->template getTrailingObjects<GenericParamPackShapeDescriptor>(),
493-
header->NumTypePacks};
504+
header.NumTypePacks};
494505
}
495506

496507
/// Return the amount of space that the generic arguments take up in
@@ -504,7 +515,9 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
504515
if (!asSelf()->isGeneric()) return RuntimeGenericSignature<Runtime>();
505516
return {getGenericContextHeader(),
506517
getGenericParams().data(),
507-
getGenericRequirements().data()};
518+
getGenericRequirements().data(),
519+
getGenericParamPackShapeHeader(),
520+
getGenericParamPackShapeDescriptors().data()};
508521
}
509522

510523
protected:
@@ -534,7 +547,7 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
534547
if (!getGenericContextHeader().Flags.hasTypePacks())
535548
return 0;
536549

537-
return getGenericParamPackShapeHeader()->NumTypePacks;
550+
return getGenericParamPackShapeHeader().NumTypePacks;
538551
}
539552

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

include/swift/ABI/Metadata.h

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,13 @@ struct TargetExtendedExistentialTypeShape
19291929
GenericParamDescriptor,
19301930
// Requirements for requirement signature, followed by requirements
19311931
// for generalization signature
1932-
TargetGenericRequirementDescriptor<Runtime>> {
1932+
TargetGenericRequirementDescriptor<Runtime>,
1933+
// Optional header describing any type packs in the generalization
1934+
// signature.
1935+
GenericParamPackShapeHeader,
1936+
// For each type pack in the generalization signature, a descriptor
1937+
// storing the shape class.
1938+
GenericParamPackShapeDescriptor> {
19331939
private:
19341940
using RelativeValueWitnessTablePointer =
19351941
TargetRelativeIndirectablePointer<Runtime,
@@ -1942,7 +1948,9 @@ struct TargetExtendedExistentialTypeShape
19421948
TargetExistentialTypeExpression<Runtime>,
19431949
RelativeValueWitnessTablePointer,
19441950
GenericParamDescriptor,
1945-
TargetGenericRequirementDescriptor<Runtime>>;
1951+
TargetGenericRequirementDescriptor<Runtime>,
1952+
GenericParamPackShapeHeader,
1953+
GenericParamPackShapeDescriptor>;
19461954
friend TrailingObjects;
19471955

19481956
template<typename T>
@@ -1969,6 +1977,17 @@ struct TargetExtendedExistentialTypeShape
19691977
return getNumGenSigRequirements() + getNumReqSigRequirements();
19701978
}
19711979

1980+
size_t numTrailingObjects(OverloadToken<GenericParamPackShapeHeader>) const {
1981+
return (Flags.hasTypePacks() ? 1 : 0);
1982+
}
1983+
1984+
size_t numTrailingObjects(OverloadToken<GenericParamPackShapeDescriptor>) const {
1985+
if (!Flags.hasTypePacks())
1986+
return 0;
1987+
1988+
return getGenSigPackShapeHeader().NumTypePacks;
1989+
}
1990+
19721991
const TargetGenericContextDescriptorHeader<Runtime> *
19731992
getGenSigHeader() const {
19741993
assert(hasGeneralizationSignature());
@@ -2013,7 +2032,8 @@ struct TargetExtendedExistentialTypeShape
20132032
TargetGenericContextDescriptorHeader<Runtime> ReqSigHeader;
20142033

20152034
RuntimeGenericSignature<Runtime> getRequirementSignature() const {
2016-
return {ReqSigHeader, getReqSigParams(), getReqSigRequirements()};
2035+
return {ReqSigHeader, getReqSigParams(), getReqSigRequirements(),
2036+
{0, 0}, nullptr};
20172037
}
20182038

20192039
unsigned getNumReqSigParams() const {
@@ -2092,7 +2112,8 @@ struct TargetExtendedExistentialTypeShape
20922112

20932113
RuntimeGenericSignature<Runtime> getGeneralizationSignature() const {
20942114
if (!hasGeneralizationSignature()) return RuntimeGenericSignature<Runtime>();
2095-
return {*getGenSigHeader(), getGenSigParams(), getGenSigRequirements()};
2115+
return {*getGenSigHeader(), getGenSigParams(), getGenSigRequirements(),
2116+
getGenSigPackShapeHeader(), getGenSigPackShapeDescriptors()};
20962117
}
20972118

20982119
unsigned getNumGenSigParams() const {
@@ -2121,6 +2142,20 @@ struct TargetExtendedExistentialTypeShape
21212142
return getReqSigRequirements() + ReqSigHeader.NumRequirements;
21222143
}
21232144

2145+
GenericParamPackShapeHeader getGenSigPackShapeHeader() const {
2146+
assert(hasGeneralizationSignature());
2147+
if (!Flags.hasTypePacks())
2148+
return {0, 0};
2149+
return *this->template getTrailingObjects<GenericParamPackShapeHeader>();
2150+
}
2151+
2152+
const GenericParamPackShapeDescriptor *getGenSigPackShapeDescriptors() const {
2153+
assert(hasGeneralizationSignature());
2154+
if (!Flags.hasTypePacks())
2155+
return nullptr;
2156+
return this->template getTrailingObjects<GenericParamPackShapeDescriptor>();
2157+
}
2158+
21242159
/// Return the amount of space used in ExtendedExistentialTypeMetadata
21252160
/// for this shape to store the generalization arguments.
21262161
unsigned getGenSigArgumentLayoutSizeInWords() const {

include/swift/ABI/MetadataValues.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ class ExtendedExistentialTypeShapeFlags {
853853
HasSuggestedValueWitnesses = 0x00000400U,
854854
HasImplicitReqSigParams = 0x00000800U,
855855
HasImplicitGenSigParams = 0x00001000U,
856+
HasTypePacks = 0x00002000U,
856857
};
857858
int_type Data;
858859

@@ -894,6 +895,12 @@ class ExtendedExistentialTypeShapeFlags {
894895
implicit ? (Data | HasImplicitGenSigParams)
895896
: (Data & ~HasImplicitGenSigParams));
896897
}
898+
constexpr ExtendedExistentialTypeShapeFlags
899+
withTypePacks(bool hasTypePacks) const {
900+
return ExtendedExistentialTypeShapeFlags(
901+
hasTypePacks ? (Data | HasTypePacks)
902+
: (Data & ~HasTypePacks));
903+
}
897904

898905
/// Is this a special kind of existential?
899906
SpecialKind getSpecialKind() const {
@@ -939,6 +946,14 @@ class ExtendedExistentialTypeShapeFlags {
939946
return Data & HasImplicitGenSigParams;
940947
}
941948

949+
/// Whether the generic context has type parameter packs. This
950+
/// occurs when the existential has a superclass requirement
951+
/// whose class declaration has a type parameter pack, eg
952+
/// `any P & C<...>` with `class C<each T> {}`.
953+
bool hasTypePacks() const {
954+
return Data & HasTypePacks;
955+
}
956+
942957
int_type getIntValue() const {
943958
return Data;
944959
}

0 commit comments

Comments
 (0)