Skip to content

Commit 8453978

Browse files
authored
Merge pull request #64692 from gottesmm/pr-f1e588ca3b1fd387de94e5afc8350ef1dd1caf3e
[move-only] Temporarily ban deinits on non-copyable enums.
2 parents 9807267 + aa75e6d commit 8453978

16 files changed

+45
-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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ EXPERIMENTAL_FEATURE(FreestandingMacros, true)
118118
EXPERIMENTAL_FEATURE(MoveOnlyClasses, true)
119119
EXPERIMENTAL_FEATURE(NoImplicitCopy, true)
120120
EXPERIMENTAL_FEATURE(OldOwnershipOperatorSpellings, true)
121+
EXPERIMENTAL_FEATURE(MoveOnlyEnumDeinits, true)
121122

122123
EXPERIMENTAL_FEATURE(OneWayClosureParameters, false)
123124
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference, false)

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,6 +3246,13 @@ static bool usesFeatureOldOwnershipOperatorSpellings(Decl *decl) {
32463246
return false;
32473247
}
32483248

3249+
static bool usesFeatureMoveOnlyEnumDeinits(Decl *decl) {
3250+
if (auto *ei = dyn_cast<EnumDecl>(decl)) {
3251+
return usesFeatureMoveOnly(ei) && ei->getValueTypeDestructor();
3252+
}
3253+
return false;
3254+
}
3255+
32493256
static bool usesFeatureOneWayClosureParameters(Decl *decl) {
32503257
return false;
32513258
}

lib/Sema/TypeCheckDeclPrimary.cpp

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

3612+
// Temporarily ban deinit on noncopyable enums, unless the experimental
3613+
// feature flag is set.
3614+
if (!DD->getASTContext().LangOpts.hasFeature(
3615+
Feature::MoveOnlyEnumDeinits) &&
3616+
nom->isMoveOnly() && isa<EnumDecl>(nom)) {
3617+
DD->diagnose(diag::destructor_decl_on_noncopyable_enum);
3618+
}
3619+
36123620
// If we have a noncopyable type, check if we have an @objc enum with a
36133621
// deinit and emit a specialized error. We will have technically already
36143622
// 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

0 commit comments

Comments
 (0)