Skip to content

Commit 94f611c

Browse files
bitjammertkremenek
authored andcommitted
[SwiftRemoteMirror] Consider ObjCClass field descriptors when convert… (#2855)
* [SwiftRemoteMirror] Consider ObjCClass field descriptors when converting TypeInfos @slava_pestov recently folded in @objc classes when building class field descriptors - we just need to update the switch when considering records for converting TypeRefs to TypeInfos. rdar://problem/26594130 * Reflection: Fix inherits_NSObject test for 32-bit Looks like class instances are still aligned on 16 byte boundaries here, probably because of SIMD.
1 parent 76adb59 commit 94f611c

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,8 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
10131013
return nullptr;
10141014

10151015
switch (FD->Kind) {
1016-
case FieldDescriptorKind::Class: {
1016+
case FieldDescriptorKind::Class:
1017+
case FieldDescriptorKind::ObjCClass: {
10171018
// Lower the class's fields using substitutions from the
10181019
// TypeRef to make field types concrete.
10191020
RecordTypeInfoBuilder builder(*this, RecordKind::ClassInstance);
@@ -1030,7 +1031,6 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
10301031
case FieldDescriptorKind::ObjCProtocol:
10311032
case FieldDescriptorKind::ClassProtocol:
10321033
case FieldDescriptorKind::Protocol:
1033-
case FieldDescriptorKind::ObjCClass:
10341034
// Invalid field descriptor.
10351035
return nullptr;
10361036
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: %target-build-swift -lswiftSwiftReflectionTest %s -o %t/inherits_NSObject
3+
// RUN: %target-run %target-swift-reflection-test %t/inherits_NSObject | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
4+
5+
// REQUIRES: objc_interop
6+
// REQUIRES: executable_test
7+
8+
import Foundation
9+
10+
import SwiftReflectionTest
11+
12+
class InheritsNSObject : NSObject {}
13+
class ContainsInheritsNSObject : NSObject {
14+
var a: InheritsNSObject
15+
var _b: InheritsNSObject
16+
17+
var b: InheritsNSObject {
18+
get { return _b }
19+
set (newVal) { _b = newVal }
20+
}
21+
22+
override init() {
23+
a = InheritsNSObject()
24+
_b = InheritsNSObject()
25+
}
26+
}
27+
28+
let inheritsNSObject = InheritsNSObject()
29+
reflect(object: inheritsNSObject)
30+
31+
// CHECK-64: Reflecting an object.
32+
// CHECK-64: Type reference:
33+
// CHECK-64: (class inherits_NSObject.InheritsNSObject)
34+
35+
// CHECK-64: Type info:
36+
// CHECK-64: (class_instance size=8 alignment=16 stride=16 num_extra_inhabitants=0)
37+
38+
// CHECK-32: Reflecting an object.
39+
// CHECK-32: Type reference:
40+
// CHECK-32: (class inherits_NSObject.InheritsNSObject)
41+
42+
// CHECK-32: Type info:
43+
// CHECK-32: (class_instance size=4 alignment=16 stride=16 num_extra_inhabitants=0)
44+
45+
let sc = ContainsInheritsNSObject()
46+
reflect(object: sc)
47+
48+
// CHECK-64: Reflecting an object.
49+
// CHECK-64: Type reference:
50+
// CHECK-64: (class inherits_NSObject.ContainsInheritsNSObject)
51+
52+
// CHECK-64: Type info:
53+
// CHECK-64: (class_instance size=24 alignment=16 stride=32 num_extra_inhabitants=0
54+
// CHECK-64-NEXT: (field name=a offset=8
55+
// CHECK-64-NEXT: (reference kind=strong refcounting=unknown))
56+
// CHECK-64-NEXT: (field name=_b offset=16
57+
// CHECK-64-NEXT: (reference kind=strong refcounting=unknown)))
58+
59+
// CHECK-32: Reflecting an object.
60+
// CHECK-32: Type reference:
61+
// CHECK-32: (class inherits_NSObject.ContainsInheritsNSObject)
62+
63+
// CHECK-32: Type info:
64+
// CHECK-32: (class_instance size=12 alignment=16 stride=16 num_extra_inhabitants=0
65+
// CHECK-32-NEXT: (field name=a offset=4
66+
// CHECK-32-NEXT: (reference kind=strong refcounting=unknown))
67+
// CHECK-32-NEXT: (field name=_b offset=8
68+
// CHECK-32-NEXT: (reference kind=strong refcounting=unknown)))
69+
70+
doneReflecting()

0 commit comments

Comments
 (0)