swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.25k stars 10.32k forks source link

inout parameter pack compiler crash #72209

Open roopekv opened 6 months ago

roopekv commented 6 months ago

Description

Declaring a function with an inout parameter pack causes the compiler to crash.

Reproduction

func foo<each T>(_ t: repeat inout each T) {}

Stack dump

1.      Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
2.      Compiling with the current language version
3.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/username/dev/swift-test/Sources/main.swift")
4.      While silgen emitFunction SIL function "@$s10swift_test3fooyyxxQpzRvzlF".
 for 'foo(_:)' (at /Users/username/dev/swift-test/Sources/main.swift:1:1)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x000000010a86bf3c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a86b0f8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010a86c544 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x000000019c773584 _sigtramp + 56
4  swift-frontend           0x000000010587ba80 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 6976
5  swift-frontend           0x00000001058795f0 swift::Lowering::SILGenFunction::emitOrigToSubstValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::SGFContext) + 336
6  swift-frontend           0x0000000105899c88 (anonymous namespace)::EmitBBArguments::handleScalar(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::Initialization*, bool) + 2256
7  swift-frontend           0x0000000105898e74 (anonymous namespace)::ArgumentInitHelper::makeArgument(swift::SILLocation, swift::ParamDecl*) + 1164
8  swift-frontend           0x00000001058971e0 (anonymous namespace)::ArgumentInitHelper::emitParam(swift::ParamDecl*) + 264
9  swift-frontend           0x0000000105895308 swift::Lowering::SILGenFunction::emitBasicProlog(swift::ParameterList*, swift::ParamDecl*, swift::Type, swift::DeclContext*, bool, swift::SourceLoc, unsigned int, llvm::Optional<swift::Lowering::AbstractionPattern>) + 1044
10 swift-frontend           0x000000010589302c swift::Lowering::SILGenFunction::emitProlog(swift::CaptureInfo, swift::ParameterList*, swift::ParamDecl*, swift::DeclContext*, swift::Type, bool, swift::SourceLoc, llvm::Optional<swift::Lowering::AbstractionPattern>) + 128
11 swift-frontend           0x00000001058363f0 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 304
12 swift-frontend           0x000000010578ae48 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8344
13 swift-frontend           0x000000010578b5bc swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 172
14 swift-frontend           0x0000000105788d9c swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 292
15 swift-frontend           0x000000010578eb54 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1668
16 swift-frontend           0x000000010589df1c 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
17 swift-frontend           0x0000000105791f44 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 584
18 swift-frontend           0x0000000105169408 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 548
19 swift-frontend           0x000000010516d694 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1448
20 swift-frontend           0x000000010516b6d0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4968
21 swift-frontend           0x00000001050fae8c swift::mainEntry(int, char const**) + 2612
22 dyld                     0x000000019c3ba0e0 start + 2360

Expected behavior

Compiler shouldn't crash. I would expect the code to compile, but if inout parameter packs are not supported, then I would expect an error message informing about the limitation.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)

Additional information

No response

roopekv commented 5 months ago

Additional information with 6.0-dev-branch:

[cleanup]   %1 = alloc_stack $Pack{repeat each T}, var, name "t" // user: %2
Unhandled transform?
UNREACHABLE executed at /home/build-user/swift/lib/SILGen/SILGenPoly.cpp:681!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.

I believe this is the assertion being hit: https://github.com/apple/swift/blob/bd1b99bad0dcc42c784e7b5632b1339710b8caad/lib/SILGen/SILGenPoly.cpp#L681

Try it yourself: https://godbolt.org/z/aKMYb48ob

Would really like for this issue to get resolved. Any help is greatly appreciated.