Skip to content

Commit ca1f3f7

Browse files
authored
Merge pull request swiftlang#63179 from kavon/moveonly-structs-or-enums
Limit `@_moveOnly` to structs and enums
2 parents 98856b1 + 1978553 commit ca1f3f7

18 files changed

+34
-21
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6704,7 +6704,7 @@ ERROR(concurrency_task_to_thread_model_global_actor_annotation,none,
67046704
(TypeRepr*, StringRef))
67056705

67066706
ERROR(moveOnly_not_allowed_here,none,
6707-
"'moveOnly' may only be applied to classes, structs, and enums", ())
6707+
"'moveOnly' only applies to structs or enums", ())
67086708
ERROR(move_expression_not_passed_lvalue,none,
67096709
"'move' can only be applied to lvalues", ())
67106710
ERROR(borrow_expression_not_passed_lvalue,none,

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ EXPERIMENTAL_FEATURE(VariadicGenerics, false)
103103
EXPERIMENTAL_FEATURE(NamedOpaqueTypes, false)
104104
EXPERIMENTAL_FEATURE(FlowSensitiveConcurrencyCaptures, false)
105105
EXPERIMENTAL_FEATURE(MoveOnly, false)
106+
EXPERIMENTAL_FEATURE(MoveOnlyClasses, false)
106107
EXPERIMENTAL_FEATURE(OneWayClosureParameters, false)
107108
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference, false)
108109
EXPERIMENTAL_FEATURE(LayoutPrespecialization, false)

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,9 +3114,15 @@ static bool usesFeatureFlowSensitiveConcurrencyCaptures(Decl *decl) {
31143114
}
31153115

31163116
static bool usesFeatureMoveOnly(Decl *decl) {
3117+
if (auto nominal = dyn_cast<NominalTypeDecl>(decl))
3118+
return nominal->isMoveOnly();
31173119
return false;
31183120
}
31193121

3122+
static bool usesFeatureMoveOnlyClasses(Decl *decl) {
3123+
return isa<ClassDecl>(decl) && usesFeatureMoveOnly(decl);
3124+
}
3125+
31203126
static bool usesFeatureOneWayClosureParameters(Decl *decl) {
31213127
return false;
31223128
}

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,9 +2096,15 @@ void AttributeChecker::visitMoveOnlyAttr(MoveOnlyAttr *attr) {
20962096
return;
20972097
}
20982098

2099-
if (isa<NominalTypeDecl>(D))
2099+
if (isa<StructDecl>(D) || isa<EnumDecl>(D))
21002100
return;
21012101

2102+
// for development purposes, allow it if specifically requested for classes.
2103+
if (D->getASTContext().LangOpts.hasFeature(Feature::MoveOnlyClasses)) {
2104+
if (isa<ClassDecl>(D))
2105+
return;
2106+
}
2107+
21022108
diagnose(attr->getLocation(), diag::moveOnly_not_allowed_here)
21032109
.fixItRemove(attr->getRange());
21042110
}

test/SILGen/moveonly.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-silgen -enable-experimental-move-only %s | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen -enable-experimental-move-only -enable-experimental-feature MoveOnlyClasses %s | %FileCheck %s
22

33
//////////////////
44
// Declarations //

test/SILGen/moveonly_var.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-emit-silgen -enable-experimental-move-only %s | %FileCheck %s
2-
// RUN: %target-swift-emit-sil -enable-experimental-move-only %s | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen -enable-experimental-move-only -enable-experimental-feature MoveOnlyClasses %s | %FileCheck %s
2+
// RUN: %target-swift-emit-sil -enable-experimental-move-only -enable-experimental-feature MoveOnlyClasses %s | %FileCheck %s
33

44
//////////////////
55
// Declarations //

test/SILOptimizer/moveonly_addresschecker.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -sil-move-only-address-checker -enable-experimental-move-only -enable-sil-verify-all %s | %FileCheck %s
1+
// RUN: %target-sil-opt -sil-move-only-address-checker -enable-experimental-move-only -enable-experimental-feature MoveOnlyClasses -enable-sil-verify-all %s | %FileCheck %s
22

33
sil_stage raw
44

test/SILOptimizer/moveonly_addresschecker_diagnostics.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -sil-move-only-address-checker -enable-experimental-move-only -enable-sil-verify-all %s -verify
1+
// RUN: %target-sil-opt -sil-move-only-address-checker -enable-experimental-move-only -enable-experimental-feature MoveOnlyClasses -enable-sil-verify-all %s -verify
22

33
// TODO: Add FileCheck
44

test/SILOptimizer/moveonly_addresschecker_diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-sil -verify -enable-experimental-move-only %s
1+
// RUN: %target-swift-emit-sil -verify -enable-experimental-move-only -enable-experimental-feature MoveOnlyClasses %s
22

33
//////////////////
44
// Declarations //

test/SILOptimizer/moveonly_deinit_insertion.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -module-name main -enable-sil-verify-all -sil-move-only-deinit-insertion -enable-experimental-move-only %s | %FileCheck %s
1+
// RUN: %target-sil-opt -module-name main -enable-sil-verify-all -sil-move-only-deinit-insertion -enable-experimental-move-only -enable-experimental-feature MoveOnlyClasses %s | %FileCheck %s
22

33
sil_stage raw
44

0 commit comments

Comments
 (0)