Skip to content

Commit 1d5fecb

Browse files
authored
Merge pull request #82584 from DougGregor/nonisolated-deinit-availability
"nonisolated deinit" does not have back-deployment constraints
2 parents a9f696b + a9d0a05 commit 1d5fecb

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7771,8 +7771,6 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
77717771
}
77727772
}
77737773

7774-
diagnoseIsolatedDeinitInValueTypes(attr);
7775-
77767774
if (auto VD = dyn_cast<ValueDecl>(D)) {
77777775
//'nonisolated(unsafe)' is meaningless for computed properties, functions etc.
77787776
auto var = dyn_cast<VarDecl>(VD);
@@ -7807,8 +7805,6 @@ void AttributeChecker::visitGlobalActorAttr(GlobalActorAttr *attr) {
78077805
return;
78087806
}
78097807

7810-
diagnoseIsolatedDeinitInValueTypes(attr);
7811-
78127808
(void)nominal->isGlobalActor();
78137809
}
78147810

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -swift-version 5 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift5- -enable-experimental-feature SendableProhibitsMainActorInference
2+
// RUN: %target-swift-frontend -swift-version 6 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift6- -enable-experimental-feature SendableProhibitsMainActorInference
3+
4+
// REQUIRES: swift_feature_SendableProhibitsMainActorInference
5+
6+
// Ensure that a Sendable-conforming protocol suppresses @MainActor inference
7+
// for a type.
8+
enum CK: CodingKey {
9+
case one
10+
11+
func f() { }
12+
}
13+
14+
nonisolated func testCK(x: CK) {
15+
x.f() // okay, because CK and CK.f are not @MainActor.
16+
}

test/Concurrency/deinit_isolation_in_value_types.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct CS: ~Copyable {
1919
}
2020

2121
struct DS: ~Copyable {
22-
nonisolated deinit {} // expected-error {{only classes and actors can have isolated deinit}}
22+
nonisolated deinit {}
2323
}
2424

2525
struct ES: ~Copyable {
@@ -47,7 +47,7 @@ enum CE: ~Copyable {
4747
enum DE: ~Copyable {
4848
case dummy
4949
// expected-error@+1 {{deinitializers are not yet supported on noncopyable enums}}
50-
nonisolated deinit {} // expected-error {{only classes and actors can have isolated deinit}}
50+
nonisolated deinit {}
5151
}
5252

5353
enum EE: ~Copyable {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 5 %s -strict-concurrency=complete -target %target-swift-5.1-abi-triple
2+
3+
// REQUIRES: concurrency
4+
// REQUIRES: OS=macosx
5+
6+
class NotSendable {}
7+
8+
@MainActor class C {
9+
var x: Int = 0
10+
11+
nonisolated deinit {
12+
print(x)
13+
}
14+
}
15+
16+
// expected-note@+1{{add '@available' attribute to enclosing class}}
17+
@MainActor class C2 {
18+
var x: Int = 0
19+
20+
isolated deinit { // expected-error{{isolated deinit is only available in macOS 15.4.0 or newer}}
21+
print(x)
22+
}
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// REQUIRES: swift_swift_parser, executable_test
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
5+
6+
// Check for errors
7+
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) %s -I %t -disable-availability-checking -swift-version 6 -default-isolation MainActor -enable-experimental-feature SendableProhibitsMainActorInference
8+
9+
// REQUIRES: swift_feature_SendableProhibitsMainActorInference
10+
11+
@attached(extension, conformances: Sendable)
12+
macro AddSendable() = #externalMacro(module: "MacroDefinition", type: "SendableMacro")
13+
14+
@AddSendable
15+
final class SendableClass {
16+
var property: Int { 0 }
17+
18+
func f() { }
19+
}
20+
21+
nonisolated func acceptSendable<T: Sendable>(_: T) { }
22+
23+
@concurrent func test(sc: SendableClass) async {
24+
acceptSendable(sc) // SendableClass is Sendable
25+
acceptSendable(\SendableClass.property) // so is its property
26+
sc.f() // not on the main actor, so this is okay
27+
}

0 commit comments

Comments
 (0)