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-11521] Compiler crash - segfault when trying to make an extension on Result type #53922

Closed
swift-ci opened this issue Sep 25, 2019 · 6 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11521
Radar rdar://problem/55705702
Original Reporter skoleckm (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

swiftc --version

Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)

Target: x86_64-apple-darwin18.7.0

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

md5: 3e36a7ddfc9129e44469fcbc551daf41

is duplicated by:

  • SR-11561 Letting SwiftUI Binding conditionally conform to Sequence and Collection crashes compiler

Issue Description:

When trying to extend the built in Result type to conform to RandomAccessCollection, the compiler seg faults.

Here's the code on question (attached separately as well)

extension Result: RandomAccessCollection, BidirectionalCollection, Collection, Sequence where Success: RandomAccessCollection, Success.Index == Int {
   public typealias Element = Result<Success.Element, Failure>
   public typealias Index = Int
   public var startIndex: Int {
       switch self {
       case .success(let array):
           return array.startIndex
       case .failure:
           return 0
       }
   }
   public var endIndex: Int {
       switch self {
       case .success(let array):
           return array.endIndex
       case .failure:
           return 1
       }
   }
   public subscript(position: Int) -> Result<Success.Element, Failure> {
       switch self {
       case .success(let array):
           return .success(array[position])
       case .failure(let error):
           return .failure(error)
       }
   }
}
print("Hello World")

Stack trace:

Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file CompilerCrash.swift -target x86_64-apple-darwin18.7.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name CompilerCrash -o /var/folders/4n/4dy99jsd3c9bbwwmsy69gtt80000gn/T/CompilerCrash-e9e241.o 
1.  While emitting witness table for protocol conformance to 'Collection' (in module 'Swift') for type 'Result<Success, Failure>'
0  swift                    0x0000000104b92eb3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000104b92686 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff5be7eb5d _sigtramp + 29
3  libsystem_platform.dylib 0x0000000000000060 _sigtramp + 2753041696
4  swift                    0x000000010171658f swift::GenericSignature::getConformanceAccessPath(swift::Type, swift::ProtocolDecl*) + 31
5  swift                    0x0000000101671768 swift::Mangle::ASTMangler::appendConcreteProtocolConformance(swift::ProtocolConformance const*) + 1784
6  swift                    0x000000010166e893 swift::Mangle::ASTMangler::appendRetroactiveConformances(swift::SubstitutionMap, swift::ModuleDecl*) + 179
7  swift                    0x000000010166de05 swift::Mangle::ASTMangler::appendRetroactiveConformances(swift::Type) + 389
8  swift                    0x000000010166ccb0 swift::Mangle::ASTMangler::appendType(swift::Type, swift::ValueDecl const*) + 8864
9  swift                    0x0000000100a12b2f swift::irgen::IRGenMangler::mangleTypeForReflection(swift::irgen::IRGenModule&, swift::Type) + 255
10 swift                    0x00000001009ba35b swift::irgen::IRGenModule::getTypeRef(swift::CanType, swift::irgen::MangledTypeRefRole) + 587
11 swift                    0x00000001009b0ce0 swift::irgen::IRGenModule::emitSILWitnessTable(swift::SILWitnessTable*) + 2304
12 swift                    0x00000001008cd9e8 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1976
13 swift                    0x00000001009fe065 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1189
14 swift                    0x00000001007ea78a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 36682
15 swift                    0x00000001007de034 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
16 swift                    0x000000010076b5a3 main + 1219
17 libdyld.dylib            0x00007fff5bc933d5 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)
@mikeash
Copy link
Contributor

mikeash commented Sep 25, 2019

With asserts enabled, the compiler hits this:

Assertion failed: (CurGenericSignature && "Need a generic signature to resolve conformance"), function appendConcreteProtocolConformance, file /Volumes/Hum/mikeash/Development/swift-source-github/swift/lib/AST/ASTMangler.cpp, line 2659.

@belkadan
Copy link
Contributor

@swift-ci create

@theblixguy
Copy link
Collaborator

PR: #27547 should fix it

@theblixguy
Copy link
Collaborator

Fixed on master. Please verify using the next available development snapshot!

@tonyarnold
Copy link
Contributor

Will this fix be backported to Swift 5.1? I hit it today - any chance of it getting into Xcode 11.3?

@theblixguy
Copy link
Collaborator

At this point, only critical fixes can be cherry-picked into 5.1 and I am not sure if this meets the criteria. It depends on whether people at Apple think this is important enough to be cherry-picked into 5.1 and made available through the next Xcode release.

@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

6 participants