Skip to content

Commit 007ff1b

Browse files
committed
Add tests and a few fixes
1 parent 0fd74b8 commit 007ff1b

File tree

6 files changed

+121
-19
lines changed

6 files changed

+121
-19
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,26 @@ public struct ComplexNesting<A, B, C, D> {
365365
}
366366
}
367367

368+
public struct PrespecializedStruct<T> {
369+
let y: Int = 0
370+
let x: T
371+
let z: T
372+
373+
public init(x: T) {
374+
self.x = x
375+
self.z = x
376+
}
377+
}
378+
379+
@inline(never)
380+
public func consume<T>(_ x: T.Type) {
381+
withExtendedLifetime(x) {}
382+
}
383+
public func preSpec() {
384+
consume(PrespecializedStruct<AnyObject>.self)
385+
consume(PrespecializedStruct<SimpleClass>.self)
386+
consume(PrespecializedStruct<Int>.self)
387+
}
368388

369389
@inline(never)
370390
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

test/Interpreter/layout_string_witnesses_static.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -enable-experimental-feature LayoutStringValueWitnesses -enable-type-layout -parse-stdlib -emit-module -emit-module-path=%t/layout_string_witnesses_types.swiftmodule %S/Inputs/layout_string_witnesses_types.swift
3-
// RUN: %target-build-swift -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-type-layout -Xfrontend -parse-stdlib -c -parse-as-library -o %t/layout_string_witnesses_types.o %S/Inputs/layout_string_witnesses_types.swift
4-
// RUN: %target-swift-frontend -enable-experimental-feature LayoutStringValueWitnesses -enable-library-evolution -emit-module -emit-module-path=%t/layout_string_witnesses_types_resilient.swiftmodule %S/Inputs/layout_string_witnesses_types_resilient.swift
5-
// RUN: %target-build-swift -g -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-library-evolution -c -parse-as-library -o %t/layout_string_witnesses_types_resilient.o %S/Inputs/layout_string_witnesses_types_resilient.swift
6-
// RUN: %target-build-swift -g -Xfrontend -enable-experimental-feature -Xfrontend LayoutStringValueWitnesses -Xfrontend -enable-type-layout -Xfrontend -parse-stdlib -module-name layout_string_witnesses_static %t/layout_string_witnesses_types.o %t/layout_string_witnesses_types_resilient.o -I %t -o %t/main %s
2+
// 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
3+
// 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
4+
// 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
5+
// 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
6+
// 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_static %t/layout_string_witnesses_types.o %t/layout_string_witnesses_types_resilient.o -I %t -o %t/main %s
77
// RUN: %target-codesign %t/main
88
// RUN: %target-run %t/main | %FileCheck %s --check-prefix=CHECK -check-prefix=CHECK-%target-os
99

0 commit comments

Comments
 (0)