File: devirt_override.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 (138 lines) | stat: -rw-r--r-- 4,077 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
// RUN: %target-sil-opt -enable-sil-verify-all %s -inline -devirtualizer | %FileCheck %s

sil_stage canonical

import Builtin
import Swift

class Hash {
  func update()
  func hash()
}

class MD5 : Hash {
  override init()
  override func hash()
}


sil @_TFC4test4HashcfMS0_FT_S0_ : $@convention(method) (@owned Hash) -> @owned Hash

sil @_TFC4test3MD5cfMS0_FT_S0_ : $@convention(method) (@owned MD5) -> @owned MD5 {
bb0(%0 : $MD5):
  release_value %0 : $MD5
  return %0 : $MD5
}

sil @_TFC4test3MD54hashfS0_FT3MsgVs5UInt8_T_ : $@convention(method) (@guaranteed MD5) -> ()
sil @_TFC4test4Hash4hashfS0_FT3MsgVs5UInt8_T_ : $@convention(method) (@guaranteed Hash) -> ()
sil @_TFC9hash2_new4Hash6updatefS0_FT3MsgVs5UInt83CntSi_T_ : $@convention(method) (@guaranteed Hash) -> ()

// CHECK-LABEL: @_TF4test8testHashFT_T_
sil @_TF4test8testHashFT_T_ : $@convention(thin) () -> () {
bb0:
  %0 = alloc_ref $MD5

  %1 = function_ref @_TFC4test3MD5cfMS0_FT_S0_ : $@convention(method) (@owned MD5) -> @owned MD5
  %2 = apply %1(%0) : $@convention(method) (@owned MD5) -> @owned MD5
  strong_retain %2 : $MD5
  %69 = upcast %2 : $MD5 to $Hash
  strong_retain %69 : $Hash
  // CHECK: function_ref @_TFC4test3MD54hashfS0_FT3MsgVs5UInt8_T_ : $@convention(method) (@guaranteed MD5) -> ()
  // CHECK: apply {{%[0-9]+}}({{%[0-9]+}}) : $@convention(method) (@guaranteed MD5) -> ()
  %134 = class_method %69 : $Hash, #Hash.hash : (Hash) -> () -> (), $@convention(method) (@guaranteed Hash) -> ()
  %135 = apply %134(%69) : $@convention(method) (@guaranteed Hash) -> ()
  strong_release %2 : $MD5
  %17 = tuple ()
  return %17 : $()
}

// CHECK-LABEL: @test_unchecked_ref
sil @test_unchecked_ref : $@convention(thin) () -> () {
bb0:
  %0 = alloc_ref $MD5
  %11 = upcast %0 : $MD5 to $Hash
  %21 = unchecked_ref_cast %11 : $Hash to $MD5
  %61 = upcast %21 : $MD5 to $Hash
  // CHECK: function_ref @_TFC9hash2_new4Hash6updatefS0_FT3MsgVs5UInt83CntSi_T_ : $@convention(method) (@guaranteed Hash) -> ()
  // CHECK: apply {{%[0-9]+}}({{%[0-9]+}}) : $@convention(method) (@guaranteed Hash) -> ()
  %62 = class_method %61 : $Hash, #Hash.update : (Hash) -> () -> (), $@convention(method) (@guaranteed Hash) -> ()
  %135 = apply %62(%61) : $@convention(method) (@guaranteed Hash) -> ()
  %17 = tuple ()
  // CHECK: return
  return %17 : $()
}

sil_vtable Hash {
  #Hash.update: @_TFC9hash2_new4Hash6updatefS0_FT3MsgVs5UInt83CntSi_T_
  #Hash.hash: @_TFC4test4Hash4hashfS0_FT3MsgVs5UInt8_T_
  #Hash.init!initializer: @_TFC4test4HashcfMS0_FT_S0_
}

sil_vtable MD5 {
  // vtable should be keyed with the least-derived method, otherwise
  // devirtualizer will choose the wrong function ref.
  #Hash.hash: @_TFC4test3MD54hashfS0_FT3MsgVs5UInt8_T_ [override]
  #Hash.init!initializer: @_TFC4test3MD5cfMS0_FT_S0_ [override]
  #Hash.update: @_TFC9hash2_new4Hash6updatefS0_FT3MsgVs5UInt83CntSi_T_ [override]
}

class C {
  func doIt()
}

class D : C {
  override func doIt()
}

class E : D {
  override func doIt()
}

// CHECK-LABEL: sil @_TFC1b1C4doItfS0_FT_T_
sil @_TFC1b1C4doItfS0_FT_T_ : $@convention(method) (@guaranteed C) -> () {
bb0(%0 : $C):
  %2 = tuple ()
  return %2 : $()
}

// CHECK-LABEL: sil @_TFC1b1D4doItfS0_FT_T_
sil @_TFC1b1D4doItfS0_FT_T_ : $@convention(method) (@guaranteed D) -> () {
bb0(%0 : $D):
  %2 = tuple ()
  return %2 : $()
}


// CHECK-LABEL: sil @_TFC1b1E4doItfS0_FT_T_
sil @_TFC1b1E4doItfS0_FT_T_ : $@convention(method) (@guaranteed E) -> () {
bb0(%0 : $E):
  %2 = tuple ()
  return %2 : $()
}


// CHECK-LABEL: sil @_TF1b3fooFT_T_
sil @_TF1b3fooFT_T_ : $@convention(thin) () -> () {
bb0:
  %0 = alloc_ref $E
  %1 = upcast %0 : $E to $C
  %2 = unconditional_checked_cast %1 : $C to D
  %3 = class_method %2 : $D, #D.doIt : (D) -> () -> (), $@convention(method) (@guaranteed D) -> ()
  %4 = apply %3(%2) : $@convention(method) (@guaranteed D) -> ()
  %5 = tuple ()
// CHECK: return
  return %5 : $()
}

sil_vtable C {
  #C.doIt: @_TFC1b1C4doItfS0_FT_T_
}

sil_vtable D {
  #C.doIt: @_TFC1b1D4doItfS0_FT_T_ [override]
}

sil_vtable E {
  #C.doIt: @_TFC1b1E4doItfS0_FT_T_ [override]
}