File: super.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (219 lines) | stat: -rw-r--r-- 11,902 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -I %t -o %t %S/../Inputs/resilient_struct.swift
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -I %t -o %t %S/../Inputs/resilient_class.swift

// Note: we build fixed_layout_class without -enable-library-evolution, since with
// -enable-library-evolution even @_fixed_layout classes have resilient metadata, and
// we want to test the fragile access pattern here.

// RUN: %target-swift-frontend -emit-module -I %t -o %t %S/../Inputs/fixed_layout_class.swift

// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -enable-library-evolution -parse-sil -parse-as-library -emit-ir -I %t %s | %FileCheck %s

// CHECK: %swift.type = type { [[INT:i32|i64]] }

sil_stage canonical

import Builtin
import Swift
import SwiftShims
import resilient_class
import fixed_layout_class

public class ChildToResilientParent : ResilientOutsideParent {
  public override func method()
  public override class func classMethod()
   deinit
  override init()
}

public class ChildToFixedParent : OutsideParent {
  public override func method()
  public override class func classMethod()
   deinit
  override init()
}

public extension ResilientOutsideChild {
  public func callSuperMethod()
  public class func callSuperClassMethod()
}

// resilient_class.ResilientOutsideParent.method () -> ()
sil @$s15resilient_class22ResilientOutsideParentC6methodyyF : $@convention(method) (@guaranteed ResilientOutsideParent) -> ()

// static resilient_class.ResilientOutsideParent.classMethod () -> ()
sil @$s15resilient_class22ResilientOutsideParentC0B6MethodyyFZ : $@convention(method) (@thick ResilientOutsideParent.Type) -> ()

// super.ChildToResilientParent.method () -> ()
sil @$s5super22ChildToResilientParentC6methodyyF : $@convention(method) (@guaranteed ChildToResilientParent) -> () {
// %0
bb0(%0 : $ChildToResilientParent):
  debug_value %0 : $ChildToResilientParent, let, name "self", argno 1
  strong_retain %0 : $ChildToResilientParent
  %3 = upcast %0 : $ChildToResilientParent to $ResilientOutsideParent
  %4 = super_method %0 : $ChildToResilientParent, #ResilientOutsideParent.method : (ResilientOutsideParent) -> () -> (), $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
  %5 = apply %4(%3) : $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
  strong_release %3 : $ResilientOutsideParent
  %7 = tuple ()
  return %7 : $()
}

// ChildToResilientParent is in our resilience domain - can load the superclass's metadata directly.
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s5super22ChildToResilientParentC6methodyyF"(ptr swiftself %0)
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s15resilient_class22ResilientOutsideParentCMa"([[INT]] 0)
// CHECK: [[SUPER_METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
// CHECK: [[FN:%.*]] =  call swiftcc ptr @"$s15resilient_class22ResilientOutsideParentCMu"(ptr [[SUPER_METADATA]], ptr @"$s15resilient_class22ResilientOutsideParentC6methodyyFTq")
// CHECK: call void

// static super.ChildToResilientParent.classMethod () -> ()
sil @$s5super22ChildToResilientParentC11classMethodyyFZ : $@convention(method) (@thick ChildToResilientParent.Type) -> () {
bb0(%0 : $@thick ChildToResilientParent.Type):
  debug_value %0 : $@thick ChildToResilientParent.Type, let, name "self", argno 1
  %2 = upcast %0 : $@thick ChildToResilientParent.Type to $@thick ResilientOutsideParent.Type
  %3 = super_method %0 : $@thick ChildToResilientParent.Type, #ResilientOutsideParent.classMethod : (ResilientOutsideParent.Type) -> () -> (), $@convention(method) (@thick ResilientOutsideParent.Type) -> ()
  %4 = apply %3(%2) : $@convention(method) (@thick ResilientOutsideParent.Type) -> ()
  %5 = tuple ()
  return %5 : $()
}

// ChildToResilientParent is in our resilience domain - can load the superclass's metadata directly.
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s5super22ChildToResilientParentC11classMethodyyFZ"(ptr swiftself %0)
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s15resilient_class22ResilientOutsideParentCMa"([[INT]] 0)
// CHECK: [[SUPER_METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
// CHECK: [[FN:%.*]] =  call swiftcc ptr @"$s15resilient_class22ResilientOutsideParentCMu"(ptr [[SUPER_METADATA]], ptr @"$s15resilient_class22ResilientOutsideParentC0B6MethodyyFZTq")
// CHECK: call swiftcc void

// resilient_class.OutsideParent.method () -> ()
sil @$s15resilient_class13OutsideParentC6methodyyF : $@convention(method) (@guaranteed OutsideParent) -> ()

// static resilient_class.OutsideParent.classMethod () -> ()
sil @$s15resilient_class13OutsideParentC0B6MethodyyFZ : $@convention(thin) (@thick OutsideParent.Type) -> ()

// super.ChildToFixedParent.method () -> ()
sil @$s5super18ChildToFixedParentC6methodyyF : $@convention(method) (@guaranteed ChildToFixedParent) -> () {
// %0
bb0(%0 : $ChildToFixedParent):
  debug_value %0 : $ChildToFixedParent, let, name "self", argno 1
  strong_retain %0 : $ChildToFixedParent
  %3 = upcast %0 : $ChildToFixedParent to $OutsideParent
  %4 = super_method %0 : $ChildToFixedParent, #OutsideParent.method : (OutsideParent) -> () -> (), $@convention(method) (@guaranteed OutsideParent) -> ()
  %5 = apply %4(%3) : $@convention(method) (@guaranteed OutsideParent) -> ()
  strong_release %3 : $OutsideParent
  %7 = tuple ()
  return %7 : $()
}

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s5super18ChildToFixedParentC6methodyyF"(ptr swiftself %0)
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s18fixed_layout_class13OutsideParentCMa"([[INT]] 0)
// CHECK: [[SUPER_METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
// CHECK: [[VTABLE_SLOT:%.*]] = getelementptr inbounds ptr, ptr [[SUPER_METADATA]]
// CHECK: [[FN_PTR:%.*]] = load ptr, ptr [[VTABLE_SLOT]]
// CHECK: call swiftcc void

// static super.ChildToFixedParent.classMethod () -> ()
sil @$s5super18ChildToFixedParentC11classMethodyyFZ : $@convention(method) (@thick ChildToFixedParent.Type) -> () {
// %0
bb0(%0 : $@thick ChildToFixedParent.Type):
  debug_value %0 : $@thick ChildToFixedParent.Type, let, name "self", argno 1
  %2 = upcast %0 : $@thick ChildToFixedParent.Type to $@thick OutsideParent.Type
  %3 = super_method %0 : $@thick ChildToFixedParent.Type, #OutsideParent.classMethod : (OutsideParent.Type) -> () -> (), $@convention(method) (@thick OutsideParent.Type) -> ()
  %4 = apply %3(%2) : $@convention(method) (@thick OutsideParent.Type) -> ()
  %5 = tuple ()
  return %5 : $()
}

// ChildToFixedParent is in our resilience domain - load super metadata directly.
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s5super18ChildToFixedParentC11classMethodyyFZ"(ptr swiftself %0)
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s18fixed_layout_class13OutsideParentCMa"([[INT]] 0)
// CHECK: [[SUPER_METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
// CHECK: [[VTABLE_SLOT:%.*]] = getelementptr inbounds ptr, ptr [[SUPER_METADATA]]
// CHECK: [[FN_PTR:%.*]] = load ptr, ptr [[VTABLE_SLOT]]
// CHECK: call swiftcc void

// ext.super.resilient_class.ResilientOutsideChild.callSuperMethod () -> ()
sil @$s15resilient_class21ResilientOutsideChildC5superE15callSuperMethodyyF : $@convention(method) (@guaranteed ResilientOutsideChild) -> () {
// %0
bb0(%0 : $ResilientOutsideChild):
  debug_value %0 : $ResilientOutsideChild, let, name "self", argno 1
  strong_retain %0 : $ResilientOutsideChild
  %3 = upcast %0 : $ResilientOutsideChild to $ResilientOutsideParent
  %4 = super_method %0 : $ResilientOutsideChild, #ResilientOutsideParent.method : (ResilientOutsideParent) -> () -> (), $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
  %5 = apply %4(%3) : $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
  strong_release %3 : $ResilientOutsideParent
  %7 = tuple ()
  return %7 : $()
}

// Extending a resilient class - load super metadata indirectly.
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s15resilient_class21ResilientOutsideChildC5superE15callSuperMethodyyF"(ptr swiftself %0)
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s15resilient_class21ResilientOutsideChildCMa"([[INT]] 0)
// CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
// CHECK: [[SUPER_METADATA_PTR:%.*]] = getelementptr inbounds ptr, ptr [[METADATA]], i32 1
// CHECK: [[SUPER_METADATA:%.*]] = load ptr, ptr [[SUPER_METADATA_PTR]]
// CHECK: [[FN:%.*]] = call swiftcc ptr @"$s15resilient_class22ResilientOutsideParentCMu"(ptr [[SUPER_METADATA]], ptr @"$s15resilient_class22ResilientOutsideParentC6methodyyFTq")
// CHECK: call void

// static ext.super.resilient_class.ResilientOutsideChild.callSuperClassMethod () -> ()
sil @$s15resilient_class21ResilientOutsideChildC5superE20callSuperClassMethodyyFZ : $@convention(method) (@thick ResilientOutsideChild.Type) -> () {
// %0
bb0(%0 : $@thick ResilientOutsideChild.Type):
  debug_value %0 : $@thick ResilientOutsideChild.Type, let, name "self", argno 1
  %2 = upcast %0 : $@thick ResilientOutsideChild.Type to $@thick ResilientOutsideParent.Type
  %3 = super_method %0 : $@thick ResilientOutsideChild.Type, #ResilientOutsideParent.classMethod : (ResilientOutsideParent.Type) -> () -> (), $@convention(method) (@thick ResilientOutsideParent.Type) -> ()
  %4 = apply %3(%2) : $@convention(method) (@thick ResilientOutsideParent.Type) -> ()
  %5 = tuple ()
  return %5 : $()
}

// Extending a resilient class - load super metadata indirectly.
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s15resilient_class21ResilientOutsideChildC5superE20callSuperClassMethodyyFZ"(ptr swiftself %0)
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s15resilient_class21ResilientOutsideChildCMa"([[INT]] 0)
// CHECK: [[METADATA:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
// CHECK: [[SUPER_METADATA_PTR:%.*]] = getelementptr inbounds ptr, ptr [[METADATA]], i32 1
// CHECK: [[SUPER_METADATA:%.*]] = load ptr, ptr [[SUPER_METADATA_PTR]]
// CHECK: [[FN:%.*]] = call swiftcc ptr @"$s15resilient_class22ResilientOutsideParentCMu"(ptr [[SUPER_METADATA]], ptr @"$s15resilient_class22ResilientOutsideParentC0B6MethodyyFZTq")
// CHECK: call swiftcc void

sil_vtable ChildToResilientParent {
  #ResilientOutsideParent.method: @$s5super22ChildToResilientParentC6methodyyF [override]	// super.ChildToResilientParent.method () -> ()
  #ResilientOutsideParent.classMethod: @$s5super22ChildToResilientParentC11classMethodyyFZ [override]	// static super.ChildToResilientParent.classMethod () -> ()
}

sil_vtable ChildToFixedParent {
  #OutsideParent.method: @$s5super18ChildToFixedParentC6methodyyF [override]	// super.ChildToFixedParent.method () -> ()
  #OutsideParent.classMethod: @$s5super18ChildToFixedParentC11classMethodyyFZ [override]	// static super.ChildToFixedParent.classMethod () -> ()
}

protocol Proto {
}

public class Base<T: Proto> {
  func Method() { }
}

struct Str : Proto {
}

public class Derived : Base<Str> {
  override func Method()
}

sil_vtable Base {
}

sil_vtable Derived {
}

// CHECK-LABEL: define{{.*}} @test_super_method_of_generic_base
// CHECK: [[METADATA:%.*]] = call {{.*}}@"$s5super4BaseCyAA3StrVGMD"
// CHECK: [[GEP:%.*]] = getelementptr inbounds ptr, ptr [[METADATA]]
// CHECK: [[SUPERMT:%.*]] = load ptr, ptr [[GEP]]
// CHECK: ret void
sil @test_super_method_of_generic_base : $@convention(method) (@guaranteed Derived) -> () {
bb0(%0 : $Derived):
  %4 = super_method %0 : $Derived, #Base.Method : <T where T : Proto> (Base<T>) -> () -> () , $@convention(method) <τ_0_0 where τ_0_0 : Proto> (@guaranteed Base<τ_0_0>) -> ()
  %7 = tuple ()
  return %7 : $()
}