Skip to content

Commit a1a975f

Browse files
authored
Merge pull request #71002 from hborla/preconcurrency-downgrade-take-two
[Concurrency] Set `preconcurrency` for actor isolation created from unsafe global actor attributes.
2 parents 5bbead3 + 7959341 commit a1a975f

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4125,7 +4125,7 @@ getIsolationFromAttributes(const Decl *decl, bool shouldDiagnose = true,
41254125

41264126
return ActorIsolation::forGlobalActor(
41274127
globalActorType->mapTypeOutOfContext(), isUnsafe)
4128-
.withPreconcurrency(decl->preconcurrency());
4128+
.withPreconcurrency(decl->preconcurrency() || isUnsafe);
41294129
}
41304130

41314131
llvm_unreachable("Forgot about an attribute?");

test/Concurrency/actor_isolation_unsafe.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct S5_P2: P2 {
6060
}
6161

6262
nonisolated func testP2(x: S5_P2, p2: P2) {
63-
p2.f() // expected-error{{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
63+
p2.f() // expected-warning{{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
6464
p2.g() // OKAY
6565
x.f() // expected-error{{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
6666
x.g() // OKAY
@@ -69,7 +69,7 @@ nonisolated func testP2(x: S5_P2, p2: P2) {
6969
func testP2_noconcurrency(x: S5_P2, p2: P2) {
7070
// expected-complete-tns-note @-1 2{{add '@MainActor' to make global function 'testP2_noconcurrency(x:p2:)' part of global actor 'MainActor'}}
7171
p2.f() // okay without complete. with targeted/minimal not concurrency-related code.
72-
// expected-complete-tns-error @-1 {{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
72+
// expected-complete-tns-warning @-1 {{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
7373
p2.g() // okay
7474
x.f() // okay without complete. with targeted/minimal not concurrency-related code
7575
// expected-complete-tns-error @-1 {{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
@@ -86,19 +86,19 @@ class C1 {
8686
class C2: C1 {
8787
override func method() { // expected-note 2{{overridden declaration is here}}
8888
globalSome() // okay when not in complete
89-
// expected-complete-tns-error @-1 {{call to global actor 'SomeGlobalActor'-isolated global function 'globalSome()' in a synchronous main actor-isolated context}}
89+
// expected-complete-tns-warning @-1 {{call to global actor 'SomeGlobalActor'-isolated global function 'globalSome()' in a synchronous main actor-isolated context}}
9090
}
9191
}
9292

9393
class C3: C1 {
9494
nonisolated override func method() {
95-
globalSome() // expected-error{{call to global actor 'SomeGlobalActor'-isolated global function 'globalSome()' in a synchronous nonisolated context}}
95+
globalSome() // expected-warning{{call to global actor 'SomeGlobalActor'-isolated global function 'globalSome()' in a synchronous nonisolated context}}
9696
}
9797
}
9898

9999
class C4: C1 {
100100
@MainActor override func method() {
101-
globalSome() // expected-error{{call to global actor 'SomeGlobalActor'-isolated global function 'globalSome()' in a synchronous main actor-isolated context}}
101+
globalSome() // expected-warning{{call to global actor 'SomeGlobalActor'-isolated global function 'globalSome()' in a synchronous main actor-isolated context}}
102102
}
103103
}
104104

@@ -115,7 +115,7 @@ class C6: C2 {
115115

116116
class C7: C2 {
117117
@SomeGlobalActor(unsafe) override func method() { // expected-error{{global actor 'SomeGlobalActor'-isolated instance method 'method()' has different actor isolation from main actor-isolated overridden declaration}}
118-
globalMain() // expected-error{{call to main actor-isolated global function 'globalMain()' in a synchronous global actor 'SomeGlobalActor'-isolated context}}
118+
globalMain() // expected-warning{{call to main actor-isolated global function 'globalMain()' in a synchronous global actor 'SomeGlobalActor'-isolated context}}
119119
globalSome() // okay
120120
}
121121
}

test/Concurrency/async_initializer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func globActorTest1() {
126126

127127
_ = SomeStruct(asyncMainActorUnsafe: 0) // expected-error {{'async' call in a function that does not support concurrency}}
128128

129-
_ = SomeStruct(mainActorUnsafe: 0) // expected-complete-and-tns-error {{call to main actor-isolated initializer 'init(mainActorUnsafe:)' in a synchronous nonisolated context}}
129+
_ = SomeStruct(mainActorUnsafe: 0) // expected-complete-and-tns-warning {{call to main actor-isolated initializer 'init(mainActorUnsafe:)' in a synchronous nonisolated context}}
130130
}
131131

132132
func globActorTestAsyncEdition() async {

test/Concurrency/global_actor_function_types.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func testClosures(i: Int) async {
7171
}
7272

7373
acceptOnSomeGlobalActor { () -> Int in
74-
let i = onOtherGlobalActorUnsafe() // expected-error{{call to global actor 'OtherGlobalActor'-isolated global function 'onOtherGlobalActorUnsafe()' in a synchronous global actor 'SomeGlobalActor'-isolated context}}
74+
let i = onOtherGlobalActorUnsafe() // expected-warning{{call to global actor 'OtherGlobalActor'-isolated global function 'onOtherGlobalActorUnsafe()' in a synchronous global actor 'SomeGlobalActor'-isolated context}}
7575
return i
7676
}
7777
}
@@ -93,12 +93,12 @@ func testClosuresOld() {
9393
}
9494

9595
acceptOnSomeGlobalActor { () -> Int in
96-
let i = onOtherGlobalActorUnsafe() // expected-complete-tns-error {{call to global actor 'OtherGlobalActor'-isolated global function 'onOtherGlobalActorUnsafe()' in a synchronous global actor 'SomeGlobalActor'-isolated context}}
96+
let i = onOtherGlobalActorUnsafe() // expected-complete-tns-warning {{call to global actor 'OtherGlobalActor'-isolated global function 'onOtherGlobalActorUnsafe()' in a synchronous global actor 'SomeGlobalActor'-isolated context}}
9797
return i
9898
}
9999

100100
acceptOnSomeGlobalActor { @SomeGlobalActor () -> Int in
101-
let i = onOtherGlobalActorUnsafe() // expected-error{{call to global actor 'OtherGlobalActor'-isolated global function 'onOtherGlobalActorUnsafe()' in a synchronous global actor 'SomeGlobalActor'-isolated context}}
101+
let i = onOtherGlobalActorUnsafe() // expected-warning{{call to global actor 'OtherGlobalActor'-isolated global function 'onOtherGlobalActorUnsafe()' in a synchronous global actor 'SomeGlobalActor'-isolated context}}
102102
return i
103103
}
104104
}

test/Concurrency/global_actor_inference.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ struct StructUGA3: UGA {
524524

525525
@GenericGlobalActor<String>
526526
func testUGA<T: UGA>(_ value: T) {
527-
value.req() // expected-error{{call to global actor 'SomeGlobalActor'-isolated instance method 'req()' in a synchronous global actor 'GenericGlobalActor<String>'-isolated context}}
527+
value.req() // expected-warning{{call to global actor 'SomeGlobalActor'-isolated instance method 'req()' in a synchronous global actor 'GenericGlobalActor<String>'-isolated context}}
528528
}
529529

530530
class UGAClass {
@@ -569,15 +569,15 @@ struct HasWrapperOnUnsafeActor {
569569
// expected-complete-tns-note @-1 {{add '@OtherGlobalActor' to make instance method 'testUnsafeOkay()' part of global actor 'OtherGlobalActor'}}
570570
// expected-complete-tns-note @-2 {{add '@SomeGlobalActor' to make instance method 'testUnsafeOkay()' part of global actor 'SomeGlobalActor'}}
571571
// expected-complete-tns-note @-3 {{add '@MainActor' to make instance method 'testUnsafeOkay()' part of global actor 'MainActor'}}
572-
_ = synced // expected-complete-tns-error {{main actor-isolated property 'synced' can not be referenced from a non-isolated context}}
573-
_ = $synced // expected-complete-tns-error {{global actor 'SomeGlobalActor'-isolated property '$synced' can not be referenced from a non-isolated context}}
574-
_ = _synced // expected-complete-tns-error {{global actor 'OtherGlobalActor'-isolated property '_synced' can not be referenced from a non-isolated context}}
572+
_ = synced // expected-complete-tns-warning {{main actor-isolated property 'synced' can not be referenced from a non-isolated context}}
573+
_ = $synced // expected-complete-tns-warning {{global actor 'SomeGlobalActor'-isolated property '$synced' can not be referenced from a non-isolated context}}
574+
_ = _synced // expected-complete-tns-warning {{global actor 'OtherGlobalActor'-isolated property '_synced' can not be referenced from a non-isolated context}}
575575
}
576576

577577
nonisolated func testErrors() {
578-
_ = synced // expected-error{{main actor-isolated property 'synced' can not be referenced from a non-isolated context}}
579-
_ = $synced // expected-error{{global actor 'SomeGlobalActor'-isolated property '$synced' can not be referenced from a non-isolated context}}
580-
_ = _synced // expected-error{{global actor 'OtherGlobalActor'-isolated property '_synced' can not be referenced from a non-isolated context}}
578+
_ = synced // expected-warning{{main actor-isolated property 'synced' can not be referenced from a non-isolated context}}
579+
_ = $synced // expected-warning{{global actor 'SomeGlobalActor'-isolated property '$synced' can not be referenced from a non-isolated context}}
580+
_ = _synced // expected-warning{{global actor 'OtherGlobalActor'-isolated property '_synced' can not be referenced from a non-isolated context}}
581581
}
582582

583583
@MainActor mutating func testOnMain() {

test/decl/class/actor/global_actor_conformance.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,16 @@ extension OnMain: NonIsolatedRequirement {
5656
// expected-note@+1 {{add 'nonisolated' to 'requirement()' to make this instance method not isolated to the actor}}
5757
func requirement() {}
5858
}
59+
60+
// expected-note@+1 {{calls to global function 'downgrade()' from outside of its actor context are implicitly asynchronous}}
61+
@MainActor(unsafe) func downgrade() {}
62+
63+
extension OnMain {
64+
struct Nested {
65+
// expected-note@+1 {{add '@MainActor' to make instance method 'test()' part of global actor 'MainActor'}}
66+
func test() {
67+
// expected-warning@+1 {{call to main actor-isolated global function 'downgrade()' in a synchronous nonisolated context}}
68+
downgrade()
69+
}
70+
}
71+
}

validation-test/Sema/SwiftUI/rdar76252310.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func fromMainActor() async {
3535

3636
func fromConcurrencyAware() async {
3737
// expected-note@+3 {{calls to initializer 'init()' from outside of its actor context are implicitly asynchronous}}
38-
// expected-error@+2 {{expression is 'async' but is not marked with 'await'}}
38+
// expected-warning@+2 {{expression is 'async' but is not marked with 'await'}}
3939
// expected-warning@+1 {{non-sendable type 'CoffeeTrackerView' returned by call to main actor-isolated function cannot cross actor boundary}}
4040
let view = CoffeeTrackerView()
4141

0 commit comments

Comments
 (0)