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

Implicit optional promotion of variadic tuple assertion failure: !tupleTy.containsPackExpansionType() #78814

Open
natecook1000 opened this issue Jan 22, 2025 · 0 comments
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

@natecook1000
Copy link
Member

Description

In one version of my code base, the compiler crashes when it should use implicit optional promotion of a tuple with variadic members. I can work around the issue by explicitly putting the variadic tuple in a .some(...) optional case.

Reproduction

I haven't been able to reproduce the crash in a reduced codebase, but I have a branch that exhibits the behavior with a single parameter uncommented:

https://github.com/apple/swift-argument-parser/blob/option-tuples/Sources/ArgumentParser/Parsable%20Properties/Option.swift#L957-L960

The problem is a call from within one initializer to another, where both have the same generic parameters and constraints, but the callee's first parameter is an optional.

The callee is defined here:

https://github.com/apple/swift-argument-parser/blob/option-tuples/Sources/ArgumentParser/Parsable%20Properties/Option.swift#L868-L878

If the variadic tuple value is passed as an explicit optional case value (.some(wrappedValue)), there's no compiler crash.

Stack dump

Assertion failed: (!tupleTy.containsPackExpansionType() && "can't extract elements from tuples containing pack expansions " "right now"), function extractElements, file RValue.cpp, line 715.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/bin/swift-frontend -frontend -c /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Completions/CompletionsGenerator.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/Argument.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/ArgumentDiscussion.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/ArgumentHelp.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/ArgumentVisibility.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/CompletionKind.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/Errors.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/Flag.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/NameSpecification.swift" -primary-file "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/Option.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/OptionGroup.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Types/AsyncParsableCommand.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Types/CommandConfiguration.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Types/CommandGroup.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Types/EnumerableFlag.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Types/ExpressibleByArgument.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Types/ParsableArguments.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Types/ParsableArgumentsValidation.swift" "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Types/ParsableCommand.swift" /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/ArgumentDecoder.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/ArgumentDefinition.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/ArgumentSet.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/CommandParser.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/InputKey.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/InputOrigin.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/Name.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/Parsed.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/ParsedValues.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/ParserError.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsing/SplitArguments.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Usage/HelpCommand.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Usage/HelpGenerator.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Usage/MessageInfo.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Usage/UsageGenerator.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Utilities/CollectionExtensions.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Utilities/SequenceExtensions.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Utilities/StringExtensions.swift /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Utilities/Tree.swift -emit-dependencies-path /Volumes/Data/Projects/swift-argument-parser/.build/arm64-apple-macosx/debug/ArgumentParser-tool.build/Option.d -emit-reference-dependencies-path /Volumes/Data/Projects/swift-argument-parser/.build/arm64-apple-macosx/debug/ArgumentParser-tool.build/Option.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.0.sdk -I /Volumes/Data/Projects/swift-argument-parser/.build/arm64-apple-macosx/debug/Modules-tool -I /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/lib/swift/macosx/testing -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 /Volumes/Data/Projects/swift-argument-parser/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -enable-experimental-feature StrictConcurrency -empty-abi-descriptor -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/lib/swift/host/plugins/testing -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Volumes/Data/Projects/swift-argument-parser -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.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 ArgumentParser -in-process-plugin-server-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/local/lib/swift/host/plugins -target-sdk-version 15.0 -target-sdk-name macosx15.0 -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 -parse-as-library -o /Volumes/Data/Projects/swift-argument-parser/.build/arm64-apple-macosx/debug/ArgumentParser-tool.build/Option.swift.o -index-store-path /Volumes/Data/Projects/swift-argument-parser/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.	Apple Swift version 6.2-dev (LLVM 81859ac55f8d09a, Swift 8ec8a1229a7ea14)
2.	Compiling with effective version 5.10
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/Option.swift")
4.	While silgen emitValueConstructor SIL function "@$s14ArgumentParser6OptionV12wrappedValue4name7parsing4help10completionACyqd___qd_0_qd_1_qd_1_QptGqd___qd_0_qd_1_qd_1_Qpt_AA17NameSpecificationVAA06SingleE15ParsingStrategyVAA0A4HelpVSgAA14CompletionKindVSgtcRvd_1_qd___qd_0_qd_1_qd_1_QptRszAA013ExpressibleByA0Rd__AaTRd_0_AaTRd_1_r1_lufC".
 for 'init(wrappedValue:name:parsing:help:completion:)' (at /Volumes/Data/Projects/swift-argument-parser/Sources/ArgumentParser/Parsable Properties/Option.swift:946:10)
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           0x0000000106ba5f60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000106ba4644 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000106ba65bc SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000019afcd6a4 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000019af938cc pthread_kill + 296
5  libsystem_c.dylib        0x000000019ae99b48 abort + 124
6  libsystem_c.dylib        0x000000019ae98e58 err + 0
7  swift-frontend           0x0000000106c9e788 swift::Lowering::RValue::extractElements(llvm::SmallVectorImpl<swift::Lowering::RValue>&) && (.cold.3) + 0
8  swift-frontend           0x0000000101343108 swift::Lowering::RValue::extractElements(llvm::SmallVectorImpl<swift::Lowering::RValue>&) && + 936
9  swift-frontend           0x00000001013369b0 swift::Lowering::ArgumentSourceExpansion::ArgumentSourceExpansion(swift::Lowering::SILGenFunction&, swift::Lowering::ArgumentSource&&, bool) + 296
10 swift-frontend           0x000000010136cd44 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 756
11 swift-frontend           0x000000010135e644 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::__1::optional<swift::AnyFunctionType::Param>) + 320
12 swift-frontend           0x000000010136beec (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 220
13 swift-frontend           0x0000000101377308 (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&) && + 532
14 swift-frontend           0x0000000101376b68 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1052
15 swift-frontend           0x00000001013620c4 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1800
16 swift-frontend           0x0000000101360744 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2028
17 swift-frontend           0x00000001013bfa88 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 56
18 swift-frontend           0x00000001013cf1cc (anonymous namespace)::RValueEmitter::visitRebindSelfInConstructorExpr(swift::RebindSelfInConstructorExpr*, swift::Lowering::SGFContext) + 348
19 swift-frontend           0x00000001013c0060 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 912
20 swift-frontend           0x000000010145698c swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4288
21 swift-frontend           0x00000001014558c0 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 24
22 swift-frontend           0x0000000101398bd4 swift::Lowering::SILGenFunction::emitValueConstructor(swift::ConstructorDecl*) + 7152
23 swift-frontend           0x000000010134dd6c swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 5400
24 swift-frontend           0x000000010134f254 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 268
25 swift-frontend           0x0000000101350110 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 364
26 swift-frontend           0x000000010146ba10 swift::ASTVisitor<SILGenExtension, void, void, void, void, void, void>::visit(swift::Decl*) + 204
27 swift-frontend           0x0000000101468030 SILGenExtension::emitExtension(swift::ExtensionDecl*) + 180
28 swift-frontend           0x0000000101467f70 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 24
29 swift-frontend           0x00000001013519f8 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 176
30 swift-frontend           0x0000000101351f14 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 632
31 swift-frontend           0x0000000101455280 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&) + 148
32 swift-frontend           0x0000000101357424 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'()) + 340
33 swift-frontend           0x000000010135254c swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 96
34 swift-frontend           0x0000000100ced6e0 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
35 swift-frontend           0x0000000100cf96a4 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
36 swift-frontend           0x0000000100cef418 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 716
37 swift-frontend           0x0000000100ceec34 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2208
38 swift-frontend           0x0000000100aa11b8 swift::mainEntry(int, char const**) + 3100
39 dyld                     0x000000019abeee4c start + 6768

Expected behavior

Successful compilation of the initializer.

Environment

Apple Swift version 6.2-dev (LLVM 81859ac55f8d09a, Swift 8ec8a12)
Target: arm64-apple-macosx15.0

Additional information

No response

@natecook1000 natecook1000 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 22, 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. 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

1 participant