Skip to content

Commit e4f2412

Browse files
authored
Merge pull request #65707 from kavon/5.9-consuming-nonescaping-closures
[5.9🍒] consuming cannot be applied to nonescaping closures
2 parents b606a32 + 838f958 commit e4f2412

File tree

4 files changed

+32
-267
lines changed

4 files changed

+32
-267
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7123,6 +7123,8 @@ ERROR(ownership_specifier_copyable,none,
71237123
ERROR(self_ownership_specifier_copyable,none,
71247124
"%0 is not yet valid on %1s in a Copyable type",
71257125
(SelfAccessKind, DescriptiveDeclKind))
7126+
ERROR(ownership_specifier_nonescaping_closure,none,
7127+
"'%0' cannot be applied to nonescaping closure", (StringRef))
71267128

71277129
//------------------------------------------------------------------------------
71287130
// MARK: Runtime discoverable attributes (@runtimeMetadata)

lib/Sema/TypeCheckType.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,20 +4283,30 @@ TypeResolver::resolveOwnershipTypeRepr(OwnershipTypeRepr *repr,
42834283
if (result->hasError())
42844284
return result;
42854285

4286-
// Unless we have the experimental no-implicit-copy feature enabled, Copyable
4287-
// types can't use 'consuming' or 'borrowing' ownership specifiers.
4288-
if (!getASTContext().LangOpts.hasFeature(Feature::NoImplicitCopy)) {
4289-
if (!result->isPureMoveOnly()) {
4290-
// Prevent copyable types from using the non-underscored ownership parameter
4291-
// specifiers, other than 'inout'.
4292-
switch (ownershipRepr->getSpecifier()) {
4293-
case ParamSpecifier::Default:
4294-
case ParamSpecifier::InOut:
4295-
case ParamSpecifier::LegacyShared:
4296-
case ParamSpecifier::LegacyOwned:break;
4297-
4298-
case ParamSpecifier::Borrowing:
4299-
case ParamSpecifier::Consuming:
4286+
// Check for illegal combinations of ownership specifiers and types.
4287+
switch (ownershipRepr->getSpecifier()) {
4288+
case ParamSpecifier::Default:
4289+
case ParamSpecifier::InOut:
4290+
case ParamSpecifier::LegacyShared:
4291+
case ParamSpecifier::LegacyOwned:
4292+
break;
4293+
4294+
case ParamSpecifier::Consuming:
4295+
if (auto *fnTy = result->getAs<FunctionType>()) {
4296+
if (fnTy->isNoEscape()) {
4297+
diagnoseInvalid(ownershipRepr,
4298+
ownershipRepr->getLoc(),
4299+
diag::ownership_specifier_nonescaping_closure,
4300+
ownershipRepr->getSpecifierSpelling());
4301+
return ErrorType::get(getASTContext());
4302+
}
4303+
}
4304+
SWIFT_FALLTHROUGH;
4305+
case ParamSpecifier::Borrowing:
4306+
// Unless we have the experimental no-implicit-copy feature enabled, Copyable
4307+
// types can't use 'consuming' or 'borrowing' ownership specifiers.
4308+
if (!getASTContext().LangOpts.hasFeature(Feature::NoImplicitCopy)) {
4309+
if (!result->isPureMoveOnly()) {
43004310
diagnoseInvalid(ownershipRepr,
43014311
ownershipRepr->getLoc(),
43024312
diag::ownership_specifier_copyable);

test/Parse/ownership_modifiers.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ enum Exercising {
101101
__consuming get { 0 }
102102
}
103103
}
104+
105+
func consumingClosure1(_ f: consuming () -> ()) { } // expected-error {{'consuming' cannot be applied to nonescaping closure}}
106+
func consumingClosure2(_ f: consuming @escaping () -> ()) { } // expected-error {{Copyable types cannot be 'consuming' or 'borrowing' yet}}
107+
108+
func borrowingClosure1(_ f: borrowing () -> ()) { } // expected-error {{Copyable types cannot be 'consuming' or 'borrowing' yet}}
109+
func borrowingClosure2(_ f: borrowing @escaping () -> ()) { } // expected-error {{Copyable types cannot be 'consuming' or 'borrowing' yet}}

test/SILGen/moveonly_escaping_closure.swift

Lines changed: 0 additions & 253 deletions
Original file line numberDiff line numberDiff line change
@@ -257,71 +257,6 @@ func testInOutVarClosureCaptureVar(_ f: inout () -> ()) {
257257
f()
258258
}
259259

260-
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure38testConsumingNoEscapeClosureCaptureVaryyyyXEnF : $@convention(thin) (@owned @noescape @callee_guaranteed () -> ()) -> () {
261-
// CHECK: bb0([[ARG:%.*]] : @_eagerMove @owned
262-
// CHECK: [[FUNC_BOX:%.*]] = alloc_box ${ var @noescape @callee_guaranteed () -> () }
263-
// CHECK: [[FUNC_PROJECT:%.*]] = project_box [[FUNC_BOX]]
264-
// CHECK: store [[ARG]] to [init] [[FUNC_PROJECT]]
265-
//
266-
// CHECK: [[BOX:%.*]] = alloc_box ${ var SingleElt }
267-
// CHECK: [[PROJECT:%.*]] = project_box [[BOX]]
268-
// CHECK: [[CLOSURE:%.*]] = function_ref @$s16moveonly_closure38testConsumingNoEscapeClosureCaptureVaryyyyXEnFyyXEfU_ : $@convention(thin) (@inout_aliasable SingleElt) -> ()
269-
// CHECK: [[PAI:%.*]] = partial_apply [callee_guaranteed] [[CLOSURE]]([[PROJECT]])
270-
// CHECK: [[NO_ESCAPE:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PAI]]
271-
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [unknown] [[FUNC_PROJECT]]
272-
// CHECK: assign [[NO_ESCAPE]] to [[ACCESS]]
273-
// CHECK: end_access [[ACCESS]]
274-
// CHECK: } // end sil function '$s16moveonly_closure38testConsumingNoEscapeClosureCaptureVaryyyyXEnF'
275-
//
276-
// CHECK-LABEL: sil private [ossa] @$s16moveonly_closure38testConsumingNoEscapeClosureCaptureVaryyyyXEnFyyXEfU_ : $@convention(thin) (@inout_aliasable SingleElt) -> () {
277-
// CHECK: bb0([[ARG:%.*]] :
278-
// CHECK: [[CHECK:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
279-
//
280-
// CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[CHECK]]
281-
// CHECK: [[LOADED:%.*]] = load [copy] [[ACCESS]]
282-
// CHECK: apply {{%.*}}([[LOADED]])
283-
// CHECK: destroy_value [[LOADED]]
284-
// CHECK: end_access [[ACCESS]]
285-
//
286-
// CHECK: [[ACCESS:%.*]] = begin_access [deinit] [unknown] [[CHECK]]
287-
// CHECK: [[LOADED:%.*]] = load [take] [[ACCESS]]
288-
// CHECK: apply {{%.*}}([[LOADED]])
289-
// CHECK: end_access [[ACCESS]]
290-
//
291-
// CHECK: [[ACCESS:%.*]] = begin_access [deinit] [unknown] [[CHECK]]
292-
// CHECK: [[LOADED:%.*]] = load [take] [[ACCESS]]
293-
// CHECK: apply {{%.*}}([[LOADED]])
294-
// CHECK: end_access [[ACCESS]]
295-
//
296-
// CHECK: [[READ_ACCESS:%.*]] = begin_access [read] [unknown] [[CHECK]]
297-
// CHECK: [[LOADED_READ:%.*]] = load [copy] [[READ_ACCESS]]
298-
// CHECK: [[DEINIT_ACCESS:%.*]] = begin_access [deinit] [unknown] [[CHECK]]
299-
// CHECK: [[LOADED_TAKE:%.*]] = load [take] [[DEINIT_ACCESS]]
300-
// CHECK: apply {{%.*}}([[LOADED_READ]], [[LOADED_TAKE]])
301-
// CHECK: end_access [[DEINIT_ACCESS]]
302-
// CHECK: destroy_value [[LOADED_READ]]
303-
// CHECK: end_access [[READ_ACCESS]]
304-
// CHECK: } // end sil function '$s16moveonly_closure38testConsumingNoEscapeClosureCaptureVaryyyyXEnFyyXEfU_'
305-
func testConsumingNoEscapeClosureCaptureVar(_ f: consuming () -> ()) {
306-
var x = SingleElt()
307-
// expected-error @-1 {{'x' used after consume}}
308-
// expected-error @-2 {{'x' used after consume}}
309-
// expected-error @-3 {{'x' consumed more than once}}
310-
x = SingleElt()
311-
f = {
312-
borrowVal(x)
313-
consumeVal(x) // expected-note {{consuming use here}}
314-
consumeVal(x) // expected-note {{consuming use here}}
315-
// expected-note @-1 {{consuming use here}}
316-
borrowConsumeVal(x, x)
317-
// expected-note @-1 {{consuming use here}}
318-
// expected-note @-2 {{consuming use here}}
319-
// expected-note @-3 {{non-consuming use here}}
320-
// expected-error @-4 {{overlapping accesses to 'x', but deinitialization requires exclusive access}}
321-
// expected-note @-5 {{conflicting access is here}}
322-
}
323-
f()
324-
}
325260

326261
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure36testConsumingEscapeClosureCaptureVaryyyycnF : $@convention(thin) (@owned @callee_guaranteed () -> ()) -> () {
327262
// CHECK: bb0([[ARG:%.*]] : @_eagerMove @owned
@@ -579,39 +514,6 @@ func testInOutVarClosureCaptureLet(_ f: inout () -> ()) {
579514
f()
580515
}
581516

582-
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure38testConsumingNoEscapeClosureCaptureLetyyyyXEnF : $@convention(thin) (@owned @noescape @callee_guaranteed () -> ()) -> () {
583-
// CHECK: bb0([[ARG:%.*]] :
584-
// CHECK: [[FUNC_BOX:%.*]] = alloc_box ${ var @noescape @callee_guaranteed () -> () }
585-
// CHECK: [[FUNC_PROJECT:%.*]] = project_box [[FUNC_BOX]]
586-
// CHECK: store [[ARG]] to [init] [[FUNC_PROJECT]]
587-
//
588-
// CHECK: [[BOX:%.*]] = alloc_box ${ let SingleElt }
589-
// CHECK: [[PROJECT:%.*]] = project_box [[BOX]]
590-
// CHECK: [[CLOSURE:%.*]] = function_ref @$s16moveonly_closure38testConsumingNoEscapeClosureCaptureLetyyyyXEnFyyXEfU_ : $@convention(thin) (@guaranteed SingleElt) -> ()
591-
// CHECK: [[MARKED:%.*]] = mark_must_check [assignable_but_not_consumable] [[PROJECT]]
592-
// CHECK: [[LOADED_VALUE:%.*]] = load [copy] [[MARKED]]
593-
// CHECK: [[PAI:%.*]] = partial_apply [callee_guaranteed] [[CLOSURE]]([[LOADED_VALUE]])
594-
// CHECK: [[NO_ESCAPE:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PAI]]
595-
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [unknown] [[FUNC_PROJECT]]
596-
// CHECK: assign [[NO_ESCAPE]] to [[ACCESS]]
597-
// CHECK: end_access [[ACCESS]]
598-
// CHECK: } // end sil function '$s16moveonly_closure38testConsumingNoEscapeClosureCaptureLetyyyyXEnF'
599-
//
600-
// CHECK-LABEL: sil private [ossa] @$s16moveonly_closure38testConsumingNoEscapeClosureCaptureLetyyyyXEnFyyXEfU_ : $@convention(thin) (@guaranteed SingleElt) -> () {
601-
// CHECK: bb0([[ARG:%.*]] :
602-
// CHECK: [[ARG_COPY:%.*]] = copy_value [[ARG]]
603-
// CHECK: [[CHECK:%.*]] = mark_must_check [no_consume_or_assign] [[ARG_COPY]]
604-
// CHECK: } // end sil function '$s16moveonly_closure38testConsumingNoEscapeClosureCaptureLetyyyyXEnFyyXEfU_'
605-
func testConsumingNoEscapeClosureCaptureLet(_ f: consuming () -> ()) {
606-
let x = SingleElt() // expected-error {{'x' consumed and used at the same time}}
607-
f = {
608-
borrowVal(x)
609-
consumeVal(x)
610-
consumeVal(x)
611-
borrowConsumeVal(x, x) // expected-note {{consuming and non-consuming uses here}}
612-
}
613-
f()
614-
}
615517

616518
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure36testConsumingEscapeClosureCaptureLetyyyycnF : $@convention(thin) (@owned @callee_guaranteed () -> ()) -> () {
617519
// CHECK: bb0([[ARG:%.*]] : @_eagerMove @owned
@@ -869,63 +771,6 @@ func testInOutVarClosureCaptureInOut(_ f: inout () -> (), _ x: inout SingleElt)
869771
f()
870772
}
871773

872-
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure40testConsumingNoEscapeClosureCaptureInOutyyyyXEn_AA9SingleEltVztF : $@convention(thin) (@owned @noescape @callee_guaranteed () -> (), @inout SingleElt) -> () {
873-
// CHECK: bb0([[OWNED_F:%.*]] : @_eagerMove @owned $@noescape @callee_guaranteed () -> (), [[PROJECT:%.*]] : $*SingleElt):
874-
// CHECK: [[FUNC_BOX:%.*]] = alloc_box ${ var @noescape @callee_guaranteed () -> () }
875-
// CHECK: [[FUNC_PROJECT:%.*]] = project_box [[FUNC_BOX]]
876-
// CHECK: store [[OWNED_F]] to [init] [[FUNC_PROJECT]]
877-
//
878-
// CHECK: [[MARKED_PROJECT:%.*]] = mark_must_check [consumable_and_assignable] [[PROJECT]]
879-
// CHECK: [[CLOSURE:%.*]] = function_ref @$s16moveonly_closure40testConsumingNoEscapeClosureCaptureInOutyyyyXEn_AA9SingleEltVztFyyXEfU_ : $@convention(thin) (@inout_aliasable SingleElt) -> ()
880-
// CHECK: [[PAI:%.*]] = partial_apply [callee_guaranteed] [[CLOSURE]]([[MARKED_PROJECT]])
881-
// CHECK: [[NO_ESCAPE:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PAI]]
882-
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [unknown] [[FUNC_PROJECT]]
883-
// CHECK: assign [[NO_ESCAPE]] to [[ACCESS]]
884-
// CHECK: end_access [[ACCESS]]
885-
// CHECK: } // end sil function '$s16moveonly_closure40testConsumingNoEscapeClosureCaptureInOutyyyyXEn_AA9SingleEltVztF'
886-
//
887-
// CHECK-LABEL: sil private [ossa] @$s16moveonly_closure40testConsumingNoEscapeClosureCaptureInOutyyyyXEn_AA9SingleEltVztFyyXEfU_ : $@convention(thin) (@inout_aliasable SingleElt) -> () {
888-
// CHECK: bb0([[PROJECT:%.*]] : @closureCapture
889-
// CHECK: [[MARKED:%.*]] = mark_must_check [consumable_and_assignable] [[PROJECT]]
890-
//
891-
// CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[MARKED]]
892-
// CHECK: [[LOADED:%.*]] = load [copy] [[ACCESS]]
893-
// CHECK: apply {{%.*}}([[LOADED]])
894-
// CHECK: destroy_value [[LOADED]]
895-
//
896-
// CHECK: [[ACCESS:%.*]] = begin_access [deinit] [unknown] [[MARKED]]
897-
// CHECK: [[LOADED:%.*]] = load [take] [[ACCESS]]
898-
// CHECK: apply {{%.*}}([[LOADED]])
899-
//
900-
// CHECK: [[ACCESS:%.*]] = begin_access [deinit] [unknown] [[MARKED]]
901-
// CHECK: [[LOADED:%.*]] = load [take] [[ACCESS]]
902-
// CHECK: apply {{%.*}}([[LOADED]])
903-
//
904-
// CHECK: [[READ_ACCESS:%.*]] = begin_access [read] [unknown] [[MARKED]]
905-
// CHECK: [[LOADED_READ:%.*]] = load [copy] [[READ_ACCESS]]
906-
// CHECK: [[TAKE_ACCESS:%.*]] = begin_access [deinit] [unknown] [[MARKED]]
907-
// CHECK: [[LOADED_TAKE:%.*]] = load [take] [[TAKE_ACCESS]]
908-
// CHECK: apply {{%.*}}([[LOADED_READ]], [[LOADED_TAKE]])
909-
// CHECK: } // end sil function '$s16moveonly_closure40testConsumingNoEscapeClosureCaptureInOutyyyyXEn_AA9SingleEltVztFyyXEfU_'
910-
func testConsumingNoEscapeClosureCaptureInOut(_ f: consuming () -> (), _ x: inout SingleElt) {
911-
// expected-error @-1 {{'x' consumed but not reinitialized before end of function}}
912-
// expected-error @-2 {{'x' used after consume}}
913-
// expected-error @-3 {{'x' consumed more than once}}
914-
// expected-error @-4 {{'x' used after consume}}
915-
f = { // expected-note {{consuming use here}}
916-
borrowVal(x)
917-
consumeVal(x) // expected-note {{consuming use here}}
918-
consumeVal(x) // expected-note {{consuming use here}}
919-
// expected-note @-1 {{consuming use here}}
920-
borrowConsumeVal(x, x)
921-
// expected-error @-1 {{overlapping accesses to 'x', but deinitialization requires exclusive access}}
922-
// expected-note @-2 {{conflicting access is here}}
923-
// expected-note @-3 {{non-consuming use here}}
924-
// expected-note @-4 {{non-consuming use here}}
925-
// expected-note @-5 {{consuming use here}}
926-
}
927-
f()
928-
}
929774

930775
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure38testConsumingEscapeClosureCaptureInOutyyyycn_AA9SingleEltVztF : $@convention(thin) (@owned @callee_guaranteed () -> (), @inout SingleElt) -> () {
931776
// CHECK: bb0([[FUNC_ARG:%.*]] : @_eagerMove @owned $@callee_guaranteed () -> (), [[PROJECT:%.*]] : $*SingleElt):
@@ -1159,70 +1004,6 @@ func testLocalVarClosureCaptureConsuming(_ x: consuming SingleElt) {
11591004
f()
11601005
}
11611006

1162-
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure035testConsumingNoEscapeClosureCaptureD0yyyyXEn_AA9SingleEltVntF : $@convention(thin) (@owned @noescape @callee_guaranteed () -> (), @owned SingleElt) -> () {
1163-
// CHECK: bb0([[F:%.*]] : @_eagerMove @owned $@noescape @callee_guaranteed () -> (),
1164-
// CHECK: [[FUNC_BOX:%.*]] = alloc_box ${ var @noescape @callee_guaranteed () -> () }
1165-
// CHECK: [[FUNC_PROJECT:%.*]] = project_box [[FUNC_BOX]]
1166-
// CHECK: store [[F]] to [init] [[FUNC_PROJECT]]
1167-
//
1168-
// CHECK: [[BOX:%.*]] = alloc_box ${ var SingleElt }
1169-
// CHECK: [[PROJECT:%.*]] = project_box [[BOX]]
1170-
// CHECK: [[CLOSURE:%.*]] = function_ref @$s16moveonly_closure035testConsumingNoEscapeClosureCaptureD0yyyyXEn_AA9SingleEltVntFyyXEfU_ : $@convention(thin) (@inout_aliasable SingleElt) -> ()
1171-
// CHECK: [[PAI:%.*]] = partial_apply [callee_guaranteed] [[CLOSURE]]([[PROJECT]])
1172-
// CHECK: [[NO_ESCAPE:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PAI]]
1173-
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [unknown] [[FUNC_PROJECT]]
1174-
// CHECK: assign [[NO_ESCAPE]] to [[ACCESS]]
1175-
// CHECK: end_access [[ACCESS]]
1176-
// CHECK: } // end sil function '$s16moveonly_closure035testConsumingNoEscapeClosureCaptureD0yyyyXEn_AA9SingleEltVntF'
1177-
//
1178-
// CHECK-LABEL: sil private [ossa] @$s16moveonly_closure035testConsumingNoEscapeClosureCaptureD0yyyyXEn_AA9SingleEltVntFyyXEfU_ : $@convention(thin) (@inout_aliasable SingleElt) -> () {
1179-
// CHECK: bb0([[ARG:%.*]] :
1180-
// CHECK: [[CHECK:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
1181-
//
1182-
// CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[CHECK]]
1183-
// CHECK: [[LOADED:%.*]] = load [copy] [[ACCESS]]
1184-
// CHECK: apply {{%.*}}([[LOADED]])
1185-
// CHECK: destroy_value [[LOADED]]
1186-
// CHECK: end_access [[ACCESS]]
1187-
//
1188-
// CHECK: [[ACCESS:%.*]] = begin_access [deinit] [unknown] [[CHECK]]
1189-
// CHECK: [[LOADED:%.*]] = load [take] [[ACCESS]]
1190-
// CHECK: apply {{%.*}}([[LOADED]])
1191-
// CHECK: end_access [[ACCESS]]
1192-
//
1193-
// CHECK: [[ACCESS:%.*]] = begin_access [deinit] [unknown] [[CHECK]]
1194-
// CHECK: [[LOADED:%.*]] = load [take] [[ACCESS]]
1195-
// CHECK: apply {{%.*}}([[LOADED]])
1196-
// CHECK: end_access [[ACCESS]]
1197-
//
1198-
// CHECK: [[READ_ACCESS:%.*]] = begin_access [read] [unknown] [[CHECK]]
1199-
// CHECK: [[LOADED_READ:%.*]] = load [copy] [[READ_ACCESS]]
1200-
// CHECK: [[DEINIT_ACCESS:%.*]] = begin_access [deinit] [unknown] [[CHECK]]
1201-
// CHECK: [[LOADED_TAKE:%.*]] = load [take] [[DEINIT_ACCESS]]
1202-
// CHECK: apply {{%.*}}([[LOADED_READ]], [[LOADED_TAKE]])
1203-
// CHECK: end_access [[DEINIT_ACCESS]]
1204-
// CHECK: destroy_value [[LOADED_READ]]
1205-
// CHECK: end_access [[READ_ACCESS]]
1206-
// CHECK: } // end sil function '$s16moveonly_closure035testConsumingNoEscapeClosureCaptureD0yyyyXEn_AA9SingleEltVntFyyXEfU_'
1207-
func testConsumingNoEscapeClosureCaptureConsuming(_ f: consuming () -> (),
1208-
_ x: consuming SingleElt) {
1209-
// expected-error @-1 {{'x' consumed more than once}}
1210-
// expected-error @-2 {{'x' used after consume}}
1211-
// expected-error @-3 {{'x' used after consume}}
1212-
f = {
1213-
borrowVal(x)
1214-
consumeVal(x) // expected-note {{consuming use here}}
1215-
consumeVal(x) // expected-note {{consuming use here}}
1216-
// expected-note @-1 {{consuming use here}}
1217-
borrowConsumeVal(x, x)
1218-
// expected-note @-1 {{consuming use here}}
1219-
// expected-note @-2 {{consuming use here}}
1220-
// expected-note @-3 {{non-consuming use here}}
1221-
// expected-error @-4 {{overlapping accesses to 'x', but deinitialization requires exclusive access}}
1222-
// expected-note @-5 {{conflicting access is here}}
1223-
}
1224-
f()
1225-
}
12261007

12271008
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure033testConsumingEscapeClosureCaptureD0yyyycn_AA9SingleEltVntF : $@convention(thin) (@owned @callee_guaranteed () -> (), @owned SingleElt) -> () {
12281009
// CHECK: bb0([[ARG:%.*]] : @_eagerMove @owned $@callee_guaranteed () -> (),
@@ -1474,40 +1255,6 @@ func testInOutVarClosureCaptureOwned(_ f: inout () -> (), _ x: __owned SingleElt
14741255
f()
14751256
}
14761257

1477-
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure40testConsumingNoEscapeClosureCaptureOwnedyyyyXEn_AA9SingleEltVntF : $@convention(thin) (@owned @noescape @callee_guaranteed () -> (), @owned SingleElt) -> () {
1478-
// CHECK: bb0([[ARG:%.*]] : @_eagerMove @owned $@noescape @callee_guaranteed () -> (),
1479-
// CHECK: [[FUNC_BOX:%.*]] = alloc_box ${ var @noescape @callee_guaranteed () -> () }
1480-
// CHECK: [[FUNC_PROJECT:%.*]] = project_box [[FUNC_BOX]]
1481-
// CHECK: store [[ARG]] to [init] [[FUNC_PROJECT]]
1482-
//
1483-
// CHECK: [[BOX:%.*]] = alloc_box ${ let SingleElt }
1484-
// CHECK: [[PROJECT:%.*]] = project_box [[BOX]]
1485-
// CHECK: [[CLOSURE:%.*]] = function_ref @$s16moveonly_closure40testConsumingNoEscapeClosureCaptureOwnedyyyyXEn_AA9SingleEltVntFyyXEfU_ : $@convention(thin) (@guaranteed SingleElt) -> ()
1486-
// CHECK: [[MARKED:%.*]] = mark_must_check [assignable_but_not_consumable] [[PROJECT]]
1487-
// CHECK: [[LOADED_VALUE:%.*]] = load [copy] [[MARKED]]
1488-
// CHECK: [[PAI:%.*]] = partial_apply [callee_guaranteed] [[CLOSURE]]([[LOADED_VALUE]])
1489-
// CHECK: [[NO_ESCAPE:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PAI]]
1490-
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [unknown] [[FUNC_PROJECT]]
1491-
// CHECK: assign [[NO_ESCAPE]] to [[ACCESS]]
1492-
// CHECK: end_access [[ACCESS]]
1493-
// CHECK: } // end sil function '$s16moveonly_closure40testConsumingNoEscapeClosureCaptureOwnedyyyyXEn_AA9SingleEltVntF'
1494-
//
1495-
// CHECK-LABEL: sil private [ossa] @$s16moveonly_closure40testConsumingNoEscapeClosureCaptureOwnedyyyyXEn_AA9SingleEltVntFyyXEfU_ : $@convention(thin) (@guaranteed SingleElt) -> () {
1496-
// CHECK: bb0([[ARG:%.*]] :
1497-
// CHECK: [[ARG_COPY:%.*]] = copy_value [[ARG]]
1498-
// CHECK: [[CHECK:%.*]] = mark_must_check [no_consume_or_assign] [[ARG_COPY]]
1499-
// CHECK: } // end sil function '$s16moveonly_closure40testConsumingNoEscapeClosureCaptureOwnedyyyyXEn_AA9SingleEltVntFyyXEfU_'
1500-
func testConsumingNoEscapeClosureCaptureOwned(_ f: consuming () -> (),
1501-
_ x: __owned SingleElt) {
1502-
// expected-error @-1 {{'x' consumed and used at the same time}}
1503-
f = {
1504-
borrowVal(x)
1505-
consumeVal(x)
1506-
consumeVal(x)
1507-
borrowConsumeVal(x, x) // expected-note {{consuming and non-consuming uses here}}
1508-
}
1509-
f()
1510-
}
15111258

15121259
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure38testConsumingEscapeClosureCaptureOwnedyyyycn_AA9SingleEltVntF : $@convention(thin) (@owned @callee_guaranteed () -> (), @owned SingleElt) -> () {
15131260
// CHECK: bb0([[ARG:%.*]] : @_eagerMove @owned $@callee_guaranteed () -> (),

0 commit comments

Comments
 (0)