Skip to content

Compiler crash with variadic generics, closures and tuples #76010

@mbrandonw

Description

@mbrandonw

Description

The code below demonstrates a compiler crash when using variadic generics. This crash does not happen in Swift 5.10. So far I have reproduced it in the Swift shipping with Xcode 16.0 beta 4+ and Xcode 16.1 beta.

Reproduction

public func f<each Argument, Result>() -> @Sendable (repeat each Argument) throws -> Result {
  return { (argument: repeat each Argument) in
    throw SomeError()
  }
}
struct SomeError: Error {}

func bug() {
  let _: ((String, Int)) throws -> String = f()  // 💥
}

Stack dump

1.	Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
2.	Compiling with the current language version
3.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for IssueReportingTests)
4.	While running pass #295 SILFunctionTransform "OnoneSimplification" on SILFunction "@$sSS_Sit_QSiSSs5Error_pIeghprzo_SSSiSSsAA_pIeghgyozo_TR".
 for <<debugloc at "<compiler-generated>":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           0x00000001082bb0fc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001082b9350 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001082bb6c8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x0000000185083584 _sigtramp + 56
4  swift-frontend           0x00000001029b12c0 $s9Optimizer15MutatingContextPAAE5erase29instructionIncludingDebugUsesy3SIL11InstructionC_tFAA08SimplifyC0V_Tg5 + 156
5  swift-frontend           0x00000001029b40ac $s9Optimizer31tryReplaceConstructDestructPair33_B8998A2F5E7442F740F7CF2D6D86D22CLL9construct8destruct_y3SIL22SingleValueInstructionC_AF08MultipleuV0CAA15SimplifyContextVtF + 516
6  swift-frontend           0x00000001029bf040 $s9Optimizer17runSimplification2on_17preserveDebugInfo_Sb3SIL8FunctionC_AA0I11PassContextVSbyAE11InstructionC_AA08SimplifyK0VtXEtF019$s9Optimizer23ononecj4AA08i23D0Vvpfiy3SIL0E0C_AA0eD7k11VtcfU_yAE11l2C_pM9G0VtXEfU_Tf1nnnc_n + 704
7  swift-frontend           0x0000000103aa7554 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 3448
8  swift-frontend           0x0000000103aa3b38 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 11968
9  swift-frontend           0x0000000103add084 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 56
10 swift-frontend           0x0000000103ac09e8 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 412
11 swift-frontend           0x0000000103ac3164 swift::runSILDiagnosticPasses(swift::SILModule&) + 612
12 swift-frontend           0x000000010303afc4 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 84
13 swift-frontend           0x0000000102c65d68 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*) + 1376
14 swift-frontend           0x0000000102c64f74 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 984
15 swift-frontend           0x0000000102c68228 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1680
16 swift-frontend           0x0000000102c66f58 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
17 swift-frontend           0x0000000102bee01c swift::mainEntry(int, char const**) + 3680
18 dyld                     0x0000000184cca0e0 start + 2360

Expected behavior

This code should compile, and it does on Swift 5.10 and Xcode 15.4.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0

Additional information

It's worth noting that it appears to be related to using a tuple in the argument for the closure:

let _: (String, Int) throws -> String = f()    // ✅
let _: ((String, Int)) throws -> String = f()  // 💥

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions