forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtables.swift
171 lines (138 loc) · 4.15 KB
/
vtables.swift
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
// RUN: %target-swift-frontend -sdk %S/Inputs -emit-silgen -I %S/Inputs -enable-source-import %s -disable-objc-attr-requires-foundation-module | %FileCheck %s
// FIXME: rdar://problem/19648117 Needs splitting objc parts out
// XFAIL: linux
import gizmo
// TODO: Generic base classes
// Test for compilation order independence
class C : B {
// foo inherited from B
override func bar() {}
// bas inherited from A
override func qux() {}
// zim inherited from B
override func zang() {}
required init(int i: Int) { }
func flopsy() {}
func mopsy() {}
}
// CHECK: sil_vtable C {
// CHECK: #A.foo!1: _TFC7vtables1B3foo
// CHECK: #A.bar!1: _TFC7vtables1C3bar
// CHECK: #A.bas!1: _TFC7vtables1A3bas
// CHECK: #A.qux!1: _TFC7vtables1C3qux
// CHECK: #B.init!allocator.1: _TFC7vtables1CC
// CHECK: #B.init!initializer.1: _TFC7vtables1Cc
// CHECK: #B.zim!1: _TFC7vtables1B3zim
// CHECK: #B.zang!1: _TFC7vtables1C4zang
// CHECK: #C.flopsy!1: _TFC7vtables1C6flopsy
// CHECK: #C.mopsy!1: _TFC7vtables1C5mopsy
// CHECK: }
class A {
func foo() {}
func bar() {}
func bas() {}
func qux() {}
}
// CHECK: sil_vtable A {
// CHECK: #A.foo!1: _TFC7vtables1A3foo
// CHECK: #A.bar!1: _TFC7vtables1A3bar
// CHECK: #A.bas!1: _TFC7vtables1A3bas
// CHECK: #A.qux!1: _TFC7vtables1A3qux
// CHECK: #A.init!initializer.1: _TFC7vtables1Ac
// CHECK: }
class B : A {
required init(int i: Int) { }
override func foo() {}
// bar inherited from A
// bas inherited from A
override func qux() {}
func zim() {}
func zang() {}
}
// CHECK: sil_vtable B {
// CHECK: #A.foo!1: _TFC7vtables1B3foo
// CHECK: #A.bar!1: _TFC7vtables1A3bar
// CHECK: #A.bas!1: _TFC7vtables1A3bas
// CHECK: #A.qux!1: _TFC7vtables1B3qux
// CHECK: #B.init!allocator.1: _TFC7vtables1BC
// CHECK: #B.init!initializer.1: _TFC7vtables1Bc
// CHECK: #B.zim!1: _TFC7vtables1B3zim
// CHECK: #B.zang!1: _TFC7vtables1B4zang
// CHECK: }
// Test ObjC base class
class Hoozit : Gizmo {
// Overrides Gizmo.frob
override func frob() {}
// Overrides Gizmo.funge
override func funge() {}
func anse() {}
func incorrige() {}
}
// Entries only exist for native Swift methods
// CHECK: sil_vtable Hoozit {
// CHECK: #Hoozit.frob!1: _TFC7vtables6Hoozit4frob
// CHECK: #Hoozit.funge!1: _TFC7vtables6Hoozit5funge
// CHECK: #Hoozit.anse!1: _TFC7vtables6Hoozit4anse
// CHECK: #Hoozit.incorrige!1: _TFC7vtables6Hoozit9incorrige
// CHECK: }
class Wotsit : Hoozit {
override func funge() {}
override func incorrige() {}
}
// CHECK: sil_vtable Wotsit {
// CHECK: #Hoozit.frob!1: _TFC7vtables6Hoozit4frob
// CHECK: #Hoozit.funge!1: _TFC7vtables6Wotsit5funge
// CHECK: #Hoozit.anse!1: _TFC7vtables6Hoozit4anse
// CHECK: #Hoozit.incorrige!1: _TFC7vtables6Wotsit9incorrige
// CHECK: }
// <rdar://problem/15282548>
// CHECK: sil_vtable Base {
// CHECK: #Base.init!initializer.1: _TFC7vtables4Basec
// CHECK: }
// CHECK: sil_vtable Derived {
// CHECK: #Base.init!initializer.1: _TFC7vtables7Derivedc
// CHECK: }
@objc class Base {}
extension Base {
// note: does not have a vtable slot, because it is from an extension
func identify() -> Int {
return 0
}
}
class Derived : Base {
override func identify() -> Int {
return 1
}
}
// CHECK: sil_vtable RequiredInitDerived {
// CHECK-NEXT: #SimpleInitBase.init!initializer.1: _TFC7vtables19RequiredInitDerivedc
// CHECK-NEXT #RequiredInitDerived.init!allocator.1: _TFC7vtables19RequiredInitDerivedC
// CHECK-NEXT}
class SimpleInitBase { }
class RequiredInitDerived : SimpleInitBase {
required override init() { }
}
class Observed {
var x: Int = 0 {
didSet {
}
willSet {
}
}
}
// rdar://problem/21298214
class BaseWithDefaults {
func a(_ object: AnyObject? = nil) {}
}
class DerivedWithoutDefaults : BaseWithDefaults {
override func a(_ object: AnyObject?) {
super.a(object)
}
}
// CHECK-LABEL: sil_vtable Observed {
// CHECK-NOT: #Observed.x!didSet
// CHECK-NOT: #Observed.x!willSet
// CHECK: #Observed.x!getter
// CHECK: #Observed.x!setter
// CHECK-LABEL: sil_vtable DerivedWithoutDefaults {
// CHECK: #BaseWithDefaults.a!1: _TFC7vtables22DerivedWithoutDefaults1a