Skip to content

Commit c4abca3

Browse files
committed
Add a test case for an unresolvable dynamic metadata cycle.
1 parent e9cb62d commit c4abca3

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public struct ResilientGenericStruct<T> {
2+
public init(value: T) {
3+
size = MemoryLayout<T>.size
4+
}
5+
public var size: Int
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public struct ResilientGenericStruct<T> {
2+
public init(value: T) {
3+
size = MemoryLayout<T>.size
4+
storage = value
5+
}
6+
public var size: Int
7+
private var storage: T
8+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift-dylib(%t/libresil.%target-dylib-extension) -Xfrontend -enable-resilience %S/Inputs/resilient_generic_struct_v1.swift -emit-module -emit-module-path %t/resil.swiftmodule -module-name resil
4+
// RUN: %target-codesign %t/libresil.%target-dylib-extension
5+
6+
// RUN: %target-build-swift %s -L %t -I %t -lresil -o %t/main -Xlinker -rpath -Xlinker %t
7+
8+
// RUN: %target-build-swift-dylib(%t/libresil.%target-dylib-extension) -Xfrontend -enable-resilience %S/Inputs/resilient_generic_struct_v2.swift -emit-module -emit-module-path %t/resil.swiftmodule -module-name resil
9+
// RUN: %target-codesign %t/libresil.%target-dylib-extension
10+
11+
// RUN: %target-run %t/main %t/libresil.%target-dylib-extension
12+
13+
import StdlibUnittest
14+
15+
// We build this code against a version of 'resil' where
16+
// ResilientGenericStruct<T> doesn't store a T, then switch the
17+
// dynamic library to a new version where it does, introducing
18+
// an unresolvable dynamic cycle.
19+
//
20+
// It would also be sufficient to demonstrate this crash if the
21+
// compiler *actually* didn't know about the internal implementation
22+
// details of 'resil' when building this file, but since it currently
23+
// still does, it'll report a cycle immediately if we don't pull
24+
// this switcharoo.
25+
import resil
26+
27+
var DynamicMetadataCycleTests =
28+
TestSuite("Unresolvable dynamic metadata cycle tests")
29+
30+
enum test0_Node {
31+
case link(ResilientGenericStruct<test0_Node>)
32+
33+
static func test() -> [test0_Node] {
34+
return []
35+
}
36+
}
37+
DynamicMetadataCycleTests.test("cycle through enum")
38+
.crashOutputMatches("runtime error: unresolvable type metadata dependency cycle detected")
39+
.crashOutputMatches(" main.test0_Node")
40+
.crashOutputMatches(" depends on layout of resil.ResilientGenericStruct<main.test0_Node")
41+
.crashOutputMatches(" depends on layout of main.test0_Node")
42+
.code {
43+
expectCrashLater()
44+
_ = test0_Node.test()
45+
}
46+
47+
runAllTests()

0 commit comments

Comments
 (0)