File: vtable_non_overridden.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 (305 lines) | stat: -rw-r--r-- 13,206 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=NO-LIBRARY-EVOLUTION
// RUN: %target-swift-frontend -enable-library-evolution -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=LIBRARY-EVOLUTION

sil_stage canonical

class InternalA {
  init()
  func foo()
  func bar()
  func bas()
}

sil @InternalA_foo : $@convention(method) (@guaranteed InternalA) -> ()
sil @InternalA_bar : $@convention(method) (@guaranteed InternalA) -> ()
sil @InternalA_bas : $@convention(method) (@guaranteed InternalA) -> ()
sil @InternalA_init : $@convention(method) (@thick InternalA.Type) -> @owned InternalA
sil @InternalA_dealloc : $@convention(method) (@owned InternalA) -> ()

sil_vtable InternalA {
  #InternalA.deinit!deallocator : @InternalA_dealloc
  #InternalA.init!allocator : @InternalA_init
  #InternalA.foo : @InternalA_foo [nonoverridden]
  #InternalA.bar : @InternalA_bar
  #InternalA.bas : @InternalA_bas [nonoverridden]
}

// -- we should still generate method descriptors for the elided methods
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalAC3fooyyFTq" = hidden constant %swift.method_descriptor {{.*}} section "{{(__TEXT,__const|\.rodata|\.rdata)}}"
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalAC3basyyFTq" = hidden constant %swift.method_descriptor {{.*}} section "{{(__TEXT,__const|\.rodata|\.rdata)}}"

// -- only overridden entries in internal method descriptor table
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalACMn" =
// CHECK-SAME:     i32 2, %swift.method_descriptor
// CHECK-SAME:     @InternalA_init
// CHECK-NOT:      @InternalA_foo
// CHECK-SAME:     @InternalA_bar
// CHECK-NOT:      @InternalA_bas

// -- only overridden entries in internal vtable
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalACMf" = 
// CHECK-SAME:     @InternalA_init
// CHECK-NOT:      @InternalA_foo
// CHECK-SAME:     @InternalA_bar
// CHECK-NOT:      @InternalA_bas

sil @InternalB_bar : $@convention(method) (@guaranteed InternalB) -> ()
sil @InternalB_init : $@convention(method) (@thick InternalB.Type) -> @owned InternalB
sil @InternalB_dealloc : $@convention(method) (@owned InternalB) -> ()

class InternalB: InternalA {
  override func bar()
}

sil_vtable InternalB {
  #InternalB.deinit!deallocator : @InternalB_dealloc
  #InternalA.init!allocator : @InternalB_init [override]
  #InternalA.foo : @InternalA_foo [inherited] [nonoverridden]
  #InternalA.bar : @InternalB_bar [override]
  #InternalA.bas : @InternalA_bas [inherited] [nonoverridden]
}

// -- only overridden entries in internal method descriptor table
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalBCMn" =
// CHECK-SAME:     i32 2, %swift.method_override_descriptor
// CHECK-NOT:      @InternalA_foo
// CHECK-SAME:     @InternalB_bar
// CHECK-NOT:      @InternalA_bas
// CHECK-SAME:     @InternalB_init

// -- only overridden entries in internal vtable
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalBCMf" = 
// CHECK-SAME:     @InternalB_init
// CHECK-NOT:      @InternalA_foo
// CHECK-SAME:     @InternalB_bar
// CHECK-NOT:      @InternalA_bas
// CHECK-SAME:     {{$}}

@_fixed_layout
public class PublicFragileA {
  init()
  func foo()
  func bar()
  func bas()
}

sil @PublicFragileA_foo : $@convention(method) (@guaranteed PublicFragileA) -> ()
sil @PublicFragileA_bar : $@convention(method) (@guaranteed PublicFragileA) -> ()
sil @PublicFragileA_bas : $@convention(method) (@guaranteed PublicFragileA) -> ()
sil @PublicFragileA_init : $@convention(method) (@thick PublicFragileA.Type) -> @owned PublicFragileA
sil @PublicFragileA_dealloc : $@convention(method) (@owned PublicFragileA) -> ()

sil_vtable PublicFragileA {
  #PublicFragileA.deinit!deallocator : @PublicFragileA_dealloc
  #PublicFragileA.init!allocator : @PublicFragileA_init
  #PublicFragileA.foo : @PublicFragileA_foo [nonoverridden]
  #PublicFragileA.bar : @PublicFragileA_bar
  #PublicFragileA.bas : @PublicFragileA_bas [nonoverridden]
}

// -- all entries should be preserved in public fragile method descriptor table
// CHECK-LABEL: @"$s21vtable_non_overridden14PublicFragileACMn" =
// CHECK-SAME:     i32 4, %swift.method_descriptor
// CHECK-SAME:     @PublicFragileA_init
// CHECK-SAME:     @PublicFragileA_foo
// CHECK-SAME:     @PublicFragileA_bar
// CHECK-SAME:     @PublicFragileA_bas

// -- all entries should be preserved in public fragile vtable
// CHECK-LABEL: @"$s21vtable_non_overridden14PublicFragileACMf" = 
// CHECK-SAME:     @PublicFragileA_init
// CHECK-SAME:     @PublicFragileA_foo
// CHECK-SAME:     @PublicFragileA_bar
// CHECK-SAME:     @PublicFragileA_bas

sil @PublicFragileB_bar : $@convention(method) (@guaranteed PublicFragileB) -> ()
sil @PublicFragileB_init : $@convention(method) (@thick PublicFragileB.Type) -> @owned PublicFragileB
sil @PublicFragileB_dealloc : $@convention(method) (@owned PublicFragileB) -> ()

@_fixed_layout
public class PublicFragileB: PublicFragileA {
  override func bar()
}

sil_vtable PublicFragileB {
  #PublicFragileB.deinit!deallocator : @PublicFragileB_dealloc
  #PublicFragileA.init!allocator : @PublicFragileB_init [override]
  #PublicFragileA.foo : @PublicFragileA_foo [inherited] [nonoverridden]
  #PublicFragileA.bar : @PublicFragileB_bar [override]
  #PublicFragileA.bas : @PublicFragileA_bas [inherited] [nonoverridden]
}

// -- all entries should be preserved in public fragile method descriptor table
// CHECK-LABEL: @"$s21vtable_non_overridden14PublicFragileBCMn" =
// CHECK-SAME:     i32 2, %swift.method_override_descriptor
// CHECK-SAME:     @PublicFragileB_bar
// CHECK-SAME:     @PublicFragileB_init

// -- all entries should be preserved in public fragile vtable
// CHECK-LABEL: @"$s21vtable_non_overridden14PublicFragileBCMf" = 
// CHECK-SAME:     @PublicFragileB_init
// CHECK-SAME:     @PublicFragileA_foo
// CHECK-SAME:     @PublicFragileB_bar
// CHECK-SAME:     @PublicFragileA_bas

sil @PublicResilientSubclassOfFragile_bar : $@convention(method) (@guaranteed PublicResilientSubclassOfFragile) -> ()
sil @PublicResilientSubclassOfFragile_init : $@convention(method) (@thick PublicResilientSubclassOfFragile.Type) -> @owned PublicResilientSubclassOfFragile
sil @PublicResilientSubclassOfFragile_dealloc : $@convention(method) (@owned PublicResilientSubclassOfFragile) -> ()

public class PublicResilientSubclassOfFragile: PublicFragileA {
  override func bar()
}

sil_vtable PublicResilientSubclassOfFragile {
  #PublicResilientSubclassOfFragile.deinit!deallocator : @PublicResilientSubclassOfFragile_dealloc
  #PublicFragileA.init!allocator : @PublicResilientSubclassOfFragile_init [override]
  #PublicFragileA.foo : @PublicFragileA_foo [inherited] [nonoverridden]
  #PublicFragileA.bar : @PublicResilientSubclassOfFragile_bar [override]
  #PublicFragileA.bas : @PublicFragileA_bas [inherited] [nonoverridden]
}

// -- all entries from fragile base class should be preserved in public method descriptor table
// CHECK-LABEL: @"$s21vtable_non_overridden32PublicResilientSubclassOfFragileCMn" =
// CHECK-SAME:     i32 2, %swift.method_override_descriptor
// CHECK-SAME:     @PublicResilientSubclassOfFragile_bar
// CHECK-SAME:     @PublicResilientSubclassOfFragile_init

// -- all entries from fragile base class should be preserved in public vtable
// CHECK-LABEL: @"$s21vtable_non_overridden32PublicResilientSubclassOfFragileCMf" = 
// CHECK-SAME:     @PublicResilientSubclassOfFragile_init
// CHECK-SAME:     @PublicFragileA_foo
// CHECK-SAME:     @PublicResilientSubclassOfFragile_bar
// CHECK-SAME:     @PublicFragileA_bas

public class PublicA {
  init()
  public func foo()
  public func bar()
  func bas()
}

sil @PublicA_foo : $@convention(method) (@guaranteed PublicA) -> ()
sil @PublicA_bar : $@convention(method) (@guaranteed PublicA) -> ()
sil @PublicA_bas : $@convention(method) (@guaranteed PublicA) -> ()
sil @PublicA_init : $@convention(method) (@thick PublicA.Type) -> @owned PublicA
sil @PublicA_dealloc : $@convention(method) (@owned PublicA) -> ()

sil_vtable PublicA {
  #PublicA.deinit!deallocator : @PublicA_dealloc
  #PublicA.init!allocator : @PublicA_init
  #PublicA.foo : @PublicA_foo [nonoverridden]
  #PublicA.bar : @PublicA_bar
  #PublicA.bas : @PublicA_bas [nonoverridden]
}

// -- nonoverridden entries can be dropped in resilient method descriptor table
// LIBRARY-EVOLUTION-LABEL: @"$s21vtable_non_overridden7PublicACMn" =
// LIBRARY-EVOLUTION-SAME:     i32 2, %swift.method_descriptor
// LIBRARY-EVOLUTION-SAME:     @PublicA_init
// LIBRARY-EVOLUTION-NOT:      @PublicA_foo
// LIBRARY-EVOLUTION-SAME:     @PublicA_bar
// LIBRARY-EVOLUTION-NOT:      @PublicA_bas

// -- nonoverridden entries can be dropped in resilient method descriptor table
// LIBRARY-EVOLUTION-LABEL: @"$s21vtable_non_overridden7PublicACMf" = 
// LIBRARY-EVOLUTION-SAME:     @PublicA_init
// LIBRARY-EVOLUTION-NOT:      @PublicA_foo
// LIBRARY-EVOLUTION-SAME:     @PublicA_bar
// LIBRARY-EVOLUTION-NOT:      @PublicA_bas
// LIBRARY-EVOLUTION-SAME:     {{$}}

// -- with library evolution disabled, treat the vtable as fragile

// NO-LIBRARY-EVOLUTION-LABEL: @"$s21vtable_non_overridden7PublicACMn" =
// NO-LIBRARY-EVOLUTION-SAME:     i32 4, %swift.method_descriptor
// NO-LIBRARY-EVOLUTION-SAME:     @PublicA_init
// NO-LIBRARY-EVOLUTION-SAME:     @PublicA_foo
// NO-LIBRARY-EVOLUTION-SAME:     @PublicA_bar
// NO-LIBRARY-EVOLUTION-SAME:     @PublicA_bas

// NO-LIBRARY-EVOLUTION-LABEL: @"$s21vtable_non_overridden7PublicACMf" = 
// NO-LIBRARY-EVOLUTION-SAME:     @PublicA_init
// NO-LIBRARY-EVOLUTION-SAME:     @PublicA_foo
// NO-LIBRARY-EVOLUTION-SAME:     @PublicA_bar
// NO-LIBRARY-EVOLUTION-SAME:     @PublicA_bas

sil @PublicB_bar : $@convention(method) (@guaranteed PublicB) -> ()
sil @PublicB_init : $@convention(method) (@thick PublicB.Type) -> @owned PublicB
sil @PublicB_dealloc : $@convention(method) (@owned PublicB) -> ()

class PublicB: PublicA {
  override func bar()
}

sil_vtable PublicB {
  #PublicB.deinit!deallocator : @PublicB_dealloc
  #PublicA.init!allocator : @PublicB_init [override]
  #PublicA.foo : @PublicA_foo [inherited] [nonoverridden]
  #PublicA.bar : @PublicB_bar [override]
  #PublicA.bas : @PublicA_bas [inherited] [nonoverridden]
}

// -- nonoverridden entries can be dropped in resilient method descriptor table
// LIBRARY-EVOLUTION-LABEL: @"$s21vtable_non_overridden7PublicBCMn" =
// LIBRARY-EVOLUTION-SAME:     i32 2, %swift.method_override_descriptor
// LIBRARY-EVOLUTION-NOT:      @PublicA_foo
// LIBRARY-EVOLUTION-SAME:     @PublicB_bar
// LIBRARY-EVOLUTION-NOT:      @PublicA_bas
// LIBRARY-EVOLUTION-SAME:     @PublicB_init

// -- nonoverridden entries can be dropped in resilient method descriptor table
// LIBRARY-EVOLUTION-LABEL: @"$s21vtable_non_overridden7PublicBCMf" = 
// LIBRARY-EVOLUTION-SAME:     @PublicB_init
// LIBRARY-EVOLUTION-NOT:      @PublicA_foo
// LIBRARY-EVOLUTION-SAME:     @PublicB_bar
// LIBRARY-EVOLUTION-NOT:      @PublicA_bas
// LIBRARY-EVOLUTION-SAME:     {{$}}

// -- with library evolution disabled, treat the vtable as fragile

// NO-LIBRARY-EVOLUTION-LABEL: @"$s21vtable_non_overridden7PublicBCMn" =
// NO-LIBRARY-EVOLUTION-SAME:     i32 2, %swift.method_override_descriptor
// NO-LIBRARY-EVOLUTION-SAME:     @PublicB_bar
// NO-LIBRARY-EVOLUTION-SAME:     @PublicB_init

// NO-LIBRARY-EVOLUTION-LABEL: @"$s21vtable_non_overridden7PublicBCMf" = 
// NO-LIBRARY-EVOLUTION-SAME:     @PublicB_init
// NO-LIBRARY-EVOLUTION-SAME:     @PublicB_bar

// Ensure we still emit a method lookup function even if the vtable is
// completely optimized away.
sil @PublicOnlyNonoverridden_foo : $@convention(method) (@guaranteed PublicOnlyNonoverridden) -> ()
sil @PublicOnlyNonoverridden_init : $@convention(method) (@thick PublicOnlyNonoverridden.Type) -> @owned PublicOnlyNonoverridden
sil @PublicOnlyNonoverridden_dealloc : $@convention(method) (@owned PublicOnlyNonoverridden) -> ()

public class PublicOnlyNonoverridden {
  public func foo()
}

sil_vtable PublicOnlyNonoverridden {
  #PublicOnlyNonoverridden.deinit!deallocator : @PublicOnlyNonoverridden_dealloc
  #PublicOnlyNonoverridden.init!allocator : @PublicOnlyNonoverridden_init [nonoverridden]
  #PublicOnlyNonoverridden.foo : @PublicOnlyNonoverridden_foo [nonoverridden]
}

// Ensure that `class_method` lookups of nonoverridden vtable entries resolve
// to the one implementation instead of trying to load a nonexistent runtime
// vtable entry.

// CHECK-LABEL: define {{.*}}@non_overridable_invocation
sil @non_overridable_invocation : $@convention(thin) (@guaranteed InternalA, @guaranteed InternalB) -> () {
entry(%a : $InternalA, %b : $InternalB):
  // CHECK: call swiftcc void @InternalA_foo
  %am = class_method %a : $InternalA, #InternalA.foo, $@convention(method) (@guaranteed InternalA) -> ()
  apply %am(%a) : $@convention(method) (@guaranteed InternalA) -> ()

  // CHECK: call swiftcc void @InternalA_foo
  %bm = class_method %b : $InternalB, #InternalA.foo, $@convention(method) (@guaranteed InternalA) -> ()
  %ba = upcast %b : $InternalB to $InternalA
  apply %bm(%ba) : $@convention(method) (@guaranteed InternalA) -> ()

  return undef : $()
}

// LIBRARY-EVOLUTION-LABEL: define{{.*}}@"$s21vtable_non_overridden23PublicOnlyNonoverriddenCMu"