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-10551] Segfault 11 when compiling with certain protocol extensions & associatedtypes #52951

Closed
swift-ci opened this issue Apr 25, 2019 · 7 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 SILGen Area → compiler: The SIL generation stage

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10551
Radar None
Original Reporter Caiopia (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.5.0

MacOSX 10.14

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

md5: 698cf7a9d1278468ca3aa1d0a7c7cad9

is duplicated by:

  • SR-11413 Failed to emit SIL function using assoctype within extension where constrained by equal operator with Self

Issue Description:

If you try to compile the file below, it fails with a segmentation fault: 11. If the extension to C at the bottom is removed, then it successfully compiles, but not with it. Stack trace with Swift version pasted below `SegFault.swift`.

// SegFault.swift

protocol A { }

typealias B = A

protocol C {
    associatedtype B
    static func c(_: B)
}

struct D { }

extension D: C {
    static func c(_: B) { }
}

extension C where Self == D {
    func c(_: B) { }
}
swiftc SegFault.swift
Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.5.0
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file SegFault.swift -target x86_64-apple-darwin18.5.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name SegFault -o /var/folders/p7/nc3phzmx7y37mn17j5fc3kkw0000gp/T/SegFault-d2e01a.o
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file SegFault.swift -target x86_64-apple-darwin18.5.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name SegFault -o /var/folders/p7/nc3phzmx7y37mn17j5fc3kkw0000gp/T/SegFault-d2e01a.o
1.  While emitting SIL for 'c(_:)' (at SegFault.swift:17:2)
0  swift                    0x000000010910bee3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010910b6bc SignalHandler(int) + 348
2  libsystem_platform.dylib 0x00007fff7db7db5d _sigtramp + 29
3  libsystem_platform.dylib 0x0000000000000009 _sigtramp + 2185766089
4  swift                    0x0000000105f97b60 getSILFunctionType(swift::SILModule&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::AnyFunctionType::ExtInfo, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, llvm::Optional<swift::ProtocolConformanceRef>) + 1504
5  swift                    0x0000000105f9712c getNativeSILFunctionType(swift::SILModule&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::AnyFunctionType::ExtInfo, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, llvm::Optional<swift::ProtocolConformanceRef>) + 908
6  swift                    0x0000000105f9a8fd getUncachedSILFunctionTypeForConstant(swift::SILModule&, swift::SILDeclRef, swift::CanTypeWrapper<swift::AnyFunctionType>) + 477
7  swift                    0x0000000105f9c904 swift::Lowering::TypeConverter::getConstantInfo(swift::SILDeclRef) + 932
8  swift                    0x0000000105fc4409 swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, swift::ProfileCounter) + 89
9  swift                    0x0000000105abcf49 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 345
10 swift                    0x0000000105abe3fe swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 782
11 swift                    0x0000000105bb9747 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 151
12 swift                    0x0000000105ac8856 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1206
13 swift                    0x0000000105aca66c swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1228
14 swift                    0x0000000104f6b7aa performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 30122
15 swift                    0x0000000104f6092e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6862
16 swift                    0x0000000104efe9ce main + 1246
17 libdyld.dylib            0x00007fff7d9983d5 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)
@theblixguy
Copy link
Collaborator

On Swift 5.1 (near-master):

should have substituted dependent type into context
UNREACHABLE executed at /Users/suyashsrijan/Documents/swift-src/swift/lib/SIL/TypeLowering.cpp:269!
Stack dump:
0.  Program arguments: ./swiftc -frontend -typecheck /Users/suyashsrijan/Desktop/test1.swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -emit-ir
1.  While emitting SIL for 'c(_:)' (at /Users/suyashsrijan/Desktop/test1.swift:17:2)
0  swiftc                   0x0000000105aa0285 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swiftc                   0x0000000105a9f545 llvm::sys::RunSignalHandlers() + 85
2  swiftc                   0x0000000105aa0868 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff58d63b5d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000000046 _sigtramp + 2804532486
5  libsystem_c.dylib        0x00007fff58c236a6 abort + 127
6  swiftc                   0x0000000105a64ed2 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 530
7  swiftc                   0x0000000102936c13 (anonymous namespace)::TypeClassifierBase<(anonymous namespace)::LowerType, swift::Lowering::TypeLowering*>::visitAbstractTypeParamType(swift::CanType) + 227
8  swiftc                   0x000000010292c0c6 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type, swift::ResilienceExpansion) + 870
9  swiftc                   0x000000010288e74f (anonymous namespace)::DestructureInputs::visit(swift::ValueOwnership, bool, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILFunctionTypeRepresentation) + 175
10 swiftc                   0x000000010288cf23 getSILFunctionType(swift::SILModule&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::AnyFunctionType::ExtInfo, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, llvm::Optional<swift::ProtocolConformanceRef>) + 1891
11 swiftc                   0x000000010288776e getNativeSILFunctionType(swift::SILModule&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::AnyFunctionType::ExtInfo, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, llvm::Optional<swift::ProtocolConformanceRef>) + 1886
12 swiftc                   0x000000010288855d getUncachedSILFunctionTypeForConstant(swift::SILModule&, swift::SILDeclRef, swift::CanTypeWrapper<swift::AnyFunctionType>) + 781
13 swiftc                   0x0000000102888f6a swift::Lowering::TypeConverter::getConstantInfo(swift::SILDeclRef) + 202
14 swiftc                   0x00000001028851cd swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, swift::ProfileCounter) + 77
15 swiftc                   0x000000010236c15a swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 410
16 swiftc                   0x000000010236c978 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 616
17 swiftc                   0x0000000102451270 SILGenExtension::visitFuncDecl(swift::FuncDecl*) + 336
18 swiftc                   0x000000010244e1fb SILGenExtension::emitExtension(swift::ExtensionDecl*) + 59
19 swiftc                   0x000000010244e1b5 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 21
20 swiftc                   0x00000001023720f6 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 822
21 swiftc                   0x00000001023730f8 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 376
22 swiftc                   0x00000001023735e0 swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&) + 16
23 swiftc                   0x000000010207555f performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 10303
24 swiftc                   0x0000000102071cc2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2978
25 swiftc                   0x000000010201c9b8 main + 696
26 libdyld.dylib            0x00007fff58b7e3d5 start + 1
27 libdyld.dylib            0x0000000000000007 start + 2806520883

@belkadan
Copy link
Contributor

@slavapestov, does this sound familiar?

@slavapestov
Copy link
Member

We should either reject that extension as invalid, or treat it like "extension D".

@theblixguy
Copy link
Collaborator

@slavapestov I was thinking it would be better to reject it with a diagnostic that explains this could be simply written as "extension D" i.e. "extension of C with same-type constraint 'Self == D' is better expressed as extension of D". What do you think? If you feel this could be magically treated as "extension D" instead then what would be the best place to do this? In the GSB (i.e. when we call 'resolveConcreteConformance' maybe)?

@slavapestov
Copy link
Member

I think the decision to reject or accept this should be made independently of fixing the crash. These sorts of inconsistencies with generic signatures end up manifesting as real issues on valid code eventually.

@theblixguy
Copy link
Collaborator

Hmm, interestingly we don't crash when the associatedtype in C is not present.

@slavapestov
Copy link
Member

No longer crashes.

@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

5 participants