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

Recursive generics causes runtime crash

    XMLWordPrintable

    Details

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

      Swift 3.0.2 and 3.1, OSX and Ubuntu 16.04

      Description

      Here is a short example:

      class Super<T> {
      }
      
      class Child: Super<Child> {
      }
      
      _ = Child()
      

      On OSX, this code will compile, but when executed, it will crash with this stack trace:

      ylin@youming-mbpr:~/Desktop$ swift main.swift 
      0  swift                    0x0000000107b5dec7 PrintStackTraceSignalHandler(void*) + 39
      1  swift                    0x0000000107b5d376 SignalHandler(int) + 646
      2  libsystem_platform.dylib 0x00007fffa7414b3a _sigtramp + 26
      3  libsystem_platform.dylib 0x000000011442c978 _sigtramp + 1828814424
      4  libdispatch.dylib        0x00007fffa71cf8ef dispatch_once_f + 92
      5  libdispatch.dylib        0x000000010a0681d8 dispatch_once_f + 1659472197
      6  libdispatch.dylib        0x000000010a068424 dispatch_once_f + 1659472785
      7  libdispatch.dylib        0x000000010a0683c4 dispatch_once_f + 1659472689
      8  libdispatch.dylib        0x00007fffa71cf8fc _dispatch_client_callout + 8
      9  libdispatch.dylib        0x00007fffa71cf8b9 dispatch_once_f + 38
      10 libdispatch.dylib        0x000000010a0681d8 dispatch_once_f + 1659472197
      11 libdispatch.dylib        0x000000010a06801c dispatch_once_f + 1659471753
      12 swift                    0x00000001054a5e2f llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 655
      13 swift                    0x00000001054aba23 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 707
      14 swift                    0x00000001049a8b09 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 3385
      15 swift                    0x000000010497eda4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 50596
      16 swift                    0x000000010492c57c main + 9052
      17 libdyld.dylib            0x00007fffa7205235 start + 1
      18 libdyld.dylib            0x000000000000000a start + 1491054038
      Stack dump:
      0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret main.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name main 
      Illegal instruction: 4
      

      However, on Ubuntu 16.04, this code will compile, but when executed it will hang and the process will not return without CTRL+C.

      I don't know if this kind of recursive generics is natively supported by Swift. If yes, then the code should not crash at runtime. If not, then the compiler should've caught this.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ylin Youming Lin
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: