swift icon indicating copy to clipboard operation
swift copied to clipboard

[SR-1686] Program with recursive class crashes because of “cyclic metadata dependency”

Open swift-ci opened this issue 10 years ago • 3 comments

Previous ID SR-1686
Radar None
Original Reporter loic (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Environment

Swift Development Snapshot 2016-05-31 (a)
Xcode 7.3.1

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

md5: 061db2b6918a918bec0dc26f02e3a62a

duplicates:

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

relates to:

  • SR-3779 Program with struct nested in generic struct crashes because of “cyclic metadata dependency”
  • SR-4383 Runtime Error: cyclic metadata dependency detected, aborting

Issue Description:

This code:

class SomeClass <T> {
    let data: (T, SomeClass<T>)?
    init() { self.data = nil }
}
let _ = SomeClass<Int>()

compiles just fine.
But it crashes at runtime with this error message:

GenericCache(0x1002f46b0): cyclic metadata dependency detected, aborting

swift-ci avatar Jun 05 '16 10:06 swift-ci

cc @rjmccall

belkadan avatar Jun 06 '16 18:06 belkadan

Comment by Vincent CARLIER (JIRA)

Catched this as well in recursive function :

enum Tree<Element> {
    case Leaf(Element)
    case Node(Element, [Tree])
}

func permutationTrees<Element>(withElements elements: [Element]) -> [Tree<Element>] {
    guard elements.count > 0 else {
        return []
    }
    guard elements.count > 1 else {
        return [.Leaf(elements[0])]
    }
    guard elements.count > 2 else {
        return [
            .Node(elements[0], [.Leaf(elements[1])]),
            .Node(elements[1], [.Leaf(elements[0])]),
        ]
    }
    // GenericCache(0x10000ef80): cyclic metadata dependency detected, aborting
    // Signal: SIGABRT (signal SIGABRT)
    var trees = [Tree<Element>]()
    for (index, element) in elements.enumerated() {
        var copy = elements
        copy.remove(at: index)
        let subtrees = permutationTrees(withElements: copy)
        trees.append(.Node(element, subtrees))
    }
    return trees
}

swift-ci avatar Jan 07 '17 17:01 swift-ci

Might this be related? https://bugs.swift.org/browse/SR-3779

jadengeller avatar Jan 29 '17 08:01 jadengeller