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-2916] Compiler crash when using a lazy var to implement property in @objc protocol #45510

Closed
swift-ci opened this issue Oct 11, 2016 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-2916
Radar rdar://28717361
Original Reporter darrenclark (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift 3 in Xcode 8.0 (8A218a)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: b364b2f201e84326b8a9667c8ba31cb4

is duplicated by:

relates to:

  • SR-2673 @NSManaged property can't satisfy protocol requirement

Issue Description:

Swift 3 compiler in Xcode 8.0 (8A218a) crashes when using a lazy var to implement a property in an @objc protocol.

A sample project that reproduces the issue is attached, but here's the gist of it:

@objc protocol MyProtocol {
    var myView: UIView? { get }
}

class ViewController: UIViewController, MyProtocol {
    lazy var myView: UIView? = {
        let myView = UIView()
        myView.backgroundColor = .red
        return myView
    }()
}

Stack trace:

0  swift                    0x000000010ec78b6d PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x000000010ec785b6 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fff89c8852a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fc7134ef588 _sigtramp + 2307289208
4  swift                    0x000000010c657233 swift::Lowering::TypeConverter::getFunctionInterfaceTypeWithCaptures(swift::CanTypeWrapper<swift::AnyFunctionType>, swift::AnyFunctionRef) + 67
5  swift                    0x000000010c659298 swift::Lowering::TypeConverter::makeConstantInterfaceType(swift::SILDeclRef) + 872
6  swift                    0x000000010c606715 swift::Lowering::TypeConverter::getConstantInfo(swift::SILDeclRef) + 165
7  swift                    0x000000010c606fd6 swift::Lowering::TypeConverter::getConstantSelfParameter(swift::SILDeclRef) + 38
8  swift                    0x000000010c2b5f9e (anonymous namespace)::AccessorBasedComponent<swift::Lowering::PhysicalPathComponent>::getBaseAccessKind(swift::Lowering::SILGenFunction&, swift::AccessKind) const + 30
9  swift                    0x000000010c2c0d99 drillToLastComponent(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::LValue&&, swift::Lowering::ManagedValue&, swift::AccessKind) + 137
10 swift                    0x000000010c2c2be3 swift::Lowering::SILGenFunction::emitLoadOfLValue(swift::SILLocation, swift::Lowering::LValue&&, swift::Lowering::SGFContext, bool) + 227
11 swift                    0x000000010c293d57 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 20439
12 swift                    0x000000010c2ef1ab swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 491
13 swift                    0x000000010c2eb9e7 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 183
14 swift                    0x000000010c2ec8e6 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4022
15 swift                    0x000000010c2ad2ca swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 314
16 swift                    0x000000010c229855 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 1877
17 swift                    0x000000010c228402 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 626
18 swift                    0x000000010c2f3967 (anonymous namespace)::SILGenType::emitType() + 1271
19 swift                    0x000000010c2f33fe swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
20 swift                    0x000000010c235173 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1795
21 swift                    0x000000010c236e2d swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1629
22 swift                    0x000000010c08e16f performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 19503
23 swift                    0x000000010c087265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
24 swift                    0x000000010c04482d main + 8685
25 libdyld.dylib            0x00007fff870025ad start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/dclark/Desktop/LazyVarCompilerSegfault/LazyVarCompilerSegfault/MyProtocol.swift -primary-file /Users/dclark/Desktop/LazyVarCompilerSegfault/LazyVarCompilerSegfault/ViewController.swift /Users/dclark/Desktop/LazyVarCompilerSegfault/LazyVarCompilerSegfault/AppDelegate.swift -target x86_64-apple-ios10.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -I /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Products/Debug-iphonesimulator -F /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/dclark/Library/Developer/Xcode/DerivedData/ModuleCache -D DEBUG -serialize-debugging-options -Xcc -I/Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/LazyVarCompilerSegfault-generated-files.hmap -Xcc -I/Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/LazyVarCompilerSegfault-own-target-headers.hmap -Xcc -I/Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/LazyVarCompilerSegfault-all-target-headers.hmap -Xcc -iquote -Xcc /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/LazyVarCompilerSegfault-project-headers.hmap -Xcc -I/Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/DerivedSources/x86_64 -Xcc -I/Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/dclark/Desktop/LazyVarCompilerSegfault -emit-module-doc-path /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/Objects-normal/x86_64/ViewController~partial.swiftdoc -Onone -module-name LazyVarCompilerSegfault -emit-module-path /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/Objects-normal/x86_64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/Objects-normal/x86_64/ViewController.dia -emit-dependencies-path /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/Objects-normal/x86_64/ViewController.d -emit-reference-dependencies-path /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/Objects-normal/x86_64/ViewController.swiftdeps -o /Users/dclark/Library/Developer/Xcode/DerivedData/LazyVarCompilerSegfault-exrswzjccbqiyfboyfxcmqtrxget/Build/Intermediates/LazyVarCompilerSegfault.build/Debug-iphonesimulator/LazyVarCompilerSegfault.build/Objects-normal/x86_64/ViewController.o 
1.  While emitting SIL for getter for myView at /Users/dclark/Desktop/LazyVarCompilerSegfault/LazyVarCompilerSegfault/ViewController.swift:26:14
@belkadan
Copy link
Contributor

This is likely the same underlying problem as with @NSManaged in SR-2673, but it'll need the more general fix.

@slavapestov
Copy link
Member

No longer crashes on master.

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

No branches or pull requests

3 participants