Skip to content

Inserting parameter pack into another parameter pack causes crash #80937

@adam-fowler

Description

@adam-fowler

Description

If I add parameters to a parameter pack by supplying them alongside the parameter pack into another function that expects a parameter pack the compiler crashes

Reproduction

func test<each T>(_ args: repeat each T) -> (repeat each T) {
    (repeat each args)
}

func test2<each T>(_ args: repeat each T) {
    let values = test("start", repeat each args, "end")
    print(values.2)
}
Callstack
Building for debugging...
error: compile command failed due to signal 11 (use -v to see invocation)
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/adamfowler/Temp/parameter-pack-crash/Sources/parameter-pack-crash/parameter_pack_crash.swift -emit-dependencies-path /Users/adamfowler/Temp/parameter-pack-crash/.build/arm64-apple-macosx/debug/parameter_pack_crash.build/parameter_pack_crash.d -emit-reference-dependencies-path /Users/adamfowler/Temp/parameter-pack-crash/.build/arm64-apple-macosx/debug/parameter_pack_crash.build/parameter_pack_crash.swiftdeps -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk -I /Users/adamfowler/Temp/parameter-pack-crash/.build/arm64-apple-macosx/debug/Modules -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/adamfowler/Temp/parameter-pack-crash/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -diagnostic-style=llvm -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/adamfowler/Temp/parameter-pack-crash -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks -Xcc -fPIC -Xcc -g -module-name parameter_pack_crash -package-name parameter_pack_crash -disable-clang-spi -target-sdk-version 15.4 -target-sdk-name macosx15.4 -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 -in-process-plugin-server-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -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 -parse-as-library -o /Users/adamfowler/Temp/parameter-pack-crash/.build/arm64-apple-macosx/debug/parameter_pack_crash.build/parameter_pack_crash.swift.o -index-store-path /Users/adamfowler/Temp/parameter-pack-crash/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.      Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
2.      Compiling with the current language version
3.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/adamfowler/Temp/parameter-pack-crash/Sources/parameter-pack-crash/parameter_pack_crash.swift")
4.      While silgen emitFunction SIL function "@$s20parameter_pack_crash5test2yyxxQpRvzlF".
 for 'test2(_:)' (at /Users/adamfowler/Temp/parameter-pack-crash/Sources/parameter-pack-crash/parameter_pack_crash.swift:7:1)
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           0x0000000106ed2c28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000106ed0a60 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000106ed3264 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x000000018e83ede4 _sigtramp + 56
4  swift-frontend           0x00000001017fa9a4 void llvm::function_ref<void (swift::SILValue)>::callback_fn<swift::Lowering::SILGenFunction::emitExistentialErasure(swift::SILLocation, swift::CanType, swift::Lowering::TypeLowering const&, swift::Lowering::TypeLowering const&, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>, bool)::$_3>(long, swift::SILValue) + 384
5  swift-frontend           0x00000001017fa9a4 void llvm::function_ref<void (swift::SILValue)>::callback_fn<swift::Lowering::SILGenFunction::emitExistentialErasure(swift::SILLocation, swift::CanType, swift::Lowering::TypeLowering const&, swift::Lowering::TypeLowering const&, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>, bool)::$_3>(long, swift::SILValue) + 384
6  swift-frontend           0x00000001017d01f4 swift::Lowering::SILGenBuilder::bufferForExpr(swift::SILLocation, swift::SILType, swift::Lowering::TypeLowering const&, swift::Lowering::SGFContext, llvm::function_ref<void (swift::SILValue)>) + 136
7  swift-frontend           0x00000001017f43ec swift::Lowering::SILGenFunction::emitExistentialErasure(swift::SILLocation, swift::CanType, swift::Lowering::TypeLowering const&, swift::Lowering::TypeLowering const&, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>, bool) + 720
8  swift-frontend           0x000000010183117c (anonymous namespace)::RValueEmitter::visitErasureExpr(swift::ErasureExpr*, swift::Lowering::SGFContext) + 736
9  swift-frontend           0x0000000101814390 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 132
10 swift-frontend           0x000000010177143c swift::Lowering::ArgumentSource::forwardInto(swift::Lowering::SILGenFunction&, swift::Lowering::Initialization*) && + 68
11 swift-frontend           0x000000010183ba1c (anonymous namespace)::RValueEmitter::visitCollectionExpr(swift::CollectionExpr*, swift::Lowering::SGFContext) + 1892
12 swift-frontend           0x00000001018178d4 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
13 swift-frontend           0x00000001017b18d4 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 5088
14 swift-frontend           0x000000010179edd8 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 204
15 swift-frontend           0x00000001017b01f8 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 252
16 swift-frontend           0x00000001017bc3ec (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&) && + 660
17 swift-frontend           0x00000001017bbe24 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1040
18 swift-frontend           0x00000001017a38dc (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1072
19 swift-frontend           0x00000001017a22b8 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3204
20 swift-frontend           0x0000000101818038 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 996
21 swift-frontend           0x00000001018ccf3c swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6432
22 swift-frontend           0x00000001018488f8 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 496
23 swift-frontend           0x000000010178cfc0 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 7596
24 swift-frontend           0x000000010178dfec swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 232
25 swift-frontend           0x000000010178b1c8 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 344
26 swift-frontend           0x0000000101791a54 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1568
27 swift-frontend           0x00000001018cacc4 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 208
28 swift-frontend           0x00000001017965e0 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'()) + 728
29 swift-frontend           0x0000000100d24064 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 968
30 swift-frontend           0x0000000100d27654 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
31 swift-frontend           0x0000000100d25fd8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3716
32 swift-frontend           0x0000000100caa0bc swift::mainEntry(int, char const**) + 5428
33 dyld                     0x000000018e488274 start + 2840

Expected behavior

Compiler doesn't crash

Environment

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.parameter packsFeature → generics: Parameter packs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions