Open schuelermine opened 1 week ago
This is an interesting case. Indeed, the code is invalid, but the compiler shouldn't crash trying to diagnose it.
In the REPL on macOS, there is no crash, but I can indeed reproduce this on godbolt.org with both the nightly and Swift 5.10 compiler. It appears to be a relatively recent regression as Swift 5.9 doesn't crash but rather correctly diagnoses the problem(s).
Interesting. Entering the first line alone into the REPL crashes the REPL on Ubuntu.
ubuntu@swift:~$ swift repl -v
Swift version 5.10.1 (swift-5.10.1-RELEASE)
Target: x86_64-unknown-linux-gnu
/opt/swift-5.10.1/bin/lldb '--repl=-disable-objc-interop -color-diagnostics -new-driver-path /opt/swift-5.10.1/bin/swift-driver -empty-abi-descriptor -resource-dir /opt/swift-5.10.1/lib/swift -plugin-path /opt/swift-5.10.1/lib/swift/host/plugins -plugin-path /opt/swift-5.10.1/local/lib/swift/host/plugins'
Welcome to Swift version 5.10.1 (swift-5.10.1-RELEASE).
Type :help for assistance.
1> func foo(x: @autoclosure () -> () = (), _ y: @autoclosure () -> (), z: @autoclosure () -> (), w: () -> ()) { }
SIL verification failed: function_ref inside fragile function cannot reference a private or hidden symbol: (SingleFunction && RefF->isExternalDeclaration()) || RefF->hasValidLinkageForFragileRef()
Verifying instruction:
-> // function_ref implicit closure #1 in default argument 0 of foo(x:_:z:w:)
%0 = function_ref @$s13__lldb_expr_13foo1x_1z1wyyyXK_yyXKyyXKyyXEtFfA_yycfu_ : $@convention(thin) () -> () // user: %1
%1 = thin_to_thick_function %0 : $@convention(thin) () -> () to $@callee_guaranteed () -> () // user: %2
In function:
// default argument 0 of foo(x:_:z:w:)
sil non_abi [serialized] [ossa] @$s13__lldb_expr_13foo1x_1z1wyyyXK_yyXKyyXKyyXEtFfA_ : $@convention(thin) () -> @owned @callee_guaranteed () -> () {
bb0:
// function_ref implicit closure #1 in default argument 0 of foo(x:_:z:w:)
%0 = function_ref @$s13__lldb_expr_13foo1x_1z1wyyyXK_yyXKyyXKyyXEtFfA_yycfu_ : $@convention(thin) () -> () // user: %1
%1 = thin_to_thick_function %0 : $@convention(thin) () -> () to $@callee_guaranteed () -> () // user: %2
return %1 : $@callee_guaranteed () -> () // id: %2
} // end sil function '$s13__lldb_expr_13foo1x_1z1wyyyXK_yyXKyyXKyyXEtFfA_'
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
#0 0x0000564c84634ec4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/swift-5.10.1/bin/lldb+0x28ec4)
#1 0x0000564c8463301e llvm::sys::RunSignalHandlers() (/opt/swift-5.10.1/bin/lldb+0x2701e)
#2 0x0000564c846354c8 SignalHandler(int) Signals.cpp:0:0
#3 0x00007f8478245320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
#4 0x00007f847829eb1c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb1c)
#5 0x00007f847824526e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4526e)
#6 0x00007f84782288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#7 0x00007f847b24bc8e (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x284bc8e)
#8 0x00007f847b272554 (anonymous namespace)::SILVerifier::checkFunctionRefBaseInst(swift::FunctionRefBaseInst*) SILVerifier.cpp:0:0
#9 0x00007f847b250bd4 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) SILVerifier.cpp:0:0
#10 0x00007f847b2504af (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) SILVerifier.cpp:0:0
#11 0x00007f847b24eb2e (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) SILVerifier.cpp:0:0
#12 0x00007f847b247599 swift::SILFunction::verify(swift::SILPassManager*, bool, bool, bool) const (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x2847599)
#13 0x00007f847af833fe swift::Lowering::SILGenModule::postEmitFunction(swift::SILDeclRef, swift::SILFunction*) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x25833fe)
#14 0x00007f847af82650 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x2582650)
#15 0x00007f847af83c6f swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x2583c6f)
#16 0x00007f847af84bfe swift::Lowering::SILGenModule::emitArgumentGenerators(llvm::PointerUnion<swift::ValueDecl*, swift::AbstractClosureExpr*, swift::FileUnit*>, swift::ParameterList*) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x2584bfe)
#17 0x00007f847af847fc swift::Lowering::SILGenModule::emitAbstractFuncDecl(swift::AbstractFunctionDecl*) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x25847fc)
#18 0x00007f847af81242 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x2581242)
#19 0x00007f847af86d67 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x2586d67)
#20 0x00007f847b05ee0b swift::SimpleRequest<swift::ASTLoweringRequest, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x265ee0b)
#21 0x00007f847aa0adb3 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x200adb3)
#22 0x00007f847af878c8 swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x25878c8)
#23 0x00007f847a242de3 lldb_private::SwiftExpressionParser::Parse(lldb_private::DiagnosticManager&, unsigned int, unsigned int) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x1842de3)
#24 0x00007f847a23a4c5 lldb_private::SwiftUserExpression::GetTextAndSetExpressionParser(lldb_private::DiagnosticManager&, std::unique_ptr<lldb_private::SwiftExpressionSourceCode, std::default_delete<lldb_private::SwiftExpressionSourceCode>>&, lldb_private::ExecutionContext&, lldb_private::ExecutionContextScope*) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x183a4c5)
#25 0x00007f847a23b507 lldb_private::SwiftUserExpression::Parse(lldb_private::DiagnosticManager&, lldb_private::ExecutionContext&, lldb_private::ExecutionPolicy, bool, bool) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x183b507)
#26 0x00007f8479a802f2 lldb_private::UserExpression::Evaluate(lldb_private::ExecutionContext&, lldb_private::EvaluateExpressionOptions const&, llvm::StringRef, llvm::StringRef, std::shared_ptr<lldb_private::ValueObject>&, lldb_private::Status&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, lldb_private::ValueObject*) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x10802f2)
#27 0x00007f8479a7c9d2 lldb_private::REPL::IOHandlerInputComplete(lldb_private::IOHandler&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x107c9d2)
#28 0x00007f8479a039f9 lldb_private::IOHandlerEditline::Run() (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x10039f9)
#29 0x00007f84799e23a6 lldb_private::Debugger::RunIOHandlers() (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0xfe23a6)
#30 0x00007f84799ea342 std::_Function_handler<void* (), lldb_private::Debugger::StartIOHandlerThread()::$_4>::_M_invoke(std::_Any_data const&) Debugger.cpp:0:0
#31 0x00007f8479aae060 lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*) (/opt/swift-5.10.1/bin/../lib/liblldb.so.15git+0x10ae060)
#32 0x00007f847829ca94 (/lib/x86_64-linux-gnu/libc.so.6+0x9ca94)
#33 0x00007f8478329c3c (/lib/x86_64-linux-gnu/libc.so.6+0x129c3c)
Aborted (core dumped)
Looks like you don't even need the autoclosure to reproduce, this also crashes:
func foo(_ y: Int, w: () -> ()) { }
foo { } w: { }
Description
No response
Reproduction
Stack dump
Expected behavior
I don’t actually know if this program should be accepted or not.
Environment
Swift version 5.10.1 (swift-5.10.1-RELEASE) Target: x86_64-unknown-linux-gnu
Additional information
No response