Skip to content

Commit 4630c43

Browse files
committed
Downgrade concurrency-related error to a warning.
We are diagnosing this condition more completely now, so downgrade from an error to a warning to not break existing code. Fixes rdar://88649197.
1 parent d4ea32c commit 4630c43

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,8 @@ namespace {
25802580
ctx.Diags.diagnose(
25812581
loc, diag::concurrent_access_of_local_capture,
25822582
parent.dyn_cast<LoadExpr *>(),
2583-
var->getDescriptiveKind(), var->getName());
2583+
var->getDescriptiveKind(), var->getName())
2584+
.warnUntilSwiftVersion(6);
25842585
return true;
25852586
}
25862587

test/ClangImporter/objc_async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func testSendable(fn: () -> Void) {
114114
func testSendableInAsync() async {
115115
var x = 17
116116
doSomethingConcurrentlyButUnsafe {
117-
x = 42 // expected-error{{mutation of captured var 'x' in concurrently-executing code}}
117+
x = 42 // expected-warning{{mutation of captured var 'x' in concurrently-executing code}}
118118
}
119119
print(x)
120120
}

test/Concurrency/actor_isolation.swift

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ extension MyActor {
309309
acceptInout(&self.mutable) // expected-error{{actor-isolated property 'mutable' can not be used 'inout' from a Sendable closure}}
310310
_ = self.immutable
311311
_ = self.synchronous() // expected-error{{actor-isolated instance method 'synchronous()' can not be referenced from a Sendable closure}}
312-
_ = localVar // expected-error{{reference to captured var 'localVar' in concurrently-executing code}}
313-
localVar = 25 // expected-error{{mutation of captured var 'localVar' in concurrently-executing code}}
312+
_ = localVar // expected-warning{{reference to captured var 'localVar' in concurrently-executing code}}
313+
localVar = 25 // expected-warning{{mutation of captured var 'localVar' in concurrently-executing code}}
314314
_ = localConstant
315315

316316
_ = otherLocalVar
@@ -341,17 +341,17 @@ extension MyActor {
341341
@Sendable func localFn1() {
342342
_ = self.text[0] // expected-error{{actor-isolated property 'text' can not be referenced from a Sendable function}}
343343
_ = self.synchronous() // expected-error{{actor-isolated instance method 'synchronous()' can not be referenced from a Sendable function}}
344-
_ = localVar // expected-error{{reference to captured var 'localVar' in concurrently-executing code}}
345-
localVar = 25 // expected-error{{mutation of captured var 'localVar' in concurrently-executing code}}
344+
_ = localVar // expected-warning{{reference to captured var 'localVar' in concurrently-executing code}}
345+
localVar = 25 // expected-warning{{mutation of captured var 'localVar' in concurrently-executing code}}
346346
_ = localConstant
347347
}
348348

349349
@Sendable func localFn2() {
350350
acceptClosure {
351351
_ = text[0] // expected-error{{actor-isolated property 'text' can not be referenced from a non-isolated context}}
352352
_ = self.synchronous() // expected-error{{actor-isolated instance method 'synchronous()' can not be referenced from a non-isolated context}}
353-
_ = localVar // expected-error{{reference to captured var 'localVar' in concurrently-executing code}}
354-
localVar = 25 // expected-error{{mutation of captured var 'localVar' in concurrently-executing code}}
353+
_ = localVar // expected-warning{{reference to captured var 'localVar' in concurrently-executing code}}
354+
localVar = 25 // expected-warning{{mutation of captured var 'localVar' in concurrently-executing code}}
355355
_ = localConstant
356356
}
357357
}
@@ -624,8 +624,8 @@ func testGlobalRestrictions(actor: MyActor) async {
624624
// code.
625625
var i = 17
626626
acceptConcurrentClosure {
627-
_ = i // expected-error{{reference to captured var 'i' in concurrently-executing code}}
628-
i = 42 // expected-error{{mutation of captured var 'i' in concurrently-executing code}}
627+
_ = i // expected-warning{{reference to captured var 'i' in concurrently-executing code}}
628+
i = 42 // expected-warning{{mutation of captured var 'i' in concurrently-executing code}}
629629
}
630630
print(i)
631631

@@ -722,7 +722,7 @@ func checkLocalFunctions() async {
722722
}
723723

724724
func local3() { // expected-error{{concurrently-executed local function 'local3()' must be marked as '@Sendable'}}
725-
k = 25 // expected-error{{mutation of captured var 'k' in concurrently-executing code}}
725+
k = 25 // expected-warning{{mutation of captured var 'k' in concurrently-executing code}}
726726
}
727727

728728
print(k)
@@ -1141,12 +1141,12 @@ extension MyActor {
11411141
_ = synchronous() // expected-error{{expression is 'async' but is not marked with 'await'}}
11421142
// expected-note@-1{{calls to instance method 'synchronous()' from outside of its actor context are implicitly asynchronous}}
11431143

1144-
counter += 1 // expected-error{{mutation of captured var 'counter' in concurrently-executing code}}
1144+
counter += 1 // expected-warning{{mutation of captured var 'counter' in concurrently-executing code}}
11451145
}
11461146

11471147
acceptAsyncSendableClosure {
11481148
_ = await synchronous() // ok
1149-
counter += 1 // expected-error{{mutation of captured var 'counter' in concurrently-executing code}}
1149+
counter += 1 // expected-warning{{mutation of captured var 'counter' in concurrently-executing code}}
11501150
}
11511151

11521152
acceptAsyncSendableClosureInheriting {
@@ -1167,14 +1167,13 @@ func testGlobalActorInheritance() {
11671167
var counter = 0
11681168

11691169
acceptAsyncSendableClosure {
1170-
counter += 1 // expected-error{{mutation of captured var 'counter' in concurrently-executing code}}
1170+
counter += 1 // expected-warning{{mutation of captured var 'counter' in concurrently-executing code}}
11711171
}
11721172

11731173
acceptAsyncSendableClosure { @SomeGlobalActor in
11741174
counter += 1 // ok
11751175
}
11761176

1177-
11781177
acceptAsyncSendableClosureInheriting {
11791178
counter += 1 // ok
11801179
}

test/Concurrency/async_let_isolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ actor MyActor {
1616
async let z = synchronous()
1717

1818
var localText = text
19-
async let w = localText.removeLast() // expected-error{{mutation of captured var 'localText' in concurrently-executing code}}
19+
async let w = localText.removeLast() // expected-warning{{mutation of captured var 'localText' in concurrently-executing code}}
2020

2121
_ = await x
2222
_ = await y

test/Concurrency/concurrent_value_checking.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func testConcurrency() {
165165
acceptConcurrent {
166166
print(x) // expected-warning{{capture of 'x' with non-sendable type 'NotConcurrent' in a `@Sendable` closure}}
167167
print(y) // expected-warning{{capture of 'y' with non-sendable type 'NotConcurrent' in a `@Sendable` closure}}
168-
// expected-error@-1{{reference to captured var 'y' in concurrently-executing code}}
168+
// expected-warning@-1{{reference to captured var 'y' in concurrently-executing code}}
169169
}
170170
}
171171

@@ -182,7 +182,7 @@ func testUnsafeSendableNothing() {
182182
func testUnsafeSendableInAsync() async {
183183
var x = 5
184184
acceptUnsafeSendable {
185-
x = 17 // expected-error{{mutation of captured var 'x' in concurrently-executing code}}
185+
x = 17 // expected-warning{{mutation of captured var 'x' in concurrently-executing code}}
186186
}
187187
print(x)
188188
}

test/Concurrency/dispatch_inference.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ func testMe() {
1717
func testUnsafeSendableInMainAsync() async {
1818
var x = 5
1919
DispatchQueue.main.async {
20-
x = 17 // expected-error{{mutation of captured var 'x' in concurrently-executing code}}
20+
x = 17 // expected-warning{{mutation of captured var 'x' in concurrently-executing code}}
2121
}
2222
print(x)
2323
}
2424

2525
func testUnsafeSendableInAsync(queue: DispatchQueue) async {
2626
var x = 5
2727
queue.async {
28-
x = 17 // expected-error{{mutation of captured var 'x' in concurrently-executing code}}
28+
x = 17 // expected-warning{{mutation of captured var 'x' in concurrently-executing code}}
2929
}
3030
print(x)
3131
}

test/attr/attr_concurrent.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ func mutationOfLocal() {
8080
}()
8181

8282
// Mutations of captured variables executing concurrently are bad.
83-
localInt = 17 // expected-error{{mutation of captured var 'localInt' in concurrently-executing code}}
84-
localInt += 1 // expected-error{{mutation of captured var 'localInt' in concurrently-executing code}}
85-
localInt.makeNegative() // expected-error{{mutation of captured var 'localInt' in concurrently-executing code}}
83+
localInt = 17 // expected-warning{{mutation of captured var 'localInt' in concurrently-executing code}}
84+
localInt += 1 // expected-warning{{mutation of captured var 'localInt' in concurrently-executing code}}
85+
localInt.makeNegative() // expected-warning{{mutation of captured var 'localInt' in concurrently-executing code}}
8686

8787
_ = {
88-
localInt = localInt + 12 // expected-error{{mutation of captured var 'localInt' in concurrently-executing code}}
88+
localInt = localInt + 12 // expected-warning{{mutation of captured var 'localInt' in concurrently-executing code}}
8989
}()
9090

9191
return i + localInt
@@ -110,8 +110,8 @@ func testCaseNonTrivialValue() {
110110
print(i.optArray?[j] ?? 0)
111111
print(i.optArray![j])
112112

113-
i.int = 5 // expected-error{{mutation of captured var 'i' in concurrently-executing code}}
114-
i.array[0] = 5 // expected-error{{mutation of captured var 'i' in concurrently-executing code}}
113+
i.int = 5 // expected-warning{{mutation of captured var 'i' in concurrently-executing code}}
114+
i.array[0] = 5 // expected-warning{{mutation of captured var 'i' in concurrently-executing code}}
115115

116116
return value
117117
}

0 commit comments

Comments
 (0)