Skip to content

Commit 22df096

Browse files
committed
[sil] Add a helper SILType::isBoxedNonCopyableType().
I am using this query a lot in SILGen when adding support for escaping captures. Makes sense to chop it off into a nice little helper on SILType.
1 parent d458ed1 commit 22df096

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

include/swift/SIL/SILType.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ class SILType {
695695
///
696696
/// \p field Return the type of the ith field of the box. Default set to 0
697697
/// since we only support one field today. This is just future proofing.
698-
SILType getSILBoxFieldType(const SILFunction *f, unsigned field = 0);
698+
SILType getSILBoxFieldType(const SILFunction *f, unsigned field = 0) const;
699699

700700
/// Returns the hash code for the SILType.
701701
llvm::hash_code getHashCode() const {
@@ -708,6 +708,17 @@ class SILType {
708708
SILType getSingletonAggregateFieldType(SILModule &M,
709709
ResilienceExpansion expansion) const;
710710

711+
/// \returns true if this is a SILBoxType containing a noncopyable type.
712+
bool isBoxedNonCopyableType(const SILFunction *fn) const {
713+
if (!this->is<SILBoxType>())
714+
return false;
715+
return getSILBoxFieldType(fn).isMoveOnly();
716+
}
717+
718+
bool isBoxedNonCopyableType(const SILFunction &fn) const {
719+
return isBoxedNonCopyableType(&fn);
720+
}
721+
711722
//
712723
// Accessors for types used in SIL instructions:
713724
//

lib/SIL/IR/SILType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ bool SILType::isEffectivelyExhaustiveEnumType(SILFunction *f) {
861861
f->getResilienceExpansion());
862862
}
863863

864-
SILType SILType::getSILBoxFieldType(const SILFunction *f, unsigned field) {
864+
SILType SILType::getSILBoxFieldType(const SILFunction *f, unsigned field) const {
865865
auto *boxTy = getASTType()->getAs<SILBoxType>();
866866
if (!boxTy)
867867
return SILType();

0 commit comments

Comments
 (0)