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-13418] Assigning wrapped value of nested property wrapper in outer property wrapper crashes the compiler #55859

Closed
ffried opened this issue Aug 19, 2020 · 5 comments
Assignees
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 IRGen LLVM IR generation regression swift 5.3

Comments

@ffried
Copy link
Contributor

ffried commented Aug 19, 2020

Previous ID SR-13418
Radar rdar://problem/67445345
Original Reporter @ffried
Type Bug
Status Resolved
Resolution Done

Attachment: Download

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

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.3Regression, Crash, IRGen
Assignee @ffried
Priority Medium

md5: b0d4a78fbc9855db43cd35ed8075a746

Issue 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)
@ffried
Copy link
Contributor Author

ffried commented Aug 19, 2020

Note that assigning __storage to other.__storage works. It only crashes when the assignment has to reach through the wrapper.

@LucianoPAlmeida
Copy link
Collaborator

Able to reproduce on master with `%target-swift-emit-silgen %s -verify`

cc @hborla

@hborla
Copy link
Member

hborla commented Aug 20, 2020

@swift-ci create

@hborla
Copy link
Member

hborla commented Jan 12, 2021

This will be fixed by #35218

@hborla
Copy link
Member

hborla commented Jan 20, 2021

Fixed![]( Could you please verify using the latest main development snapshot from https://swift.org/download/#snapshots ? Thank you)

@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 crash Bug: A crash, i.e., an abnormal termination of software IRGen LLVM IR generation regression swift 5.3
Projects
None yet
Development

No branches or pull requests

4 participants