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

Recursive enum (via Array as indirection) compiles but causes runtime deadlock.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: Compiler
    • Environment:

      OS X El Capitan.
      Shouldn't matter though.

      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:

      #0	0x00007fff99c59de6 in __psynch_mutexwait ()
      #1	0x00007fff95bcbe4a in _pthread_mutex_lock_wait ()
      #2	0x00007fff88318f6d in std::__1::mutex::lock() ()
      #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* ()>) ()
      #4	0x0000000102579739 in swift_getGenericMetadata2 ()
      #5	0x00000001023102f1 in ___lldb_unnamed_function23$$Tree ()
      #6	0x000000010257c9b8 in (anonymous namespace)::GenericCacheEntry* llvm::function_ref<(anonymous namespace)::GenericCacheEntry* ()>::callback_fn<swift_getGenericMetadata::$_1>(long) ()
      #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* ()>) ()
      #8	0x0000000102579739 in swift_getGenericMetadata2 ()
      #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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              Regexident Vincent Esche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: