@@ -33,13 +33,31 @@ func callIt(fn: () -> ()) {
33
33
fn ( )
34
34
}
35
35
36
+ class BaseZ {
37
+ final func baseCapturesSelf( ) -> Self {
38
+ let fn = { [ weak self] in _ = self }
39
+ callIt ( fn: fn)
40
+ return self
41
+ }
42
+ }
43
+
36
44
// Do not inline C.capturesSelf() into main either.
37
- class Z {
38
- func capturesSelf( ) -> Self {
45
+ class Z : BaseZ {
46
+ final func capturesSelf( ) -> Self {
39
47
let fn = { [ weak self] in _ = self }
40
48
callIt ( fn: fn)
41
49
return self
42
50
}
51
+
52
+ // Inline captureSelf into callCaptureSelf,
53
+ // because their respective Self types refer to the same type.
54
+ final func callCapturesSelf( ) -> Self {
55
+ return capturesSelf ( )
56
+ }
57
+
58
+ final func callBaseCapturesSelf( ) -> Self {
59
+ return baseCapturesSelf ( )
60
+ }
43
61
}
44
62
45
63
_ = Z ( ) . capturesSelf ( )
@@ -49,7 +67,16 @@ _ = Z().capturesSelf()
49
67
// CHECK: [[F:%[0-9]+]] = function_ref @_TZFC11inline_self1C7factory{{.*}} : $@convention(method) (Int, @thick C.Type) -> @owned C
50
68
// CHECK: apply [[F]](%{{.+}}, %{{.+}}) : $@convention(method) (Int, @thick C.Type) -> @owned C
51
69
52
- // CHECK: [[Z:%.*]] = alloc_ref $Z
53
70
// CHECK: function_ref inline_self.Z.capturesSelf () -> Self
54
71
// CHECK: [[F:%[0-9]+]] = function_ref @_TFC11inline_self1Z12capturesSelffT_DS0_ : $@convention(method) (@guaranteed Z) -> @owned Z
55
- // CHECK: apply [[F]]([[Z]]) : $@convention(method) (@guaranteed Z) -> @owned Z
72
+ // CHECK: [[Z:%.*]] = alloc_ref $Z
73
+ // CHECK: apply [[F]]([[Z]]) : $@convention(method) (@guaranteed Z) -> @owned
74
+ // CHECK: return
75
+
76
+ // CHECK-LABEL: sil hidden @_TFC11inline_self1Z16callCapturesSelffT_DS0_ : $@convention(method)
77
+ // CHECK-NOT: function_ref @_TFC11inline_self1Z12capturesSelffT_DS0_
78
+ // CHECK: }
79
+
80
+ // CHECK-LABEL: sil hidden @_TFC11inline_self1Z20callBaseCapturesSelffT_DS0_
81
+ // CHECK-NOT: function_ref @_TFC11inline_self5BaseZ16baseCapturesSelffT_DS0_
82
+ // CHECK: }
0 commit comments