Skip to content

Commit 045253e

Browse files
committed
Add SILType::isEscapable
1 parent fca92e4 commit 045253e

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
5858
public var isMetatype: Bool { bridged.isMetatype() }
5959
public var isNoEscapeFunction: Bool { bridged.isNoEscapeFunction() }
6060
public var isAsyncFunction: Bool { bridged.isAsyncFunction() }
61+
public var isEscapable: Bool { bridged.isEscapable() }
6162

6263
public var canBeClass: BridgedType.TraitResult { bridged.canBeClass() }
6364

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct BridgedType {
110110
BRIDGED_INLINE bool isAsyncFunction() const;
111111
BRIDGED_INLINE TraitResult canBeClass() const;
112112
BRIDGED_INLINE bool isMoveOnly() const;
113+
BRIDGED_INLINE bool isEscapable() const;
113114
BRIDGED_INLINE bool isOrContainsObjectiveCClass() const;
114115
BRIDGED_INLINE bool isBuiltinInteger() const;
115116
BRIDGED_INLINE bool isBuiltinFloat() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ bool BridgedType::isMoveOnly() const {
140140
return get().isMoveOnly();
141141
}
142142

143+
bool BridgedType::isEscapable() const {
144+
return get().isEscapable();
145+
}
146+
143147
bool BridgedType::isOrContainsObjectiveCClass() const {
144148
return get().isOrContainsObjectiveCClass();
145149
}

include/swift/SIL/SILType.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ class SILType {
881881
ProtocolConformanceRef conformsToProtocol(SILFunction *fn,
882882
ProtocolDecl *protocol) const;
883883

884+
/// False if SILValues of this type cannot be used outside the scope of their
885+
/// lifetime dependence.
886+
bool isEscapable() const;
887+
884888
//
885889
// Accessors for types used in SIL instructions:
886890
//

lib/SIL/IR/SILType.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,13 @@ bool SILType::isMarkedAsImmortal() const {
11301130
return false;
11311131
}
11321132

1133+
bool SILType::isEscapable() const {
1134+
if (auto *nom = getASTType().getAnyNominal())
1135+
return nom->isEscapable();
1136+
1137+
return true;
1138+
}
1139+
11331140
intptr_t SILType::getFieldIdxOfNominalType(StringRef fieldName) const {
11341141
auto *nominal = getNominalOrBoundGenericNominal();
11351142
if (!nominal)

0 commit comments

Comments
 (0)