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-2982] Silgen segfault with initialized var and extension in second file #45572

Closed
tkrajacic opened this issue Oct 19, 2016 · 4 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 SILGen Area → compiler: The SIL generation stage

Comments

@tkrajacic
Copy link

Previous ID SR-2982
Radar None
Original Reporter @tkrajacic
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

MacOS Sierra, Xcode 8.1 beta, Macbook Early 2016

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

md5: a6c9b28d72699b7829d2c24bec07005b

relates to:

  • SR-3191 Compiler crashes when compiling extension for struct

Issue Description:

The following crashes the compiler in Xcode 8.1 beta and the latest snapshots (tested with DEVELOPMENT-SNAPSHOT-2016-10-14-a).
An example project is attached.

Two files:

public struct Item {
    public enum Version: Int {
        case version1 = 1
    }
    // skipping the default value and doing it in initializers also makes compiler happy
    public var version: Version = .version1
    init() {
        /* version = .version1 */
    }
}

// Putting the extension here works fine
//extension Item {
//    public init(a dictionary: [String: Any]) throws { }
//}

and

// Putting the extension here crashes
extension Item {
    public init(dictionary: Any) { /* version = .version1 */ }
}

The comments above the extension describe one crash case. When the extension is in the second file the compiler crashes, is it in the same file as the definition there is no problem.

The second variant to make the compiler happy is to comment out the default value assignment in the struct's definition and assigning the default values in the initializers. Then the extension can be in the second file.

Xcode log:

CompileSwift normal x86_64 /Users/tkrajacic/Downloads/InitOverloadCrasher/InitOverloadCrasher/File.swift
    cd /Users/tkrajacic/Downloads/InitOverloadCrasher
    /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/tkrajacic/Downloads/InitOverloadCrasher/InitOverloadCrasher/AppDelegate.swift -primary-file /Users/tkrajacic/Downloads/InitOverloadCrasher/InitOverloadCrasher/File.swift -target x86_64-apple-macosx10.12 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Products/Debug -F /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Products/Debug -enable-testing -g -module-cache-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/ModuleCache -D DEBUG -serialize-debugging-options -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/InitOverloadCrasher-generated-files.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/InitOverloadCrasher-own-target-headers.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/InitOverloadCrasher-all-target-headers.hmap -Xcc -iquote -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/InitOverloadCrasher-project-headers.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Products/Debug/include -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/DerivedSources/x86_64 -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/tkrajacic/Downloads/InitOverloadCrasher -emit-module-doc-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File~partial.swiftdoc -Onone -module-name InitOverloadCrasher -emit-module-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File~partial.swiftmodule -serialize-diagnostics-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File.dia -emit-dependencies-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File.d -emit-reference-dependencies-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File.swiftdeps -o /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File.o

0  swift                    0x00000001045772ed PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x0000000104576d36 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fffe8e8fbba _sigtramp + 26
3  libsystem_malloc.dylib   0x00007fffe8e06edc free + 87
4  swift                    0x0000000101b6193e swift::Lowering::SILGenFunction::emitMemberInitializers(swift::VarDecl*, swift::NominalTypeDecl*) + 574
5  swift                    0x0000000101b60295 swift::Lowering::SILGenFunction::emitValueConstructor(swift::ConstructorDecl*) + 8309
6  swift                    0x0000000101b212ac swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 2876
7  swift                    0x0000000101be9c3e swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 446
8  swift                    0x0000000101b2a52b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1835
9  swift                    0x0000000101b2c1bd swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1629
10 swift                    0x000000010198207f performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 19503
11 swift                    0x000000010197b175 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
12 swift                    0x00000001019383bd main + 8685
13 libdyld.dylib            0x00007fffe8c83255 start + 1
14 libdyld.dylib            0x000000000000003d start + 389533161
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/tkrajacic/Downloads/InitOverloadCrasher/InitOverloadCrasher/AppDelegate.swift -primary-file /Users/tkrajacic/Downloads/InitOverloadCrasher/InitOverloadCrasher/File.swift -target x86_64-apple-macosx10.12 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Products/Debug -F /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Products/Debug -enable-testing -g -module-cache-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/ModuleCache -D DEBUG -serialize-debugging-options -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/InitOverloadCrasher-generated-files.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/InitOverloadCrasher-own-target-headers.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/InitOverloadCrasher-all-target-headers.hmap -Xcc -iquote -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/InitOverloadCrasher-project-headers.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Products/Debug/include -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/DerivedSources/x86_64 -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/tkrajacic/Downloads/InitOverloadCrasher -emit-module-doc-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File~partial.swiftdoc -Onone -module-name InitOverloadCrasher -emit-module-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File~partial.swiftmodule -serialize-diagnostics-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File.dia -emit-dependencies-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File.d -emit-reference-dependencies-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File.swiftdeps -o /Users/tkrajacic/Library/Developer/Xcode/DerivedData/InitOverloadCrasher-gqruvtzzqxgknbhjoailfwxpakzs/Build/Intermediates/InitOverloadCrasher.build/Debug/InitOverloadCrasher.build/Objects-normal/x86_64/File.o 
1.  While silgen emitConstructor SIL function @_TFV19InitOverloadCrasher4ItemCfzT1aGVs10DictionarySSP___S0_ for 'init' at /Users/tkrajacic/Downloads/InitOverloadCrasher/InitOverloadCrasher/File.swift:13:12
@swift-ci
Copy link
Collaborator

Comment by Txai Wieser (JIRA)

I'm having this issue, its reproducible 100% of the time.

@slavapestov
Copy link
Member

#6473

@tkrajacic
Copy link
Author

While the compiler doesn't crash anymore, SourceKit crashes all the time when putting the extension in another file.
I am using the latest snapshot (2017-01-04) and latest Xcode (8.2.1)

Is SourceKit not using the latest toolchain?

@tkrajacic
Copy link
Author

Confirmed

@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 SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

4 participants