mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This adds a new reflection record type carrying spare bit information for multi-payload enums. The compiler includes this for any type that might need it in order to accurately reflect the contents of the enum. The RemoteMirror library will use this if present to determine how to project the contents of the enum. If not present (for example, in older binaries), the RemoteMirror library falls back on an internal calculation of the spare bitmask. A few notes: * The internal calculation is not perfect. In particular, it does not support MPEs that contain other enums (e.g., optionals). It should accurately refuse to project any MPE that it does not correctly support. * The new reflection field is designed to be expandable; this might someday avoid the need for a new section. Resolves rdar://61158214
60 lines
1.4 KiB
Swift
60 lines
1.4 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-build-swift -lswiftSwiftReflectionTest %s -o %t/reflect_Enum_MultiPayload_bulky
|
|
// RUN: %target-codesign %t/reflect_Enum_MultiPayload_bulky
|
|
|
|
// RUN: %target-run %target-swift-reflection-test %t/reflect_Enum_MultiPayload_bulky | tee /dev/stderr | %FileCheck %s --check-prefix=CHECK --check-prefix=X%target-ptrsize --dump-input=fail
|
|
|
|
// REQUIRES: reflection_test_support
|
|
// REQUIRES: objc_interop
|
|
// REQUIRES: executable_test
|
|
// UNSUPPORTED: use_os_stdlib
|
|
|
|
import SwiftReflectionTest
|
|
|
|
struct Q {
|
|
var a = 1
|
|
var b = 2
|
|
var c = 3
|
|
var d = 4
|
|
|
|
init(a: Int, b: Int) {
|
|
self.a = a
|
|
self.b = b
|
|
}
|
|
}
|
|
|
|
enum E {
|
|
case A(String,Q,Q?)
|
|
case B(Q,[Q]?)
|
|
case D(Q,Q?)
|
|
case V(Q,Q)
|
|
case X(String,Q,Q)
|
|
case Y(Q,Q?)
|
|
}
|
|
|
|
reflect(enumValue: E.X("hello world", Q(a: 100, b: 200), Q(a: 300, b: 400)))
|
|
|
|
// CHECK: Reflecting an enum value.
|
|
// CHECK-NEXT: Type reference:
|
|
// CHECK-NEXT: (enum reflect_Enum_MultiPayload_bulky.E)
|
|
// CHECK-NEXT: Value: .X(_)
|
|
|
|
reflect(enumValue: E.V(Q(a: 100, b: 200), Q(a: 300, b: 400)))
|
|
|
|
// CHECK: Reflecting an enum value.
|
|
// CHECK-NEXT: Type reference:
|
|
// CHECK-NEXT: (enum reflect_Enum_MultiPayload_bulky.E)
|
|
// CHECK-NEXT: Value: .V(_)
|
|
|
|
reflect(enumValue: E.A("hello, universe", Q(a: 100, b: 200), Q(a: 300, b: 400)))
|
|
|
|
// CHECK: Reflecting an enum value.
|
|
// CHECK-NEXT: Type reference:
|
|
// CHECK-NEXT: (enum reflect_Enum_MultiPayload_bulky.E)
|
|
// CHECK-NEXT: Value: .A(_)
|
|
|
|
doneReflecting()
|
|
|
|
// CHECK: Done.
|
|
|