-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathexample.swift
114 lines (92 loc) · 3.5 KB
/
example.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
// RUN: rm -rf %t && mkdir -p %t
// RUN: %target-build-swift -Xfrontend -enable-reflection-metadata -Xfrontend -enable-reflection-names -lswiftSwiftReflectionTest %s -o %t/example
// RUN: %target-run %target-swift-reflection-test %t/example 2>&1 | FileCheck %s --check-prefix=CHECK-%target-ptrsize
// REQUIRES: objc_interop
import SwiftReflectionTest
class Container {
var x: Int
var y: Int
var z: Container?
init(x: Int, y: Int, z: Container? = nil) {
self.x = x
self.y = y
self.z = z
}
}
class MyClass<T, U> {
let f: () -> ()
var x: T
var y: U
init(x: T, y: U, f: () -> ()) {
self.x = x
self.y = y
self.f = f
}
func doFoo() {
f()
}
}
var lhs = Container(x: 111, y: 222, z: nil)
var rhs = Container(x: 111, y: 222, z: nil)
func doFoo() {
lhs.x *= 10
rhs.x *= 10
print(lhs)
print(rhs)
}
var mc = MyClass(x: lhs, y: rhs, f: doFoo)
reflect(object: mc)
// CHECK-64: Reflecting an object.
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
// CHECK-64: Type reference:
// CHECK-64: (bound_generic_class example.MyClass
// CHECK-64: (class example.Container)
// CHECK-64: (class example.Container))
// CHECK-64: Type info:
// CHECK-64: (class_instance size=48 alignment=16 stride=48 num_extra_inhabitants=0
// CHECK-64: (field name=f offset=16
// CHECK-64: (thick_function size=16 alignment=8 stride=16 num_extra_inhabitants=0
// CHECK-64: (field name=function offset=0
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=1))
// CHECK-64: (field name=context offset=8
// CHECK-64: (reference kind=strong refcounting=native))))
// CHECK-64: (field name=x offset=32
// CHECK-64: (reference kind=strong refcounting=native))
// CHECK-64: (field name=y offset=40
// CHECK-64: (reference kind=strong refcounting=native)))
// CHECK-32: Reflecting an object.
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
// CHECK-32: Type reference:
// CHECK-32: (bound_generic_class example.MyClass
// CHECK-32: (class example.Container)
// CHECK-32: (class example.Container))
// CHECK-32: Type info:
// CHECK-32: (class_instance size=28 alignment=16 stride=32 num_extra_inhabitants=0
// CHECK-32: (field name=f offset=12
// CHECK-32: (thick_function size=8 alignment=4 stride=8 num_extra_inhabitants=0
// CHECK-32: (field name=function offset=0
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=1))
// CHECK-32: (field name=context offset=4
// CHECK-32: (reference kind=strong refcounting=native))))
// CHECK-32: (field name=x offset=20
// CHECK-32: (reference kind=strong refcounting=native))
// CHECK-32: (field name=y offset=24
// CHECK-32: (reference kind=strong refcounting=native)))
reflect(any: mc)
// CHECK-64: Reflecting an existential.
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
// CHECK-64: Type reference:
// CHECK-64: (bound_generic_class example.MyClass
// CHECK-64: (class example.Container)
// CHECK-64: (class example.Container))
// CHECK-64: Type info:
// CHECK-64: (reference kind=strong refcounting=native)
// CHECK-32: Reflecting an existential.
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
// CHECK-32: Type reference:
// CHECK-32: (bound_generic_class example.MyClass
// CHECK-32: (class example.Container)
// CHECK-32: (class example.Container))
// CHECK-32: Type info:
// CHECK-32: (reference kind=strong refcounting=native)
doneReflecting()