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

Parameter pack crash: Can't "untuple" a single parameter pack from a tuple #78671

Open
stephencelis opened this issue Jan 16, 2025 · 1 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 triage needed This issue needs more specific labels

Comments

@stephencelis
Copy link
Contributor

stephencelis commented Jan 16, 2025

Description

It is current impossible to "untuple" a parameter pack from a tuple. Worse, it crashes the compiler.

Reproduction

func uncons2<each T, U>(_ t: repeat each T, u: U) -> (repeat each T) {
  return (repeat each t)
}

func untuple<each T, U>(_ fn: (repeat each T) -> U) -> ((repeat each T)) -> U {
  return { tuple in fn(repeat each tuple) }
}

func uncons<each T, U>(_ t: (repeat each T, U)) -> (repeat each T) {
  let fn: (repeat each T, U) -> (repeat each T) = uncons2
  let fn2: ((repeat each T, U)) -> (repeat each T) = untuple(fn)
  return fn2(t)
}

Stack dump

Stack dump:
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 "Foo.swift")
4.	While silgen emitFunction SIL function "@$s7Parsing6unconsyxxQp_txxQp_q_t_tRvzr0_lF".
 for 'uncons(_:)' (at Foo.swift:9: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           0x00000001087e6a9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001087e4cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001087e7068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00000001877aae04 _sigtramp + 56
4  swift-frontend           0x0000000103a2d828 swift::SILLocation::getSourceLoc(llvm::PointerIntPair<llvm::PointerUnion<swift::Stmt*, swift::Expr*, swift::Decl*, swift::Pattern*>, 1u, unsigned int, llvm::PointerLikeTypeTraits<llvm::PointerUnion<swift::Stmt*, swift::Expr*, swift::Decl*, swift::Pattern*>>, llvm::PointerIntPairInfo<llvm::PointerUnion<swift::Stmt*, swift::Expr*, swift::Decl*, swift::Pattern*>, 1u, llvm::PointerLikeTypeTraits<llvm::PointerUnion<swift::Stmt*, swift::Expr*, swift::Decl*, swift::Pattern*>>>>) const + 272
5  swift-frontend           0x0000000103a2d828 swift::SILLocation::getSourceLoc(llvm::PointerIntPair<llvm::PointerUnion<swift::Stmt*, swift::Expr*, swift::Decl*, swift::Pattern*>, 1u, unsigned int, llvm::PointerLikeTypeTraits<llvm::PointerUnion<swift::Stmt*, swift::Expr*, swift::Decl*, swift::Pattern*>>, llvm::PointerIntPairInfo<llvm::PointerUnion<swift::Stmt*, swift::Expr*, swift::Decl*, swift::Pattern*>, 1u, llvm::PointerLikeTypeTraits<llvm::PointerUnion<swift::Stmt*, swift::Expr*, swift::Decl*, swift::Pattern*>>>>) const + 272
6  swift-frontend           0x0000000103c5ab60 swift::Lowering::SILGenFunction::getScopeOrNull(swift::SILLocation, bool) + 132
7  swift-frontend           0x0000000103be97a0 swift::Lowering::SILGenBuilder::getSILDebugLocation(swift::SILLocation, bool) + 92
8  swift-frontend           0x0000000103831658 swift::SILBuilder::createAllocStack(swift::SILLocation, swift::SILType, std::__1::optional<swift::SILDebugVariable>, swift::HasDynamicLifetime_t, swift::IsLexical_t, swift::IsFromVarDecl_t, swift::UsesMoveableValueDebugInfo_t, bool) + 164
9  swift-frontend           0x0000000103c2d1dc swift::Lowering::SILGenFunction::emitTemporaryAllocation(swift::SILLocation, swift::SILType, swift::HasDynamicLifetime_t, swift::IsLexical_t, swift::IsFromVarDecl_t, bool) + 240
10 swift-frontend           0x0000000103bcfb98 (anonymous namespace)::ArgEmitter::emitPackArg(llvm::MutableArrayRef<swift::Lowering::ArgumentSource>, swift::Lowering::AbstractionPattern) + 3516
11 swift-frontend           0x0000000103bced08 void llvm::function_ref<void (swift::Lowering::TupleElementGenerator&)>::callback_fn<(anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern)::'lambda'(swift::Lowering::TupleElementGenerator&)>(long, swift::Lowering::TupleElementGenerator&) + 352
12 swift-frontend           0x00000001039b15f0 swift::Lowering::AbstractionPattern::forEachTupleElement(swift::CanType, llvm::function_ref<void (swift::Lowering::TupleElementGenerator&)>) const + 188
13 swift-frontend           0x0000000103bcd960 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 3228
14 swift-frontend           0x0000000103bbc0f0 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 216
15 swift-frontend           0x0000000103bcc9ac (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 256
16 swift-frontend           0x0000000103bd8878 (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
17 swift-frontend           0x0000000103bd8298 (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
18 swift-frontend           0x0000000103bc0e7c (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2028
19 swift-frontend           0x0000000103bbf408 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3116
20 swift-frontend           0x0000000103c2c37c swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 128
21 swift-frontend           0x0000000103cea704 swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 1024
22 swift-frontend           0x0000000103ce7f7c swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 8848
23 swift-frontend           0x0000000103ce72f4 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 5640
24 swift-frontend           0x0000000103c5efc8 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 492
25 swift-frontend           0x0000000103baab1c swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8420
26 swift-frontend           0x0000000103bab3bc swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 216
27 swift-frontend           0x0000000103ba89ec swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 364
28 swift-frontend           0x0000000103baf038 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1804
29 swift-frontend           0x0000000103ce592c 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
30 swift-frontend           0x0000000103bb3f14 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
31 swift-frontend           0x000000010318db90 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 920
32 swift-frontend           0x0000000103190e88 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1684
33 swift-frontend           0x000000010318fbb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
34 swift-frontend           0x0000000103116a5c swift::mainEntry(int, char const**) + 3680
35 dyld                     0x00000001873f4274 start + 2840

Expected behavior

I expect the compiler not to crash and the ability to destructure the parameter pack from the tuple.

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

Additional information

Mentioned here but with no link to existing issue: https://forums.swift.org/t/passing-a-parameter-pack-to-a-function-call-fails-to-compile/72243/2

@stephencelis stephencelis 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 16, 2025
@Lancelotbronner
Copy link

Maybe also relevant, since I'm also playing with swift-parsing and parameter packs:

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 triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants