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-13402] Compiler crash in .map(\.localizedDescription) with Error existentials #55843

Open
ole opened this issue Aug 15, 2020 · 2 comments
Open

Comments

@ole
Copy link
Contributor

@ole ole commented Aug 15, 2020

Previous ID SR-13402
Radar rdar://problem/67363034
Original Reporter @ole
Type Bug
Environment

Apple Swift version 5.3 (swiftlang-1200.0.25.2 clang-1200.0.27.1)
Target: x86_64-apple-darwin19.6.0

Tested with Xcode 12.0 beta 4 and Xcode 11.6 on macOS 10.15.6. I have not tested it with recent master snapshot.

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

md5: 8583f4625786a8e3410481c25675562e

Issue Description:

This code crashes the compiler (Segmentation fault: 11):

import Foundation

struct MyError: Error {}

let errors: [Error] = [MyError()]
print(errors.map(\.localizedDescription))

It has something to do with the key path used as a function passed to map (and possibly also with the fact that the values are Error existentials). Using a normal closure expression instead of the key path does not crash:

// Does not crash
import Foundation

struct MyError: Error {}

let errors: [Error] = [MyError()]
print(errors.map { $0.localizedDescription })

Stack trace:

$ swiftc error-existential-crash.swift
Stack dump:
0.  Program arguments: /Applications/Xcode-12.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file existential-crash.swift -target x86_64-apple-darwin19.6.0 -enable-objc-interop -stack-check -sdk /Applications/Xcode-12.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -color-diagnostics -target-sdk-version 11.0 -module-name main -o /var/folders/v8/tft1qrhx7xl5zps2sbxx5zdc0000gp/T/existential-crash-c7a656.o
1.  Apple Swift version 5.3 (swiftlang-1200.0.25.2 clang-1200.0.27.1)
2.  While evaluating request IRGenSourceFileRequest(IR Generation for file "existential-crash.swift")
3.  While emitting IR SIL function "@main".
0  swift                    0x0000000112da4345 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000112da3345 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000112da48ff SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff686095fd _sigtramp + 29
4  libsystem_platform.dylib 0x00007f989b100800 _sigtramp + 18446743632178278944
5  swift                    0x000000010fbc090f swift::GenericSignatureImpl::getConformanceAccessPath(swift::Type, swift::ProtocolDecl*) + 31
6  swift                    0x000000010fabaef9 swift::Mangle::ASTMangler::appendAnyProtocolConformance(swift::CanGenericSignature, swift::CanType, swift::ProtocolConformanceRef) + 217
7  swift                    0x000000010ecfd9e1 swift::irgen::IRGenMangler::mangleSymbolNameForMangledConformanceAccessorString(char const*, swift::CanGenericSignature, swift::CanType, swift::ProtocolConformanceRef) + 241
8  swift                    0x000000010ec9899f swift::irgen::IRGenModule::emitWitnessTableRefString(swift::CanType, swift::ProtocolConformanceRef, swift::GenericSignature, bool) + 687
9  swift                    0x000000010ec45af4 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::irgen::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool)::$_5>(long, swift::irgen::GenericRequirement) + 452
10 swift                    0x000000010ec86fce swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 318
11 swift                    0x000000010ec3ad4a emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::irgen::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool) + 1658
12 swift                    0x000000010ec39c50 swift::irgen::IRGenModule::getAddrOfKeyPathPattern(swift::KeyPathPattern*, swift::SILLocation) + 2688
13 swift                    0x000000010ed1259b swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 13467
14 swift                    0x000000010ed0abe6 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8982
15 swift                    0x000000010eba5137 swift::irgen::IRGenerator::emitGlobalTopLevel(llvm::StringSet<llvm::MallocAllocator>*) + 1559
16 swift                    0x000000010ecdf997 performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1687
17 swift                    0x000000010ed08641 swift::SimpleRequest<swift::IRGenSourceFileRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenSourceFileRequest const&, swift::Evaluator&) + 97
18 swift                    0x000000010ece3dac llvm::Expected<swift::IRGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenSourceFileRequest>(swift::IRGenSourceFileRequest const&) + 940
19 swift                    0x000000010ecdfffd swift::performIRGeneration(swift::IRGenOptions const&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 269
20 swift                    0x000000010e92c1ca performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 3002
21 swift                    0x000000010e91bdd8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 20712
22 swift                    0x000000010e89d107 main + 1255
23 libdyld.dylib            0x00007fff68410cc9 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)
@typesanitizer
Copy link

@typesanitizer typesanitizer commented Aug 19, 2020

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@ole
Copy link
Contributor Author

@ole ole commented Apr 26, 2022

The crash is still there in Swift 5.6

Tested in the REPL with swiftlang-5.6.0.323.62 (Xcode 13.3.1), macOS 12.3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants