Skip to content

Commit 667459e

Browse files
committed
tighten up consistency in terminology
- refer to a "consuming use" as simply a "consume", to reserve "use" for non-consuming uses. - refer to "non-consuming uses" as just a "use". - don't call it a "user defined deinit" and instead a "deinitializer" to match Sema - be specific about what binding a closure is capturing that is preventing consumption. rdar://109281444
1 parent e9e6cda commit 667459e

16 files changed

+2795
-2795
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ ERROR(sil_moveonlychecker_capture_consumed, none,
764764
ERROR(sil_moveonlychecker_inout_not_reinitialized_before_end_of_function, none,
765765
"missing reinitialization of inout parameter '%0' after consume", (StringRef))
766766
ERROR(sil_moveonlychecker_value_consumed_in_a_loop, none,
767-
"'%0' consumed by a use in a loop", (StringRef))
767+
"'%0' consumed in a loop", (StringRef))
768768

769769
ERROR(sil_moveonlychecker_use_after_partial_consume, none,
770770
"cannot use '%0' after partial consume", (StringRef))
@@ -774,28 +774,23 @@ ERROR(sil_moveonlychecker_notconsumable_but_assignable_was_consumed, none,
774774
(StringRef, bool))
775775

776776
ERROR(sil_moveonlychecker_cannot_destructure_has_deinit, none,
777-
"cannot partially consume '%0' since it has a user defined deinit",
777+
"cannot partially consume '%0' when it has a deinitializer",
778778
(StringRef))
779779

780780
NOTE(sil_moveonlychecker_partial_consume_here, none,
781-
"partial consume here", ())
781+
"partially consumed here", ())
782782
NOTE(sil_moveonlychecker_consuming_use_here, none,
783-
"consuming use here", ())
783+
"consumed here", ())
784784
NOTE(sil_moveonlychecker_other_consuming_use_here, none,
785-
"other consuming use here", ())
785+
"other consume here", ())
786786
NOTE(sil_moveonlychecker_two_consuming_uses_here, none,
787-
"two consuming uses here", ())
787+
"multiple consumes here", ())
788788
NOTE(sil_moveonlychecker_consuming_and_non_consuming_uses_here, none,
789-
"consuming and non-consuming uses here", ())
789+
"consumed and used here", ())
790790
NOTE(sil_moveonlychecker_consuming_closure_use_here, none,
791-
"closure capture here", ())
792-
793-
// TODO: a lot of these "non-consuming use" notes are just emitted to point out
794-
// an "invalid use after consume". I'd say most of them are for that.
795-
// In the other narrow cases where that's not quite right, we could go with
796-
// something vague like "use here"
791+
"closure capturing '%0' here", (StringRef))
797792
NOTE(sil_moveonlychecker_nonconsuming_use_here, none,
798-
"non-consuming use here", ())
793+
"used here", ())
799794

800795
NOTE(sil_movekillscopyablevalue_value_cyclic_consumed_in_loop_here, none,
801796
"consuming in loop use here", ())

lib/SILOptimizer/Mandatory/MoveOnlyDiagnostics.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void DiagnosticEmitter::emitObjectGuaranteedDiagnostic(
205205
diagnose(astContext, markedValue,
206206
diag::sil_moveonlychecker_guaranteed_value_captured_by_closure,
207207
varName);
208-
emitObjectDiagnosticsForPartialApplyUses();
208+
emitObjectDiagnosticsForPartialApplyUses(varName);
209209
registerDiagnosticEmitted(markedValue);
210210
}
211211

@@ -379,22 +379,27 @@ void DiagnosticEmitter::emitObjectDiagnosticsForGuaranteedUses(
379379
}
380380
}
381381

382-
void DiagnosticEmitter::emitObjectDiagnosticsForPartialApplyUses() const {
382+
void DiagnosticEmitter::emitObjectDiagnosticsForPartialApplyUses(
383+
StringRef capturedVarName) const {
383384
auto &astContext = fn->getASTContext();
384385

385386
for (auto *user : getCanonicalizer().consumingUsesNeedingCopy) {
386387
if (!isa<PartialApplyInst>(user))
387388
continue;
388-
diagnose(astContext, user,
389-
diag::sil_moveonlychecker_consuming_closure_use_here);
389+
diagnose(astContext,
390+
user,
391+
diag::sil_moveonlychecker_consuming_closure_use_here,
392+
capturedVarName);
390393
}
391394

392395
for (auto *user : getCanonicalizer().consumingBoundaryUsers) {
393396
if (!isa<PartialApplyInst>(user))
394397
continue;
395398

396-
diagnose(astContext, user,
397-
diag::sil_moveonlychecker_consuming_closure_use_here);
399+
diagnose(astContext,
400+
user,
401+
diag::sil_moveonlychecker_consuming_closure_use_here,
402+
capturedVarName);
398403
}
399404
}
400405

lib/SILOptimizer/Mandatory/MoveOnlyDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class DiagnosticEmitter {
166166
/// the caller processed it correctly. false, then we continue to process it.
167167
void
168168
emitObjectDiagnosticsForGuaranteedUses(bool ignorePartialApply = false) const;
169-
void emitObjectDiagnosticsForPartialApplyUses() const;
169+
void emitObjectDiagnosticsForPartialApplyUses(StringRef capturedVarName) const;
170170

171171
void registerDiagnosticEmitted(MarkMustCheckInst *value) {
172172
++diagnosticCount;

test/SILGen/moveonly_escaping_closure.swift

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

test/SILOptimizer/moveonly_addresschecker_destructure_through_deinit_diagnostics.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ func testConsumeCopyable(_ x: consuming DeinitStruct) {
7474
}
7575

7676
func testConsumeNonCopyable1(_ x: consuming DeinitStruct) {
77-
// expected-error @+1 {{cannot partially consume 'x' since it has a user defined deinit}}
77+
// expected-error @+1 {{cannot partially consume 'x' when it has a deinitializer}}
7878
consume(x.third.rhs)
7979
}
8080

8181
func testConsumeNonCopyable2(_ x: consuming DeinitStruct) {
82-
// expected-error @+1 {{cannot partially consume 'x' since it has a user defined deinit}}
82+
// expected-error @+1 {{cannot partially consume 'x' when it has a deinitializer}}
8383
consume(x.fourth.0)
8484
}
8585

8686
func testConsumeNonCopyable3(_ x: consuming DeinitStruct) {
87-
// expected-error @+1 {{cannot partially consume 'x' since it has a user defined deinit}}
87+
// expected-error @+1 {{cannot partially consume 'x' when it has a deinitializer}}
8888
consume(x.fourth.1)
8989
}
9090

9191

9292
func testConsumeNonCopyable4(_ x: consuming DeinitStruct) {
93-
// expected-error @+1 {{cannot partially consume 'x' since it has a user defined deinit}}
93+
// expected-error @+1 {{cannot partially consume 'x' when it has a deinitializer}}
9494
consume(x.fifth)
9595
}
9696

@@ -120,33 +120,33 @@ func testStructContainDeinitStructConsumeCopyable1(_ x: consuming StructContainD
120120

121121

122122
func testStructContainStructContainDeinitStructConsumeNonCopyable1(_ xyz: consuming StructContainDeinitStruct) {
123-
// expected-error @+1 {{cannot partially consume 'xyz.first' since it has a user defined deinit}}
123+
// expected-error @+1 {{cannot partially consume 'xyz.first' when it has a deinitializer}}
124124
consume(xyz.first.third.rhs)
125125
}
126126

127127
func testStructContainStructContainDeinitStructConsumeNonCopyable1a(_ x: consuming StructContainDeinitStruct) {
128-
// expected-error @+1 {{cannot partially consume 'x.second.0' since it has a user defined deinit}}
128+
// expected-error @+1 {{cannot partially consume 'x.second.0' when it has a deinitializer}}
129129
consume(x.second.0.third.rhs)
130130
}
131131

132132
func testStructContainStructContainDeinitStructConsumeNonCopyable2(_ x: consuming StructContainDeinitStruct) {
133-
// expected-error @+1 {{cannot partially consume 'x.first' since it has a user defined deinit}}
133+
// expected-error @+1 {{cannot partially consume 'x.first' when it has a deinitializer}}
134134
consume(x.first.fourth.0)
135135
}
136136

137137
func testStructContainStructContainDeinitStructConsumeNonCopyable2a(_ x: consuming StructContainDeinitStruct) {
138-
// expected-error @+1 {{cannot partially consume 'x.second.1' since it has a user defined deinit}}
138+
// expected-error @+1 {{cannot partially consume 'x.second.1' when it has a deinitializer}}
139139
consume(x.second.1.fourth.0)
140140
}
141141

142142
func testStructContainStructContainDeinitStructConsumeNonCopyable3(_ x: consuming StructContainDeinitStruct) {
143-
// expected-error @+1 {{cannot partially consume 'x.first' since it has a user defined deinit}}
143+
// expected-error @+1 {{cannot partially consume 'x.first' when it has a deinitializer}}
144144
consume(x.first.fourth.1)
145145
}
146146

147147

148148
func testStructContainStructContainDeinitStructConsumeNonCopyable4(_ x: consuming StructContainDeinitStruct) {
149-
// expected-error @+1 {{cannot partially consume 'x.first' since it has a user defined deinit}}
149+
// expected-error @+1 {{cannot partially consume 'x.first' when it has a deinitializer}}
150150
consume(x.first.fifth)
151151
}
152152

test/SILOptimizer/moveonly_addresschecker_diagnostics.sil

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ bb0(%0 : $Int):
103103
end_access %8 : $*AggStruct
104104
%12 = begin_access [read] [static] %3 : $*AggStruct
105105
%13 = struct_element_addr %12 : $*AggStruct, #AggStruct.lhs
106-
%14 = load [copy] %13 : $*Klass // expected-note {{consuming use here}}
106+
%14 = load [copy] %13 : $*Klass // expected-note {{consumed here}}
107107
end_access %12 : $*AggStruct
108108
%16 = move_value [lexical] %14 : $Klass
109109
%17 = mark_must_check [consumable_and_assignable] %16 : $Klass
@@ -112,7 +112,7 @@ bb0(%0 : $Int):
112112
%20 = move_value %19 : $Klass
113113
destroy_value %20 : $Klass
114114
destroy_value %17 : $Klass
115-
%23 = load [copy] %3 : $*AggStruct // expected-note {{consuming use here}}
115+
%23 = load [copy] %3 : $*AggStruct // expected-note {{consumed here}}
116116
destroy_addr %3 : $*AggStruct
117117
dealloc_stack %2 : $*AggStruct
118118
return %23 : $AggStruct
@@ -123,14 +123,14 @@ bb0(%arg : @owned $AggStruct):
123123
%0 = alloc_stack [lexical] $AggStruct, var, name "x2"
124124
%1 = mark_must_check [consumable_and_assignable] %0 : $*AggStruct
125125
// expected-error @-1 {{'x2' consumed more than once}}
126-
// expected-error @-2 {{'x2' consumed by a use in a loop}}
126+
// expected-error @-2 {{'x2' consumed in a loop}}
127127
%9 = begin_access [modify] [static] %1 : $*AggStruct
128128
store %arg to [init] %9 : $*AggStruct
129129
end_access %9 : $*AggStruct
130130
%12 = begin_access [read] [static] %1 : $*AggStruct
131131
%13 = struct_element_addr %12 : $*AggStruct, #AggStruct.pair
132132
%14 = struct_element_addr %13 : $*KlassPair, #KlassPair.lhs
133-
%15 = load [copy] %14 : $*Klass // expected-note {{consuming use here}}
133+
%15 = load [copy] %14 : $*Klass // expected-note {{consumed here}}
134134
end_access %12 : $*AggStruct
135135
%17 = function_ref @classConsume : $@convention(thin) (@owned Klass) -> ()
136136
%18 = apply %17(%15) : $@convention(thin) (@owned Klass) -> ()
@@ -144,8 +144,8 @@ bb2(%55 : $Int):
144144
%57 = struct_element_addr %56 : $*AggStruct, #AggStruct.pair
145145
%58 = struct_element_addr %57 : $*KlassPair, #KlassPair.lhs
146146
%59 = load [copy] %58 : $*Klass
147-
// expected-note @-1 {{consuming use here}}
148-
// expected-note @-2 {{consuming use here}}
147+
// expected-note @-1 {{consumed here}}
148+
// expected-note @-2 {{consumed here}}
149149
end_access %56 : $*AggStruct
150150
%61 = function_ref @classConsume : $@convention(thin) (@owned Klass) -> ()
151151
%62 = apply %61(%59) : $@convention(thin) (@owned Klass) -> ()
@@ -208,13 +208,13 @@ bb0(%arg : @owned $NonTrivialStruct, %arg1 : @owned $NonTrivialStruct):
208208
end_access %12 : $*NonTrivialStruct
209209
%19 = begin_access [read] [static] %1 : $*NonTrivialStruct
210210
%20 = struct_element_addr %19 : $*NonTrivialStruct, #NonTrivialStruct.k
211-
%21 = load [copy] %20 : $*Klass // expected-note {{consuming use here}}
211+
%21 = load [copy] %20 : $*Klass // expected-note {{consumed here}}
212212
end_access %19 : $*NonTrivialStruct
213213
%23 = function_ref @classConsume : $@convention(thin) (@owned Klass) -> ()
214214
%24 = apply %23(%21) : $@convention(thin) (@owned Klass) -> ()
215215
%25 = begin_access [read] [static] %1 : $*NonTrivialStruct
216216
%26 = struct_element_addr %25 : $*NonTrivialStruct, #NonTrivialStruct.k
217-
%27 = load [copy] %26 : $*Klass // expected-note {{consuming use here}}
217+
%27 = load [copy] %26 : $*Klass // expected-note {{consumed here}}
218218
end_access %25 : $*NonTrivialStruct
219219
%29 = function_ref @classConsume : $@convention(thin) (@owned Klass) -> ()
220220
%30 = apply %29(%27) : $@convention(thin) (@owned Klass) -> ()
@@ -257,7 +257,7 @@ bb0(%0 : @owned $NonTrivialStruct):
257257
%4 = mark_must_check [consumable_and_assignable] %3 : $*NonTrivialStruct // expected-error {{'x2' consumed more than once}}
258258
store %1 to [init] %4 : $*NonTrivialStruct
259259
%6 = function_ref @nonConsumingUseNonTrivialStruct : $@convention(thin) (@guaranteed NonTrivialStruct) -> ()
260-
%7 = load [copy] %4 : $*NonTrivialStruct // expected-note {{consuming use here}}
260+
%7 = load [copy] %4 : $*NonTrivialStruct // expected-note {{consumed here}}
261261
%8 = partial_apply [callee_guaranteed] %6(%7) : $@convention(thin) (@guaranteed NonTrivialStruct) -> ()
262262
%9 = begin_borrow [lexical] %8 : $@callee_guaranteed () -> ()
263263
debug_value %9 : $@callee_guaranteed () -> (), let, name "f"
@@ -266,7 +266,7 @@ bb0(%0 : @owned $NonTrivialStruct):
266266
destroy_value %11 : $@callee_guaranteed () -> ()
267267
%14 = alloc_stack $NonTrivialStruct, let, name "x3"
268268
%15 = mark_must_check [consumable_and_assignable] %14 : $*NonTrivialStruct
269-
%16 = load [copy] %4 : $*NonTrivialStruct // expected-note {{consuming use here}}
269+
%16 = load [copy] %4 : $*NonTrivialStruct // expected-note {{consumed here}}
270270
store %16 to [init] %15 : $*NonTrivialStruct
271271
%18 = load [copy] %15 : $*NonTrivialStruct
272272
%19 = move_value %18 : $NonTrivialStruct
@@ -289,10 +289,10 @@ bb0(%0 : @owned $NonTrivialStruct):
289289
%2 = mark_must_check [consumable_and_assignable] %1 : $*NonTrivialStruct // expected-error {{'x' used after consume}}
290290
store %0 to [init] %2 : $*NonTrivialStruct
291291
%4 = load_borrow %2 : $*NonTrivialStruct
292-
%5 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consuming use here}}
292+
%5 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consumed here}}
293293
%6 = function_ref @borrow_and_consume : $@convention(thin) (@guaranteed NonTrivialStruct, @owned NonTrivialStruct) -> ()
294294
%7 = apply %6(%4, %5) : $@convention(thin) (@guaranteed NonTrivialStruct, @owned NonTrivialStruct) -> ()
295-
end_borrow %4 : $NonTrivialStruct // expected-note {{non-consuming use here}}
295+
end_borrow %4 : $NonTrivialStruct // expected-note {{used here}}
296296
destroy_addr %2 : $*NonTrivialStruct
297297
dealloc_stack %1 : $*NonTrivialStruct
298298
%11 = tuple ()
@@ -309,12 +309,12 @@ bb0(%0 : $*Klass):
309309
%3 = alloc_stack [lexical] $Klass, var, name "y2"
310310
%4 = mark_must_check [consumable_and_assignable] %3 : $*Klass
311311
%5 = begin_access [read] [static] %1 : $*Klass
312-
copy_addr %5 to [init] %4 : $*Klass // expected-note {{consuming use here}}
312+
copy_addr %5 to [init] %4 : $*Klass // expected-note {{consumed here}}
313313
end_access %5 : $*Klass
314314
%8 = begin_access [read] [static] %1 : $*Klass
315315
%9 = load [copy] %8 : $*Klass
316-
// expected-note @-1 {{consuming use here}}
317-
// expected-note @-2 {{consuming use here}}
316+
// expected-note @-1 {{consumed here}}
317+
// expected-note @-2 {{consumed here}}
318318
end_access %8 : $*Klass
319319
%11 = begin_access [modify] [static] %4 : $*Klass
320320
store %9 to [assign] %11 : $*Klass
@@ -407,9 +407,9 @@ bb0(%0 : @owned $NonTrivialStruct):
407407

408408
%8 = function_ref @coroutine_callee_uses_partial_apply : $@yield_once @convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> @yields ()
409409
(%9, %10) = begin_apply %8(%6) : $@yield_once @convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> @yields ()
410-
%11 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consuming use here}}
410+
%11 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consumed here}}
411411
%12 = apply %7(%11) : $@convention(thin) (@owned NonTrivialStruct) -> ()
412-
end_apply %10 // expected-note {{non-consuming use here}}
412+
end_apply %10 // expected-note {{used here}}
413413
destroy_value %6 : $@callee_guaranteed () -> ()
414414
destroy_addr %2 : $*NonTrivialStruct
415415
dealloc_stack %1 : $*NonTrivialStruct
@@ -431,9 +431,9 @@ bb0(%0 : @owned $NonTrivialStruct):
431431

432432
%8 = function_ref @coroutine_callee_uses_partial_apply : $@yield_once @convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> @yields ()
433433
(%9, %10) = begin_apply %8(%6) : $@yield_once @convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> @yields ()
434-
%11 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consuming use here}}
434+
%11 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consumed here}}
435435
%12 = apply %7(%11) : $@convention(thin) (@owned NonTrivialStruct) -> ()
436-
abort_apply %10 // expected-note {{non-consuming use here}}
436+
abort_apply %10 // expected-note {{used here}}
437437
destroy_value %6 : $@callee_guaranteed () -> ()
438438
destroy_addr %2 : $*NonTrivialStruct
439439
dealloc_stack %1 : $*NonTrivialStruct
@@ -489,15 +489,15 @@ bb0(%0 : @owned $NonTrivialStruct):
489489
cond_br undef, bb1, bb2
490490

491491
bb1:
492-
%12 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consuming use here}}
492+
%12 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consumed here}}
493493
%13 = apply %7(%12) : $@convention(thin) (@owned NonTrivialStruct) -> ()
494-
abort_apply %10 // expected-note {{non-consuming use here}}
494+
abort_apply %10 // expected-note {{used here}}
495495
br bb3
496496

497497
bb2:
498-
%16 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consuming use here}}
498+
%16 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consumed here}}
499499
%17 = apply %7(%16) : $@convention(thin) (@owned NonTrivialStruct) -> ()
500-
end_apply %10 // expected-note {{non-consuming use here}}
500+
end_apply %10 // expected-note {{used here}}
501501
br bb3
502502

503503
bb3:

0 commit comments

Comments
 (0)