Skip to content

Commit c464e7d

Browse files
committed
Add tests and a few fixes
1 parent 3408078 commit c464e7d

File tree

5 files changed

+123
-21
lines changed

5 files changed

+123
-21
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4524,13 +4524,6 @@ namespace {
45244524
return !!getLayoutString();
45254525
}
45264526

4527-
llvm::Constant *emitNominalTypeDescriptor() {
4528-
auto descriptor =
4529-
StructContextDescriptorBuilder(IGM, Target, RequireMetadata,
4530-
hasLayoutString()).emit();
4531-
return descriptor;
4532-
}
4533-
45344527
ConstantReference emitValueWitnessTable(bool relativeReference) {
45354528
return irgen::emitValueWitnessTable(IGM, type, false, relativeReference);
45364529
}
@@ -5386,6 +5379,13 @@ namespace {
53865379
StructDecl &decl,
53875380
ConstantStructBuilder &B)
53885381
: super(IGM, type, decl, B) {}
5382+
5383+
llvm::Constant *emitNominalTypeDescriptor() {
5384+
auto descriptor =
5385+
StructContextDescriptorBuilder(IGM, Target, RequireMetadata,
5386+
hasLayoutString()).emit();
5387+
return descriptor;
5388+
}
53895389
};
53905390

53915391
} // end anonymous namespace

stdlib/public/runtime/Metadata.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2833,7 +2833,10 @@ void swift::swift_initStructMetadataWithLayoutString(
28332833
previousFieldOffset = fieldType->vw_size();
28342834
fullOffset += previousFieldOffset;
28352835
} else if (fieldType->isAnyExistentialType()) {
2836-
auto tag = RefCountingKind::Existential;
2836+
auto *existential = dyn_cast<ExistentialTypeMetadata>(fieldType);
2837+
assert(existential);
2838+
auto tag = existential->isClassBounded() ? RefCountingKind::Unknown
2839+
: RefCountingKind::Existential;
28372840
*(uint64_t*)(layoutStr + layoutStrOffset) =
28382841
((uint64_t)tag << 56) | offset;
28392842
layoutStrOffset += sizeof(uint64_t);

test/IRGen/layout_string_union_types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -enable-experimental-feature LayoutStringValueWitnesses -enable-type-layout -emit-ir -import-objc-header %S/Inputs/union_type.h %s
1+
// RUN: %target-swift-frontend -enable-experimental-feature LayoutStringValueWitnesses -enable-layout-string-value-witnesses -enable-type-layout -emit-ir -import-objc-header %S/Inputs/union_type.h %s
22

33
struct UnionWrapper {
44
let x: TestUnion

test/Interpreter/Inputs/layout_string_witnesses_types.swift

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,20 +365,40 @@ public struct ComplexNesting<A, B, C, D> {
365365
}
366366

367367
internal enum InternalEnum {
368-
case a(Int, AnyObject)
369-
case b(Int)
370-
case c(String)
368+
case a(Int, AnyObject)
369+
case b(Int)
370+
case c(String)
371371
}
372372

373373
public struct InternalEnumWrapper {
374-
internal let x: InternalEnum
375-
internal let y: Int = 32
374+
internal let x: InternalEnum
375+
internal let y: Int = 32
376376

377-
public init(x: AnyObject) {
378-
self.x = .a(23, x)
377+
public init(x: AnyObject) {
378+
self.x = .a(23, x)
379+
}
380+
}
381+
382+
public struct PrespecializedStruct<T> {
383+
let y: Int = 0
384+
let x: T
385+
let z: T
386+
387+
public init(x: T) {
388+
self.x = x
389+
self.z = x
379390
}
380391
}
381392

393+
@inline(never)
394+
public func consume<T>(_ x: T.Type) {
395+
withExtendedLifetime(x) {}
396+
}
397+
public func preSpec() {
398+
consume(PrespecializedStruct<AnyObject>.self)
399+
consume(PrespecializedStruct<SimpleClass>.self)
400+
consume(PrespecializedStruct<Int>.self)
401+
}
382402

383403
@inline(never)
384404
public func testAssign<T>(_ ptr: UnsafeMutablePointer<T>, from x: T) {

test/Interpreter/layout_string_witnesses_dynamic.swift

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22

33
// RUN: %empty-directory(%t)
4-
// RUN: %target-swift-frontend -enable-experimental-feature LayoutStringValueWitnesses -enable-experimental-feature LayoutStringValueWitnessesInstantiation -enable-type-layout -enable-autolinking-runtime-compatibility-bytecode-layouts -emit-module -emit-module-path=%t/layout_string_witnesses_types.swiftmodule %S/Inputs/layout_string_witnesses_types.swift
5-
// RUN: %target-build-swift -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-type-layout -Xfrontend -enable-autolinking-runtime-compatibility-bytecode-layouts -c -parse-as-library -o %t/layout_string_witnesses_types.o %S/Inputs/layout_string_witnesses_types.swift
6-
// RUN: %target-swift-frontend -enable-experimental-feature LayoutStringValueWitnesses -enable-experimental-feature LayoutStringValueWitnessesInstantiation -enable-library-evolution -enable-autolinking-runtime-compatibility-bytecode-layouts -emit-module -emit-module-path=%t/layout_string_witnesses_types_resilient.swiftmodule %S/Inputs/layout_string_witnesses_types_resilient.swift
7-
// RUN: %target-build-swift -g -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-library-evolution -c -parse-as-library -o %t/layout_string_witnesses_types_resilient.o %S/Inputs/layout_string_witnesses_types_resilient.swift
8-
// RUN: %target-build-swift -g -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-type-layout -Xfrontend -enable-autolinking-runtime-compatibility-bytecode-layouts -module-name layout_string_witnesses_dynamic %t/layout_string_witnesses_types.o %t/layout_string_witnesses_types_resilient.o -I %t -o %t/main %s
4+
// RUN: %target-swift-frontend -prespecialize-generic-metadata -enable-experimental-feature LayoutStringValueWitnesses -enable-experimental-feature LayoutStringValueWitnessesInstantiation -enable-layout-string-value-witnesses -enable-layout-string-value-witnesses-instantiation -enable-type-layout -enable-autolinking-runtime-compatibility-bytecode-layouts -emit-module -emit-module-path=%t/layout_string_witnesses_types.swiftmodule %S/Inputs/layout_string_witnesses_types.swift
5+
// RUN: %target-build-swift -Xfrontend -prespecialize-generic-metadata -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-layout-string-value-witnesses -Xfrontend -enable-layout-string-value-witnesses-instantiation -Xfrontend -enable-type-layout -Xfrontend -enable-autolinking-runtime-compatibility-bytecode-layouts -c -parse-as-library -o %t/layout_string_witnesses_types.o %S/Inputs/layout_string_witnesses_types.swift
6+
// RUN: %target-swift-frontend -enable-experimental-feature LayoutStringValueWitnesses -enable-experimental-feature LayoutStringValueWitnessesInstantiation -enable-layout-string-value-witnesses -enable-layout-string-value-witnesses-instantiation -enable-library-evolution -enable-autolinking-runtime-compatibility-bytecode-layouts -emit-module -emit-module-path=%t/layout_string_witnesses_types_resilient.swiftmodule %S/Inputs/layout_string_witnesses_types_resilient.swift
7+
// RUN: %target-build-swift -g -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-layout-string-value-witnesses -Xfrontend -enable-layout-string-value-witnesses-instantiation -Xfrontend -enable-library-evolution -c -parse-as-library -o %t/layout_string_witnesses_types_resilient.o %S/Inputs/layout_string_witnesses_types_resilient.swift
8+
// RUN: %target-build-swift -g -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnessesInstantiation -Xfrontend -enable-layout-string-value-witnesses -Xfrontend -enable-layout-string-value-witnesses-instantiation -Xfrontend -enable-type-layout -Xfrontend -enable-autolinking-runtime-compatibility-bytecode-layouts -module-name layout_string_witnesses_dynamic %t/layout_string_witnesses_types.o %t/layout_string_witnesses_types_resilient.o -I %t -o %t/main %s
99
// RUN: %target-codesign %t/main
1010
// RUN: %target-run %t/main | %FileCheck %s --check-prefix=CHECK -check-prefix=CHECK-%target-os
1111

@@ -52,6 +52,85 @@ func testGeneric() {
5252

5353
testGeneric()
5454

55+
func testPrespecializedAnyObject() {
56+
let ptr = UnsafeMutablePointer<PrespecializedStruct<AnyObject>>.allocate(capacity: 1)
57+
58+
do {
59+
let x = PrespecializedStruct<AnyObject>(x: SimpleClass(x: 23))
60+
testInit(ptr, to: x)
61+
}
62+
63+
do {
64+
let y = PrespecializedStruct<AnyObject>(x: SimpleClass(x: 32))
65+
66+
// CHECK-NEXT: Before deinit
67+
print("Before deinit")
68+
69+
// CHECK-NEXT: SimpleClass deinitialized!
70+
testAssign(ptr, from: y)
71+
}
72+
73+
// CHECK-NEXT: Before deinit
74+
print("Before deinit")
75+
76+
77+
// CHECK-NEXT: SimpleClass deinitialized!
78+
testDestroy(ptr)
79+
80+
ptr.deallocate()
81+
}
82+
83+
testPrespecializedAnyObject()
84+
85+
func testPrespecializedSimpleClass() {
86+
let ptr = UnsafeMutablePointer<PrespecializedStruct<SimpleClass>>.allocate(capacity: 1)
87+
88+
do {
89+
let x = PrespecializedStruct<SimpleClass>(x: SimpleClass(x: 23))
90+
testInit(ptr, to: x)
91+
}
92+
93+
do {
94+
let y = PrespecializedStruct<SimpleClass>(x: SimpleClass(x: 32))
95+
96+
// CHECK-NEXT: Before deinit
97+
print("Before deinit")
98+
99+
// CHECK-NEXT: SimpleClass deinitialized!
100+
testAssign(ptr, from: y)
101+
}
102+
103+
// CHECK-NEXT: Before deinit
104+
print("Before deinit")
105+
106+
107+
// CHECK-NEXT: SimpleClass deinitialized!
108+
testDestroy(ptr)
109+
110+
ptr.deallocate()
111+
}
112+
113+
testPrespecializedSimpleClass()
114+
115+
116+
func testPrespecializedInt() {
117+
let ptr = UnsafeMutablePointer<PrespecializedStruct<Int>>.allocate(capacity: 1)
118+
119+
do {
120+
let x = PrespecializedStruct<Int>(x: 23)
121+
testInit(ptr, to: x)
122+
}
123+
124+
do {
125+
let y = PrespecializedStruct<Int>(x: 32)
126+
testAssign(ptr, from: y)
127+
}
128+
129+
ptr.deallocate()
130+
}
131+
132+
testPrespecializedInt()
133+
55134
func testGenericTuple() {
56135
let ptr = allocateInternalGenericPtr(of: GenericTupleWrapper<TestClass>.self)
57136

0 commit comments

Comments
 (0)