Skip to content

Commit 7752fbf

Browse files
committed
SIL: add Type.selfOrAnyFieldHasValueDeinit
Implemented by adding a recursive property in TypeLowering
1 parent bf62e44 commit 7752fbf

File tree

7 files changed

+40
-2
lines changed

7 files changed

+40
-2
lines changed

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
4343
return bridged.isReferenceCounted(function.bridged)
4444
}
4545

46+
public func selfOrAnyFieldHasValueDeinit(in function: Function) -> Bool {
47+
return bridged.selfOrAnyFieldHasValueDeinit(function.bridged)
48+
}
49+
4650
public var isUnownedStorageType: Bool {
4751
return bridged.isUnownedStorageType()
4852
}
@@ -207,7 +211,7 @@ extension BridgedType {
207211

208212
// TODO: use an AST type for this once we have it
209213
public struct NominalTypeDecl : Equatable, Hashable {
210-
private let bridged: BridgedNominalTypeDecl
214+
public let bridged: BridgedNominalTypeDecl
211215

212216
public init(_bridged: BridgedNominalTypeDecl) {
213217
self.bridged = _bridged
@@ -230,4 +234,8 @@ public struct NominalTypeDecl : Equatable, Hashable {
230234
public var isGlobalActor: Bool {
231235
return bridged.isGlobalActor()
232236
}
237+
238+
public var hasValueDeinit: Bool {
239+
return bridged.hasValueDeinit()
240+
}
233241
}

include/swift/AST/ASTBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ SWIFT_NAME("BridgedNominalTypeDecl.isGlobalActor(self:)")
543543
BRIDGED_INLINE
544544
bool BridgedNominalTypeDecl_isGlobalActor(BridgedNominalTypeDecl decl);
545545

546+
SWIFT_NAME("BridgedNominalTypeDecl.hasValueDeinit(self:)")
547+
BRIDGED_INLINE
548+
bool BridgedNominalTypeDecl_hasValueDeinit(BridgedNominalTypeDecl decl);
549+
546550
SWIFT_NAME("BridgedNominalTypeDecl.setParsedMembers(self:_:)")
547551
void BridgedNominalTypeDecl_setParsedMembers(BridgedNominalTypeDecl decl,
548552
BridgedArrayRef members);

include/swift/AST/ASTBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ bool BridgedNominalTypeDecl_isGlobalActor(BridgedNominalTypeDecl decl) {
4141
return decl.unbridged()->isGlobalActor();
4242
}
4343

44+
bool BridgedNominalTypeDecl_hasValueDeinit(BridgedNominalTypeDecl decl) {
45+
return decl.unbridged()->getValueTypeDestructor() != nullptr;
46+
}
47+
4448
//===----------------------------------------------------------------------===//
4549
// MARK: BridgedVarDecl
4650
//===----------------------------------------------------------------------===//

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct BridgedType {
9696
BRIDGED_INLINE bool isValueTypeWithDeinit() const;
9797
BRIDGED_INLINE bool isLoadable(BridgedFunction f) const;
9898
BRIDGED_INLINE bool isReferenceCounted(BridgedFunction f) const;
99+
BRIDGED_INLINE bool selfOrAnyFieldHasValueDeinit(BridgedFunction f) const;
99100
BRIDGED_INLINE bool isUnownedStorageType() const;
100101
BRIDGED_INLINE bool hasArchetype() const;
101102
BRIDGED_INLINE bool isNominalOrBoundGenericNominal() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ bool BridgedType::isReferenceCounted(BridgedFunction f) const {
8484
return unbridged().isReferenceCounted(f.getFunction());
8585
}
8686

87+
bool BridgedType::selfOrAnyFieldHasValueDeinit(BridgedFunction f) const {
88+
swift::SILType contextType = unbridged().hasTypeParameter() ? f.getFunction()->mapTypeIntoContext(unbridged())
89+
: unbridged();
90+
return f.getFunction()->getTypeLowering(contextType).selfOrAnyFieldHasValueDeinit();
91+
}
92+
8793
bool BridgedType::isUnownedStorageType() const {
8894
return unbridged().isUnownedStorageType();
8995
}

include/swift/SIL/TypeLowering.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ class TypeLowering {
192192
InfiniteFlag = 1 << 5,
193193
HasRawPointerFlag = 1 << 6,
194194
LexicalFlag = 1 << 7,
195+
HasValueDeinitFlag = 1 << 8,
195196
};
196197
// clang-format on
197198

198-
uint8_t Flags;
199+
uint16_t Flags;
199200
public:
200201
/// Construct a default RecursiveProperties, which corresponds to
201202
/// a trivial, loadable, fixed-layout type.
@@ -272,6 +273,9 @@ class TypeLowering {
272273
IsLexical_t isLexical() const {
273274
return IsLexical_t((Flags & LexicalFlag) != 0);
274275
}
276+
bool hasValueDeinit() const {
277+
return (Flags & HasValueDeinitFlag) != 0;
278+
}
275279

276280
void setNonTrivial() { Flags |= NonTrivialFlag; }
277281
void setNonFixedABI() { Flags |= NonFixedABIFlag; }
@@ -285,6 +289,7 @@ class TypeLowering {
285289
void setLexical(IsLexical_t isLexical) {
286290
Flags = (Flags & ~LexicalFlag) | (isLexical ? LexicalFlag : 0);
287291
}
292+
void setHasValueDeinit() { Flags |= HasValueDeinitFlag; }
288293
};
289294

290295
private:
@@ -363,6 +368,10 @@ class TypeLowering {
363368
return Properties.isOrContainsRawPointer();
364369
}
365370

371+
bool selfOrAnyFieldHasValueDeinit() const {
372+
return Properties.hasValueDeinit();
373+
}
374+
366375
/// Returns true if the type is a scalar reference-counted reference, which
367376
/// can be retained and released.
368377
bool isReferenceCounted() const {

lib/SIL/IR/TypeLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,9 @@ namespace {
23692369
properties.setLexical(IsLexical);
23702370
return handleMoveOnlyAddressOnly(structType, properties);
23712371
}
2372+
if (D->getValueTypeDestructor()) {
2373+
properties.setHasValueDeinit();
2374+
}
23722375

23732376
auto subMap = structType->getContextSubstitutionMap(&TC.M, D);
23742377

@@ -2451,6 +2454,9 @@ namespace {
24512454
return new (TC) LoadableEnumTypeLowering(enumType, properties,
24522455
Expansion);
24532456
}
2457+
if (D->getValueTypeDestructor()) {
2458+
properties.setHasValueDeinit();
2459+
}
24542460

24552461
auto subMap = enumType->getContextSubstitutionMap(&TC.M, D);
24562462

0 commit comments

Comments
 (0)