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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 3 additions & 2 deletions
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())) {

0 commit comments

Comments
 (0)