Skip to content

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

@swift-ci

Description

@swift-ci
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwarerun-time crashBug → crash: Swift code crashed during executionruntimeThe Swift Runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions