Skip to content

Commit dd7552b

Browse files
authored
Merge pull request #64919 from jckarter/disable-enum-deinit-5.9
[5.9] [move-only] Temporarily ban deinits on non-copyable enums.
2 parents 7f22ad6 + 66ffa86 commit dd7552b

16 files changed

+55
-17
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ ERROR(initializer_result_type,PointsToFirstBadToken,
424424
// Destructor
425425
ERROR(destructor_decl_outside_class_or_noncopyable,none,
426426
"deinitializers may only be declared within a class, actor, or noncopyable type", ())
427+
ERROR(destructor_decl_on_noncopyable_enum,none,
428+
"deinitializers are not yet supported on noncopyable enums", ())
427429
ERROR(destructor_decl_on_objc_enum,none,
428430
"deinitializers cannot be declared on an @objc enum type", ())
429431
ERROR(expected_lbrace_destructor,PointsToFirstBadToken,

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ EXPERIMENTAL_FEATURE(FreestandingMacros, true)
117117
// but our tests currently rely on it, and we want to run those
118118
// tests in non-asserts builds too.
119119
EXPERIMENTAL_FEATURE(MoveOnlyClasses, true)
120+
EXPERIMENTAL_FEATURE(NoImplicitCopy, true)
121+
EXPERIMENTAL_FEATURE(OldOwnershipOperatorSpellings, true)
122+
EXPERIMENTAL_FEATURE(MoveOnlyEnumDeinits, true)
120123

121124
EXPERIMENTAL_FEATURE(OneWayClosureParameters, false)
122125
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference, false)

lib/AST/ASTPrinter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,21 @@ static bool usesFeatureMoveOnlyClasses(Decl *decl) {
32563256
return isa<ClassDecl>(decl) && usesFeatureMoveOnly(decl);
32573257
}
32583258

3259+
static bool usesFeatureNoImplicitCopy(Decl *decl) {
3260+
return decl->isNoImplicitCopy();
3261+
}
3262+
3263+
static bool usesFeatureOldOwnershipOperatorSpellings(Decl *decl) {
3264+
return false;
3265+
}
3266+
3267+
static bool usesFeatureMoveOnlyEnumDeinits(Decl *decl) {
3268+
if (auto *ei = dyn_cast<EnumDecl>(decl)) {
3269+
return usesFeatureMoveOnly(ei) && ei->getValueTypeDestructor();
3270+
}
3271+
return false;
3272+
}
3273+
32593274
static bool usesFeatureOneWayClosureParameters(Decl *decl) {
32603275
return false;
32613276
}

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3614,6 +3614,14 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
36143614
DD->diagnose(diag::destructor_decl_outside_class_or_noncopyable);
36153615
}
36163616

3617+
// Temporarily ban deinit on noncopyable enums, unless the experimental
3618+
// feature flag is set.
3619+
if (!DD->getASTContext().LangOpts.hasFeature(
3620+
Feature::MoveOnlyEnumDeinits) &&
3621+
nom->isMoveOnly() && isa<EnumDecl>(nom)) {
3622+
DD->diagnose(diag::destructor_decl_on_noncopyable_enum);
3623+
}
3624+
36173625
// If we have a noncopyable type, check if we have an @objc enum with a
36183626
// deinit and emit a specialized error. We will have technically already
36193627
// emitted an error since @objc enum cannot be marked noncopyable, but

test/IRGen/moveonly_deinit.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/chex.py < %s > %t/moveonly_deinit.sil
3-
// RUN: %target-swift-frontend -emit-ir %t/moveonly_deinit.sil | %FileCheck %t/moveonly_deinit.sil --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
3+
// RUN: %target-swift-frontend -enable-experimental-feature MoveOnlyEnumDeinits -emit-ir %t/moveonly_deinit.sil | %FileCheck %t/moveonly_deinit.sil --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
44

55
// UNSUPPORTED: CPU=arm64e
66

test/IRGen/moveonly_deinits.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// TODO: re-enable the simplification passes once rdar://104875010 is fixed
2-
// RUN: %target-swift-emit-ir -Xllvm -sil-disable-pass=simplification %s | %FileCheck -check-prefix=IR %s
2+
// RUN: %target-swift-emit-ir -enable-experimental-feature MoveOnlyEnumDeinits -Xllvm -sil-disable-pass=simplification %s | %FileCheck -check-prefix=IR %s
33

44
// Test that makes sure that at IRGen time we properly handle conditional
55
// releases for trivial and non-trivial move only types. The SIL/SILGen part of
66
// this test is in test/SILGen/moveonly_deinits. We have a separate test so that
77
// we can test on other platforms the other behavior.
88

99
// REQUIRES: asserts
10-
// REQUIRES: CPU=x86_64
10+
// REQUIRES: CODEGENERATOR=X86
1111

1212
//////////////////////
1313
// Misc Declaration //

test/Interpreter/moveonly_forget.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all) | %FileCheck %s --implicit-check-not closing
1+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-feature -Xfrontend MoveOnlyEnumDeinits -Xfrontend -sil-verify-all) | %FileCheck %s --implicit-check-not closing
22

33
// REQUIRES: executable_test
44

test/SILGen/forget.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 -module-name test %s | %FileCheck %s --enable-var-scope
2-
// RUN: %target-swift-emit-sil -module-name test -sil-verify-all %s | %FileCheck %s --check-prefix CHECK-SIL --enable-var-scope
1+
// RUN: %target-swift-emit-silgen -enable-experimental-feature MoveOnlyEnumDeinits -module-name test %s | %FileCheck %s --enable-var-scope
2+
// RUN: %target-swift-emit-sil -enable-experimental-feature MoveOnlyEnumDeinits -module-name test -sil-verify-all %s | %FileCheck %s --check-prefix CHECK-SIL --enable-var-scope
33

44
func invokedDeinit() {}
55

test/SILGen/moveonly_deinits.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// TODO: re-enable the simplification passes once rdar://104875010 is fixed
2-
// RUN: %target-swift-emit-silgen -Xllvm -sil-disable-pass=simplification %s | %FileCheck -check-prefix=SILGEN %s
3-
// RUN: %target-swift-emit-sil -Xllvm -sil-disable-pass=simplification %s | %FileCheck -check-prefix=SIL %s
2+
// RUN: %target-swift-emit-silgen -enable-experimental-feature MoveOnlyEnumDeinits -Xllvm -sil-disable-pass=simplification %s | %FileCheck -check-prefix=SILGEN %s
3+
// RUN: %target-swift-emit-sil -enable-experimental-feature MoveOnlyEnumDeinits -Xllvm -sil-disable-pass=simplification %s | %FileCheck -check-prefix=SIL %s
44

55
// Test that makes sure that throughout the pipeline we properly handle
66
// conditional releases for trivial and non-trivial move only types.

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-feature MoveOnlyClasses %s | %FileCheck %s
1+
// RUN: %target-sil-opt -module-name main -enable-sil-verify-all -sil-move-only-deinit-insertion -enable-experimental-feature MoveOnlyClasses -enable-experimental-feature MoveOnlyEnumDeinits %s | %FileCheck %s
22

33
sil_stage raw
44

test/SILOptimizer/moveonly_deinits.swift

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

33
class Klass {}
44

test/Sema/forget.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature MoveOnlyEnumDeinits
22

33
// Typechecking for the forget statement.
44

test/Sema/moveonly_enum.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
@_moveOnly
4+
enum Foo {
5+
deinit {} // expected-error {{deinitializers are not yet supported on noncopyable enums}}
6+
}
7+
8+
@_moveOnly
9+
enum Foo2 {
10+
}

test/Sema/moveonly_objc_enum.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature MoveOnlyEnumDeinits
22

33
// REQUIRES: objc_interop
44

test/Serialization/moveonly_deinit.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// TODO: re-enable the simplification passes once rdar://104875010 is fixed
3-
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -g -emit-module -module-name OtherModule %S/Inputs/moveonly_deinit.swift -emit-module-path %t/OtherModule.swiftmodule
4-
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -g -I %t %s -emit-silgen
3+
// RUN: %target-swift-frontend -enable-experimental-feature MoveOnlyEnumDeinits -Xllvm -sil-disable-pass=simplification -g -emit-module -module-name OtherModule %S/Inputs/moveonly_deinit.swift -emit-module-path %t/OtherModule.swiftmodule
4+
// RUN: %target-swift-frontend -enable-experimental-feature MoveOnlyEnumDeinits -Xllvm -sil-disable-pass=simplification -g -I %t %s -emit-silgen
55

66
// Make sure we can deserialize deinits of both enums and structs.
77

test/Serialization/moveonly_error_on_import_into_module_without_flag.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// RUN: %empty-directory(%t)
22
// TODO: re-enable the simplification passes once rdar://104875010 is fixed
3-
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -emit-module -o %t/Library.swiftmodule -module-name Library %S/Inputs/moveonly_deinit.swift
3+
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -emit-module -o %t/Library.swiftmodule -module-name Library %S/Inputs/moveonly_deinit.swift -enable-experimental-feature MoveOnlyEnumDeinits
44

55
// >>> make sure borrow scopes are required when using a move-only type from another module
6-
// RUN: not %target-swift-frontend -DUSE_MOVEONLY_TYPE -typecheck -enable-lexical-borrow-scopes=false -I %t %s 2>&1 | %FileCheck %s --check-prefix CHECK-ERROR
6+
// RUN: not %target-swift-frontend -DUSE_MOVEONLY_TYPE -typecheck -enable-experimental-feature MoveOnlyEnumDeinits -enable-lexical-borrow-scopes=false -I %t %s 2>&1 | %FileCheck %s --check-prefix CHECK-ERROR
77
// RUN: %target-swift-frontend -DUSE_MOVEONLY_TYPE -typecheck -I %t %s 2>&1 | %FileCheck %s --allow-empty
88

99
// >>> try turning off lexical borrow scopes with no move-only types; shouldn't be an error.
1010
// we have to pipe into FileCheck because -verify ignores errors from other files.
11-
// RUN: %target-swift-frontend -enable-lexical-borrow-scopes=false -typecheck -I %t %s 2>&1 | %FileCheck %s --allow-empty
11+
// RUN: %target-swift-frontend -enable-experimental-feature MoveOnlyEnumDeinits -enable-lexical-borrow-scopes=false -typecheck -I %t %s 2>&1 | %FileCheck %s --allow-empty
1212

1313
// This test makes sure that if we import a move only type
1414
// and do not have lexical borrow scopes enabled, we emit an error.

0 commit comments

Comments
 (0)