Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
/// Copyable.
bool isNoncopyable();

/// Returns true if this contextual type satisfies a conformance to Copyable.
bool isCopyable();

/// Returns true if this contextual type satisfies a conformance to Escapable.
bool isEscapable();

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

public:
Expand Down
5 changes: 5 additions & 0 deletions lib/AST/ConformanceLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,11 @@ bool TypeBase::isNoncopyable() {
return !Bits.TypeBase.IsCopyable;
}

/// \returns true iff this type conforms to Copyable.
bool TypeBase::isCopyable() {
return !isNoncopyable();
}

/// \returns true iff this type conforms to Escaping.
bool TypeBase::isEscapable() {
if (!Bits.TypeBase.ComputedInvertibleConformances)
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8571,7 +8571,7 @@ LifetimeAnnotation ParamDecl::getLifetimeAnnotation() const {
auto specifier = getSpecifier();
// Copyable parameters which are consumed have eager-move semantics.
if (specifier == ParamDecl::Specifier::Consuming &&
!getTypeInContext()->isNoncopyable()) {
getTypeInContext()->isCopyable()) {
if (getAttrs().hasAttribute<NoEagerMoveAttr>())
return LifetimeAnnotation::Lexical;
return LifetimeAnnotation::EagerMove;
Expand Down Expand Up @@ -11429,7 +11429,7 @@ LifetimeAnnotation FuncDecl::getLifetimeAnnotation() const {
// Copyable parameters which are consumed have eager-move semantics.
if (getSelfAccessKind() == SelfAccessKind::Consuming) {
auto *selfDecl = getImplicitSelfDecl();
if (selfDecl && !selfDecl->getTypeInContext()->isNoncopyable()) {
if (selfDecl && selfDecl->getTypeInContext()->isCopyable()) {
if (getAttrs().hasAttribute<NoEagerMoveAttr>())
return LifetimeAnnotation::Lexical;
return LifetimeAnnotation::EagerMove;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ Pattern::getOwnership(
case VarDecl::Introducer::Var:
// If the subpattern type is copyable, then we can bind the variable
// by copying without requiring more than a borrow of the original.
if (!p->hasType() || !p->getType()->isNoncopyable()) {
if (!p->hasType() || p->getType()->isCopyable()) {
break;
}
// TODO: An explicit `consuming` binding kind consumes regardless of
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3054,7 +3054,7 @@ IsABIAccessible_t irgen::isTypeABIAccessibleIfFixedSize(IRGenModule &IGM,
CanType ty) {

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

// Check for a deinit. If this type does not define a deinit it is ABI
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/SIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ getKeyPathSupportingGenericSignature(Type ty, GenericSignature contextSig) {

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

Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/SILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ SILType SILType::addingMoveOnlyWrapperToBoxedType(const SILFunction *fn) {
auto oldField = oldLayout->getFields()[0];
if (oldField.getLoweredType()->is<SILMoveOnlyWrappedType>())
return *this;
assert(!oldField.getLoweredType()->isNoncopyable() &&
assert(oldField.getLoweredType()->isCopyable() &&
"Cannot moveonlywrapped in a moveonly type");
auto newField =
SILField(SILMoveOnlyWrappedType::get(oldField.getLoweredType()),
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ CaptureKind TypeConverter::getDeclCaptureKind(CapturedValue capture,
contextTy, TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
expansion.getResilienceExpansion()));

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

Expand Down
6 changes: 3 additions & 3 deletions lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ class LocalVariableInitialization : public SingleBufferInitialization {

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

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

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

// If the variable has no initial value, emit a mark_uninitialized instruction
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ void PatternMatchEmission::bindIrrefutableBorrows(const ClauseRow &row,
// explicitly `borrowing`, then we can bind it as a normal copyable
// value.
if (named->getDecl()->getIntroducer() != VarDecl::Introducer::Borrowing
&& !named->getType()->isNoncopyable()) {
&& named->getType()->isCopyable()) {
bindVariable(pattern, named->getDecl(), args[i], forIrrefutableRow,
hasMultipleItems);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ static bool willHaveConfusingConsumption(Type type,
ConstraintLocatorBuilder locator,
ConstraintSystem &cs) {
assert(type);
if (!type->isNoncopyable())
if (type->isCopyable())
return false; /// If it's a copyable type, there's no confusion.

auto loc = cs.getConstraintLocator(locator);
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/PlaygroundTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,9 @@ class Instrumenter : InstrumenterBase {
if (auto *VD = dyn_cast_or_null<ValueDecl>(node.dyn_cast<Decl *>())) {
auto interfaceTy = VD->getInterfaceType();
auto contextualTy = VD->getInnermostDeclContext()->mapTypeIntoContext(interfaceTy);
return !contextualTy->isNoncopyable();
return contextualTy->isCopyable();
} else if (auto *E = node.dyn_cast<Expr *>()) {
return !E->getType()->isNoncopyable();
return E->getType()->isCopyable();
} else {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckInvertible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static void checkInvertibleConformanceCommon(DeclContext *dc,
// For a type conforming to IP, ensure that the storage conforms to IP.
switch (IP) {
case InvertibleProtocolKind::Copyable:
if (!type->isNoncopyable())
if (type->isCopyable())
return false;
break;
case InvertibleProtocolKind::Escapable:
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
fn->mapTypeIntoContext(nominalDecl->getDeclaredInterfaceType());

// must be noncopyable
if (!nominalType->isNoncopyable()) {
if (nominalType->isCopyable()) {
ctx.Diags.diagnose(DS->getDiscardLoc(),
diag::discard_wrong_context_copyable);
diagnosed = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@ bool swift::diagnoseMissingOwnership(ParamSpecifier ownership,
resolution.getGenericSignature().getGenericEnvironment(),
ty);

if (ty->hasError() || !ty->isNoncopyable())
if (ty->hasError() || ty->isCopyable())
return false; // copyable types do not need ownership

if (ownership != ParamSpecifier::Default)
Expand Down