1- // RUN: %target-swift-frontend -parse-as-library -emit-sil %s | %FileCheck %s
1+ // RUN: %target-swift-frontend -parse-as-library -emit-sil %s -module-name test | %FileCheck %s
22
33// REQUIRES: concurrency
44
@@ -9,17 +9,19 @@ nonisolated(nonsending) func nonisolatedNonsending() async {
99
1010func take( iso: ( any Actor ) ? ) { }
1111
12+ func takeDefaulted( iso: isolated ( any Actor ) ? = #isolation) { }
13+
1214// CHECK-LABEL: // nonisolatedNonsending()
1315// CHECK-NEXT: // Isolation: caller_isolation_inheriting
14- // CHECK-NEXT: sil hidden @$s39isolated_nonsending_isolation_macro_sil21nonisolatedNonsendingyyYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> () {
16+ // CHECK-NEXT: sil hidden @$s4test21nonisolatedNonsendingyyYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> () {
1517// CHECK: bb0([[ACTOR:%.*]] : $Optional<any Actor>):
1618// CHECK: hop_to_executor [[ACTOR]]
1719// CHECK: retain_value [[ACTOR]]
1820// CHECK: debug_value [[ACTOR]], let, name "iso"
19- // CHECK: [[FUNC:%.*]] = function_ref @$s39isolated_nonsending_isolation_macro_sil4take3isoyScA_pSg_tF : $@convention(thin) (@guaranteed Optional<any Actor>) -> ()
21+ // CHECK: [[FUNC:%.*]] = function_ref @$s4test4take3isoyScA_pSg_tF : $@convention(thin) (@guaranteed Optional<any Actor>) -> ()
2022// CHECK: apply [[FUNC]]([[ACTOR]]) : $@convention(thin) (@guaranteed Optional<any Actor>) -> ()
2123// CHECK: release_value [[ACTOR]]
22- // CHECK: } // end sil function '$s39isolated_nonsending_isolation_macro_sil21nonisolatedNonsendingyyYaF '
24+ // CHECK: } // end sil function '$s4test21nonisolatedNonsendingyyYaF '
2325
2426// Check that we emit #isolation correctly in closures.
2527// CHECK-LABEL: // closure #1 in containsClosure()
@@ -34,6 +36,49 @@ func containsClosure() {
3436 }
3537}
3638
39+ // Check that we capture variables as necessary to emit #isolation
40+ // correctly in defer bodies.
41+ func deferWithIsolatedParam( _ iso: isolated ( any Actor ) ) {
42+ defer {
43+ take ( iso: #isolation)
44+ }
45+ do { }
46+ }
47+ // CHECK-LABEL: sil hidden @$s4test22deferWithIsolatedParamyyScA_pYiF :
48+ // CHECK: bb0(%0 : $any Actor)
49+ // CHECK: [[DEFER:%.*]] = function_ref @$s4test22deferWithIsolatedParamyyScA_pYiF6$deferL_yyF :
50+ // CHECK-NEXT: apply [[DEFER]](%0)
51+
52+ // CHECK-LABEL: sil private @$s4test22deferWithIsolatedParamyyScA_pYiF6$deferL_yyF :
53+ // CHECK: bb0(%0 : @closureCapture $any Actor):
54+ // CHECK: [[T0:%.*]] = enum $Optional<any Actor>, #Optional.some!enumelt, %0
55+ // CHECK: [[FN:%.*]] = function_ref @$s4test4take3isoyScA_pSg_tF :
56+ // CHECK-NEXT: apply [[FN]]([[T0]])
57+
58+ // Check that that happens even with uses in caller-side default
59+ // arguments, which capture analysis was not previously walking into.
60+ func deferWithIsolatedParam_defaultedUse( _ iso: isolated ( any Actor ) ) {
61+ defer {
62+ takeDefaulted ( )
63+ }
64+ do { }
65+ }
66+
67+ // CHECK-LABEL: sil hidden @$s4test35deferWithIsolatedParam_defaultedUseyyScA_pYiF :
68+ // CHECK: bb0(%0 : $any Actor):
69+ // CHECK: [[DEFER:%.*]] = function_ref @$s4test35deferWithIsolatedParam_defaultedUseyyScA_pYiF6$deferL_yyF :
70+ // CHECK-NEXT: apply [[DEFER]](%0)
71+
72+ // CHECK-LABEL: sil private @$s4test35deferWithIsolatedParam_defaultedUseyyScA_pYiF6$deferL_yyF :
73+ // CHECK: bb0(%0 : @closureCapture $any Actor):
74+ // CHECK: [[T0:%.*]] = enum $Optional<any Actor>, #Optional.some!enumelt, %0
75+ // CHECK: [[FN:%.*]] = function_ref @$s4test13takeDefaulted3isoyScA_pSgYi_tF :
76+ // CHECK-NEXT: apply [[FN]]([[T0]])
77+
78+ // TODO: we can't currently call nonisolated(nonsending) functions in
79+ // defer bodies because they have to be async, but that should be
80+ // tested here as well.
81+
3782// Check that we emit #isolation correctly in defer bodies.
3883nonisolated ( nonsending)
3984func hasDefer( ) async {
@@ -42,7 +87,7 @@ func hasDefer() async {
4287 }
4388 do { }
4489}
45- // CHECK-LABEL: sil hidden @$s39isolated_nonsending_isolation_macro_sil8hasDeferyyYaF :
90+ // CHECK-LABEL: sil hidden @$s4test8hasDeferyyYaF :
4691// CHECK: bb0(%0 : $Optional<any Actor>):
4792// CHECK: // function_ref $defer
4893// CHECK-NEXT: [[DEFER:%.*]] = function_ref
@@ -67,7 +112,7 @@ func hasNestedDefer() async {
67112 do { }
68113}
69114
70- // CHECK-LABEL: sil hidden @$s39isolated_nonsending_isolation_macro_sil14hasNestedDeferyyYaF :
115+ // CHECK-LABEL: sil hidden @$s4test14hasNestedDeferyyYaF :
71116// CHECK: bb0(%0 : $Optional<any Actor>):
72117// CHECK: // function_ref $defer #1 () in hasNestedDefer()
73118// CHECK-NEXT: [[DEFER:%.*]] = function_ref
0 commit comments