|
| 1 | +// RUN: rm -rf %t && mkdir -p %t |
| 2 | +// RUN: %target-build-swift -Xfrontend -enable-reflection-metadata -Xfrontend -enable-reflection-names -lswiftSwiftReflectionTest %s -o %t/functions |
| 3 | +// RUN: %target-run %target-swift-reflection-test %t/functions 2>&1 | FileCheck %s --check-prefix=CHECK-%target-ptrsize |
| 4 | +// REQUIRES: objc_interop |
| 5 | + |
| 6 | +/* |
| 7 | + This file pokes at the swift_reflection_infoForInstance() API |
| 8 | + of the SwiftRemoteMirror library. |
| 9 | + |
| 10 | + It tests introspection of function closure contexts. |
| 11 | + |
| 12 | + - See also: SwiftReflectionTest.reflect(function:) |
| 13 | +*/ |
| 14 | + |
| 15 | +import SwiftReflectionTest |
| 16 | + |
| 17 | +func concrete(x: Int, y: Any) { |
| 18 | + reflect(function: {print(x)}) |
| 19 | +// CHECK: Type reference: |
| 20 | +// CHECK-NEXT: (builtin Builtin.NativeObject) |
| 21 | + |
| 22 | +// CHECK-32: Type info: |
| 23 | +// CHECK-32-NEXT: (closure_context size=16 alignment=4 stride=16 num_extra_inhabitants=0 |
| 24 | +// CHECK-32-NEXT: (field offset=12 |
| 25 | +// CHECK-32-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=0 |
| 26 | +// CHECK-32-NEXT: (field offset=0 |
| 27 | +// CHECK-32-NEXT: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=0))))) |
| 28 | + |
| 29 | +// CHECK-64: Type info: |
| 30 | +// CHECK-64-NEXT: (closure_context size=24 alignment=8 stride=24 num_extra_inhabitants=0 |
| 31 | +// CHECK-64-NEXT: (field offset=16 |
| 32 | +// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=0 |
| 33 | +// CHECK-64-NEXT: (field offset=0 |
| 34 | +// CHECK-64-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=0))))) |
| 35 | + |
| 36 | + // FIXME: Need @box reflection -- here the context is a single boxed value |
| 37 | + reflect(function: {print(y)}) |
| 38 | +// CHECK: Type reference: |
| 39 | +// CHECK-NEXT: (builtin Builtin.NativeObject) |
| 40 | + |
| 41 | +// CHECK-32: Type info: |
| 42 | +// CHECK-32-NEXT: <null type info> |
| 43 | + |
| 44 | +// CHECK-64: Type info: |
| 45 | +// CHECK-64-NEXT: <null type info> |
| 46 | +} |
| 47 | + |
| 48 | +concrete(x: 10, y: true) |
| 49 | + |
| 50 | +protocol P {} |
| 51 | +extension Int : P {} |
| 52 | + |
| 53 | +class C {} |
| 54 | + |
| 55 | +func generic<T : P, U, V : C>(x: T, y: U, z: V, i: Int) { |
| 56 | + reflect(function: {print(i)}) |
| 57 | +// CHECK: Type reference: |
| 58 | +// CHECK-NEXT: (builtin Builtin.NativeObject) |
| 59 | + |
| 60 | +// CHECK-32: Type info: |
| 61 | +// CHECK-32-NEXT: (closure_context size=16 alignment=4 stride=16 num_extra_inhabitants=0 |
| 62 | +// CHECK-32-NEXT: (field offset=12 |
| 63 | +// CHECK-32-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=0 |
| 64 | +// CHECK-32-NEXT: (field offset=0 |
| 65 | +// CHECK-32-NEXT: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=0))))) |
| 66 | + |
| 67 | +// CHECK-64: Type info: |
| 68 | +// CHECK-64-NEXT: (closure_context size=24 alignment=8 stride=24 num_extra_inhabitants=0 |
| 69 | +// CHECK-64-NEXT: (field offset=16 |
| 70 | +// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=0 |
| 71 | +// CHECK-64-NEXT: (field offset=0 |
| 72 | +// CHECK-64-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=0))))) |
| 73 | + |
| 74 | + reflect(function: {print(x); print(y); print(z)}) |
| 75 | +// CHECK: Type reference: |
| 76 | +// CHECK-NEXT: (builtin Builtin.NativeObject) |
| 77 | + |
| 78 | +// CHECK-32: Type info: |
| 79 | +// CHECK-32-NEXT: (closure_context size=24 alignment=4 stride=24 num_extra_inhabitants=0 |
| 80 | +// CHECK-32-NEXT: (field offset=12 |
| 81 | +// CHECK-32-NEXT: (reference kind=strong refcounting=native)) |
| 82 | +// CHECK-32-NEXT: (field offset=16 |
| 83 | +// CHECK-32-NEXT: (reference kind=strong refcounting=native)) |
| 84 | +// CHECK-32-NEXT: (field offset=20 |
| 85 | +// CHECK-32-NEXT: (reference kind=strong refcounting=native))) |
| 86 | + |
| 87 | +// CHECK-64: Type info: |
| 88 | +// CHECK-64-NEXT: (closure_context size=40 alignment=8 stride=40 num_extra_inhabitants=0 |
| 89 | +// CHECK-64-NEXT: (field offset=16 |
| 90 | +// CHECK-64-NEXT: (reference kind=strong refcounting=native)) |
| 91 | +// CHECK-64-NEXT: (field offset=24 |
| 92 | +// CHECK-64-NEXT: (reference kind=strong refcounting=native)) |
| 93 | +// CHECK-64-NEXT: (field offset=32 |
| 94 | +// CHECK-64-NEXT: (reference kind=strong refcounting=native))) |
| 95 | +} |
| 96 | + |
| 97 | +generic(x: 10, y: "", z: C(), i: 101) |
| 98 | + |
| 99 | +class GC<A, B, C> {} |
| 100 | + |
| 101 | +func genericWithSources<A, B, C>(a: A, b: B, c: C, gc: GC<A, B, C>) { |
| 102 | + reflect(function: {print(a); print(b); print(c); print(gc)}) |
| 103 | +// CHECK: Type reference: |
| 104 | +// CHECK-NEXT: (builtin Builtin.NativeObject) |
| 105 | + |
| 106 | +// CHECK-32: Type info: |
| 107 | +// CHECK-32-NEXT: (closure_context size=28 alignment=4 stride=28 num_extra_inhabitants=0 |
| 108 | +// CHECK-32-NEXT: (field offset=12 |
| 109 | +// CHECK-32-NEXT: (reference kind=strong refcounting=native)) |
| 110 | +// CHECK-32-NEXT: (field offset=16 |
| 111 | +// CHECK-32-NEXT: (reference kind=strong refcounting=native)) |
| 112 | +// CHECK-32-NEXT: (field offset=20 |
| 113 | +// CHECK-32-NEXT: (reference kind=strong refcounting=native)) |
| 114 | +// CHECK-32-NEXT: (field offset=24 |
| 115 | +// CHECK-32-NEXT: (reference kind=strong refcounting=native))) |
| 116 | + |
| 117 | +// CHECK-64: Type info: |
| 118 | +// CHECK-64-NEXT: (closure_context size=48 alignment=8 stride=48 num_extra_inhabitants=0 |
| 119 | +// CHECK-64-NEXT: (field offset=16 |
| 120 | +// CHECK-64-NEXT: (reference kind=strong refcounting=native)) |
| 121 | +// CHECK-64-NEXT: (field offset=24 |
| 122 | +// CHECK-64-NEXT: (reference kind=strong refcounting=native)) |
| 123 | +// CHECK-64-NEXT: (field offset=32 |
| 124 | +// CHECK-64-NEXT: (reference kind=strong refcounting=native)) |
| 125 | +// CHECK-64-NEXT: (field offset=40 |
| 126 | +// CHECK-64-NEXT: (reference kind=strong refcounting=native))) |
| 127 | +} |
| 128 | + |
| 129 | +genericWithSources(a: (), b: ((), ()), c: ((), (), ()), gc: GC<(), ((), ()), ((), (), ())>()) |
| 130 | + |
| 131 | +doneReflecting() |
0 commit comments