Skip to content

Commit f1142d5

Browse files
committed
[nfc] rename or eliminate isPureMoveOnly APIs
I think from SIL's perspective, it should only worry about whether the type is move-only. That includes MoveOnlyWrapped SILTypes and regular types that cannot be copied. Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where it's very likely that the original AST type is sitting around already. In such cases, I think it's fine to ask the AST type if it is noncopyable. The clarity of only asking the ASTType if it's noncopyable is beneficial, I think.
1 parent c01360d commit f1142d5

30 files changed

+65
-71
lines changed

include/swift/AST/Types.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ class alignas(1 << TypeAlignInBits) TypeBase
634634

635635
bool isPlaceholder();
636636

637-
/// Returns true if this is a move-only type.
638-
bool isPureMoveOnly();
637+
/// Returns true if this is a noncopyable type.
638+
bool isNoncopyable();
639639

640640
/// Does the type have outer parenthesis?
641641
bool hasParenSugar() const { return getKind() == TypeKind::Paren; }
@@ -5351,7 +5351,7 @@ class SILMoveOnlyWrappedType final : public TypeBase,
53515351
: TypeBase(TypeKind::SILMoveOnlyWrapped, &innerType->getASTContext(),
53525352
innerType->getRecursiveProperties()),
53535353
innerType(innerType) {
5354-
assert(!innerType->isPureMoveOnly() && "Inner type must be copyable");
5354+
assert(!innerType->isNoncopyable() && "Inner type must be copyable");
53555355
}
53565356

53575357
public:

include/swift/SIL/SILType.h

-4
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,6 @@ class SILType {
748748
/// wrapped type.
749749
bool isMoveOnly() const;
750750

751-
/// Is this a type that is a first class move only type. This returns false
752-
/// for a move only wrapped type.
753-
bool isPureMoveOnly() const;
754-
755751
/// Return true if this is a value type (struct/enum) that requires
756752
/// deinitialization beyond destruction of its members.
757753
bool isValueTypeWithDeinit() const;

lib/AST/ASTPrinter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3337,7 +3337,7 @@ static bool usesFeatureMoveOnly(Decl *decl) {
33373337
// Check for move-only types in the types of this declaration.
33383338
if (Type type = value->getInterfaceType()) {
33393339
bool hasMoveOnly = type.findIf([](Type type) {
3340-
return type->isPureMoveOnly();
3340+
return type->isNoncopyable();
33413341
});
33423342

33433343
if (hasMoveOnly)

lib/AST/Decl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7529,7 +7529,7 @@ LifetimeAnnotation ParamDecl::getLifetimeAnnotation() const {
75297529
auto specifier = getSpecifier();
75307530
// Copyable parameters which are consumed have eager-move semantics.
75317531
if (specifier == ParamDecl::Specifier::Consuming &&
7532-
!getTypeInContext()->isPureMoveOnly()) {
7532+
!getTypeInContext()->isNoncopyable()) {
75337533
if (getAttrs().hasAttribute<NoEagerMoveAttr>())
75347534
return LifetimeAnnotation::Lexical;
75357535
return LifetimeAnnotation::EagerMove;
@@ -9765,7 +9765,7 @@ LifetimeAnnotation FuncDecl::getLifetimeAnnotation() const {
97659765
// Copyable parameters which are consumed have eager-move semantics.
97669766
if (getSelfAccessKind() == SelfAccessKind::Consuming) {
97679767
auto *selfDecl = getImplicitSelfDecl();
9768-
if (selfDecl && !selfDecl->getTypeInContext()->isPureMoveOnly()) {
9768+
if (selfDecl && !selfDecl->getTypeInContext()->isNoncopyable()) {
97699769
if (getAttrs().hasAttribute<NoEagerMoveAttr>())
97709770
return LifetimeAnnotation::Lexical;
97719771
return LifetimeAnnotation::EagerMove;

lib/AST/Module.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ static ProtocolConformanceRef getBuiltinMetaTypeTypeConformance(
17971797

17981798
// Only metatypes of Copyable types are Copyable.
17991799
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable) &&
1800-
!metatypeType->getInstanceType()->isPureMoveOnly()) {
1800+
!metatypeType->getInstanceType()->isNoncopyable()) {
18011801
return ProtocolConformanceRef(
18021802
ctx.getBuiltinConformance(type, protocol,
18031803
BuiltinConformanceKind::Synthesized));

lib/AST/Type.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,18 @@ bool TypeBase::isMarkerExistential() {
157157
return true;
158158
}
159159

160-
bool TypeBase::isPureMoveOnly() {
160+
bool TypeBase::isNoncopyable() {
161161
if (auto *nom = getAnyNominal())
162162
return nom->isMoveOnly();
163163

164164
if (auto *expansion = getAs<PackExpansionType>()) {
165-
return expansion->getPatternType()->isPureMoveOnly();
165+
return expansion->getPatternType()->isNoncopyable();
166166
}
167167

168168
// if any components of the tuple are move-only, then the tuple is move-only.
169169
if (auto *tupl = getCanonicalType()->getAs<TupleType>()) {
170170
for (auto eltTy : tupl->getElementTypes())
171-
if (eltTy->isPureMoveOnly())
171+
if (eltTy->isNoncopyable())
172172
return true;
173173
}
174174

lib/IRGen/GenReflection.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ getTypeRefByFunction(IRGenModule &IGM,
266266

267267
// If a type is noncopyable, lie about the resolved type unless the
268268
// runtime is sufficiently aware of noncopyable types.
269-
if (substT->isPureMoveOnly()) {
269+
if (substT->isNoncopyable()) {
270270
// Darwin-based platforms have ABI stability, and we want binaries
271271
// that use noncopyable types nongenerically today to be forward
272272
// compatible with a future OS runtime that supports noncopyable
@@ -391,7 +391,7 @@ getTypeRefImpl(IRGenModule &IGM,
391391
// noncopyable, use a function to emit the type ref which will look for a
392392
// signal from future runtimes whether they support noncopyable types before
393393
// exposing their metadata to them.
394-
if (type->isPureMoveOnly()) {
394+
if (type->isNoncopyable()) {
395395
IGM.IRGen.noteUseOfTypeMetadata(type);
396396
return getTypeRefByFunction(IGM, sig, type);
397397
}

lib/SIL/IR/SIL.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static bool isUnsupportedKeyPathValueType(Type ty) {
333333
// They would also need a new ABI that's yet to be implemented in order to
334334
// be properly supported, so let's suppress the descriptor for now if either
335335
// the container or storage type of the declaration is non-copyable.
336-
if (ty->isPureMoveOnly())
336+
if (ty->isNoncopyable())
337337
return true;
338338

339339
return false;
@@ -345,7 +345,7 @@ bool AbstractStorageDecl::exportsPropertyDescriptor() const {
345345

346346
if (!isStatic()) {
347347
if (auto contextTy = getDeclContext()->getDeclaredTypeInContext()) {
348-
if (contextTy->isPureMoveOnly()) {
348+
if (contextTy->isNoncopyable()) {
349349
return false;
350350
}
351351
}

lib/SIL/IR/SILType.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ SILType::getSingletonAggregateFieldType(SILModule &M,
10361036

10371037
bool SILType::isMoveOnly() const {
10381038
// Nominal types are move-only if declared as such.
1039-
if (isPureMoveOnly())
1039+
if (getASTType()->isNoncopyable())
10401040
return true;
10411041

10421042

@@ -1054,10 +1054,6 @@ bool SILType::isMoveOnly() const {
10541054
return isMoveOnlyWrapped();
10551055
}
10561056

1057-
bool SILType::isPureMoveOnly() const {
1058-
return getASTType()->isPureMoveOnly();
1059-
}
1060-
10611057

10621058

10631059
bool SILType::isValueTypeWithDeinit() const {
@@ -1186,7 +1182,7 @@ SILType SILType::addingMoveOnlyWrapperToBoxedType(const SILFunction *fn) {
11861182
auto oldField = oldLayout->getFields()[0];
11871183
if (oldField.getLoweredType()->is<SILMoveOnlyWrappedType>())
11881184
return *this;
1189-
assert(!oldField.getLoweredType()->isPureMoveOnly() &&
1185+
assert(!oldField.getLoweredType()->isNoncopyable() &&
11901186
"Cannot moveonlywrapped in a moveonly type");
11911187
auto newField =
11921188
SILField(SILMoveOnlyWrappedType::get(oldField.getLoweredType()),

lib/SIL/IR/TypeLowering.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ CaptureKind TypeConverter::getDeclCaptureKind(CapturedValue capture,
123123
// If this is a noncopyable 'let' constant that is not a shared paramdecl or
124124
// used by a noescape capture, then we know it is boxed and want to pass it in
125125
// its boxed form so we can obey Swift's capture reference semantics.
126-
if (!var->supportsMutation() && lowering.getLoweredType().isPureMoveOnly() &&
127-
!capture.isNoEscape()) {
126+
if (!var->supportsMutation()
127+
&& lowering.getLoweredType().getASTType()->isNoncopyable()
128+
&& !capture.isNoEscape()) {
128129
auto *param = dyn_cast<ParamDecl>(var);
129130
if (!param || (param->getValueOwnership() != ValueOwnership::Shared &&
130131
!param->isSelfParameter())) {

lib/SIL/Verifier/SILVerifier.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6128,7 +6128,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
61286128
auto type = ddi->getType();
61296129
require(type == ddi->getOperand()->getType(),
61306130
"Result and operand must have the same type.");
6131-
require(type.isPureMoveOnly(),
6131+
require(type.getASTType()->isNoncopyable(),
61326132
"drop_deinit only allowed for move-only types");
61336133
require(type.getNominalOrBoundGenericNominal()
61346134
->getValueTypeDestructor(), "drop_deinit only allowed for "

lib/SILGen/SILGenApply.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3144,7 +3144,7 @@ Expr *ArgumentSource::findStorageReferenceExprForMoveOnly(
31443144

31453145
SILType ty =
31463146
SGF.getLoweredType(type->getWithoutSpecifierType()->getCanonicalType());
3147-
bool isMoveOnly = ty.isPureMoveOnly();
3147+
bool isMoveOnly = ty.getASTType()->isNoncopyable();
31483148
if (auto *pd = dyn_cast<ParamDecl>(storage)) {
31493149
isMoveOnly |= pd->getSpecifier() == ParamSpecifier::Borrowing;
31503150
isMoveOnly |= pd->getSpecifier() == ParamSpecifier::Consuming;

lib/SILGen/SILGenBuilder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static ManagedValue createInputFunctionArgument(
530530
"Function arguments of non-bare functions must have a decl");
531531
auto *arg = F.begin()->createFunctionArgument(type, decl);
532532
if (auto *pd = dyn_cast_or_null<ParamDecl>(decl)) {
533-
if (!arg->getType().isPureMoveOnly()) {
533+
if (!arg->getType().getASTType()->isNoncopyable()) {
534534
isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Borrowing;
535535
isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Consuming;
536536
}

lib/SILGen/SILGenDecl.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ class LocalVariableInitialization : public SingleBufferInitialization {
517517

518518
// If we have a no implicit copy param decl, make our instance type
519519
// @moveOnly.
520-
if (!instanceType->isPureMoveOnly()) {
520+
if (!instanceType->isNoncopyable()) {
521521
if (auto *pd = dyn_cast<ParamDecl>(decl)) {
522522
bool isNoImplicitCopy = pd->isNoImplicitCopy();
523523
isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Consuming;
@@ -535,7 +535,7 @@ class LocalVariableInitialization : public SingleBufferInitialization {
535535

536536
auto boxType = SGF.SGM.Types.getContextBoxTypeForCapture(
537537
decl, instanceType, SGF.F.getGenericEnvironment(),
538-
/*mutable*/ !instanceType->isPureMoveOnly() || !decl->isLet());
538+
/*mutable*/ !instanceType->isNoncopyable() || !decl->isLet());
539539

540540
// The variable may have its lifetime extended by a closure, heap-allocate
541541
// it using a box.
@@ -689,7 +689,7 @@ class LetValueInitialization : public Initialization {
689689
// For noncopyable types, we always need to box them.
690690
needsTemporaryBuffer =
691691
(lowering->isAddressOnly() && SGF.silConv.useLoweredAddresses()) ||
692-
lowering->getLoweredType().isPureMoveOnly();
692+
lowering->getLoweredType().getASTType()->isNoncopyable();
693693
}
694694

695695
// Make sure that we have a non-address only type when binding a
@@ -774,7 +774,7 @@ class LetValueInitialization : public Initialization {
774774
if (value->getOwnershipKind() == OwnershipKind::None) {
775775
// Then check if we have a pure move only type. In that case, we need to
776776
// insert a no implicit copy
777-
if (value->getType().isPureMoveOnly()) {
777+
if (value->getType().getASTType()->isNoncopyable()) {
778778
value = SGF.B.createMoveValue(PrologueLoc, value, /*isLexical*/ true);
779779
return SGF.B.createMarkUnresolvedNonCopyableValueInst(
780780
PrologueLoc, value,
@@ -824,7 +824,7 @@ class LetValueInitialization : public Initialization {
824824
// We do this before the begin_borrow "normal" path below since move only
825825
// types do not have no implicit copy attr on them.
826826
if (value->getOwnershipKind() == OwnershipKind::Owned &&
827-
value->getType().isPureMoveOnly()) {
827+
value->getType().getASTType()->isNoncopyable()) {
828828
value = SGF.B.createMoveValue(PrologueLoc, value, true /*isLexical*/);
829829
return SGF.B.createMarkUnresolvedNonCopyableValueInst(
830830
PrologueLoc, value,
@@ -1455,7 +1455,7 @@ SILGenFunction::emitInitializationForVarDecl(VarDecl *vd, bool forceImmutable,
14551455
// If this is a 'let' initialization for a copyable non-global, set up a let
14561456
// binding, which stores the initialization value into VarLocs directly.
14571457
if (forceImmutable && vd->getDeclContext()->isLocalContext() &&
1458-
!isa<ReferenceStorageType>(varType) && !varType->isPureMoveOnly())
1458+
!isa<ReferenceStorageType>(varType) && !varType->isNoncopyable())
14591459
return InitializationPtr(new LetValueInitialization(vd, *this));
14601460

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

lib/SILGen/SILGenLValue.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2938,19 +2938,19 @@ class LLVM_LIBRARY_VISIBILITY SILGenBorrowedBaseVisitor
29382938
/// Returns the subexpr
29392939
static bool isNonCopyableBaseBorrow(SILGenFunction &SGF, Expr *e) {
29402940
if (auto *le = dyn_cast<LoadExpr>(e))
2941-
return le->getType()->isPureMoveOnly();
2941+
return le->getType()->isNoncopyable();
29422942
if (auto *m = dyn_cast<MemberRefExpr>(e)) {
29432943
// If our m is a pure noncopyable type or our base is, we need to perform
29442944
// a noncopyable base borrow.
29452945
//
29462946
// DISCUSSION: We can have a noncopyable member_ref_expr with a copyable
29472947
// base if the noncopyable member_ref_expr is from a computed method. In
29482948
// such a case, we want to ensure that we wrap things the right way.
2949-
return m->getType()->isPureMoveOnly() ||
2950-
m->getBase()->getType()->isPureMoveOnly();
2949+
return m->getType()->isNoncopyable() ||
2950+
m->getBase()->getType()->isNoncopyable();
29512951
}
29522952
if (auto *d = dyn_cast<DeclRefExpr>(e))
2953-
return e->getType()->isPureMoveOnly();
2953+
return e->getType()->isNoncopyable();
29542954
return false;
29552955
}
29562956

lib/SILGen/SILGenProlog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ class ArgumentInitHelper {
705705
// - @_eagerMove
706706
// - @_noEagerMove
707707
bool isNoImplicitCopy = pd->isNoImplicitCopy();
708-
if (!argrv.getType().isPureMoveOnly()) {
708+
if (!argrv.getType().getASTType()->isNoncopyable()) {
709709
isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Borrowing;
710710
isNoImplicitCopy |= pd->getSpecifier() == ParamSpecifier::Consuming;
711711
if (pd->isSelfParameter()) {
@@ -1168,7 +1168,7 @@ static void emitCaptureArguments(SILGenFunction &SGF,
11681168
// in SIL since it is illegal to capture an inout value in an escaping
11691169
// closure. The later code knows how to handle that we have the
11701170
// mark_unresolved_non_copyable_value here.
1171-
if (isInOut && ty.isPureMoveOnly()) {
1171+
if (isInOut && ty.getASTType()->isNoncopyable()) {
11721172
arg = SGF.B.createMarkUnresolvedNonCopyableValueInst(
11731173
Loc, arg,
11741174
MarkUnresolvedNonCopyableValueInst::CheckKind::

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ struct AllocStackAnalyzer : SILInstructionVisitor<AllocStackAnalyzer> {
379379
// analysis assumes memory is deinitialized on all paths, which is not the
380380
// case for discarded values. Eventually copyable types may also be
381381
// discarded; to support that, we will leave a drop_deinit_addr in place.
382-
if (ASI->getType().isPureMoveOnly()) {
382+
if (ASI->getType().getASTType()->isNoncopyable()) {
383383
LegalUsers = false;
384384
return;
385385
}

lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static bool performTransform(SILFunction &fn) {
6969

7070
if (auto *dvi = dyn_cast<DestroyValueInst>(inst)) {
7171
auto destroyType = dvi->getOperand()->getType();
72-
if (destroyType.isPureMoveOnly() &&
72+
if (destroyType.getASTType()->isNoncopyable() &&
7373
!isa<DropDeinitInst>(lookThroughOwnershipInsts(dvi->getOperand()))) {
7474
LLVM_DEBUG(llvm::dbgs() << "Handling: " << *dvi);
7575
auto *nom = destroyType.getNominalOrBoundGenericNominal();
@@ -112,7 +112,8 @@ static bool performTransform(SILFunction &fn) {
112112

113113
if (auto *dai = dyn_cast<DestroyAddrInst>(inst)) {
114114
auto destroyType = dai->getOperand()->getType();
115-
if (destroyType.isLoadable(fn) && destroyType.isPureMoveOnly() &&
115+
if (destroyType.isLoadable(fn)
116+
&& destroyType.getASTType()->isNoncopyable() &&
116117
!isa<DropDeinitInst>(dai->getOperand())) {
117118
LLVM_DEBUG(llvm::dbgs() << "Handling: " << *dai);
118119
auto *nom = destroyType.getNominalOrBoundGenericNominal();

lib/SILOptimizer/Transforms/SILLowerAggregateInstrs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static bool shouldExpandShim(SILFunction *fn, SILType type) {
5252
// shouldExpand returns false for struct-with-deinit types, so bypassing it is
5353
// incorrect for move-only types
5454
if (EnableExpandAll) {
55-
assert(!type.isPureMoveOnly()
55+
assert(!type.getASTType()->isNoncopyable()
5656
&& "sil-lower-agg-instrs-expand-all is incompatible with move-only "
5757
"types");
5858
return true;

lib/SILOptimizer/Utils/InstructionDeleter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static bool isScopeAffectingInstructionDead(SILInstruction *inst,
7070
// move_value instructions. And `move_value %moveOnlyValue` must not be
7171
// deleted.
7272
for (auto result : inst->getResults()) {
73-
if (result->getType().isPureMoveOnly() &&
73+
if (result->getType().getASTType()->isNoncopyable() &&
7474
result->getOwnershipKind() == OwnershipKind::Owned) {
7575
return false;
7676
}

lib/Sema/CSSimplify.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3865,7 +3865,7 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
38653865
}
38663866

38673867
// move-only types (and their metatypes) cannot match with existential types.
3868-
if (type1->getMetatypeInstanceType()->isPureMoveOnly()) {
3868+
if (type1->getMetatypeInstanceType()->isNoncopyable()) {
38693869
// tailor error message
38703870
if (shouldAttemptFixes()) {
38713871
auto *fix = MustBeCopyable::create(*this,
@@ -11842,7 +11842,7 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
1184211842

1184311843
// Move-only types can't be involved in a bridging conversion since a bridged
1184411844
// type assumes the ability to copy.
11845-
if (type1->isPureMoveOnly()) {
11845+
if (type1->isNoncopyable()) {
1184611846
return SolutionKind::Error;
1184711847
}
1184811848

0 commit comments

Comments
 (0)