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

Assigning wrapped value of nested property wrapper in outer property wrapper crashes the compiler

    XMLWordPrintable

    Details

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

      Swift 5.3 as included in Xcode 12 beta 5:
      Apple Swift version 5.3 (swiftlang-1200.0.28.1 clang-1200.0.30.1)
      Target: x86_64-apple-darwin20.0.0

      Description

      The following code (source file is also attached) crashes the compiler as of Swift 5.3 (Xcode 12 beta 5) but worked in Swift 5.2 (Xcode 11.6):

      @propertyWrapper
      final class Wrap1<T> {
         var wrappedValue: T
      
         init(wrappedValue: T) {
            self.wrappedValue = wrappedValue
         }
      }
      
      extension Wrap1 where T: ExpressibleByNilLiteral {
         convenience init() { self.init(wrappedValue: nil) }
      }
      
      @propertyWrapper
      struct Wrap2<T> {
         @Wrap1
         private var _storage: T?
      
         var wrappedValue: T { fatalError("irrelevant") }
      
         init(other: Wrap2) {
            _storage = other._storage
         }
      }
      

      Compiling with swiftc -v InitializeThroughWrapper.swift fails with:

      Apple Swift version 5.3 (swiftlang-1200.0.28.1 clang-1200.0.30.1)
      Target: x86_64-apple-darwin20.0.0
      /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file InitializeThroughWrapper.swift -target x86_64-apple-darwin20.0.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -color-diagnostics -target-sdk-version 11.0 -module-name InitializeThroughWrapper -o /var/folders/0z/101fmx1n5hl3g6l0vrn5g9qh0000gn/T/InitializeThroughWrapper-110cf3.o
      Stack dump:
      0.	Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file InitializeThroughWrapper.swift -target x86_64-apple-darwin20.0.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -color-diagnostics -target-sdk-version 11.0 -module-name InitializeThroughWrapper -o /var/folders/0z/101fmx1n5hl3g6l0vrn5g9qh0000gn/T/InitializeThroughWrapper-110cf3.o 
      1.	Apple Swift version 5.3 (swiftlang-1200.0.28.1 clang-1200.0.30.1)
      2.	While evaluating request IRGenSourceFileRequest(IR Generation for file "InitializeThroughWrapper.swift")
      3.	While emitting IR SIL function "@$s24InitializeThroughWrapper5Wrap2V5otherACyxGAE_tcfC".
       for 'init(other:)' (at InitializeThroughWrapper.swift:21:4)
      0  swift                    0x0000000106f1da85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
      1  swift                    0x0000000106f1ca85 llvm::sys::RunSignalHandlers() + 85
      2  swift                    0x0000000106f1e03f SignalHandler(int) + 111
      3  libsystem_platform.dylib 0x00007fff6ab84d7d _sigtramp + 29
      4  libsystem_platform.dylib 0x00007fca30f275b0 _sigtramp + 18446743845107017808
      5  swift                    0x0000000102e78bd3 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 1379
      6  swift                    0x0000000102e74156 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8982
      7  swift                    0x0000000102d0e2f7 swift::irgen::IRGenerator::emitGlobalTopLevel(llvm::StringSet<llvm::MallocAllocator>*) + 1607
      8  swift                    0x0000000102e48f07 performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1687
      9  swift                    0x0000000102e71bb1 swift::SimpleRequest<swift::IRGenSourceFileRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenSourceFileRequest const&, swift::Evaluator&) + 97
      10 swift                    0x0000000102e4d31c llvm::Expected<swift::IRGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenSourceFileRequest>(swift::IRGenSourceFileRequest const&) + 940
      11 swift                    0x0000000102e4956d swift::performIRGeneration(swift::IRGenOptions const&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 269
      12 swift                    0x0000000102a9538a performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 3002
      13 swift                    0x0000000102a84f98 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 20712
      14 swift                    0x0000000102a06277 main + 1255
      15 libdyld.dylib            0x00007fff6a956851 start + 1
      <unknown>:0: error: unable to execute command: Segmentation fault: 11
      <unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)
      

        Attachments

          Activity

            People

            Assignee:
            ffried Florian Friedrich
            Reporter:
            ffried Florian Friedrich
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: