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] Reproducible crash: headbutt between callAsFunction and parameter packs? #79001

Open
GarthSnyder opened this issue Jan 29, 2025 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@GarthSnyder
Copy link
Contributor

GarthSnyder commented Jan 29, 2025

Description

The code below crashes the compiler.

Here's the backtrace
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/garth/Work/Playgrounds/CountOnes/CountOnes/main.swift -emit-dependencies-path /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/Objects-normal/arm64/main.d -emit-const-values-path /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/Objects-normal/arm64/main.swiftconstvalues -emit-reference-dependencies-path /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/Objects-normal/arm64/main.swiftdeps -serialize-diagnostics-path /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/Objects-normal/arm64/main.dia -target arm64-apple-macos15.2 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -I /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Products/Debug -F /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Products/Debug -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=5 -module-cache-path /Users/garth/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 6 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -const-gather-protocols-file /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/Objects-normal/arm64/CountOnes_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -enable-experimental-feature OpaqueTypeErasure -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Users/garth/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/garth/Work/Playgrounds/CountOnes -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/garth/Work/Playgrounds/CountOnes -Xcc -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -Xcc -ivfsstatcache -Xcc /Users/garth/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.2-24C94-1dd28740b163f220e3e9b9fd2a542f53.sdkstatcache -Xcc -I/Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/CountOnes-generated-files.hmap -Xcc -I/Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/CountOnes-own-target-headers.hmap -Xcc -I/Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/CountOnes-all-target-headers.hmap -Xcc -iquote -Xcc /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/CountOnes-project-headers.hmap -Xcc -I/Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Products/Debug/include -Xcc -I/Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/DerivedSources-normal/arm64 -Xcc -I/Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/DerivedSources/arm64 -Xcc -I/Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/DerivedSources -Xcc -DDEBUG=1 -module-name CountOnes -frontend-parseable-output -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Build/Intermediates.noindex/CountOnes.build/Debug/CountOnes.build/Objects-normal/arm64/main.o -index-unit-output-path /CountOnes.build/Debug/CountOnes.build/Objects-normal/arm64/main.o -index-store-path /Users/garth/Library/Developer/Xcode/DerivedData/CountOnes-dhgmkxrmzfqlwdhgdleunjujyglm/Index.noindex/DataStore -index-system-modules
1.	Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/garth/Work/Playgrounds/CountOnes/CountOnes/main.swift")
4.	While silgen emitFunction SIL function "@$s9CountOnes7MemoizeC14callAsFunctionyq_xxQpF".
 for 'callAsFunction(_:)' (at /Users/garth/Work/Playgrounds/CountOnes/CountOnes/main.swift:34:5)
5.	While silgen closureexpr SIL function "@$s9CountOnes7MemoizeC14callAsFunctionyq_xxQpFq_xxQpcACyxxQp_QPq_Gcfu_".
 for expression at [/Users/garth/Work/Playgrounds/CountOnes/CountOnes/main.swift:39:29 - line:39:29] RangeText=""
6.	While silgen closureexpr SIL function "@$s9CountOnes7MemoizeC14callAsFunctionyq_xxQpFq_xxQpcACyxxQp_QPq_Gcfu_q_xxQpcfu0_".
 for expression at [/Users/garth/Work/Playgrounds/CountOnes/CountOnes/main.swift:39:29 - line:39:29] RangeText=""
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           0x000000010a606a9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a604cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010a607068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x0000000190aeee04 _sigtramp + 56
4  swift-frontend           0x00000001059f0918 void llvm::function_ref<void (swift::SILValue, swift::SILValue, swift::SILValue)>::callback_fn<(anonymous namespace)::ArgEmitter::emitPackExpansionIntoPack(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, swift::SILType, bool, swift::SILValue, swift::CanTypeWrapper<swift::PackType>, unsigned int)::'lambda'(swift::SILValue, swift::SILValue, swift::SILValue)>(long, swift::SILValue, swift::SILValue, swift::SILValue) + 484
5  swift-frontend           0x00000001059f0918 void llvm::function_ref<void (swift::SILValue, swift::SILValue, swift::SILValue)>::callback_fn<(anonymous namespace)::ArgEmitter::emitPackExpansionIntoPack(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, swift::SILType, bool, swift::SILValue, swift::CanTypeWrapper<swift::PackType>, unsigned int)::'lambda'(swift::SILValue, swift::SILValue, swift::SILValue)>(long, swift::SILValue, swift::SILValue, swift::SILValue) + 484
6  swift-frontend           0x0000000105ac2494 swift::Lowering::SILGenFunction::emitDynamicPackLoop(swift::SILLocation, swift::CanTypeWrapper<swift::PackType>, unsigned int, swift::SILValue, swift::SILValue, swift::GenericEnvironment*, bool, llvm::function_ref<void (swift::SILValue, swift::SILValue, swift::SILValue)>, swift::SILBasicBlock*) + 1448
7  swift-frontend           0x00000001059efc38 (anonymous namespace)::ArgEmitter::emitPackArg(llvm::MutableArrayRef<swift::Lowering::ArgumentSource>, swift::Lowering::AbstractionPattern) + 3676
8  swift-frontend           0x00000001059ecaa8 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 508
9  swift-frontend           0x00000001059f8878 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 664
10 swift-frontend           0x00000001059f8298 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1000
11 swift-frontend           0x00000001059e0e7c (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2028
12 swift-frontend           0x00000001059df408 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3116
13 swift-frontend           0x0000000105a4c37c swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 128
14 swift-frontend           0x0000000105b0a704 swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 1024
15 swift-frontend           0x0000000105a7f398 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 888
16 swift-frontend           0x00000001059c9b10 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 4312
17 swift-frontend           0x00000001059d370c void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_0>(long) + 200
18 swift-frontend           0x00000001059cc810 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) + 280
19 swift-frontend           0x0000000105a73b30 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 2948
20 swift-frontend           0x0000000105b0a61c swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 792
21 swift-frontend           0x0000000105a7f398 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 888
22 swift-frontend           0x00000001059c9b10 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 4312
23 swift-frontend           0x00000001059d370c void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_0>(long) + 200
24 swift-frontend           0x00000001059cc810 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) + 280
25 swift-frontend           0x00000001059f69cc (anonymous namespace)::SILGenApply::visitAbstractClosureExpr(swift::AbstractClosureExpr*) + 104
26 swift-frontend           0x00000001059de93c swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 352
27 swift-frontend           0x0000000105a671c0 (anonymous namespace)::RValueEmitter::visitFunctionConversionExpr(swift::FunctionConversionExpr*, swift::Lowering::SGFContext) + 3528
28 swift-frontend           0x0000000105a4f58c swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
29 swift-frontend           0x00000001059ee068 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 5028
30 swift-frontend           0x00000001059dc0f0 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 216
31 swift-frontend           0x00000001059ec9ac (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 256
32 swift-frontend           0x00000001059f8878 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 664
33 swift-frontend           0x00000001059f8298 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1000
34 swift-frontend           0x00000001059e0e7c (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2028
35 swift-frontend           0x00000001059df408 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3116
36 swift-frontend           0x0000000105a4c37c swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 128
37 swift-frontend           0x0000000105a3790c swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 2016
38 swift-frontend           0x0000000105a3e840 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 140
39 swift-frontend           0x0000000105b07368 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 5756
40 swift-frontend           0x0000000105a7efc8 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 492
41 swift-frontend           0x00000001059cab1c swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8420
42 swift-frontend           0x00000001059cb3bc swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 216
43 swift-frontend           0x00000001059c89ec swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 364
44 swift-frontend           0x0000000105b1ec8c (anonymous namespace)::SILGenType::visitFuncDecl(swift::FuncDecl*) + 32
45 swift-frontend           0x0000000105b1b234 (anonymous namespace)::SILGenType::emitType() + 424
46 swift-frontend           0x00000001059c8624 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 104
47 swift-frontend           0x00000001059cf038 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1804
48 swift-frontend           0x0000000105b0592c swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 196
49 swift-frontend           0x00000001059d3f14 swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 528
50 swift-frontend           0x0000000104fadb90 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 920
51 swift-frontend           0x0000000104fb0e88 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1684
52 swift-frontend           0x0000000104fafbb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
53 swift-frontend           0x0000000104f36a5c swift::mainEntry(int, char const**) + 3680
54 dyld                     0x0000000190738274 start + 2840
Command SwiftCompile failed with a nonzero exit code

Reproduction

final class Memoize<each A: Hashable, R> {
    typealias BaseFunction = ((repeat each A) -> R, repeat each A) -> R
    let f: BaseFunction
    init(_ f: @escaping BaseFunction) {
        self.f = f
    }
    func callAsFunction(_ argument: repeat each A) -> R {
        let result = f(self.callAsFunction, repeat each argument)
        return result
    }
}

Expected behavior

No crash

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
Swift 6 language mode, but also happens on 5.10

Additional information

No response

@GarthSnyder GarthSnyder added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 29, 2025
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. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant