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-1686] Program with recursive class crashes because of “cyclic metadata dependency” #44295

Closed
swift-ci opened this issue Jun 5, 2016 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself runtime The Swift Runtime

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 5, 2016

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
@belkadan
Copy link
Contributor

belkadan commented Jun 6, 2016

cc @rjmccall

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 7, 2017

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
}

@jadengeller
Copy link
Mannequin

jadengeller mannequin commented Jan 29, 2017

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

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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. compiler The Swift compiler in itself runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

2 participants