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

Using sending with parameter packs crashes the compiler #76306

Open
dehesa opened this issue Sep 6, 2024 · 0 comments
Open

Using sending with parameter packs crashes the compiler #76306

dehesa opened this issue Sep 6, 2024 · 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

@dehesa
Copy link

dehesa commented Sep 6, 2024

Description

I noticed compiler crashes while writing code in Xcode 16 Beta 6 transferring non-sendable values. I managed to boil it down to the reproduction below.

I brought it up in the Swift Forums and I was told by @slavapestov that sending is currently not supported in conjunction with parameter packs. That is good to know, but I think the compiler shouldn't crash, anyways.

Please notice, I am aware the code below is not "technically" correct. You can also make the compiler crash by writing the sending keywords in different places.

Reproduction

import Testing

@Test func testVariadic() async throws {
  let runner = Runner()
  await runner.run(1, 2, "3", "Paco", 5)
}

struct Runner {
  func run<each V>(_ value: repeat (sending each V)) async {
    let params = Wrapper(repeat each value)
    await compute(params)
  }
}

@MainActor func compute<each V>(_ value: Wrapper<repeat each V>) {
  for v in repeat each value.parameters {
    print(v)
  }
}

struct Wrapper<each V> {
  let parameters: (repeat each V)

  init(_ parameters: repeat each V) {
    self.parameters = (repeat each parameters)
  }
}

Stack dump

Stack dump:
0.	Program arguments: /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/marcos/Developer/Github/Private/swift-belt/sqlite-utils/tests/Issue.swift -primary-file /Users/marcos/Developer/Github/Private/swift-belt/sqlite-utils/tests/SQLiteTests.swift -emit-dependencies-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/sqlite-utils.build/Debug/SQLiteUtilsTests.build/Objects-normal/arm64/SQLiteTests.d -emit-const-values-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/sqlite-utils.build/Debug/SQLiteUtilsTests.build/Objects-normal/arm64/SQLiteTests.swiftconstvalues -emit-reference-dependencies-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/sqlite-utils.build/Debug/SQLiteUtilsTests.build/Objects-normal/arm64/SQLiteTests.swiftdeps -serialize-diagnostics-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/sqlite-utils.build/Debug/SQLiteUtilsTests.build/Objects-normal/arm64/SQLiteTests.dia -target arm64-apple-macos15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -I /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug -I /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug -F /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=5 -module-cache-path /Users/marcos/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 -warn-long-function-bodies=80 -warn-long-expression-type-checking=30 -serialize-debugging-options -const-gather-protocols-file /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/sqlite-utils.build/Debug/SQLiteUtilsTests.build/Objects-normal/arm64/SQLiteUtilsTests_const_extract_protocols.json -enable-experimental-feature AccessLevelOnImport -enable-experimental-feature DebugDescriptionMacro -enable-experimental-feature OpaqueTypeErasure -enable-upcoming-feature ExistentialAny -enable-upcoming-feature InternalImportsByDefault -empty-abi-descriptor -plugin-path /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing -validate-clang-modules-once -clang-build-session-file /Users/marcos/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/marcos/Developer/Github/Private/swift-belt -resource-dir /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/marcos/Developer/Github/Private/swift-belt -Xcc -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -Xcc -ivfsstatcache -Xcc /Users/marcos/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.0-24A5324a-b8eb52f7cfe01464b1c5d9af15dcd1f8.sdkstatcache -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/SourcePackages/checkouts/swift-numerics/Sources/_NumericsShims/include -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/include -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/sqlite-utils.build/Debug/SQLiteUtilsTests.build/DerivedSources-normal/arm64 -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/sqlite-utils.build/Debug/SQLiteUtilsTests.build/DerivedSources/arm64 -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/sqlite-utils.build/Debug/SQLiteUtilsTests.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name SQLiteUtilsTests -package-name sqlite_utils -frontend-parseable-output -disable-clang-spi -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-16.0.0-Beta.6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/sqlite-utils.build/Debug/SQLiteUtilsTests.build/Objects-normal/arm64/SQLiteTests.o -index-unit-output-path /sqlite-utils.build/Debug/SQLiteUtilsTests.build/Objects-normal/arm64/SQLiteTests.o -index-store-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Index.noindex/DataStore -index-system-modules
1.	Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/marcos/Developer/Github/Private/swift-belt/sqlite-utils/tests/SQLiteTests.swift")
4.	While silgen emitFunction SIL function "@$s16SQLiteUtilsTests6RunnerV3runyyxxQpnYaRvzlF".
 for 'run(_:)' (at /Users/marcos/Developer/Github/Private/swift-belt/sqlite-utils/tests/SQLiteTests.swift:10:3)
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           0x0000000107fa70fc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107fa5350 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000107fa76c8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x0000000194658184 _sigtramp + 56
4  swift-frontend           0x0000000103455514 swift::Lowering::SILGenFunction::emitSemanticStore(swift::SILLocation, swift::SILValue, swift::SILValue, swift::Lowering::TypeLowering const&, swift::IsInitialization_t) + 1036
5  swift-frontend           0x00000001033d7dcc swift::Lowering::SingleBufferInitialization::copyOrInitValueIntoSingleBuffer(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, bool, swift::SILValue) + 148
6  swift-frontend           0x00000001034a3990 (anonymous namespace)::ArgumentInitHelper::emitParam(swift::ParamDecl*) + 1424
7  swift-frontend           0x00000001034a1f74 swift::Lowering::SILGenFunction::emitBasicProlog(swift::DeclContext*, swift::ParameterList*, swift::ParamDecl*, swift::Type, std::__1::optional<swift::Type>, swift::SourceLoc, unsigned int) + 2656
8  swift-frontend           0x000000010349f76c swift::Lowering::SILGenFunction::emitProlog(swift::DeclContext*, swift::CaptureInfo, swift::ParameterList*, swift::ParamDecl*, swift::Type, std::__1::optional<swift::Type>, swift::SourceLoc) + 160
9  swift-frontend           0x0000000103421c34 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 212
10 swift-frontend           0x000000010336d8a0 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8420
11 swift-frontend           0x000000010336e140 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 216
12 swift-frontend           0x000000010336b770 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 364
13 swift-frontend           0x00000001034c1a10 (anonymous namespace)::SILGenType::visitFuncDecl(swift::FuncDecl*) + 32
14 swift-frontend           0x00000001034bdfb8 (anonymous namespace)::SILGenType::emitType() + 424
15 swift-frontend           0x000000010336b3a8 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 104
16 swift-frontend           0x0000000103371dbc swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1804
17 swift-frontend           0x00000001034a86b0 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
18 swift-frontend           0x0000000103376c98 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
19 swift-frontend           0x0000000102950f34 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 920
20 swift-frontend           0x0000000102954228 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1680
21 swift-frontend           0x0000000102952f58 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
22 swift-frontend           0x00000001028da01c swift::mainEntry(int, char const**) + 3680
23 dyld                     0x00000001942a0274 start + 2840

Expected behavior

No crashes and ideally future sending support by code blocks 😄

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0

Additional information

No response

@dehesa dehesa 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 Sep 6, 2024
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