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-1722] Recursive enum (via Array as indirection) compiles but causes runtime deadlock. #44331

Closed
regexident opened this issue Jun 9, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself 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

@regexident
Copy link
Contributor

Previous ID SR-1722
Radar None
Original Reporter @regexident
Type Bug
Status Resolved
Resolution Duplicate
Environment

OS X El Capitan.
Shouldn't matter though.

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

md5: 99032780a3fad302fa3f0e9d99fddca8

duplicates:

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

Issue Description:

This code compiles without warnings/errors but deadlocks:

enum Tree<Value> {
    case Leaf(Value)
    case Branch(Value, [Tree<Value>])
}

let tree = Tree<Int>.Branch(42, [.Leaf(42)])
print(tree)

Pausing the program returns the following stack trace:

#&#8203;0  0x00007fff99c59de6 in __psynch_mutexwait ()
#&#8203;1  0x00007fff95bcbe4a in _pthread_mutex_lock_wait ()
#&#8203;2  0x00007fff88318f6d in std::__1::mutex::lock() ()
#&#8203;3  0x000000010257c801 in swift::MetadataCache<(anonymous namespace)::GenericCacheEntry>::addMetadataEntry(swift::EntryRef<(anonymous namespace)::GenericCacheEntry>, ConcurrentList<swift::MetadataCache<(anonymous namespace)::GenericCacheEntry>::EntryPair>&, llvm::function_ref<(anonymous namespace)::GenericCacheEntry* ()>) ()
#&#8203;4  0x0000000102579739 in swift_getGenericMetadata2 ()
#&#8203;5  0x00000001023102f1 in ___lldb_unnamed_function23$$Tree ()
#&#8203;6  0x000000010257c9b8 in (anonymous namespace)::GenericCacheEntry* llvm::function_ref<(anonymous namespace)::GenericCacheEntry* ()>::callback_fn<swift_getGenericMetadata::$_1>(long) ()
#&#8203;7  0x000000010257c851 in swift::MetadataCache<(anonymous namespace)::GenericCacheEntry>::addMetadataEntry(swift::EntryRef<(anonymous namespace)::GenericCacheEntry>, ConcurrentList<swift::MetadataCache<(anonymous namespace)::GenericCacheEntry>::EntryPair>&, llvm::function_ref<(anonymous namespace)::GenericCacheEntry* ()>) ()
#&#8203;8  0x0000000102579739 in swift_getGenericMetadata2 ()
#&#8203;9  0x000000010231dbdb in static …(…) -> Tree<Int> at …/Tree.swift:167

Replacing "enum" with "indirect enum" fixes the problem.

I have the feeling that this should either work (preferred, obviously) or not compile in the first place.

@regexident
Copy link
Contributor Author

With …

Apple Swift version 4.0 (swiftlang-900.0.54.11 clang-900.0.31)
Target: x86_64-apple-macosx10.9

… this code now fails to compile with …

Terminated due to signal: ABORT TRAP (6)
GenericCache(0x101e4a0e8): cyclic metadata dependency detected, aborting

…which still isn't a particularly useful and human-friendly error message, but at least it doesn't compile anymore.

@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. compiler The Swift compiler in itself 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

2 participants