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

Compiler crash with multi-argument function containing existential #71035

Open
GeorgeElsham opened this issue Jan 20, 2024 · 0 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software mangling Area → compiler: Mangling triage needed This issue needs more specific labels

Comments

@GeorgeElsham
Copy link

GeorgeElsham commented Jan 20, 2024

Description

I have several other recent bug reports about existentials (#70988, #71000, #71012, #71019). They all fail in unique cases. However, this one appears to crash from a different function in swift-frontend, so it could be a different bug entirely.

Reproduction

protocol A<T> {
    associatedtype T
}
protocol B {}
typealias C = A & B
typealias D<T> = A<T> & B

struct Foo<Value>: C {
    typealias T = Value
}

struct Bar<T> {}

@available(iOS 16, *)
struct Baz<T> {
    init(fn: (any D<T>, Bar<T>) -> Void) {}
}

Stack dump

NOTE: This only appeared to crash within a package—moving the reproduction code to a separate file appeared to compile fine, so likely something I'm doing wrong on my part. Instances of <FILE> and <PROJECT> replace actual file name and package name respectfully. Log fetched from Xcode:

1.	Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for file "<FILE>")
4.	While emitting IR SIL function "@$s14<PROJECT>3BazV2fnACyxGyAA1A_AA1Bpx1TRts_XP_AA3BarVyxGtXE_tcfC".
 for 'init(fn:)' (at <FILE>:173:5)
5.	While mangling type for debugger type '@noescape @callee_guaranteed (@in_guaranteed A<T> & B, Bar<τ_0_0>) -> ()'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001032edabc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000105f53cb0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000105cbd054 SignalHandler(int) + 352
3  libsystem_platform.dylib 0x0000000187b5da24 _sigtramp + 56
4  swift-frontend           0x000000010371e3ec swift::Mangle::ASTMangler::appendRequirement(swift::Requirement const&, swift::GenericSignature, bool) + 140
5  swift-frontend           0x000000010371e3ec swift::Mangle::ASTMangler::appendRequirement(swift::Requirement const&, swift::GenericSignature, bool) + 140
6  swift-frontend           0x0000000103716378 swift::Mangle::ASTMangler::appendConstrainedExistential(swift::Type, swift::GenericSignature, swift::ValueDecl const*) + 624
7  swift-frontend           0x00000001037180a0 swift::Mangle::ASTMangler::appendImplFunctionType(swift::SILFunctionType*, swift::GenericSignature, swift::ValueDecl const*) + 1572
8  swift-frontend           0x000000010370e7d0 swift::Mangle::ASTMangler::mangleTypeForDebugger(swift::Type, swift::GenericSignature) + 496
9  swift-frontend           0x0000000102c29214 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) + 1164
10 swift-frontend           0x000000010518ae44 (anonymous namespace)::IRGenDebugInfoImpl::emitVariableDeclaration(swift::irgen::IRBuilder&, llvm::ArrayRef<llvm::Value*>, swift::irgen::DebugTypeInfo, swift::SILDebugScope const*, llvm::Optional<swift::SILLocation>, swift::SILDebugVariable, swift::irgen::IndirectionKind, swift::irgen::ArtificialKind, swift::irgen::AddrDbgInstrKind) (.llvm.11273107327267601125) + 592
11 swift-frontend           0x0000000102bfe454 swift::irgen::IRGenDebugInfo::emitVariableDeclaration(swift::irgen::IRBuilder&, llvm::ArrayRef<llvm::Value*>, swift::irgen::DebugTypeInfo, swift::SILDebugScope const*, llvm::Optional<swift::SILLocation>, swift::SILDebugVariable, swift::irgen::IndirectionKind, swift::irgen::ArtificialKind, swift::irgen::AddrDbgInstrKind) + 276
12 swift-frontend           0x0000000102efd364 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 129848
13 swift-frontend           0x0000000105671fdc swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 11680
14 swift-frontend           0x00000001032709c8 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) + 2516
15 swift-frontend           0x00000001019159d0 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 6532
16 swift-frontend           0x00000001011e8adc swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 176
17 swift-frontend           0x0000000102bb9f64 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 1480
18 swift-frontend           0x0000000104e60fb8 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 264
19 swift-frontend           0x000000010582d99c generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 156
20 swift-frontend           0x00000001058356d4 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1596
21 swift-frontend           0x0000000105830a08 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1748
22 swift-frontend           0x0000000105834854 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
23 swift-frontend           0x000000010589bd44 swift::mainEntry(int, char const**) + 4408
24 dyld                     0x00000001877ad0e0 start + 2360
Command SwiftCompile failed with a nonzero exit code

Expected behavior

The program should compile without the compiler crashing.

Environment

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0

Additional information

Workaround

Removing either of the two function arguments stops the compiler crashing, but obviously changes behaviour.

@GeorgeElsham GeorgeElsham added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Jan 20, 2024
@tshortli tshortli added the mangling Area → compiler: Mangling label Jan 27, 2024
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. crash Bug: A crash, i.e., an abnormal termination of software mangling Area → compiler: Mangling triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants