diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index f8ff0bbafa6..d2918eb6189 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -634,8 +634,8 @@ public: bool isPlaceholder(); - /// Returns true if this is a move-only type. - bool isPureMoveOnly(); + /// Returns true if this is a noncopyable type. + bool isNoncopyable(); /// Does the type have outer parenthesis? bool hasParenSugar() const { return getKind() == TypeKind::Paren; } @@ -5351,7 +5351,7 @@ class SILMoveOnlyWrappedType final : public TypeBase, : TypeBase(TypeKind::SILMoveOnlyWrapped, &innerType->getASTContext(), innerType->getRecursiveProperties()), innerType(innerType) { - assert(!innerType->isPureMoveOnly() && "Inner type must be copyable"); + assert(!innerType->isNoncopyable() && "Inner type must be copyable"); } public: diff --git a/include/swift/SIL/SILType.h b/include/swift/SIL/SILType.h index 1d835d77f43..37e7e296f27 100644 --- a/include/swift/SIL/SILType.h +++ b/include/swift/SIL/SILType.h @@ -748,10 +748,6 @@ public: /// wrapped type. bool isMoveOnly() const; - /// Is this a type that is a first class move only type. This returns false - /// for a move only wrapped type. - bool isPureMoveOnly() const; - /// Return true if this is a value type (struct/enum) that requires /// deinitialization beyond destruction of its members. bool isValueTypeWithDeinit() const; diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 8be7c867458..63019ac970d 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -3337,7 +3337,7 @@ static bool usesFeatureMoveOnly(Decl *decl) { // Check for move-only types in the types of this declaration. if (Type type = value->getInterfaceType()) { bool hasMoveOnly = type.findIf([](Type type) { - return type->isPureMoveOnly(); + return type->isNoncopyable(); }); if (hasMoveOnly) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 0397439d0a9..45fae07b916 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -7529,7 +7529,7 @@ LifetimeAnnotation ParamDecl::getLifetimeAnnotation() const { auto specifier = getSpecifier(); // Copyable parameters which are consumed have eager-move semantics. if (specifier == ParamDecl::Specifier::Consuming && - !getTypeInContext()->isPureMoveOnly()) { + !getTypeInContext()->isNoncopyable()) { if (getAttrs().hasAttribute()) return LifetimeAnnotation::Lexical; return LifetimeAnnotation::EagerMove; @@ -9765,7 +9765,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()->isPureMoveOnly()) { + if (selfDecl && !selfDecl->getTypeInContext()->isNoncopyable()) { if (getAttrs().hasAttribute()) return LifetimeAnnotation::Lexical; return LifetimeAnnotation::EagerMove; diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index b47940c1e42..3fd81d022ad 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -1797,7 +1797,7 @@ static ProtocolConformanceRef getBuiltinMetaTypeTypeConformance( // Only metatypes of Copyable types are Copyable. if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable) && - !metatypeType->getInstanceType()->isPureMoveOnly()) { + !metatypeType->getInstanceType()->isNoncopyable()) { return ProtocolConformanceRef( ctx.getBuiltinConformance(type, protocol, BuiltinConformanceKind::Synthesized)); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 0c3fe0e51f1..05e736315a7 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -157,18 +157,18 @@ bool TypeBase::isMarkerExistential() { return true; } -bool TypeBase::isPureMoveOnly() { +bool TypeBase::isNoncopyable() { if (auto *nom = getAnyNominal()) return nom->isMoveOnly(); if (auto *expansion = getAs()) { - return expansion->getPatternType()->isPureMoveOnly(); + return expansion->getPatternType()->isNoncopyable(); } // if any components of the tuple are move-only, then the tuple is move-only. if (auto *tupl = getCanonicalType()->getAs()) { for (auto eltTy : tupl->getElementTypes()) - if (eltTy->isPureMoveOnly()) + if (eltTy->isNoncopyable()) return true; } diff --git a/lib/IRGen/GenReflection.cpp b/lib/IRGen/GenReflection.cpp index 9ddf221768a..fa10becdc87 100644 --- a/lib/IRGen/GenReflection.cpp +++ b/lib/IRGen/GenReflection.cpp @@ -266,7 +266,7 @@ getTypeRefByFunction(IRGenModule &IGM, // If a type is noncopyable, lie about the resolved type unless the // runtime is sufficiently aware of noncopyable types. - if (substT->isPureMoveOnly()) { + if (substT->isNoncopyable()) { // Darwin-based platforms have ABI stability, and we want binaries // that use noncopyable types nongenerically today to be forward // compatible with a future OS runtime that supports noncopyable @@ -391,7 +391,7 @@ getTypeRefImpl(IRGenModule &IGM, // noncopyable, use a function to emit the type ref which will look for a // signal from future runtimes whether they support noncopyable types before // exposing their metadata to them. - if (type->isPureMoveOnly()) { + if (type->isNoncopyable()) { IGM.IRGen.noteUseOfTypeMetadata(type); return getTypeRefByFunction(IGM, sig, type); } diff --git a/lib/SIL/IR/SIL.cpp b/lib/SIL/IR/SIL.cpp index 033a3e89415..db43c43d8b3 100644 --- a/lib/SIL/IR/SIL.cpp +++ b/lib/SIL/IR/SIL.cpp @@ -333,7 +333,7 @@ static bool isUnsupportedKeyPathValueType(Type ty) { // They would also need a new ABI that's yet to be implemented in order to // be properly supported, so let's suppress the descriptor for now if either // the container or storage type of the declaration is non-copyable. - if (ty->isPureMoveOnly()) + if (ty->isNoncopyable()) return true; return false; @@ -345,7 +345,7 @@ bool AbstractStorageDecl::exportsPropertyDescriptor() const { if (!isStatic()) { if (auto contextTy = getDeclContext()->getDeclaredTypeInContext()) { - if (contextTy->isPureMoveOnly()) { + if (contextTy->isNoncopyable()) { return false; } } diff --git a/lib/SIL/IR/SILType.cpp b/lib/SIL/IR/SILType.cpp index 7ed9a35399c..21cb826e044 100644 --- a/lib/SIL/IR/SILType.cpp +++ b/lib/SIL/IR/SILType.cpp @@ -1036,7 +1036,7 @@ SILType::getSingletonAggregateFieldType(SILModule &M, bool SILType::isMoveOnly() const { // Nominal types are move-only if declared as such. - if (isPureMoveOnly()) + if (getASTType()->isNoncopyable()) return true; @@ -1054,10 +1054,6 @@ bool SILType::isMoveOnly() const { return isMoveOnlyWrapped(); } -bool SILType::isPureMoveOnly() const { - return getASTType()->isPureMoveOnly(); -} - bool SILType::isValueTypeWithDeinit() const { @@ -1186,7 +1182,7 @@ SILType SILType::addingMoveOnlyWrapperToBoxedType(const SILFunction *fn) { auto oldField = oldLayout->getFields()[0]; if (oldField.getLoweredType()->is()) return *this; - assert(!oldField.getLoweredType()->isPureMoveOnly() && + assert(!oldField.getLoweredType()->isNoncopyable() && "Cannot moveonlywrapped in a moveonly type"); auto newField = SILField(SILMoveOnlyWrappedType::get(oldField.getLoweredType()), diff --git a/lib/SIL/IR/TypeLowering.cpp b/lib/SIL/IR/TypeLowering.cpp index ac923421817..e2d36a3a763 100644 --- a/lib/SIL/IR/TypeLowering.cpp +++ b/lib/SIL/IR/TypeLowering.cpp @@ -123,8 +123,9 @@ CaptureKind TypeConverter::getDeclCaptureKind(CapturedValue capture, // If this is a noncopyable 'let' constant that is not a shared paramdecl or // used by a noescape capture, then we know it is boxed and want to pass it in // its boxed form so we can obey Swift's capture reference semantics. - if (!var->supportsMutation() && lowering.getLoweredType().isPureMoveOnly() && - !capture.isNoEscape()) { + if (!var->supportsMutation() + && lowering.getLoweredType().getASTType()->isNoncopyable() + && !capture.isNoEscape()) { auto *param = dyn_cast(var); if (!param || (param->getValueOwnership() != ValueOwnership::Shared && !param->isSelfParameter())) { diff --git a/lib/SIL/Verifier/SILVerifier.cpp b/lib/SIL/Verifier/SILVerifier.cpp index 1433a35da4c..fa5c181d9d1 100644 --- a/lib/SIL/Verifier/SILVerifier.cpp +++ b/lib/SIL/Verifier/SILVerifier.cpp @@ -6128,7 +6128,7 @@ public: auto type = ddi->getType(); require(type == ddi->getOperand()->getType(), "Result and operand must have the same type."); - require(type.isPureMoveOnly(), + require(type.getASTType()->isNoncopyable(), "drop_deinit only allowed for move-only types"); require(type.getNominalOrBoundGenericNominal() ->getValueTypeDestructor(), "drop_deinit only allowed for " diff --git a/lib/SILGen/SILGenApply.cpp b/lib/SILGen/SILGenApply.cpp index 4d27f2e227a..65be1ffe455 100644 --- a/lib/SILGen/SILGenApply.cpp +++ b/lib/SILGen/SILGenApply.cpp @@ -3144,7 +3144,7 @@ Expr *ArgumentSource::findStorageReferenceExprForMoveOnly( SILType ty = SGF.getLoweredType(type->getWithoutSpecifierType()->getCanonicalType()); - bool isMoveOnly = ty.isPureMoveOnly(); + bool isMoveOnly = ty.getASTType()->isNoncopyable(); if (auto *pd = dyn_cast(storage)) { isMoveOnly |= pd->getSpecifier() == ParamSpecifier::Borrowing; isMoveOnly |= pd->getSpecifier() == ParamSpecifier::Consuming; diff --git a/lib/SILGen/SILGenBuilder.cpp b/lib/SILGen/SILGenBuilder.cpp index 40b7c9c7ff0..905b8f86eff 100644 --- a/lib/SILGen/SILGenBuilder.cpp +++ b/lib/SILGen/SILGenBuilder.cpp @@ -530,7 +530,7 @@ static ManagedValue createInputFunctionArgument( "Function arguments of non-bare functions must have a decl"); auto *arg = F.begin()->createFunctionArgument(type, decl); if (auto *pd = dyn_cast_or_null(decl)) { - if (!arg->getType().isPureMoveOnly()) { + if (!arg->getType().getASTType()->isNoncopyable()) { isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Borrowing; isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Consuming; } diff --git a/lib/SILGen/SILGenDecl.cpp b/lib/SILGen/SILGenDecl.cpp index 44912abc918..914eb499638 100644 --- a/lib/SILGen/SILGenDecl.cpp +++ b/lib/SILGen/SILGenDecl.cpp @@ -517,7 +517,7 @@ public: // If we have a no implicit copy param decl, make our instance type // @moveOnly. - if (!instanceType->isPureMoveOnly()) { + if (!instanceType->isNoncopyable()) { if (auto *pd = dyn_cast(decl)) { bool isNoImplicitCopy = pd->isNoImplicitCopy(); isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Consuming; @@ -535,7 +535,7 @@ public: auto boxType = SGF.SGM.Types.getContextBoxTypeForCapture( decl, instanceType, SGF.F.getGenericEnvironment(), - /*mutable*/ !instanceType->isPureMoveOnly() || !decl->isLet()); + /*mutable*/ !instanceType->isNoncopyable() || !decl->isLet()); // The variable may have its lifetime extended by a closure, heap-allocate // it using a box. @@ -689,7 +689,7 @@ public: // For noncopyable types, we always need to box them. needsTemporaryBuffer = (lowering->isAddressOnly() && SGF.silConv.useLoweredAddresses()) || - lowering->getLoweredType().isPureMoveOnly(); + lowering->getLoweredType().getASTType()->isNoncopyable(); } // Make sure that we have a non-address only type when binding a @@ -774,7 +774,7 @@ public: if (value->getOwnershipKind() == OwnershipKind::None) { // Then check if we have a pure move only type. In that case, we need to // insert a no implicit copy - if (value->getType().isPureMoveOnly()) { + if (value->getType().getASTType()->isNoncopyable()) { value = SGF.B.createMoveValue(PrologueLoc, value, /*isLexical*/ true); return SGF.B.createMarkUnresolvedNonCopyableValueInst( PrologueLoc, value, @@ -824,7 +824,7 @@ public: // We do this before the begin_borrow "normal" path below since move only // types do not have no implicit copy attr on them. if (value->getOwnershipKind() == OwnershipKind::Owned && - value->getType().isPureMoveOnly()) { + value->getType().getASTType()->isNoncopyable()) { value = SGF.B.createMoveValue(PrologueLoc, value, true /*isLexical*/); return SGF.B.createMarkUnresolvedNonCopyableValueInst( PrologueLoc, value, @@ -1455,7 +1455,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(varType) && !varType->isPureMoveOnly()) + !isa(varType) && !varType->isNoncopyable()) return InitializationPtr(new LetValueInitialization(vd, *this)); // If the variable has no initial value, emit a mark_uninitialized instruction diff --git a/lib/SILGen/SILGenLValue.cpp b/lib/SILGen/SILGenLValue.cpp index ed565d12cd6..50f8c7df903 100644 --- a/lib/SILGen/SILGenLValue.cpp +++ b/lib/SILGen/SILGenLValue.cpp @@ -2938,7 +2938,7 @@ public: /// Returns the subexpr static bool isNonCopyableBaseBorrow(SILGenFunction &SGF, Expr *e) { if (auto *le = dyn_cast(e)) - return le->getType()->isPureMoveOnly(); + return le->getType()->isNoncopyable(); if (auto *m = dyn_cast(e)) { // If our m is a pure noncopyable type or our base is, we need to perform // a noncopyable base borrow. @@ -2946,11 +2946,11 @@ public: // DISCUSSION: We can have a noncopyable member_ref_expr with a copyable // base if the noncopyable member_ref_expr is from a computed method. In // such a case, we want to ensure that we wrap things the right way. - return m->getType()->isPureMoveOnly() || - m->getBase()->getType()->isPureMoveOnly(); + return m->getType()->isNoncopyable() || + m->getBase()->getType()->isNoncopyable(); } if (auto *d = dyn_cast(e)) - return e->getType()->isPureMoveOnly(); + return e->getType()->isNoncopyable(); return false; } diff --git a/lib/SILGen/SILGenProlog.cpp b/lib/SILGen/SILGenProlog.cpp index 6f6bbd7b1c6..7408c6c0890 100644 --- a/lib/SILGen/SILGenProlog.cpp +++ b/lib/SILGen/SILGenProlog.cpp @@ -705,7 +705,7 @@ private: // - @_eagerMove // - @_noEagerMove bool isNoImplicitCopy = pd->isNoImplicitCopy(); - if (!argrv.getType().isPureMoveOnly()) { + if (!argrv.getType().getASTType()->isNoncopyable()) { isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Borrowing; isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Consuming; if (pd->isSelfParameter()) { @@ -1168,7 +1168,7 @@ static void emitCaptureArguments(SILGenFunction &SGF, // in SIL since it is illegal to capture an inout value in an escaping // closure. The later code knows how to handle that we have the // mark_unresolved_non_copyable_value here. - if (isInOut && ty.isPureMoveOnly()) { + if (isInOut && ty.getASTType()->isNoncopyable()) { arg = SGF.B.createMarkUnresolvedNonCopyableValueInst( Loc, arg, MarkUnresolvedNonCopyableValueInst::CheckKind:: diff --git a/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp b/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp index b1664389c1d..110ffcf1c04 100644 --- a/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp +++ b/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp @@ -379,7 +379,7 @@ public: // analysis assumes memory is deinitialized on all paths, which is not the // case for discarded values. Eventually copyable types may also be // discarded; to support that, we will leave a drop_deinit_addr in place. - if (ASI->getType().isPureMoveOnly()) { + if (ASI->getType().getASTType()->isNoncopyable()) { LegalUsers = false; return; } diff --git a/lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp b/lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp index ae671e69742..2ef2d7b4bd5 100644 --- a/lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp +++ b/lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp @@ -69,7 +69,7 @@ static bool performTransform(SILFunction &fn) { if (auto *dvi = dyn_cast(inst)) { auto destroyType = dvi->getOperand()->getType(); - if (destroyType.isPureMoveOnly() && + if (destroyType.getASTType()->isNoncopyable() && !isa(lookThroughOwnershipInsts(dvi->getOperand()))) { LLVM_DEBUG(llvm::dbgs() << "Handling: " << *dvi); auto *nom = destroyType.getNominalOrBoundGenericNominal(); @@ -112,7 +112,8 @@ static bool performTransform(SILFunction &fn) { if (auto *dai = dyn_cast(inst)) { auto destroyType = dai->getOperand()->getType(); - if (destroyType.isLoadable(fn) && destroyType.isPureMoveOnly() && + if (destroyType.isLoadable(fn) + && destroyType.getASTType()->isNoncopyable() && !isa(dai->getOperand())) { LLVM_DEBUG(llvm::dbgs() << "Handling: " << *dai); auto *nom = destroyType.getNominalOrBoundGenericNominal(); diff --git a/lib/SILOptimizer/Transforms/SILLowerAggregateInstrs.cpp b/lib/SILOptimizer/Transforms/SILLowerAggregateInstrs.cpp index 66883bebe3e..06a1f3b9721 100644 --- a/lib/SILOptimizer/Transforms/SILLowerAggregateInstrs.cpp +++ b/lib/SILOptimizer/Transforms/SILLowerAggregateInstrs.cpp @@ -52,7 +52,7 @@ static bool shouldExpandShim(SILFunction *fn, SILType type) { // shouldExpand returns false for struct-with-deinit types, so bypassing it is // incorrect for move-only types if (EnableExpandAll) { - assert(!type.isPureMoveOnly() + assert(!type.getASTType()->isNoncopyable() && "sil-lower-agg-instrs-expand-all is incompatible with move-only " "types"); return true; diff --git a/lib/SILOptimizer/Utils/InstructionDeleter.cpp b/lib/SILOptimizer/Utils/InstructionDeleter.cpp index ebaa13b6b9f..81f52b6334c 100644 --- a/lib/SILOptimizer/Utils/InstructionDeleter.cpp +++ b/lib/SILOptimizer/Utils/InstructionDeleter.cpp @@ -70,7 +70,7 @@ static bool isScopeAffectingInstructionDead(SILInstruction *inst, // move_value instructions. And `move_value %moveOnlyValue` must not be // deleted. for (auto result : inst->getResults()) { - if (result->getType().isPureMoveOnly() && + if (result->getType().getASTType()->isNoncopyable() && result->getOwnershipKind() == OwnershipKind::Owned) { return false; } diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index d00025df460..2a0148b5276 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -3865,7 +3865,7 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2, } // move-only types (and their metatypes) cannot match with existential types. - if (type1->getMetatypeInstanceType()->isPureMoveOnly()) { + if (type1->getMetatypeInstanceType()->isNoncopyable()) { // tailor error message if (shouldAttemptFixes()) { auto *fix = MustBeCopyable::create(*this, @@ -11842,7 +11842,7 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1, // Move-only types can't be involved in a bridging conversion since a bridged // type assumes the ability to copy. - if (type1->isPureMoveOnly()) { + if (type1->isNoncopyable()) { return SolutionKind::Error; } diff --git a/lib/Sema/MiscDiagnostics.cpp b/lib/Sema/MiscDiagnostics.cpp index bbfd97356ec..198ab0ea241 100644 --- a/lib/Sema/MiscDiagnostics.cpp +++ b/lib/Sema/MiscDiagnostics.cpp @@ -325,7 +325,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC, tupleExpr->getElementNames()); // Diagnose attempts to form a tuple with any noncopyable elements. - if (E->getType()->isPureMoveOnly() + if (E->getType()->isNoncopyable() && !Ctx.LangOpts.hasFeature(Feature::MoveOnlyTuples)) { auto noncopyableTy = E->getType(); assert(noncopyableTy->is() && "will use poor wording"); @@ -388,7 +388,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC, if (!castType) return; - if (castType->isPureMoveOnly()) { + if (castType->isNoncopyable()) { // can't cast anything to move-only; there should be no valid ones. Ctx.Diags.diagnose(cast->getLoc(), diag::noncopyable_cast); return; @@ -398,7 +398,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC, // as of now there is no type it could be cast to except itself, so // there's no reason for it to happen at runtime. if (auto fromType = cast->getSubExpr()->getType()) { - if (fromType->isPureMoveOnly()) { + if (fromType->isNoncopyable()) { // can't cast move-only to anything. Ctx.Diags.diagnose(cast->getLoc(), diag::noncopyable_cast); return; @@ -436,7 +436,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC, void checkCopyExpr(CopyExpr *copyExpr) { // Do not allow for copy_expr to be used with pure move only types. We // /do/ allow it to be used with no implicit copy types though. - if (copyExpr->getType()->isPureMoveOnly()) { + if (copyExpr->getType()->isNoncopyable()) { Ctx.Diags.diagnose( copyExpr->getLoc(), diag::copy_expression_cannot_be_used_with_noncopyable_types); @@ -4093,7 +4093,7 @@ diagnoseMoveOnlyPatternMatchSubject(ASTContext &C, auto subjectType = subjectExpr->getType(); if (!subjectType || subjectType->hasError() - || !subjectType->isPureMoveOnly()) { + || !subjectType->isNoncopyable()) { return; } @@ -6292,7 +6292,7 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType( for (auto *fieldDecl : structDecl->getStoredProperties()) { LLVM_DEBUG(llvm::dbgs() << "Visiting struct field: " << fieldDecl->getName() << '\n'); - if (!fieldDecl->getInterfaceType()->isPureMoveOnly()) + if (!fieldDecl->getInterfaceType()->isNoncopyable()) continue; emitError(fieldDecl, structDecl->getBaseName(), fieldDecl->getDescriptiveKind(), fieldDecl->getBaseName()); @@ -6322,7 +6322,7 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType( for (auto payloadParam : *enumEltDecl->getParameterList()) { LLVM_DEBUG(llvm::dbgs() << "Visiting payload param: " << payloadParam->getName() << '\n'); - if (payloadParam->getInterfaceType()->isPureMoveOnly()) { + if (payloadParam->getInterfaceType()->isNoncopyable()) { emitError(enumEltDecl, enumDecl->getBaseName(), enumEltDecl->getDescriptiveKind(), enumEltDecl->getBaseName()); diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index 9751f50e12d..115d3663e49 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -6848,20 +6848,20 @@ void AttributeChecker::visitEagerMoveAttr(EagerMoveAttr *attr) { if (visitLifetimeAttr(attr)) return; if (auto *nominal = dyn_cast(D)) { - if (nominal->getDeclaredInterfaceType()->isPureMoveOnly()) { + if (nominal->getDeclaredInterfaceType()->isNoncopyable()) { diagnoseAndRemoveAttr(attr, diag::eagermove_and_noncopyable_combined); return; } } if (auto *func = dyn_cast(D)) { auto *self = func->getImplicitSelfDecl(); - if (self && self->getTypeInContext()->isPureMoveOnly()) { + if (self && self->getTypeInContext()->isNoncopyable()) { diagnoseAndRemoveAttr(attr, diag::eagermove_and_noncopyable_combined); return; } } if (auto *pd = dyn_cast(D)) { - if (pd->getTypeInContext()->isPureMoveOnly()) { + if (pd->getTypeInContext()->isNoncopyable()) { diagnoseAndRemoveAttr(attr, diag::eagermove_and_noncopyable_combined); return; } diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp index 15c27ae54bd..df4d972aaf4 100644 --- a/lib/Sema/TypeCheckConstraints.cpp +++ b/lib/Sema/TypeCheckConstraints.cpp @@ -1679,8 +1679,8 @@ TypeChecker::typeCheckCheckedCast(Type fromType, Type toType, // // Thus, right now, a move-only type is only a subtype of itself. // We also want to prevent conversions of a move-only type's metatype. - if (fromType->getMetatypeInstanceType()->isPureMoveOnly() - || toType->getMetatypeInstanceType()->isPureMoveOnly()) + if (fromType->getMetatypeInstanceType()->isNoncopyable() + || toType->getMetatypeInstanceType()->isNoncopyable()) return CheckedCastKind::Unresolved; // Check for a bridging conversion. diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index b3849768f1b..c06b6119640 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -913,7 +913,7 @@ IsFinalRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const { } bool IsMoveOnlyRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const { - // TODO: isPureMoveOnly and isMoveOnly and other checks are all spread out + // TODO: isNoncopyable and isMoveOnly and other checks are all spread out // and need to be merged together. if (isa(decl) || isa(decl) || isa(decl)) { if (decl->getAttrs().hasAttribute()) { diff --git a/lib/Sema/TypeCheckDeclPrimary.cpp b/lib/Sema/TypeCheckDeclPrimary.cpp index acaf6f87345..c9ac554b5f1 100644 --- a/lib/Sema/TypeCheckDeclPrimary.cpp +++ b/lib/Sema/TypeCheckDeclPrimary.cpp @@ -2499,7 +2499,7 @@ public: // accessors since this means that we cannot call mutating methods without // copying. We do not want to support types that one cannot define a // modify operation via a get/set or a modify. - if (var->getInterfaceType()->isPureMoveOnly()) { + if (var->getInterfaceType()->isNoncopyable()) { if (auto *read = var->getAccessor(AccessorKind::Read)) { if (!read->isImplicit()) { if (auto *set = var->getAccessor(AccessorKind::Set)) { @@ -2587,7 +2587,7 @@ public: // Reject noncopyable typed subscripts with read/set accessors since we // cannot define modify operations upon them without copying the read. - if (SD->getElementInterfaceType()->isPureMoveOnly()) { + if (SD->getElementInterfaceType()->isNoncopyable()) { if (auto *read = SD->getAccessor(AccessorKind::Read)) { if (!read->isImplicit()) { if (auto *set = SD->getAccessor(AccessorKind::Set)) { diff --git a/lib/Sema/TypeCheckProtocol.cpp b/lib/Sema/TypeCheckProtocol.cpp index f838d042702..4a0d89581b8 100644 --- a/lib/Sema/TypeCheckProtocol.cpp +++ b/lib/Sema/TypeCheckProtocol.cpp @@ -4654,7 +4654,7 @@ swift::checkTypeWitness(Type type, AssociatedTypeDecl *assocType, return CheckTypeWitnessResult::forError(); // No move-only type can witness an associatedtype requirement. - if (type->isPureMoveOnly()) { + if (type->isNoncopyable()) { // describe the failure reason as it not conforming to Copyable auto *copyable = ctx.getProtocol(KnownProtocolKind::Copyable); assert(copyable && "missing _Copyable protocol!"); diff --git a/lib/Sema/TypeCheckStmt.cpp b/lib/Sema/TypeCheckStmt.cpp index 341e31cb4c7..d676a6ff3fa 100644 --- a/lib/Sema/TypeCheckStmt.cpp +++ b/lib/Sema/TypeCheckStmt.cpp @@ -1258,7 +1258,7 @@ public: fn->mapTypeIntoContext(nominalDecl->getDeclaredInterfaceType()); // must be noncopyable - if (!nominalType->isPureMoveOnly()) { + if (!nominalType->isNoncopyable()) { ctx.Diags.diagnose(DS->getDiscardLoc(), diag::discard_wrong_context_copyable, fn->getDescriptiveKind()); diff --git a/lib/Sema/TypeCheckStorage.cpp b/lib/Sema/TypeCheckStorage.cpp index 99391bec7ba..913ae405231 100644 --- a/lib/Sema/TypeCheckStorage.cpp +++ b/lib/Sema/TypeCheckStorage.cpp @@ -733,7 +733,7 @@ OpaqueReadOwnershipRequest::evaluate(Evaluator &evaluator, if (storage->getAttrs().hasAttribute()) return usesBorrowed(DiagKind::BorrowedAttr); - if (storage->getValueInterfaceType()->isPureMoveOnly()) + if (storage->getValueInterfaceType()->isNoncopyable()) return usesBorrowed(DiagKind::NoncopyableType); return OpaqueReadOwnership::Owned; diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index 26c96c44561..60791370a94 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -1021,7 +1021,7 @@ static bool didDiagnoseMoveOnlyGenericArgs(ASTContext &ctx, bool didEmitDiag = false; for (auto t: genericArgs) { - if (!t->isPureMoveOnly()) + if (!t->isNoncopyable()) continue; ctx.Diags.diagnose(loc, diag::noncopyable_generics_specific, t, unboundTy); @@ -2303,7 +2303,7 @@ bool TypeResolver::diagnoseMoveOnlyGeneric(TypeRepr *repr, if (getASTContext().LangOpts.hasFeature(Feature::NoncopyableGenerics)) return false; - if (genericArgTy->isPureMoveOnly()) { + if (genericArgTy->isNoncopyable()) { if (unboundTy) { diagnoseInvalid(repr, repr->getLoc(), diag::noncopyable_generics_specific, genericArgTy, unboundTy); @@ -4282,7 +4282,7 @@ TypeResolver::resolveDeclRefTypeRepr(DeclRefTypeRepr *repr, } // move-only types must have an ownership specifier when used as a parameter of a function. - if (result->isPureMoveOnly()) + if (result->isNoncopyable()) diagnoseMoveOnlyMissingOwnership(repr, options); // Hack to apply context-specific @escaping to a typealias with an underlying @@ -4588,7 +4588,7 @@ NeverNullType TypeResolver::resolveVarargType(VarargTypeRepr *repr, } // do not allow move-only types as the element of a vararg - if (element->isPureMoveOnly()) { + if (element->isNoncopyable()) { diagnoseInvalid(repr, repr->getLoc(), diag::noncopyable_generics_variadic, element); return ErrorType::get(getASTContext()); @@ -4767,7 +4767,7 @@ NeverNullType TypeResolver::resolveTupleType(TupleTypeRepr *repr, // Track the presence of a noncopyable field for diagnostic purposes. // We don't need to re-diagnose if a tuple contains another tuple, though, // since we should've diagnosed the inner tuple already. - if (ty->isPureMoveOnly() && !moveOnlyElementIndex.has_value() + if (ty->isNoncopyable() && !moveOnlyElementIndex.has_value() && !isa(tyR)) { moveOnlyElementIndex = i; }