Skip to content

Commit e715947

Browse files
committed
be specific that only escaping closures prevent consumption
rdar://109908383
1 parent 2db4a03 commit e715947

9 files changed

+280
-280
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ ERROR(sil_movechecking_borrowed_parameter_captured_by_closure, none,
766766
"parameter",
767767
(StringRef))
768768
ERROR(sil_movechecking_capture_consumed, none,
769-
"noncopyable '%0' cannot be consumed when captured by a closure", (StringRef))
769+
"noncopyable '%0' cannot be consumed when captured by an escaping closure", (StringRef))
770770
ERROR(sil_movechecking_inout_not_reinitialized_before_end_of_function, none,
771771
"missing reinitialization of inout parameter '%0' after consume", (StringRef))
772772
ERROR(sil_movechecking_value_consumed_in_a_loop, none,

test/SILGen/moveonly_escaping_closure.swift

Lines changed: 56 additions & 56 deletions
Large diffs are not rendered by default.

test/SILOptimizer/definite_init_moveonly_controlflowdep_init.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ bb3:
119119
%23 = apply %22(%21) : $@convention(thin) (@guaranteed S) -> ()
120120
destroy_value %21 : $S
121121
%25 = mark_must_check [assignable_but_not_consumable] %3 : $*S
122-
// expected-error @-1 {{noncopyable 's' cannot be consumed when captured by a closure}}
122+
// expected-error @-1 {{noncopyable 's' cannot be consumed when captured by an escaping closure}}
123123
%26 = load [take] %25 : $*S
124124
%27 = function_ref @consumeVal : $@convention(thin) (@owned S) -> ()
125125
%28 = apply %27(%26) : $@convention(thin) (@owned S) -> ()

test/SILOptimizer/moveonly_addresschecker_diagnostics.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ bb0(%0 : @closureCapture @guaranteed $<τ_0_0 where τ_0_0 : P> { var AddressOnl
359359
end_access %12 : $*AddressOnlyGeneric<T>
360360
%17 = begin_access [deinit] [dynamic] %1 : $*AddressOnlyGeneric<T>
361361
%18 = mark_must_check [assignable_but_not_consumable] %17 : $*AddressOnlyGeneric<T>
362-
// expected-error @-1 {{noncopyable 'x' cannot be consumed when captured by a closure}}
362+
// expected-error @-1 {{noncopyable 'x' cannot be consumed when captured by an escaping closure}}
363363
%19 = function_ref @addressOnlyGenericConsume : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in AddressOnlyGeneric<τ_0_0>) -> ()
364364
%20 = apply %19<T>(%18) : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in AddressOnlyGeneric<τ_0_0>) -> ()
365365
end_access %17 : $*AddressOnlyGeneric<T>
@@ -528,4 +528,4 @@ bb0(%0 : @owned $NonTrivialStruct):
528528
dealloc_stack %1 : $*NonTrivialStruct
529529
%9999 = tuple()
530530
return %9999 : $()
531-
}
531+
}

test/SILOptimizer/moveonly_addresschecker_diagnostics.swift

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,11 +3143,11 @@ func closureLetStoreClosureInVariableIsEscape() {
31433143

31443144
let f = {
31453145
borrowVal(s)
3146-
consumeVal(s) // expected-error {{noncopyable 's' cannot be consumed when captured by a closure}}
3146+
consumeVal(s) // expected-error {{noncopyable 's' cannot be consumed when captured by an escaping closure}}
31473147
}
31483148
let c = StoreClosure(f: f)
31493149
_ = c
3150-
consumeVal(s) // expected-error {{noncopyable 's' cannot be consumed when captured by a closure}}
3150+
consumeVal(s) // expected-error {{noncopyable 's' cannot be consumed when captured by an escaping closure}}
31513151
}
31523152

31533153
/////////////////////////////
@@ -3202,8 +3202,8 @@ public func closureVarCaptureClassUseAfterConsume() {
32023202
var f = {}
32033203
f = {
32043204
borrowVal(x2)
3205-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3206-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3205+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3206+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
32073207
}
32083208
f()
32093209
}
@@ -3214,7 +3214,7 @@ public func closureVarCaptureClassUseAfterConsume2() {
32143214
var f = {}
32153215
f = {
32163216
borrowVal(x2)
3217-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3217+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
32183218
}
32193219
f()
32203220
}
@@ -3225,12 +3225,12 @@ public func closureVarCaptureClassUseAfterConsumeError() {
32253225
var f = {}
32263226
f = {
32273227
borrowVal(x2)
3228-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3229-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3228+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3229+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
32303230
}
32313231
f()
3232-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3233-
let x3 = x2 // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3232+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3233+
let x3 = x2 // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
32343234
x2 = Klass()
32353235
let _ = x3
32363236
}
@@ -3458,7 +3458,7 @@ public func closureVarAndDeferCaptureClassUseAfterConsume2(_ x: borrowing Klass)
34583458
x2 = x // expected-note {{consumed here}}
34593459
var f = {}
34603460
f = {
3461-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3461+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
34623462
defer {
34633463
borrowVal(x2)
34643464
consumeVal(x2) // expected-note {{consumed here}}
@@ -3479,7 +3479,7 @@ public func closureVarAndDeferCaptureClassUseAfterConsume3(_ x: borrowing Klass)
34793479
// expected-note @-1 {{consumed here}}
34803480
var f = {}
34813481
f = {
3482-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3482+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
34833483
defer {
34843484
borrowVal(x2)
34853485
consumeVal(x2) // expected-note {{consumed here}}
@@ -3489,11 +3489,11 @@ public func closureVarAndDeferCaptureClassUseAfterConsume3(_ x: borrowing Klass)
34893489
print("foo")
34903490
}
34913491
f()
3492-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3492+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
34933493
}
34943494

34953495
public func closureVarAndDeferCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
3496-
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3496+
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
34973497
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
34983498
var f = {}
34993499
f = {// expected-note {{closure capturing 'x2' here}}
@@ -3508,7 +3508,7 @@ public func closureVarAndDeferCaptureClassArgUseAfterConsume(_ x2: borrowing Kla
35083508
}
35093509

35103510
public func closureVarAndDeferCaptureClassOwnedArgUseAfterConsume(_ x2: __owned Klass) {
3511-
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3511+
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
35123512
var f = {}
35133513
f = {
35143514
defer {
@@ -3539,7 +3539,7 @@ public func closureVarAndDeferCaptureClassOwnedArgUseAfterConsume2(_ x2: consumi
35393539

35403540
// TODO: MG
35413541
public func closureVarAndDeferCaptureClassOwnedArgUseAfterConsume3(_ x2: __owned Klass) {
3542-
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3542+
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
35433543
var f = {}
35443544
f = {
35453545
defer {
@@ -3550,7 +3550,7 @@ public func closureVarAndDeferCaptureClassOwnedArgUseAfterConsume3(_ x2: __owned
35503550
print("foo")
35513551
}
35523552
f()
3553-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3553+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
35543554
}
35553555

35563556
public func closureVarAndDeferCaptureClassOwnedArgUseAfterConsume4(_ x2: consuming Klass) {
@@ -3567,7 +3567,7 @@ public func closureVarAndDeferCaptureClassOwnedArgUseAfterConsume4(_ x2: consumi
35673567
print("foo")
35683568
}
35693569
f()
3570-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3570+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
35713571
}
35723572

35733573
///////////////////////////////////////////
@@ -3582,11 +3582,11 @@ public func closureVarAndClosureCaptureClassUseAfterConsume(_ x: borrowing Klass
35823582
var g = {}
35833583
g = {
35843584
borrowVal(x2)
3585-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3586-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3585+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3586+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
35873587
}
35883588
g()
3589-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3589+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
35903590
}
35913591
f()
35923592
}
@@ -3601,14 +3601,14 @@ public func closureVarAndClosureCaptureClassUseAfterConsume2(_ x: borrowing Klas
36013601
var g = {}
36023602
g = {
36033603
borrowVal(x2)
3604-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3605-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3604+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3605+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
36063606
}
36073607
g()
36083608
}
36093609
f()
3610-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3611-
let x3 = x2 // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3610+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3611+
let x3 = x2 // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
36123612
_ = x3
36133613
}
36143614

@@ -3623,19 +3623,19 @@ public func closureVarAndClosureCaptureClassUseAfterConsume3(_ x: borrowing Klas
36233623
var g = {}
36243624
g = {
36253625
borrowVal(x2)
3626-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3627-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3626+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3627+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
36283628
}
36293629
g()
36303630
}
36313631
f()
3632-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3633-
let x3 = x2 // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3632+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3633+
let x3 = x2 // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
36343634
_ = x3
36353635
}
36363636

36373637
public func closureVarAndClosureCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
3638-
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3638+
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
36393639
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
36403640
// expected-error @-3 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
36413641
var f = {}
@@ -3657,8 +3657,8 @@ public func closureVarAndClosureCaptureClassOwnedArgUseAfterConsume(_ x2: __owne
36573657
var g = {}
36583658
g = {
36593659
borrowVal(x2)
3660-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3661-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3660+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3661+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
36623662
}
36633663
g()
36643664
}
@@ -3671,8 +3671,8 @@ public func closureVarAndClosureCaptureClassOwnedArgUseAfterConsume2(_ x2: consu
36713671
var g = {}
36723672
g = {
36733673
borrowVal(x2)
3674-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3675-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3674+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3675+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
36763676
}
36773677
g()
36783678
}
@@ -3685,13 +3685,13 @@ public func closureVarAndClosureCaptureClassOwnedArgUseAfterConsume3(_ x2: __own
36853685
var g = {}
36863686
g = {
36873687
borrowVal(x2)
3688-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3689-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3688+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3689+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
36903690
}
36913691
g()
36923692
}
36933693
f()
3694-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3694+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
36953695
}
36963696

36973697
public func closureVarAndClosureCaptureClassOwnedArgUseAfterConsume4(_ x2: consuming Klass) {
@@ -3700,13 +3700,13 @@ public func closureVarAndClosureCaptureClassOwnedArgUseAfterConsume4(_ x2: consu
37003700
var g = {}
37013701
g = {
37023702
borrowVal(x2)
3703-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3704-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3703+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
3704+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
37053705
}
37063706
g()
37073707
}
37083708
f()
3709-
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3709+
consumeVal(x2) // expected-error {{noncopyable 'x2' cannot be consumed when captured by an escaping closure}}
37103710
}
37113711

37123712
/////////////////////////////
@@ -4106,14 +4106,14 @@ func inoutCaptureTest() -> (() -> ()) {
41064106

41074107
borrowVal(x)
41084108
consumeVal(x)
4109-
// expected-error @-1 {{noncopyable 'x' cannot be consumed when captured by a closure}}
4109+
// expected-error @-1 {{noncopyable 'x' cannot be consumed when captured by an escaping closure}}
41104110
x = NonTrivialStruct()
41114111

41124112
let g = {
41134113
x = NonTrivialStruct()
41144114
useInOut(&x)
41154115
consumeVal(x)
4116-
// expected-error @-1 {{noncopyable 'x' cannot be consumed when captured by a closure}}
4116+
// expected-error @-1 {{noncopyable 'x' cannot be consumed when captured by an escaping closure}}
41174117
}
41184118
g()
41194119

@@ -4130,13 +4130,13 @@ func inoutCaptureTestAddressOnlyGeneric<T : P>(_ t: T.Type) -> (() -> ()) {
41304130
}
41314131

41324132
borrowVal(x)
4133-
consumeVal(x) // expected-error {{noncopyable 'x' cannot be consumed when captured by a closure}}
4133+
consumeVal(x) // expected-error {{noncopyable 'x' cannot be consumed when captured by an escaping closure}}
41344134
x = AddressOnlyGeneric<T>()
41354135

41364136
let g = {
41374137
x = AddressOnlyGeneric<T>()
41384138
useInOut(&x)
4139-
consumeVal(x) // expected-error {{noncopyable 'x' cannot be consumed when captured by a closure}}
4139+
consumeVal(x) // expected-error {{noncopyable 'x' cannot be consumed when captured by an escaping closure}}
41404140
}
41414141
g()
41424142

test/SILOptimizer/moveonly_nonescaping_closures.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func c2(x: consuming M) {
7777
consume(x)
7878
}
7979

80-
func d(x: __owned M) { // expected-error {{noncopyable 'x' cannot be consumed when captured by a closure}}
80+
func d(x: __owned M) { // expected-error {{noncopyable 'x' cannot be consumed when captured by an escaping closure}}
8181
clodger({ consume(x) })
8282
// expected-note @-1 {{consumed here}}
8383
}

0 commit comments

Comments
 (0)