Skip to content

Commit 1356694

Browse files
committed
experimentally allow move-only classes
A lot of existing regression tests rely on there being some form of move-only classes, despite them being something that will not be available to users (and not complete). This change introduces a `MoveOnlyClasses` experimental feature so that those tests don't need to be fully rewritten just yet. You need to include `-enable-experimental-feature MoveOnlyClasses` along with `-enable-experimental-move-only` to get move-only classes.
1 parent fef04f5 commit 1356694

16 files changed

+25
-17
lines changed

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,6 +3117,10 @@ static bool usesFeatureMoveOnly(Decl *decl) {
31173117
return false;
31183118
}
31193119

3120+
static bool usesFeatureMoveOnlyClasses(Decl *decl) {
3121+
return false;
3122+
}
3123+
31203124
static bool usesFeatureOneWayClosureParameters(Decl *decl) {
31213125
return false;
31223126
}

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,12 @@ void AttributeChecker::visitMoveOnlyAttr(MoveOnlyAttr *attr) {
20992099
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

test/SILOptimizer/moveonly_lifetime.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 -Onone -verify -enable-experimental-move-only %s | %FileCheck %s
1+
// RUN: %target-swift-emit-sil -Onone -verify -enable-experimental-move-only -enable-experimental-feature MoveOnlyClasses %s | %FileCheck %s
22

33
@_moveOnly
44
class C {}

0 commit comments

Comments
 (0)