Uploaded image for project: 'Swift'
  1. Swift
  2. SR-4732

"Tree" enum crashes at runtime "cyclic metadata dependency detected, aborting"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: None
    • 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

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              mattgallagher Matt Gallagher
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: