Skip to content

Add a test case for an unresolvable dynamic metadata cycle #18216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/Interpreter/Inputs/resilient_generic_struct_v1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public struct ResilientGenericStruct<T> {
public init(value: T) {
size = MemoryLayout<T>.size
}
public var size: Int
}
8 changes: 8 additions & 0 deletions test/Interpreter/Inputs/resilient_generic_struct_v2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public struct ResilientGenericStruct<T> {
public init(value: T) {
size = MemoryLayout<T>.size
storage = value
}
public var size: Int
private var storage: T
}
47 changes: 47 additions & 0 deletions test/Interpreter/unresolvable_dynamic_metadata_cycles.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// RUN: %empty-directory(%t)

// 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
// RUN: %target-codesign %t/libresil.%target-dylib-extension

// RUN: %target-build-swift %s -L %t -I %t -lresil -o %t/main -Xlinker -rpath -Xlinker %t

// 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
// RUN: %target-codesign %t/libresil.%target-dylib-extension

// RUN: %target-run %t/main %t/libresil.%target-dylib-extension

import StdlibUnittest

// We build this code against a version of 'resil' where
// ResilientGenericStruct<T> doesn't store a T, then switch the
// dynamic library to a new version where it does, introducing
// an unresolvable dynamic cycle.
//
// It would also be sufficient to demonstrate this crash if the
// compiler *actually* didn't know about the internal implementation
// details of 'resil' when building this file, but since it currently
// still does, it'll report a cycle immediately if we don't pull
// this switcharoo.
import resil

var DynamicMetadataCycleTests =
TestSuite("Unresolvable dynamic metadata cycle tests")

enum test0_Node {
case link(ResilientGenericStruct<test0_Node>)

static func test() -> [test0_Node] {
return []
}
}
DynamicMetadataCycleTests.test("cycle through enum")
.crashOutputMatches("runtime error: unresolvable type metadata dependency cycle detected")
.crashOutputMatches(" main.test0_Node")
.crashOutputMatches(" depends on layout of resil.ResilientGenericStruct<main.test0_Node")
.crashOutputMatches(" depends on layout of main.test0_Node")
.code {
expectCrashLater()
_ = test0_Node.test()
}

runAllTests()