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-1825] Optional var in protocol implemented as lazy produces Seg fault 11 #44434

Closed
swift-ci opened this issue Jun 19, 2016 · 3 comments
Closed
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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1825
Radar None
Original Reporter amlcurran (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Version 8.0 beta (8S128d)
Swift 3.0

Additional Detail from JIRA
Votes 8
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @slavapestov
Priority Medium

md5: 74584a9fc98466ac7aa296efa6be8ec7

Issue Description:

When a protocol declares an optional variable, and an implementer implements that variable as a lazy initialised one, the compiler will produce a Segmentation Fault 11. Changing the declaration to a non-lazy declaration will not fail to build

A demo playground is attached, this produces the problem in an implementation on UIApplicationDelegate, and a complete protocol/implementation pair.

Here is a log from another project which produces the same error.

CompileSwift normal x86_64 /ios/whatson/whatson/WhatsOnAppDelegate.swift
    cd /ios/whatson
    /Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /ios/whatson/whatson/WhatsOnViewController.swift /ios/whatson/whatson/EventDetailsViewController.swift /ios/whatson/NSDate+Time.swift /ios/whatson/whatson/RoundedRectBorderView.swift /ios/whatson/whatson/UIView+Constraints.swift /ios/whatson/whatson/WhatsOnPresenter.swift /ios/whatson/whatson/UIColor+WhatsOn.swift -primary-file /ios/whatson/whatson/WhatsOnAppDelegate.swift /ios/whatson/whatson/CalendarSourceViewCell.swift /ios/whatson/whatson/NSDateCalculator.swift -target x86_64-apple-ios9.0 -enable-objc-interop -sdk /Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -I /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Products/Debug-iphonesimulator -F /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Products/Debug-iphonesimulator -enable-testing -g -import-objc-header /ios/whatson/whatson-Bridging-Header.h -module-cache-path /Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/swift-overrides.hmap -Xcc -iquote -Xcc "/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/What's On-generated-files.hmap" -Xcc "-I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/What's On-own-target-headers.hmap" -Xcc "-I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/What's On-all-non-framework-target-headers.hmap" -Xcc -ivfsoverlay -Xcc /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/all-product-headers.yaml -Xcc -iquote -Xcc "/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/What's On-project-headers.hmap" -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Products/Debug-iphonesimulator/include -Xcc -I/Projects/j2objc/include -Xcc -Iuk/co/amlcurran/social -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/DerivedSources/x86_64 -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/ios/whatson -emit-module-doc-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate~partial.swiftdoc -Onone -module-name What_s_On -emit-module-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate~partial.swiftmodule -serialize-diagnostics-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate.dia -emit-dependencies-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate.d -emit-reference-dependencies-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate.swiftdeps -o /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate.o

0  swift                    0x0000000104f5b34b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x0000000104f5a636 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x0000000104f5b99f SignalHandler(int) + 287
3  libsystem_platform.dylib 0x00007fff890b752a _sigtramp + 26
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 1995737840
5  swift                    0x0000000102ea0c3f swift::Lowering::TypeConverter::makeConstantInterfaceType(swift::SILDeclRef) + 911
6  swift                    0x0000000102e4dc2c swift::Lowering::TypeConverter::getConstantInfo(swift::SILDeclRef) + 156
7  swift                    0x0000000102e4e566 swift::Lowering::TypeConverter::getConstantSelfParameter(swift::SILDeclRef) + 38
8  swift                    0x0000000102ba1ede (anonymous namespace)::AccessorBasedComponent<swift::Lowering::PhysicalPathComponent>::getBaseAccessKind(swift::Lowering::SILGenFunction&, swift::AccessKind) const + 30
9  swift                    0x0000000102ba0e38 drillToLastComponent(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::LValue&&, swift::Lowering::ManagedValue&, swift::AccessKind) + 120
10 swift                    0x0000000102ba0c53 swift::Lowering::SILGenFunction::emitLoadOfLValue(swift::SILLocation, swift::Lowering::LValue&&, swift::Lowering::SGFContext, bool) + 227
11 swift                    0x0000000102b860e6 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 5862
12 swift                    0x0000000102b80656 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 22
13 swift                    0x0000000102bcb185 swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 837
14 swift                    0x0000000102bc86f8 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 184
15 swift                    0x0000000102bc9281 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 3137
16 swift                    0x0000000102bc8635 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
17 swift                    0x0000000102b94695 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 309
18 swift                    0x0000000102b4bd16 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 198
19 swift                    0x0000000102b446e2 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 610
20 swift                    0x0000000102bcd595 (anonymous namespace)::SILGenType::emitType() + 1013
21 swift                    0x0000000102bcd12e swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
22 swift                    0x0000000102b491db swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 747
23 swift                    0x0000000102b49e22 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 818
24 swift                    0x0000000102b4a293 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 115
25 swift                    0x0000000102a1b8bb performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 13131
26 swift                    0x0000000102a17619 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2873
27 swift                    0x00000001029e56c4 main + 2852
28 libdyld.dylib            0x00007fff944a65ad start + 1
29 libdyld.dylib            0x000000000000004d start + 1807063713
Stack dump:
0.  Program arguments: /Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /ios/whatson/whatson/WhatsOnViewController.swift /ios/whatson/whatson/EventDetailsViewController.swift /ios/whatson/NSDate+Time.swift /ios/whatson/whatson/RoundedRectBorderView.swift /ios/whatson/whatson/UIView+Constraints.swift /ios/whatson/whatson/WhatsOnPresenter.swift /ios/whatson/whatson/UIColor+WhatsOn.swift -primary-file /ios/whatson/whatson/WhatsOnAppDelegate.swift /ios/whatson/whatson/CalendarSourceViewCell.swift /ios/whatson/whatson/NSDateCalculator.swift -target x86_64-apple-ios9.0 -enable-objc-interop -sdk /Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -I /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Products/Debug-iphonesimulator -F /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Products/Debug-iphonesimulator -enable-testing -g -import-objc-header /ios/whatson/whatson-Bridging-Header.h -module-cache-path /Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/swift-overrides.hmap -Xcc -iquote -Xcc /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/What's On-generated-files.hmap -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/What's On-own-target-headers.hmap -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/What's On-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/all-product-headers.yaml -Xcc -iquote -Xcc /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/What's On-project-headers.hmap -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Products/Debug-iphonesimulator/include -Xcc -I/Projects/j2objc/include -Xcc -Iuk/co/amlcurran/social -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/DerivedSources/x86_64 -Xcc -I/Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/ios/whatson -emit-module-doc-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate~partial.swiftdoc -Onone -module-name What_s_On -emit-module-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate~partial.swiftmodule -serialize-diagnostics-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate.dia -emit-dependencies-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate.d -emit-reference-dependencies-path /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate.swiftdeps -o /Library/Developer/Xcode/DerivedData/whatson-dvipuqvjvndytvbknzqteckkjnpc/Build/Intermediates/whatson.build/Debug-iphonesimulator/whatson.build/Objects-normal/x86_64/WhatsOnAppDelegate.o 
1.  While emitting SIL for getter for window at /ios/whatson/whatson/WhatsOnAppDelegate.swift:16:14
@swift-ci
Copy link
Collaborator Author

Comment by Shaun Bruno (JIRA)

One example where this is problematic is the lazy initialization of a custom UIWindow for UIApplicationDelegate.

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 3, 2017

Comment by tim (JIRA)

This happens in XCode 8.3.2 when trying to lazy init the TwitterKit client. I am not sure if it is an optional var in a protocol or not, I think not...

Will crash:
lazy var twitter: TWTRAPIClient = TWTRAPIClient.init(userID: Twitter.sharedInstance().sessionStore.session()!.userID)

Workaround:
{{lazy var twitter: TWTRAPIClient = self.getClient()
func getClient() -> TWTRAPIClient {
return TWTRAPIClient.init(userID: Twitter.sharedInstance().sessionStore.session()!.userID)
}
}}

@slavapestov
Copy link
Member

#9925

@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
Projects
None yet
Development

No branches or pull requests

3 participants