Skip to content

Commit 13db95e

Browse files
committed
BridgedASTType::isEscapable
1 parent 3682d8e commit 13db95e

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ struct BridgedASTType {
195195

196196
BRIDGED_INLINE bool isOpenedExistentialWithError() const;
197197

198+
BRIDGED_INLINE bool isEscapable() const;
199+
198200
// =========================================================================//
199201
// SILFunctionType
200202
// =========================================================================//

include/swift/SIL/SILBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ bool BridgedASTType::isOpenedExistentialWithError() const {
7777
return unbridged()->isOpenedExistentialWithError();
7878
}
7979

80+
bool BridgedASTType::isEscapable() const {
81+
return unbridged()->isEscapable();
82+
}
83+
8084
BridgedResultInfoArray
8185
BridgedASTType::SILFunctionType_getResultsWithError() const {
8286
return unbridged()->castTo<swift::SILFunctionType>()->getResultsWithError();

lib/SIL/IR/SILType.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,31 @@ SILType::getSingletonAggregateFieldType(SILModule &M,
10461046
}
10471047

10481048
bool SILType::isEscapable() const {
1049-
return getASTType()->isEscapable();
1049+
CanType ty = getASTType();
1050+
1051+
// For storage with reference ownership, check the referent.
1052+
if (auto refStorage = ty->getAs<ReferenceStorageType>())
1053+
ty = refStorage->getReferentType()->getCanonicalType();
1054+
1055+
if (auto fnTy = getAs<SILFunctionType>()) {
1056+
return !fnTy->isNoEscape();
1057+
}
1058+
if (auto boxTy = getAs<SILBoxType>()) {
1059+
auto fields = boxTy->getLayout()->getFields();
1060+
assert(fields.size() == 1);
1061+
ty = fields[0].getLoweredType();
1062+
}
1063+
1064+
// TODO: Support ~Escapable in parameter packs.
1065+
//
1066+
// Treat all other SIL-specific types as Escapable.
1067+
if (isa<SILBlockStorageType,
1068+
SILBoxType,
1069+
SILPackType,
1070+
SILTokenType>(ty)) {
1071+
return true;
1072+
}
1073+
return ty->isEscapable();
10501074
}
10511075

10521076
bool SILType::isMoveOnly(bool orWrapped) const {

0 commit comments

Comments
 (0)