Skip to content

Commit bb8b1e1

Browse files
authored
Merge pull request #83984 from kavon/avoid-not-noncopyable
nfc: avoid !isNoncopyable()
2 parents 2f5cfad + 3bb8fa8 commit bb8b1e1

15 files changed

+26
-18
lines changed

include/swift/AST/Types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
699699
/// Copyable.
700700
bool isNoncopyable();
701701

702+
/// Returns true if this contextual type satisfies a conformance to Copyable.
703+
bool isCopyable();
704+
702705
/// Returns true if this contextual type satisfies a conformance to Escapable.
703706
bool isEscapable();
704707

@@ -6105,7 +6108,7 @@ class SILMoveOnlyWrappedType final : public TypeBase,
61056108
innerType(innerType) {
61066109
// If it has a type parameter, we can't check whether it's copyable.
61076110
assert(innerType->hasTypeParameter() ||
6108-
!innerType->isNoncopyable() && "Inner type must be copyable");
6111+
innerType->isCopyable() && "Inner type must be copyable");
61096112
}
61106113

61116114
public:

lib/AST/ConformanceLookup.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,11 @@ bool TypeBase::isNoncopyable() {
946946
return !Bits.TypeBase.IsCopyable;
947947
}
948948

949+
/// \returns true iff this type conforms to Copyable.
950+
bool TypeBase::isCopyable() {
951+
return !isNoncopyable();
952+
}
953+
949954
/// \returns true iff this type conforms to Escaping.
950955
bool TypeBase::isEscapable() {
951956
if (!Bits.TypeBase.ComputedInvertibleConformances)

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8571,7 +8571,7 @@ LifetimeAnnotation ParamDecl::getLifetimeAnnotation() const {
85718571
auto specifier = getSpecifier();
85728572
// Copyable parameters which are consumed have eager-move semantics.
85738573
if (specifier == ParamDecl::Specifier::Consuming &&
8574-
!getTypeInContext()->isNoncopyable()) {
8574+
getTypeInContext()->isCopyable()) {
85758575
if (getAttrs().hasAttribute<NoEagerMoveAttr>())
85768576
return LifetimeAnnotation::Lexical;
85778577
return LifetimeAnnotation::EagerMove;
@@ -11429,7 +11429,7 @@ LifetimeAnnotation FuncDecl::getLifetimeAnnotation() const {
1142911429
// Copyable parameters which are consumed have eager-move semantics.
1143011430
if (getSelfAccessKind() == SelfAccessKind::Consuming) {
1143111431
auto *selfDecl = getImplicitSelfDecl();
11432-
if (selfDecl && !selfDecl->getTypeInContext()->isNoncopyable()) {
11432+
if (selfDecl && selfDecl->getTypeInContext()->isCopyable()) {
1143311433
if (getAttrs().hasAttribute<NoEagerMoveAttr>())
1143411434
return LifetimeAnnotation::Lexical;
1143511435
return LifetimeAnnotation::EagerMove;

lib/AST/Pattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ Pattern::getOwnership(
797797
case VarDecl::Introducer::Var:
798798
// If the subpattern type is copyable, then we can bind the variable
799799
// by copying without requiring more than a borrow of the original.
800-
if (!p->hasType() || !p->getType()->isNoncopyable()) {
800+
if (!p->hasType() || p->getType()->isCopyable()) {
801801
break;
802802
}
803803
// TODO: An explicit `consuming` binding kind consumes regardless of

lib/IRGen/GenType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3054,7 +3054,7 @@ IsABIAccessible_t irgen::isTypeABIAccessibleIfFixedSize(IRGenModule &IGM,
30543054
CanType ty) {
30553055

30563056
// Copyable types currently are always ABI-accessible if they're fixed size.
3057-
if (!ty->isNoncopyable())
3057+
if (ty->isCopyable())
30583058
return IsABIAccessible;
30593059

30603060
// Check for a deinit. If this type does not define a deinit it is ABI

lib/SIL/IR/SIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ getKeyPathSupportingGenericSignature(Type ty, GenericSignature contextSig) {
319319

320320
// If the type is already unconditionally Copyable and Escapable, we don't
321321
// need any further requirements.
322-
if (!ty->isNoncopyable() && ty->isEscapable()) {
322+
if (ty->isCopyable() && ty->isEscapable()) {
323323
return contextSig;
324324
}
325325

lib/SIL/IR/SILType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ SILType SILType::addingMoveOnlyWrapperToBoxedType(const SILFunction *fn) {
12391239
auto oldField = oldLayout->getFields()[0];
12401240
if (oldField.getLoweredType()->is<SILMoveOnlyWrappedType>())
12411241
return *this;
1242-
assert(!oldField.getLoweredType()->isNoncopyable() &&
1242+
assert(oldField.getLoweredType()->isCopyable() &&
12431243
"Cannot moveonlywrapped in a moveonly type");
12441244
auto newField =
12451245
SILField(SILMoveOnlyWrappedType::get(oldField.getLoweredType()),

lib/SIL/IR/TypeLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ CaptureKind TypeConverter::getDeclCaptureKind(CapturedValue capture,
128128
contextTy, TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
129129
expansion.getResilienceExpansion()));
130130

131-
assert(!contextTy->isNoncopyable() && "Not implemented");
131+
assert(contextTy->isCopyable() && "Not implemented");
132132
if (!props.isAddressOnly())
133133
return CaptureKind::Constant;
134134

lib/SILGen/SILGenDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ class LocalVariableInitialization : public SingleBufferInitialization {
561561

562562
// If our instance type is not already @moveOnly wrapped, and it's a
563563
// no-implicit-copy parameter, wrap it.
564-
if (!isNoImplicitCopy && !instanceType->isNoncopyable()) {
564+
if (!isNoImplicitCopy && instanceType->isCopyable()) {
565565
if (auto *pd = dyn_cast<ParamDecl>(decl)) {
566566
isNoImplicitCopy = pd->isNoImplicitCopy();
567567
isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Consuming;
@@ -577,7 +577,7 @@ class LocalVariableInitialization : public SingleBufferInitialization {
577577
}
578578
}
579579

580-
const bool isCopyable = isNoImplicitCopy || !instanceType->isNoncopyable();
580+
const bool isCopyable = isNoImplicitCopy || instanceType->isCopyable();
581581

582582
auto boxType = SGF.SGM.Types.getContextBoxTypeForCapture(
583583
decl, instanceType, SGF.F.getGenericEnvironment(),
@@ -1548,7 +1548,7 @@ SILGenFunction::emitInitializationForVarDecl(VarDecl *vd, bool forceImmutable,
15481548
// If this is a 'let' initialization for a copyable non-global, set up a let
15491549
// binding, which stores the initialization value into VarLocs directly.
15501550
if (forceImmutable && vd->getDeclContext()->isLocalContext() &&
1551-
!isa<ReferenceStorageType>(varType) && !varType->isNoncopyable())
1551+
!isa<ReferenceStorageType>(varType) && varType->isCopyable())
15521552
return InitializationPtr(new LetValueInitialization(vd, *this));
15531553

15541554
// If the variable has no initial value, emit a mark_uninitialized instruction

lib/SILGen/SILGenPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ void PatternMatchEmission::bindIrrefutableBorrows(const ClauseRow &row,
13081308
// explicitly `borrowing`, then we can bind it as a normal copyable
13091309
// value.
13101310
if (named->getDecl()->getIntroducer() != VarDecl::Introducer::Borrowing
1311-
&& !named->getType()->isNoncopyable()) {
1311+
&& named->getType()->isCopyable()) {
13121312
bindVariable(pattern, named->getDecl(), args[i], forIrrefutableRow,
13131313
hasMultipleItems);
13141314
} else {

0 commit comments

Comments
 (0)