Skip to content

Parameter packs for functions with arbitrary parameters causes compiler crash when passed a function with more than zero parameters #69028

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

Closed
twof opened this issue Oct 6, 2023 · 11 comments · Fixed by #70681
Assignees
Labels
assertion failure Bug → crash: An assertion failure bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. call expressions Feature → expressions: Call expressions compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software expressions Feature: expressions function types Feature → types: function types generics Feature: generic declarations and types parameter packs Feature → generics: Parameter packs SILGen Area → compiler: The SIL generation stage swift 6.0 types Feature: types

Comments

@twof
Copy link
Contributor

twof commented Oct 6, 2023

Description

I'm trying to use parameter packs to create a function that takes and arbitrary function as a parameter. It's possible to create that function, but it's not possible to call it with a function or closure that has any parameters. Doing so causes the compiler to crash.

Stack trace passing a function with a parameter:

0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/fnord/Documents/Swift/TestMacOS/TestMacOSCore/Sources/TestMacOSCore/Dependencies.swift -primary-file /Users/fnord/Documents/Swift/TestMacOS/TestMacOSCore/Sources/TestMacOSCore/TestMacOSCore.swift -emit-dependencies-path /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/Objects-normal/arm64/TestMacOSCore.d -emit-const-values-path /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/Objects-normal/arm64/TestMacOSCore.swiftconstvalues -emit-reference-dependencies-path /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/Objects-normal/arm64/TestMacOSCore.swiftdeps -serialize-diagnostics-path /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/Objects-normal/arm64/TestMacOSCore.dia -target arm64-apple-macos14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -I /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Products/Debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Products/Debug/PackageFrameworks -F /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Products/Debug/PackageFrameworks -F /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Products/Debug/PackageFrameworks -F /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Products/Debug/PackageFrameworks -F /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Products/Debug/PackageFrameworks -F /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Products/Debug -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -module-cache-path /Users/fnord/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -package-name testmacoscore -const-gather-protocols-file /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/Objects-normal/arm64/TestMacOSCore_const_extract_protocols.json -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Users/fnord/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/fnord/Documents/Swift/TestMacOS/TestMacOSCore -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -ivfsstatcache -Xcc /Users/fnord/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx14.0-23A334-4a76ee93ef69e462914ffe9883de22b8.sdkstatcache -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/swift-overrides.hmap -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Products/Debug/include -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/DerivedSources-normal/arm64 -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/DerivedSources/arm64 -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name TestMacOSCore -frontend-parseable-output -disable-clang-spi -target-sdk-version 14.0 -target-sdk-name macosx14.0 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -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/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Build/Intermediates.noindex/TestMacOSCore.build/Debug/TestMacOSCore.build/Objects-normal/arm64/TestMacOSCore.o -index-unit-output-path /TestMacOSCore.build/Debug/TestMacOSCore.build/Objects-normal/arm64/TestMacOSCore.o -index-store-path /Users/fnord/Library/Developer/Xcode/DerivedData/TestMacOSCore-ahgngaarecknxsfwsewfijgzqaot/Index.noindex/DataStore -index-system-modules
1.	Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
2.	Compiling with the current language version
3.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for TestMacOSCore)
4.	While running pass #20 SILModuleTransform "DiagnoseStaticExclusivity".
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           0x0000000107ac314c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a641f2c llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010638310c SignalHandler(int) + 352
3  libsystem_platform.dylib 0x0000000184841a24 _sigtramp + 56
4  swift-frontend           0x000000010987d8c4 checkForViolationAtApply(swift::ApplySite, (anonymous namespace)::AccessState&) + 544
5  swift-frontend           0x000000010987d8c4 checkForViolationAtApply(swift::ApplySite, (anonymous namespace)::AccessState&) + 544
6  swift-frontend           0x000000010986f1d8 (anonymous namespace)::DiagnoseStaticExclusivity::run() (.llvm.4864455472777275936) + 2220
7  swift-frontend           0x0000000109f9b08c swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 16276
8  swift-frontend           0x000000010a11ef90 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 56
9  swift-frontend           0x0000000109fd47e4 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 476
10 swift-frontend           0x0000000109fef728 swift::runSILDiagnosticPasses(swift::SILModule&) + 380
11 swift-frontend           0x0000000105a99f58 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 72
12 swift-frontend           0x0000000109ed7328 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*) + 956
13 swift-frontend           0x000000010a5f991c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1748
14 swift-frontend           0x000000010a5fd474 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
15 swift-frontend           0x0000000109f434e0 swift::mainEntry(int, char const**) + 4116
16 dyld                     0x0000000184499058 start + 2224

Steps to reproduce

This builds

func catFact() -> String { "there are more than 10 cats" }

func callable<each Input, Output>(wrappedValue: @escaping ((repeat each Input)) -> Output) {
  
}

func doSomething() {
  callable(wrappedValue: catFact)
}

This builds

func callable<each Input, Output>(wrappedValue: @escaping ((repeat each Input)) -> Output) {
  
}

func doSomething() {
  callable(wrappedValue: {})
}

This does not build

func catFact(num: Int) -> String { "there are more than 10 cats" }

func callable<each Input, Output>(wrappedValue: @escaping ((repeat each Input)) -> Output) {
  
}

func doSomething() {
  callable(wrappedValue: catFact)
}

This does not build

func callable<each Input, Output>(wrappedValue: @escaping ((repeat each Input)) -> Output) {
  
}

func doSomething() {
  callable(wrappedValue: { (num: Int) in num })
}

Expected behavior

I would expect each of the above examples to build successfully.

Environment

  • Swift compiler version info:
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0
  • Xcode version info
Xcode 15.0
Build version 15A240d
  • Deployment target: macOS 14.0

  • Additional context: Development is being done in a Swift Package using Xcode.

@twof twof added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Oct 6, 2023
@CodPro-Sui
Copy link

CodPro-Sui commented Oct 8, 2023

// Define a function that takes a closure with variadic parameters
func processVariadicFunction(_ function: (Int...) -> Int) {
    // Create an array of integers
    let numbers = [1, 2, 3, 4, 5]
    
    // Call the closure with the array as variadic arguments
    let result = function(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4])
    
    // Print the result
    print("Result: \(result)")
}

// Define a closure that calculates the sum of integers
let sumClosure: (Int...) -> Int = { numbers in
    return numbers.reduce(0, +)
}

// Call the processVariadicFunction with the sumClosure
processVariadicFunction(sumClosure)

@twof
Copy link
Contributor Author

twof commented Oct 8, 2023

@Nau56 That's different from what I'm trying to do. Your example uses a variadic parameter, and mine uses a parameter pack.

@CodPro-Sui
Copy link

CodPro-Sui commented Oct 8, 2023

typealias MyFunctionPointer = (Int, Int) -> Void

func bar(func: MyFunctionPointer) {
  func(1, 2)
}

let myFunction: MyFunctionPointer = { a, b in
  print(a + b)
}

bar(func: myFunction)

@twof
Copy link
Contributor Author

twof commented Oct 8, 2023

@Nau56 Sorry I'm not sure what that's supposed to be.

@AnthonyLatsis AnthonyLatsis added generics Feature: generic declarations and types closures Feature: closures expressions Feature: expressions parameter packs Feature → generics: Parameter packs crash Bug: A crash, i.e., an abnormal termination of software assertion failure Bug → crash: An assertion failure swift 6.0 compiler The Swift compiler itself SILGen Area → compiler: The SIL generation stage call expressions Feature → expressions: Call expressions function types Feature → types: function types types Feature: types and removed triage needed This issue needs more specific labels closures Feature: closures labels Oct 12, 2023
@AnthonyLatsis
Copy link
Collaborator

Stack dump update and slightly simpler example:

func callable<each Input>(_: ((repeat each Input)) -> Void) {}

func test(x: Int) {}

do {
  callable(test)
}
Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h, line 578.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: bin/swift-frontend /Users/mac/Desktop/test.swift -debug-diagnostic-names -emit-ir
1.	Swift version 5.11-dev (LLVM 5601e23279f85d8, Swift 140caf63be3f0fe)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module test)
4.	While emitting reabstraction thunk in SIL function "@$sSiIgy_Si_QSiIegp_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           0x00000001135a251b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43
1  swift-frontend           0x00000001135a1755 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x00000001135a2b4e SignalHandler(int) + 270
3  libsystem_platform.dylib 0x00007ff81913037d _sigtramp + 29
4  libsystem_platform.dylib 0x00007ff7b490f378 _sigtramp + 18446744072023306264
5  libsystem_c.dylib        0x00007ff819021a4d abort + 126
6  libsystem_c.dylib        0x00007ff819020d60 err + 0
7  swift-frontend           0x000000010bcd6315 decltype(auto) llvm::cast<swift::TupleType, swift::TypeBase>(swift::TypeBase*) + 101
8  swift-frontend           0x000000010bcd614d swift::CanTypeWrapper<swift::TupleType> swift::cast<swift::TupleType>(swift::CanType) + 29
9  swift-frontend           0x000000010c5f78fe (anonymous namespace)::TranslateArguments::process(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType) + 94
10 swift-frontend           0x000000010c5fff2d (anonymous namespace)::TranslateArguments::process(swift::Lowering::AbstractionPattern, swift::AnyFunctionType::CanParam, swift::Lowering::AbstractionPattern, swift::AnyFunctionType::CanParam) + 669
11 swift-frontend           0x000000010c5f8eab (anonymous namespace)::TranslateArguments::processToSingleParam(swift::Lowering::AbstractionPattern, swift::AnyFunctionType::CanParam, swift::Lowering::FunctionInputGenerator&) + 267
12 swift-frontend           0x000000010c5ebda5 (anonymous namespace)::TranslateArguments::process(swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, bool) + 1877
13 swift-frontend           0x000000010c5f4c61 buildThunkBody(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::CanType) + 1169
14 swift-frontend           0x000000010c5f392d createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 2557
15 swift-frontend           0x000000010c5f0d24 (anonymous namespace)::Transform::transformFunction(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 1556
16 swift-frontend           0x000000010c5e81a2 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 2354
17 swift-frontend           0x000000010c5e6845 swift::Lowering::SILGenFunction::emitTransformedValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 405
18 swift-frontend           0x000000010c5e6f8a swift::Lowering::SILGenFunction::emitSubstToOrigValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 362
19 swift-frontend           0x000000010c4b14c9 swift::Lowering::Conversion::emit(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::SGFContext) const + 1673
20 swift-frontend           0x000000010c4b0cdf swift::Lowering::ConvertingInitialization::finishEmission(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue) + 239
21 swift-frontend           0x000000010c4b08c9 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 665
22 swift-frontend           0x000000010c3acc22 swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 226
23 swift-frontend           0x000000010c4407ed (anonymous namespace)::ArgEmitter::emitConvertedArgument(swift::Lowering::ArgumentSource&&, swift::Lowering::Conversion, swift::Lowering::SGFContext) + 189
24 swift-frontend           0x000000010c438ab6 (anonymous namespace)::ArgEmitter::emitDirect(swift::Lowering::ArgumentSource&&, swift::SILType, swift::Lowering::AbstractionPattern, swift::SILParameterInfo, llvm::Optional<swift::AnyFunctionType::Param>) + 470
25 swift-frontend           0x000000010c43571d (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, llvm::Optional<swift::AnyFunctionType::Param>) + 2333
26 swift-frontend           0x000000010c423755 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, llvm::Optional<swift::AnyFunctionType::Param>) + 549
27 swift-frontend           0x000000010c431a0f (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 447
28 swift-frontend           0x000000010c4585a1 (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&) && + 481
29 swift-frontend           0x000000010c45754e (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 1630
30 swift-frontend           0x000000010c456890 (anonymous namespace)::CallEmission::applyNormalCall(swift::Lowering::SGFContext) + 1120
31 swift-frontend           0x000000010c454dcd (anonymous namespace)::CallEmission::applyFirstLevelCallee(swift::Lowering::SGFContext) + 205
32 swift-frontend           0x000000010c425740 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 80
33 swift-frontend           0x000000010c4250c8 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 136
34 swift-frontend           0x000000010c5279ab (anonymous namespace)::RValueEmitter::visitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 59
35 swift-frontend           0x000000010c5150e8 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visitCallExpr(swift::CallExpr*, swift::Lowering::SGFContext) + 56
36 swift-frontend           0x000000010c4fe8bc swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 2956
37 swift-frontend           0x000000010c4efd23 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 195
38 swift-frontend           0x000000010c4f49e6 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 1990
39 swift-frontend           0x000000010c62e6d9 (anonymous namespace)::StmtEmitter::visitBraceStmt(swift::BraceStmt*) + 2233
40 swift-frontend           0x000000010c62a181 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 81
41 swift-frontend           0x000000010c62fed1 (anonymous namespace)::StmtEmitter::visitDoStmt(swift::DoStmt*) + 417
42 swift-frontend           0x000000010c62a211 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 225
43 swift-frontend           0x000000010c62a0fa swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 42
44 swift-frontend           0x000000010c64292c swift::Lowering::SILGenTopLevel::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 588
45 swift-frontend           0x000000010c64215f swift::ASTVisitor<swift::Lowering::SILGenTopLevel, void, void, void, void, void, void>::visit(swift::Decl*) + 1391
46 swift-frontend           0x000000010c64141d swift::Lowering::SILGenTopLevel::visitSourceFile(swift::SourceFile*) + 189
47 swift-frontend           0x000000010c6407fa swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*, swift::SILFunction*) + 1690
48 swift-frontend           0x000000010c641928 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*) + 296
49 swift-frontend           0x000000010c40363d (anonymous namespace)::SILGenModuleRAII::emitSourceFile(swift::SourceFile*) + 77
50 swift-frontend           0x000000010c4032e4 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 916
51 swift-frontend           0x000000010c6292de std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 142
52 swift-frontend           0x000000010c6291f8 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&) + 40
53 swift-frontend           0x000000010c415ddc llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 316
54 swift-frontend           0x000000010c403ee8 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::operator()<swift::ASTLoweringRequest, (void*)0>(swift::ASTLoweringRequest const&) + 40
55 swift-frontend           0x000000010c403de0 swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 256
56 swift-frontend           0x000000010b747cfb swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 283
57 swift-frontend           0x000000010b777103 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_29::operator()(swift::CompilerInstance&) const + 147
58 swift-frontend           0x000000010b77705d bool llvm::function_ref<bool (swift::CompilerInstance&)>::callback_fn<performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_29>(long, swift::CompilerInstance&) + 29
59 swift-frontend           0x000000010b776421 llvm::function_ref<bool (swift::CompilerInstance&)>::operator()(swift::CompilerInstance&) const + 33
60 swift-frontend           0x000000010b775438 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 392
61 swift-frontend           0x000000010b76dfa5 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1349
62 swift-frontend           0x000000010b74b186 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 262
63 swift-frontend           0x000000010b749b60 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2816
64 swift-frontend           0x000000010b61c3df run_driver(llvm::StringRef, llvm::ArrayRef<char const*>, llvm::ArrayRef<char const*>) + 2431
65 swift-frontend           0x000000010b61b057 swift::mainEntry(int, char const**) + 1543
66 swift-frontend           0x000000010b61a6a2 main + 34
67 dyld                     0x00007ff818d7a3a6 start + 1942
Abort trap: 6

@hborla
Copy link
Member

hborla commented Oct 23, 2023

I believe this is a known issue with reabstraction for tuple parameters containing pack expansions, but @slavapestov can probably confirm

@rjmccall
Copy link
Contributor

rjmccall commented Jan 4, 2024

This was fixed in #70681.

@vanvoorden
Copy link
Contributor

@rjmccall I saw a similar error in #71258.

@twof
Copy link
Contributor Author

twof commented Jun 11, 2024

@rjmccall My snippet with the closure is still broken in the 6.0 beta that ships with Xcode 16.0 beta 1. The trace appears to be different from the previous two reported. Should we reopen this issue, or should I open a new one?

func callable<each Input, Output>(wrappedValue: @escaping ((repeat each Input)) -> Output) {
  
}

func doSomething() {
  callable(wrappedValue: { (num: Int) in num })
}
0.	Program arguments: /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/fnord/Documents/Swift/ScratchPad/ScratchPad/main.swift -emit-dependencies-path /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/Objects-normal/arm64/main.d -emit-const-values-path /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/Objects-normal/arm64/main.swiftconstvalues -emit-reference-dependencies-path /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/Objects-normal/arm64/main.swiftdeps -serialize-diagnostics-path /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/Objects-normal/arm64/main.dia -target arm64-apple-macos15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -I /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Products/Debug -F /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Products/Debug -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=5 -module-cache-path /Users/fnord/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 6 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -enable-experimental-opaque-type-erasure -const-gather-protocols-file /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/Objects-normal/arm64/ScratchPad_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Users/fnord/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/fnord/Documents/Swift/ScratchPad -resource-dir /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/fnord/Documents/Swift/ScratchPad -Xcc -ivfsstatcache -Xcc /Users/fnord/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.0-24A5264i-2013d1de56b54445c889d29f04b623e4.sdkstatcache -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/ScratchPad-generated-files.hmap -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/ScratchPad-own-target-headers.hmap -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/ScratchPad-all-target-headers.hmap -Xcc -iquote -Xcc /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/ScratchPad-project-headers.hmap -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Products/Debug/include -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/DerivedSources-normal/arm64 -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/DerivedSources/arm64 -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/DerivedSources -Xcc -DDEBUG=1 -module-name ScratchPad -frontend-parseable-output -disable-clang-spi -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Build/Intermediates.noindex/ScratchPad.build/Debug/ScratchPad.build/Objects-normal/arm64/main.o -index-unit-output-path /ScratchPad.build/Debug/ScratchPad.build/Objects-normal/arm64/main.o -index-store-path /Users/fnord/Library/Developer/Xcode/DerivedData/ScratchPad-adtsoutfuyrrulbbbonjnulsmovs/Index.noindex/DataStore -index-system-modules
1.	Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/fnord/Documents/Swift/ScratchPad/ScratchPad/main.swift")
4.	While silgen emitFunction SIL function "@$s10ScratchPad11doSomethingyyF".
 for 'doSomething()' (at /Users/fnord/Documents/Swift/ScratchPad/ScratchPad/main.swift:14:1)
5.	While silgen closureexpr SIL function "@$s10ScratchPad11doSomethingyyFS2icfU_".
 for expression at [/Users/fnord/Documents/Swift/ScratchPad/ScratchPad/main.swift:15:26 - line:15:46] RangeText="{ (num: Int) in num "
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           0x00000001067fecd0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001067fcf44 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001067ff2d8 SignalHandler(int) + 352
3  libsystem_platform.dylib 0x000000019317c184 _sigtramp + 56
4  libsystem_pthread.dylib  0x0000000193145f70 pthread_kill + 288
5  libsystem_c.dylib        0x0000000193052908 abort + 128
6  swift-frontend           0x00000001011d6078 PrettyStackTraceFrontend::~PrettyStackTraceFrontend() + 0
7  swift-frontend           0x000000010676da28 llvm::report_fatal_error(llvm::Twine const&, bool) + 280
8  swift-frontend           0x000000010676d910 llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9  swift-frontend           0x0000000101cd6038 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 8240
10 swift-frontend           0x0000000101cd36b4 swift::Lowering::SILGenFunction::emitOrigToSubstValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::SGFContext) + 324
11 swift-frontend           0x0000000101cf80bc (anonymous namespace)::EmitBBArguments::handleScalar(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::Initialization*, bool) + 1628
12 swift-frontend           0x0000000101cf9758 swift::CanTypeVisitor<(anonymous namespace)::EmitBBArguments, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*>::visitBuiltinIntegerType(swift::CanTypeWrapper<swift::BuiltinIntegerType>, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*) + 96
13 swift-frontend           0x0000000101cf93f4 swift::CanTypeVisitor<(anonymous namespace)::EmitBBArguments, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*>::visit(swift::CanType, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*) + 1544
14 swift-frontend           0x0000000101cf75b8 (anonymous namespace)::ArgumentInitHelper::makeArgument(swift::SILLocation, swift::ParamDecl*) + 1164
15 swift-frontend           0x0000000101cf5d9c (anonymous namespace)::ArgumentInitHelper::emitParam(swift::ParamDecl*) + 360
16 swift-frontend           0x0000000101cf47e4 swift::Lowering::SILGenFunction::emitBasicProlog(swift::DeclContext*, swift::ParameterList*, swift::ParamDecl*, swift::Type, std::__1::optional<swift::Type>, swift::SourceLoc, unsigned int) + 2540
17 swift-frontend           0x0000000101cf2790 swift::Lowering::SILGenFunction::emitProlog(swift::DeclContext*, swift::CaptureInfo, swift::ParameterList*, swift::ParamDecl*, swift::Type, std::__1::optional<swift::Type>, swift::SourceLoc) + 160
18 swift-frontend           0x0000000101c90de0 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 740
19 swift-frontend           0x0000000101bde3c4 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 4144
20 swift-frontend           0x0000000101be78f0 void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_0>(long) + 200
21 swift-frontend           0x0000000101be0d90 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) + 280
22 swift-frontend           0x0000000101c85334 (anonymous namespace)::RValueEmitter::emitClosureReference(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) + 52
23 swift-frontend           0x0000000101c84e78 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 2088
24 swift-frontend           0x0000000101c61688 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
25 swift-frontend           0x0000000101c42558 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 284
26 swift-frontend           0x0000000101bc38a8 swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 136
27 swift-frontend           0x0000000101c0216c (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 5776
28 swift-frontend           0x0000000101beffb0 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 216
29 swift-frontend           0x0000000101c007c4 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 256
30 swift-frontend           0x0000000101c0c56c (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
31 swift-frontend           0x0000000101c0bf98 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1004
32 swift-frontend           0x0000000101bf4d44 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2032
33 swift-frontend           0x0000000101bf32c4 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3116
34 swift-frontend           0x0000000101c61d70 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 888
35 swift-frontend           0x0000000101cfc7c4 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 5532
36 swift-frontend           0x0000000101c90aa4 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 492
37 swift-frontend           0x0000000101bdf3d0 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8252
38 swift-frontend           0x0000000101bdfc2c swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 212
39 swift-frontend           0x0000000101bdd380 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 172
40 swift-frontend           0x0000000101be3200 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1804
41 swift-frontend           0x0000000101cfae68 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
42 swift-frontend           0x0000000101be80f4 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'()) + 524
43 swift-frontend           0x00000001011c8fdc swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 744
44 swift-frontend           0x00000001011cd468 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1672
45 swift-frontend           0x00000001011cb438 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4752
46 swift-frontend           0x00000001011512d8 swift::mainEntry(int, char const**) + 2812
47 dyld                     0x0000000192dc5298 start + 2876

@twof
Copy link
Contributor Author

twof commented Jun 12, 2024

I have another repro, but I'm unsure if it's different or the same issue.

public protocol SpyProtocol {
  associatedtype Params
  
  /// Number of times the function was called
  var callCount: Int { get }
  
  /// Params passed to the function
  var callParams: [Params] { get }
}

public class Spy<each T>: SpyProtocol {
  public private(set) var callCount: Int = 0
  public private(set) var callParams: [(repeat each T)] = []
  
  func increment() {
    self.callCount += 1
  }
  
  func recordCall(_ params: (repeat each T)) {
    self.callParams.append(params)
  }
}

public func anyspy<each T, Result>(
  _ closure: @escaping @Sendable (repeat each T) -> Result
) -> (Spy<repeat each T>, @Sendable (repeat each T) -> Result) {
  let spy = Spy<repeat each T>()
  
  func fn(_ params: repeat each T) -> Result {
    let param = (repeat each params)
    spy.increment()
    spy.recordCall(param)
    return closure()
  }
  
  return (spy, fn)
}
0.	Program arguments: /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/EmptyClosure.swift -primary-file /Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/FunctionSpy.swift /Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/Spy.swift /Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/SpyProtocol.swift -emit-dependencies-path /Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/Objects-normal/arm64/FunctionSpy.d -emit-const-values-path /Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/Objects-normal/arm64/FunctionSpy.swiftconstvalues -emit-reference-dependencies-path /Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/Objects-normal/arm64/FunctionSpy.swiftdeps -serialize-diagnostics-path /Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/Objects-normal/arm64/FunctionSpy.dia -target arm64-apple-macos14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -I /Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Products/Debug -I /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Products/Debug -F /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/fnord/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 6 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -enable-experimental-opaque-type-erasure -const-gather-protocols-file /Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/Objects-normal/arm64/FunctionSpy_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -empty-abi-descriptor -plugin-path /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing -validate-clang-modules-once -clang-build-session-file /Users/fnord/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/fnord/Documents/Swift/FunctionSpy/.swiftpm/xcode -resource-dir /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/fnord/Documents/Swift/FunctionSpy/.swiftpm/xcode -Xcc -ivfsstatcache -Xcc /Users/fnord/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.0-24A5264i-2013d1de56b54445c889d29f04b623e4.sdkstatcache -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/swift-overrides.hmap -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Products/Debug/include -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/DerivedSources-normal/arm64 -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/DerivedSources/arm64 -Xcc -I/Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name FunctionSpy -package-name functionspy -frontend-parseable-output -disable-clang-spi -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/fnord/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Build/Intermediates.noindex/FunctionSpy.build/Debug/FunctionSpy.build/Objects-normal/arm64/FunctionSpy.o -index-unit-output-path /FunctionSpy.build/Debug/FunctionSpy.build/Objects-normal/arm64/FunctionSpy.o -index-store-path /Users/fnord/Library/Developer/Xcode/DerivedData/FunctionSpy-etfirhqtcosfdgceicodddahotgj/Index.noindex/DataStore -index-system-modules
1.	Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
2.	Compiling with the current language version
3.	While evaluating request TypeCheckSourceFileRequest(source_file "/Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/FunctionSpy.swift")
4.	While evaluating request TypeCheckFunctionBodyRequest(FunctionSpy.(file).anyspy@/Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/FunctionSpy.swift:4:13)
5.	While type-checking statement at [/Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/FunctionSpy.swift:6:64 - line:17:1] RangeText="{
  let spy = Spy<repeat each T>()
  
  func fn(_ params: repeat each T) -> Result {
    let param = (repeat each params)
    spy.increment()
    spy.recordCall(param)
    return closure()
  }
  
  return (spy, fn)
"
6.	While type-checking 'fn(_:)' (at /Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/FunctionSpy.swift:9:3)
7.	While evaluating request TypeCheckFunctionBodyRequest(FunctionSpy.(file).anyspy(_:).fn@/Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/FunctionSpy.swift:9:8)
8.	While type-checking statement at [/Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/FunctionSpy.swift:9:46 - line:14:3] RangeText="{
    let param = (repeat each params)
    spy.increment()
    spy.recordCall(param)
    return closure()
  "
9.	While type-checking statement at [/Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/FunctionSpy.swift:13:5 - line:13:20] RangeText="return closure("
10.	While type-checking-target starting at /Users/fnord/Documents/Swift/FunctionSpy/Sources/FunctionSpy/FunctionSpy.swift:13:12
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           0x000000010a8a2cd0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a8a0f44 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010a8a32d8 SignalHandler(int) + 352
3  libsystem_platform.dylib 0x000000019317c184 _sigtramp + 56
4  swift-frontend           0x000000010630f954 (anonymous namespace)::ExprRewriter::coerceCallArguments(swift::ArgumentList*, swift::AnyFunctionType*, swift::ConcreteDeclRef, swift::ApplyExpr*, swift::constraints::ConstraintLocatorBuilder, llvm::ArrayRef<swift::AppliedPropertyWrapper>) + 3492
5  swift-frontend           0x000000010630f954 (anonymous namespace)::ExprRewriter::coerceCallArguments(swift::ArgumentList*, swift::AnyFunctionType*, swift::ConcreteDeclRef, swift::ApplyExpr*, swift::constraints::ConstraintLocatorBuilder, llvm::ArrayRef<swift::AppliedPropertyWrapper>) + 3492
6  swift-frontend           0x000000010631a008 (anonymous namespace)::ExprRewriter::finishApply(swift::ApplyExpr*, swift::Type, swift::constraints::ConstraintLocatorBuilder, swift::constraints::ConstraintLocatorBuilder) + 6164
7  swift-frontend           0x00000001063214ec (anonymous namespace)::ExprRewriter::visitApplyExpr(swift::ApplyExpr*) + 520
8  swift-frontend           0x00000001063020b4 (anonymous namespace)::ExprRewriter::walkToExprPost(swift::Expr*) + 120
9  swift-frontend           0x00000001062feaa4 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 24
10 swift-frontend           0x00000001062f974c (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SyntacticElementTarget) + 2748
11 swift-frontend           0x00000001062f87ec swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SyntacticElementTarget) + 7108
12 swift-frontend           0x00000001065b3b28 swift::TypeChecker::typeCheckTarget(swift::constraints::SyntacticElementTarget&, swift::optionset::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 680
13 swift-frontend           0x00000001066a1524 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 3524
14 swift-frontend           0x00000001066a0628 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::Stmt>(swift::Stmt*&) + 316
15 swift-frontend           0x000000010669b294 (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 88
16 swift-frontend           0x00000001066a0880 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 288
17 swift-frontend           0x000000010669e294 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 316
18 swift-frontend           0x000000010669ce30 swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 1512
19 swift-frontend           0x0000000106aa74dc swift::TypeCheckFunctionBodyRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()>(swift::TypeCheckFunctionBodyRequest const&, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()) + 632
20 swift-frontend           0x0000000106a181fc swift::AbstractFunctionDecl::getTypecheckedBody() const + 160
21 swift-frontend           0x0000000106615518 (anonymous namespace)::DeclChecker::visitFuncDecl(swift::FuncDecl*) + 1212
22 swift-frontend           0x00000001066076c4 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 1296
23 swift-frontend           0x00000001066071a4 swift::TypeChecker::typeCheckDecl(swift::Decl*) + 152
24 swift-frontend           0x00000001066a0880 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 288
25 swift-frontend           0x000000010669e294 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 316
26 swift-frontend           0x000000010669ce30 swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 1512
27 swift-frontend           0x0000000106aa74dc swift::TypeCheckFunctionBodyRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()>(swift::TypeCheckFunctionBodyRequest const&, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()) + 632
28 swift-frontend           0x0000000106a181fc swift::AbstractFunctionDecl::getTypecheckedBody() const + 160
29 swift-frontend           0x00000001066ebab4 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 868
30 swift-frontend           0x00000001066f3098 swift::TypeCheckSourceFileRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()>(swift::TypeCheckSourceFileRequest const&, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()) + 616
31 swift-frontend           0x00000001066eb734 swift::performTypeChecking(swift::SourceFile&) + 328
32 swift-frontend           0x0000000105643c60 swift::CompilerInstance::performSema() + 260
33 swift-frontend           0x00000001052713d0 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1520
34 swift-frontend           0x000000010526f438 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4752
35 swift-frontend           0x00000001051f52d8 swift::mainEntry(int, char const**) + 2812
36 dyld                     0x0000000192dc5298 start + 2876

@twof
Copy link
Contributor Author

twof commented Jun 12, 2024

If it helps, here's my use case:
https://github.com/twof/FunctionSpy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertion failure Bug → crash: An assertion failure bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. call expressions Feature → expressions: Call expressions compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software expressions Feature: expressions function types Feature → types: function types generics Feature: generic declarations and types parameter packs Feature → generics: Parameter packs SILGen Area → compiler: The SIL generation stage swift 6.0 types Feature: types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants