Skip to content

Commit 5076fec

Browse files
committed
SIL: add the recursive property isOrContainsRawLayout to SILTypeProperties
1 parent 0a953b6 commit 5076fec

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

include/swift/SIL/SILTypeProperties.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ enum IsAddressableForDependencies_t : bool {
110110
IsAddressableForDependencies = true,
111111
};
112112

113+
/// Is a lowered SIL type a struct with `@_rawLayout` or contains such a struct?
114+
enum HasRawLayout_t : bool {
115+
DoesNotHaveRawLayout = false,
116+
HasRawLayout = true
117+
};
118+
113119
class SILTypeProperties {
114120
// These are chosen so that bitwise-or merges the flags properly.
115121
//
@@ -125,6 +131,7 @@ class SILTypeProperties {
125131
LexicalFlag = 1 << 7,
126132
HasPackFlag = 1 << 8,
127133
AddressableForDependenciesFlag = 1 << 9,
134+
HasRawLayoutFlag = 1 << 10,
128135
};
129136
// clang-format on
130137

@@ -142,7 +149,8 @@ class SILTypeProperties {
142149
IsNotTypeExpansionSensitive,
143150
HasRawPointer_t hasRawPointer = DoesNotHaveRawPointer,
144151
IsLexical_t isLexical = IsNotLexical, HasPack_t hasPack = HasNoPack,
145-
IsAddressableForDependencies_t isAFD = IsNotAddressableForDependencies)
152+
IsAddressableForDependencies_t isAFD = IsNotAddressableForDependencies,
153+
HasRawLayout_t hasRawLayout = DoesNotHaveRawLayout)
146154
: Flags((isTrivial ? 0U : NonTrivialFlag) |
147155
(isFixedABI ? 0U : NonFixedABIFlag) |
148156
(isAddressOnly ? AddressOnlyFlag : 0U) |
@@ -151,7 +159,8 @@ class SILTypeProperties {
151159
(hasRawPointer ? HasRawPointerFlag : 0U) |
152160
(isLexical ? LexicalFlag : 0U) |
153161
(hasPack ? HasPackFlag : 0U) |
154-
(isAFD ? AddressableForDependenciesFlag : 0U)) {}
162+
(isAFD ? AddressableForDependenciesFlag : 0U) |
163+
(hasRawLayout ? HasRawLayoutFlag : 0U)) {}
155164

156165
constexpr bool operator==(SILTypeProperties p) const {
157166
return Flags == p.Flags;
@@ -180,7 +189,7 @@ class SILTypeProperties {
180189
static constexpr SILTypeProperties forOpaque() {
181190
return {IsNotTrivial, IsNotFixedABI, IsAddressOnly, IsNotResilient,
182191
IsNotTypeExpansionSensitive, HasRawPointer, IsLexical,
183-
HasNoPack, IsAddressableForDependencies};
192+
HasNoPack, IsAddressableForDependencies, HasRawLayout};
184193
}
185194

186195
static constexpr SILTypeProperties forResilient() {
@@ -228,6 +237,9 @@ class SILTypeProperties {
228237
return IsAddressableForDependencies_t(
229238
(Flags & AddressableForDependenciesFlag) != 0);
230239
}
240+
HasRawLayout_t isOrContainsRawLayout() const {
241+
return HasRawLayout_t((Flags & HasRawLayoutFlag) != 0);
242+
}
231243

232244
void setNonTrivial() { Flags |= NonTrivialFlag; }
233245
void setIsOrContainsRawPointer() { Flags |= HasRawPointerFlag; }
@@ -247,6 +259,9 @@ class SILTypeProperties {
247259
void setAddressableForDependencies() {
248260
Flags |= AddressableForDependenciesFlag;
249261
}
262+
void setHasRawLayout() {
263+
Flags |= HasRawLayoutFlag;
264+
}
250265
};
251266

252267
} // end namespace swift

lib/SIL/IR/TypeLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,7 @@ namespace {
25472547

25482548
// If the type has raw storage, it is move-only and address-only.
25492549
if (D->getAttrs().hasAttribute<RawLayoutAttr>()) {
2550+
properties.setHasRawLayout();
25502551
properties.setAddressOnly();
25512552
properties.setAddressableForDependencies();
25522553
properties.setNonTrivial();

0 commit comments

Comments
 (0)