Skip to content

Commit 340bd26

Browse files
committed
SwiftCompilerSources: bridge isNoEscape and mayEscape.
1 parent ced850d commit 340bd26

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ 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() }
6261

6362
public var canBeClass: BridgedType.TraitResult { bridged.canBeClass() }
6463

6564
public var isMoveOnly: Bool { bridged.isMoveOnly() }
6665

66+
public var isEscapable: Bool { bridged.isEscapable() }
67+
public var mayEscape: Bool { !isNoEscapeFunction && isEscapable }
68+
6769
/// Can only be used if the type is in fact a nominal type (`isNominal` is true).
6870
public var nominal: NominalTypeDecl {
6971
NominalTypeDecl(_bridged: bridged.getNominalOrBoundGenericNominal())

include/swift/AST/Types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
657657
/// Returns true if this contextual type satisfies a conformance to Escapable.
658658
bool isEscapable();
659659

660+
/// Returns true if this contextual type is (Escapable && !isNoEscape).
661+
bool mayEscape() { return !isNoEscape() && isEscapable(); }
662+
660663
/// Does the type have outer parenthesis?
661664
bool hasParenSugar() const { return getKind() == TypeKind::Paren; }
662665

include/swift/SIL/SILBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ struct BridgedASTType {
243243

244244
BRIDGED_INLINE bool isEscapable() const;
245245

246+
BRIDGED_INLINE bool isNoEscape() const;
247+
248+
inline bool mayEscape() const { return !isNoEscape() && isEscapable(); }
249+
246250
// =========================================================================//
247251
// SILFunctionType
248252
// =========================================================================//

include/swift/SIL/SILBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ bool BridgedASTType::isEscapable() const {
9393
return unbridged()->isEscapable();
9494
}
9595

96+
bool BridgedASTType::isNoEscape() const {
97+
return unbridged()->isNoEscape();
98+
}
99+
96100
BridgedResultInfoArray
97101
BridgedASTType::SILFunctionType_getResultsWithError() const {
98102
return unbridged()->castTo<swift::SILFunctionType>()->getResultsWithError();

include/swift/SIL/SILType.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,12 @@ class SILType {
899899
/// lifetime dependence.
900900
bool isEscapable() const;
901901

902+
/// True for (isEscapable && !isNoEscapeFunction)
903+
///
904+
/// Equivalent to getASTType()->mayEscape(), but handles SIL-specific types,
905+
/// namely SILFunctionType.
906+
bool mayEscape() const { return !isNoEscapeFunction() && isEscapable(); }
907+
902908
//
903909
// Accessors for types used in SIL instructions:
904910
//

lib/SIL/IR/SILType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,8 @@ bool SILType::isEscapable() const {
10531053
ty = refStorage->getReferentType()->getCanonicalType();
10541054

10551055
if (auto fnTy = getAs<SILFunctionType>()) {
1056-
return !fnTy->isNoEscape();
1056+
// Use isNoEscape instead to determine whether a function type may escape.
1057+
return true;
10571058
}
10581059
if (auto boxTy = getAs<SILBoxType>()) {
10591060
auto fields = boxTy->getLayout()->getFields();

0 commit comments

Comments
 (0)