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
2
2
3
3
// REQUIRES: concurrency
4
4
@@ -9,16 +9,18 @@ nonisolated(nonsending) func nonisolatedNonsending() async {
9
9
10
10
func take( iso: ( any Actor ) ? ) { }
11
11
12
+ func takeDefaulted( iso: isolated ( any Actor ) ? = #isolation) { }
13
+
12
14
// CHECK-LABEL: // nonisolatedNonsending()
13
15
// 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>) -> () {
15
17
// CHECK: bb0([[ACTOR:%.*]] : $Optional<any Actor>):
16
18
// CHECK: retain_value [[ACTOR]]
17
19
// CHECK: debug_value [[ACTOR]], let, name "iso"
18
- // CHECK: [[FUNC:%.*]] = function_ref @$s39isolated_nonsending_isolation_macro_sil4take3isoyScA_pSg_tF : $@convention(thin) (@guaranteed Optional<any Actor>) -> ()
20
+ // CHECK: [[FUNC:%.*]] = function_ref @$s4test4take3isoyScA_pSg_tF : $@convention(thin) (@guaranteed Optional<any Actor>) -> ()
19
21
// CHECK: apply [[FUNC]]([[ACTOR]]) : $@convention(thin) (@guaranteed Optional<any Actor>) -> ()
20
22
// CHECK: release_value [[ACTOR]]
21
- // CHECK: } // end sil function '$s39isolated_nonsending_isolation_macro_sil21nonisolatedNonsendingyyYaF '
23
+ // CHECK: } // end sil function '$s4test21nonisolatedNonsendingyyYaF '
22
24
23
25
// Check that we emit #isolation correctly in closures.
24
26
// CHECK-LABEL: // closure #1 in containsClosure()
@@ -33,6 +35,49 @@ func containsClosure() {
33
35
}
34
36
}
35
37
38
+ // Check that we capture variables as necessary to emit #isolation
39
+ // correctly in defer bodies.
40
+ func deferWithIsolatedParam( _ iso: isolated ( any Actor ) ) {
41
+ defer {
42
+ take ( iso: #isolation)
43
+ }
44
+ do { }
45
+ }
46
+ // CHECK-LABEL: sil hidden @$s4test22deferWithIsolatedParamyyScA_pYiF :
47
+ // CHECK: bb0(%0 : $any Actor)
48
+ // CHECK: [[DEFER:%.*]] = function_ref @$s4test22deferWithIsolatedParamyyScA_pYiF6$deferL_yyF :
49
+ // CHECK-NEXT: apply [[DEFER]](%0)
50
+
51
+ // CHECK-LABEL: sil private @$s4test22deferWithIsolatedParamyyScA_pYiF6$deferL_yyF :
52
+ // CHECK: bb0(%0 : @closureCapture $any Actor):
53
+ // CHECK: [[T0:%.*]] = enum $Optional<any Actor>, #Optional.some!enumelt, %0
54
+ // CHECK: [[FN:%.*]] = function_ref @$s4test4take3isoyScA_pSg_tF :
55
+ // CHECK-NEXT: apply [[FN]]([[T0]])
56
+
57
+ // Check that that happens even with uses in caller-side default
58
+ // arguments, which capture analysis was not previously walking into.
59
+ func deferWithIsolatedParam_defaultedUse( _ iso: isolated ( any Actor ) ) {
60
+ defer {
61
+ takeDefaulted ( )
62
+ }
63
+ do { }
64
+ }
65
+
66
+ // CHECK-LABEL: sil hidden @$s4test35deferWithIsolatedParam_defaultedUseyyScA_pYiF :
67
+ // CHECK: bb0(%0 : $any Actor):
68
+ // CHECK: [[DEFER:%.*]] = function_ref @$s4test35deferWithIsolatedParam_defaultedUseyyScA_pYiF6$deferL_yyF :
69
+ // CHECK-NEXT: apply [[DEFER]](%0)
70
+
71
+ // CHECK-LABEL: sil private @$s4test35deferWithIsolatedParam_defaultedUseyyScA_pYiF6$deferL_yyF :
72
+ // CHECK: bb0(%0 : @closureCapture $any Actor):
73
+ // CHECK: [[T0:%.*]] = enum $Optional<any Actor>, #Optional.some!enumelt, %0
74
+ // CHECK: [[FN:%.*]] = function_ref @$s4test13takeDefaulted3isoyScA_pSgYi_tF :
75
+ // CHECK-NEXT: apply [[FN]]([[T0]])
76
+
77
+ // TODO: we can't currently call nonisolated(nonsending) functions in
78
+ // defer bodies because they have to be async, but that should be
79
+ // tested here as well.
80
+
36
81
// Check that we emit #isolation correctly in defer bodies.
37
82
nonisolated ( nonsending)
38
83
func hasDefer( ) async {
@@ -41,7 +86,7 @@ func hasDefer() async {
41
86
}
42
87
do { }
43
88
}
44
- // CHECK-LABEL: sil hidden @$s39isolated_nonsending_isolation_macro_sil8hasDeferyyYaF :
89
+ // CHECK-LABEL: sil hidden @$s4test8hasDeferyyYaF :
45
90
// CHECK: bb0(%0 : $Optional<any Actor>):
46
91
// CHECK: // function_ref $defer
47
92
// CHECK-NEXT: [[DEFER:%.*]] = function_ref
@@ -66,7 +111,7 @@ func hasNestedDefer() async {
66
111
do { }
67
112
}
68
113
69
- // CHECK-LABEL: sil hidden @$s39isolated_nonsending_isolation_macro_sil14hasNestedDeferyyYaF :
114
+ // CHECK-LABEL: sil hidden @$s4test14hasNestedDeferyyYaF :
70
115
// CHECK: bb0(%0 : $Optional<any Actor>):
71
116
// CHECK: // function_ref $defer #1 () in hasNestedDefer()
72
117
// CHECK-NEXT: [[DEFER:%.*]] = function_ref
0 commit comments