Skip to content

Commit a729252

Browse files
committed
[NCGenerics] fix a few isNoncopyable calls
These calls were being made on types either with a type parameter, or a SIL-only type that doesn't actually have conformances. In such cases, it's better to use SILType's move-only query methods.
1 parent 6d1e5c3 commit a729252

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5539,7 +5539,9 @@ class SILMoveOnlyWrappedType final : public TypeBase,
55395539
: TypeBase(TypeKind::SILMoveOnlyWrapped, &innerType->getASTContext(),
55405540
innerType->getRecursiveProperties()),
55415541
innerType(innerType) {
5542-
assert(!innerType->isNoncopyable() && "Inner type must be copyable");
5542+
// If it has a type parameter, we can't check whether it's copyable.
5543+
assert(innerType->hasTypeParameter() ||
5544+
!innerType->isNoncopyable() && "Inner type must be copyable");
55435545
}
55445546

55455547
public:

lib/SIL/IR/SILType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ bool SILType::isMoveOnly() const {
10621062
auto ty = getASTType();
10631063

10641064
// All kinds of references are copyable.
1065+
// FIXME: this doesn't match with how isNoncopyable in the AST handles it!
10651066
if (isa<ReferenceStorageType>(ty))
10661067
return false;
10671068

lib/SILOptimizer/Utils/InstructionDeleter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ static bool isScopeAffectingInstructionDead(SILInstruction *inst,
7171
// getSingleValueCopyOrCast returns true. That function returns true for
7272
// move_value instructions. And `move_value %moveOnlyValue` must not be
7373
// deleted.
74-
if (result->getType().getASTType()->isNoncopyable() &&
74+
auto type = result->getType();
75+
if (type.isMoveOnly() && !type.isMoveOnlyWrapped() &&
7576
result->getOwnershipKind() == OwnershipKind::Owned) {
7677
return false;
7778
}

0 commit comments

Comments
 (0)