@@ -6,6 +6,10 @@ class C {}
6
6
7
7
sil [ossa] @getC : $@convention(thin) () -> @owned C
8
8
9
+ class Storage {}
10
+
11
+ struct Val {}
12
+
9
13
// Verify that the argument to the specialized take_closure is still @_eagerMove.
10
14
11
15
// CHECK-LABEL: sil {{.*}}@$s12take_closure0B04main1CCTf1nc_n : {{.*}}{
@@ -44,3 +48,40 @@ bb0(%0 : $C):
44
48
%retval = tuple()
45
49
return %retval : $()
46
50
}
51
+
52
+ // =============================================================================
53
+ // rdar://105887096: do not insert a retain inside a read-only function.
54
+ // For now, the specialization is disabled.
55
+ //
56
+ // TODO: A @noescape closure should never be converted to an @owned argument
57
+ // regardless of the function attribute.
58
+
59
+ // This should not be specialized until we support guaranteed arguments.
60
+ // CHECK-NOT: @$s20takesReadOnlyClosure
61
+ sil private [readonly] @takesReadOnlyClosure : $@convention(thin) (@noescape @callee_guaranteed (Val) -> Val) -> Val {
62
+ bb0(%2 : $@noescape @callee_guaranteed (Val) -> Val):
63
+ %46 = struct $Val ()
64
+ %261 = apply %2(%46) : $@noescape @callee_guaranteed (Val) -> Val
65
+ return %261 : $Val
66
+ }
67
+
68
+ sil private @readOnlyClosure : $@convention(thin) (Val, @guaranteed Storage) -> Val {
69
+ bb0(%0 : $Val, %1 : @closureCapture $Storage):
70
+ %46 = struct $Val ()
71
+ return %46 : $Val
72
+ }
73
+
74
+ // CHECK-LABEL: sil @testPassReadOnlyClosure : $@convention(method) (@guaranteed Storage) -> Val {
75
+ // CHECK-NOT: @owned Storage
76
+ // CHECK: apply %{{.*}} : $@convention(thin) (@noescape @callee_guaranteed (Val) -> Val) -> Val
77
+ // CHECK-LABEL: } // end sil function 'testPassReadOnlyClosure'
78
+ sil @testPassReadOnlyClosure : $@convention(method) (@guaranteed Storage) -> Val {
79
+ bb0(%0 : $Storage):
80
+ %176 = function_ref @readOnlyClosure : $@convention(thin) (Val, @guaranteed Storage) -> Val
81
+ %177 = partial_apply [callee_guaranteed] [on_stack] %176(%0) : $@convention(thin) (Val, @guaranteed Storage) -> Val
82
+ %178 = mark_dependence %177 : $@noescape @callee_guaranteed (Val) -> Val on %0 : $Storage
83
+ %188 = function_ref @takesReadOnlyClosure : $@convention(thin) (@noescape @callee_guaranteed (Val) -> Val) -> Val
84
+ %189 = apply %188(%178) : $@convention(thin) (@noescape @callee_guaranteed (Val) -> Val) -> Val
85
+ dealloc_stack %177 : $@noescape @callee_guaranteed (Val) -> Val
86
+ return %189 : $Val
87
+ }
0 commit comments