Skip to content
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

[SR-4732] "Tree" enum crashes at runtime "cyclic metadata dependency detected, aborting" #47309

Closed
swift-ci opened this issue Apr 29, 2017 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution runtime The Swift Runtime

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4732
Radar None
Original Reporter mattgallagher (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Mac Pro 5,1, macOS Sierra 10.12.4

Tested both Xcode 8.3.2 and swift-DEVELOPMENT-SNAPSHOT-2017-04-24-a-osx

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, RunTimeCrash, Runtime
Assignee None
Priority Medium

md5: ff2afb9391fe46a532bd849ab2c2aca2

duplicates:

  • SR-263 Implement a general solution to prevent deadlocks when generic types rely on their own metadata recursively

relates to:

  • SR-5086 Cyclic metadata dependency error in generic type with nested enum with associated value of outer generic type

Issue Description:

In Xcode 8.3.2 and the latest development snapshot (April 24, 2017), the following code:

enum Tree<Node> {
   case parentAndChildren(Node, Array<Tree<Node>>)
   case leaf(Node)
}

let a = Tree<String>.parentAndChildren("parent", [Tree<String>.leaf("leaf")])

print(a)

crashes at runtime on the `let a = Tree` line with the error:

> GenericCache(0x100658d08): cyclic metadata dependency detected, aborting

By my understanding, this should be valid code, despite the recursive definition, since the layout of `Array` does not depend on its generic parameter.

Indeed, change the definition of `parentAndChildren` to:

 case parentWithChildren(Array<Tree<Node>>)

and there's no problem – the code works as expected.

In addition to changing the contents of the `case`, it is possible to declare the original `parentAndChildren` case as `indirect` and the problem goes away.

Ideally, the original code should work. If that isn't possible, a compile time error (forcing the use of `indirect`) would be preferable to a runtime crash.

Previous bugs returning the same error include:

However, it's not clear if either of these are precisely the same problem.

@belkadan
Copy link
Contributor

belkadan commented May 2, 2017

This does seem a little different. cc @rjmccall

@rjmccall
Copy link
Member

rjmccall commented May 2, 2017

I expect we're trying to compute a tuple layout at runtime because the tuple contains a dependently-sized type and we think we need a concrete metadata for all the other children in order to do so.

It's fixable without having to implement incomplete type metadata, so yes, this is worth tracking separately from the other issues.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

4 participants