Skip to content

Commit 1834469

Browse files
authored
Merge pull request #64063 from slavapestov/more-variadic-generic-types-runtime-work
More variadic generic types runtime work
2 parents cded83a + 66ed09e commit 1834469

File tree

12 files changed

+330
-267
lines changed

12 files changed

+330
-267
lines changed

include/swift/ABI/GenericContext.h

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,6 @@ struct TargetProtocolConformanceDescriptor;
3030
template <typename Runtime>
3131
struct TargetGenericContext;
3232

33-
class GenericContextDescriptorFlags {
34-
uint16_t Value;
35-
36-
public:
37-
constexpr GenericContextDescriptorFlags() : Value(0) {}
38-
39-
explicit constexpr GenericContextDescriptorFlags(uint16_t value)
40-
: Value(value) {}
41-
42-
constexpr GenericContextDescriptorFlags(bool hasTypePacks)
43-
: GenericContextDescriptorFlags(
44-
GenericContextDescriptorFlags((uint16_t)0)
45-
.withHasTypePacks(hasTypePacks)) {}
46-
47-
/// Whether this generic context has at least one type parameter
48-
/// pack, in which case the generic context will have a trailing
49-
/// GenericPackShapeHeader.
50-
constexpr bool hasTypePacks() const {
51-
return (Value & 0x1) != 0;
52-
}
53-
54-
constexpr GenericContextDescriptorFlags
55-
withHasTypePacks(bool hasTypePacks) const {
56-
return GenericContextDescriptorFlags((uint16_t)(
57-
(Value & ~0x1) | (hasTypePacks ? 0x1 : 0)));
58-
}
59-
60-
constexpr uint16_t getIntValue() const {
61-
return Value;
62-
}
63-
};
64-
6533
template <typename Runtime>
6634
struct TargetGenericContextDescriptorHeader {
6735
/// The number of (source-written) generic parameters, and thus
@@ -87,15 +55,25 @@ struct TargetGenericContextDescriptorHeader {
8755
uint16_t NumRequirements;
8856

8957
/// The size of the "key" area of the argument layout, in words.
90-
/// Key arguments include generic parameters and conformance
91-
/// requirements which are part of the identity of the context.
58+
/// Key arguments include shape classes, generic parameters and
59+
/// conformance requirements which are part of the identity of
60+
/// the context.
61+
///
62+
/// The key area of the argument layout consists of:
63+
///
64+
/// - a sequence of pack lengths, in the same order as the parameter
65+
/// descriptors which satisfy getKind() == GenericParamKind::TypePack
66+
/// and hasKeyArgument();
67+
///
68+
/// - a sequence of metadata or metadata pack pointers, in the same
69+
/// order as the parameter descriptors which satisfy hasKeyArgument();
9270
///
93-
/// The key area of the argument layout consists of a sequence
94-
/// of type metadata pointers (in the same order as the parameter
95-
/// descriptors, for those parameters which satisfy hasKeyArgument())
96-
/// followed by a sequence of witness table pointers (in the same
97-
/// order as the requirements, for those requirements which satisfy
98-
/// hasKeyArgument()).
71+
/// - a sequence of witness table or witness table pack pointers, in the
72+
/// same order as the requirement descriptors which satisfy
73+
/// hasKeyArgument().
74+
///
75+
/// The elements above which are packs are precisely those appearing
76+
/// in the sequence of trailing GenericPackShapeDescriptors.
9977
uint16_t NumKeyArguments;
10078

10179
/// Originally this was the size of the "extra" area of the argument
@@ -260,11 +238,6 @@ struct GenericPackShapeHeader {
260238
uint16_t NumShapeClasses;
261239
};
262240

263-
enum class GenericPackKind: uint16_t {
264-
Metadata = 0,
265-
WitnessTable = 1
266-
};
267-
268241
/// The GenericPackShapeHeader is followed by an array of these descriptors,
269242
/// whose length is given by the header's NumPacks field.
270243
///
@@ -536,13 +509,6 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
536509
header.NumPacks};
537510
}
538511

539-
/// Return the amount of space that the generic arguments take up in
540-
/// metadata of this type.
541-
StoredSize getGenericArgumentsStorageSize() const {
542-
return StoredSize(getGenericContextHeader().getNumArguments())
543-
* sizeof(StoredPointer);
544-
}
545-
546512
RuntimeGenericSignature<Runtime> getGenericSignature() const {
547513
if (!asSelf()->isGeneric()) return RuntimeGenericSignature<Runtime>();
548514
return {getGenericContextHeader(),

include/swift/ABI/MetadataValues.h

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,38 @@ class AnonymousContextDescriptorFlags : public FlagSet<uint16_t> {
18121812
setHasMangledName)
18131813
};
18141814

1815+
class GenericContextDescriptorFlags {
1816+
uint16_t Value;
1817+
1818+
public:
1819+
constexpr GenericContextDescriptorFlags() : Value(0) {}
1820+
1821+
explicit constexpr GenericContextDescriptorFlags(uint16_t value)
1822+
: Value(value) {}
1823+
1824+
constexpr GenericContextDescriptorFlags(bool hasTypePacks)
1825+
: GenericContextDescriptorFlags(
1826+
GenericContextDescriptorFlags((uint16_t)0)
1827+
.withHasTypePacks(hasTypePacks)) {}
1828+
1829+
/// Whether this generic context has at least one type parameter
1830+
/// pack, in which case the generic context will have a trailing
1831+
/// GenericPackShapeHeader.
1832+
constexpr bool hasTypePacks() const {
1833+
return (Value & 0x1) != 0;
1834+
}
1835+
1836+
constexpr GenericContextDescriptorFlags
1837+
withHasTypePacks(bool hasTypePacks) const {
1838+
return GenericContextDescriptorFlags((uint16_t)(
1839+
(Value & ~0x1) | (hasTypePacks ? 0x1 : 0)));
1840+
}
1841+
1842+
constexpr uint16_t getIntValue() const {
1843+
return Value;
1844+
}
1845+
};
1846+
18151847
enum class GenericParamKind : uint8_t {
18161848
/// A type parameter.
18171849
Type = 0,
@@ -1823,28 +1855,23 @@ enum class GenericParamKind : uint8_t {
18231855
};
18241856

18251857
class GenericParamDescriptor {
1858+
/// Don't set 0x40 for compatibility with pre-Swift 5.8 runtimes
18261859
uint8_t Value;
18271860

18281861
explicit constexpr GenericParamDescriptor(uint8_t Value)
18291862
: Value(Value) {}
18301863
public:
18311864
constexpr GenericParamDescriptor(GenericParamKind kind,
1832-
bool hasKeyArgument,
1833-
bool hasExtraArgument)
1865+
bool hasKeyArgument)
18341866
: GenericParamDescriptor(GenericParamDescriptor(0)
18351867
.withKind(kind)
1836-
.withKeyArgument(hasKeyArgument)
1837-
.withExtraArgument(hasExtraArgument))
1868+
.withKeyArgument(hasKeyArgument))
18381869
{}
18391870

18401871
constexpr bool hasKeyArgument() const {
18411872
return (Value & 0x80u) != 0;
18421873
}
18431874

1844-
constexpr bool hasExtraArgument() const {
1845-
return (Value & 0x40u) != 0;
1846-
}
1847-
18481875
constexpr GenericParamKind getKind() const {
18491876
return GenericParamKind(Value & 0x3Fu);
18501877
}
@@ -1855,12 +1882,6 @@ class GenericParamDescriptor {
18551882
| (hasKeyArgument ? 0x80u : 0));
18561883
}
18571884

1858-
constexpr GenericParamDescriptor
1859-
withExtraArgument(bool hasExtraArgument) const {
1860-
return GenericParamDescriptor((Value & 0xBFu)
1861-
| (hasExtraArgument ? 0x40u : 0));
1862-
}
1863-
18641885
constexpr GenericParamDescriptor withKind(GenericParamKind kind) const {
18651886
return assert((uint8_t(kind) & 0x3Fu) == uint8_t(kind)),
18661887
GenericParamDescriptor((Value & 0xC0u) | uint8_t(kind));
@@ -1882,8 +1903,7 @@ class GenericParamDescriptor {
18821903
/// The default parameter descriptor for an implicit parameter.
18831904
static constexpr GenericParamDescriptor implicit() {
18841905
return GenericParamDescriptor(GenericParamKind::Type,
1885-
/*key argument*/ true,
1886-
/*extra argument*/ false);
1906+
/*key argument*/ true);
18871907
}
18881908
};
18891909

@@ -1920,30 +1940,25 @@ enum class GenericRequirementKind : uint8_t {
19201940
};
19211941

19221942
class GenericRequirementFlags {
1943+
/// Don't set 0x40 for compatibility with pre-Swift 5.8 runtimes
19231944
uint32_t Value;
19241945

19251946
explicit constexpr GenericRequirementFlags(uint32_t Value)
19261947
: Value(Value) {}
19271948
public:
19281949
constexpr GenericRequirementFlags(GenericRequirementKind kind,
19291950
bool hasKeyArgument,
1930-
bool hasExtraArgument,
19311951
bool isPackRequirement)
19321952
: GenericRequirementFlags(GenericRequirementFlags(0)
19331953
.withKind(kind)
19341954
.withKeyArgument(hasKeyArgument)
1935-
.withExtraArgument(hasExtraArgument)
19361955
.withPackRequirement(isPackRequirement))
19371956
{}
19381957

19391958
constexpr bool hasKeyArgument() const {
19401959
return (Value & 0x80u) != 0;
19411960
}
19421961

1943-
constexpr bool hasExtraArgument() const {
1944-
return (Value & 0x40u) != 0;
1945-
}
1946-
19471962
/// If this is true, the subject type of the requirement is a pack.
19481963
/// When the requirement is a conformance requirement, the corresponding
19491964
/// entry in the generic arguments array becomes a TargetWitnessTablePack.
@@ -1961,12 +1976,6 @@ class GenericRequirementFlags {
19611976
| (hasKeyArgument ? 0x80u : 0));
19621977
}
19631978

1964-
constexpr GenericRequirementFlags
1965-
withExtraArgument(bool hasExtraArgument) const {
1966-
return GenericRequirementFlags((Value & 0xBFu)
1967-
| (hasExtraArgument ? 0x40u : 0));
1968-
}
1969-
19701979
constexpr GenericRequirementFlags
19711980
withPackRequirement(bool isPackRequirement) const {
19721981
return GenericRequirementFlags((Value & 0xBFu)
@@ -1989,6 +1998,11 @@ enum class GenericRequirementLayoutKind : uint32_t {
19891998
Class = 0,
19901999
};
19912000

2001+
enum class GenericPackKind : uint16_t {
2002+
Metadata = 0,
2003+
WitnessTable = 1
2004+
};
2005+
19922006
class GenericEnvironmentFlags {
19932007
uint32_t Value;
19942008

include/swift/Remote/MetadataReader.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,11 +3026,6 @@ class MetadataReader {
30263026
for (auto param : generics->getGenericParams()) {
30273027
switch (param.getKind()) {
30283028
case GenericParamKind::Type:
3029-
// We don't know about type parameters with extra arguments.
3030-
if (param.hasExtraArgument()) {
3031-
return {};
3032-
}
3033-
30343029
// The type should have a key argument unless it's been same-typed
30353030
// to another type.
30363031
if (param.hasKeyArgument()) {
@@ -3057,6 +3052,9 @@ class MetadataReader {
30573052
}
30583053
break;
30593054

3055+
case GenericParamKind::TypePack:
3056+
assert(false && "Packs not supported here yet");
3057+
30603058
default:
30613059
// We don't know about this kind of parameter.
30623060
return {};

include/swift/Runtime/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ bool swift_compareProtocolConformanceDescriptors(
457457
/// bit set to true.
458458
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
459459
const Metadata * const *
460-
swift_allocateMetadataPack(const Metadata * const *ptr, unsigned count);
460+
swift_allocateMetadataPack(const Metadata * const *ptr, size_t count);
461461

462462
/// Allocate a witness table pack on the heap, unless this pack is already on
463463
/// the heap.
@@ -472,7 +472,7 @@ swift_allocateMetadataPack(const Metadata * const *ptr, unsigned count);
472472
/// significant bit set to true.
473473
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
474474
const WitnessTable * const *
475-
swift_allocateWitnessTablePack(const WitnessTable * const *ptr, unsigned count);
475+
swift_allocateWitnessTablePack(const WitnessTable * const *ptr, size_t count);
476476

477477
/// Fetch a uniqued metadata for a function type.
478478
SWIFT_RUNTIME_EXPORT

0 commit comments

Comments
 (0)