Skip to content

Encoding top level array in REPL crashes compiler #80893

@tkrajacic

Description

@tkrajacic

Description

When using the REPL or a Playground, trying to encode a simple array of strings with JSONEncoder crashes the compiler.

Reproduction

$ swift repl
import Foundation
let result = try JSONEncoder().encode(["a"])

Stack dump

LLDB diagnostics will be written to /var/folders/90/xscfxllj4_1bsl5bqy4ztzmh0000gn/T/diagnostics-2eee8c
Please include the directory content when filing a bug report
PLEASE submit a bug report to  and include the crash report from ~/Library/Logs/DiagnosticReports/.
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  lldb                     0x0000000100995bf0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  lldb                     0x000000010099444c llvm::sys::RunSignalHandlers() + 112
2  lldb                     0x000000010099650c SignalHandler(int) + 320
3  libsystem_platform.dylib 0x000000018b10b624 _sigtramp + 56
4  LLDB                     0x0000000116d4eb20 swift::irgen::ClassMetadataLayout::getMethodInfo(swift::irgen::IRGenFunction&, swift::SILDeclRef) const + 56
5  LLDB                     0x0000000116baafb0 swift::irgen::emitVirtualMethodValue(swift::irgen::IRGenFunction&, llvm::Value*, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>) + 160
6  LLDB                     0x0000000116bab6ac swift::irgen::emitVirtualMethodValue(swift::irgen::IRGenFunction&, llvm::Value*, swift::SILType, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>, bool) + 496
7  LLDB                     0x0000000116d12594 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 67756
8  LLDB                     0x0000000116d00d04 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 6988
9  LLDB                     0x0000000116cfee38 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1660
10 LLDB                     0x0000000116bc13b0 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) + 596
11 LLDB                     0x0000000116cbffa0 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2564
12 LLDB                     0x0000000116cfe4cc swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)17>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 180
13 LLDB                     0x0000000116ccba80 swift::IRGenRequest::OutputType swift::Evaluator::getResultUncached<swift::IRGenRequest, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()>(swift::IRGenRequest const&, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()) + 188
14 LLDB                     0x0000000116cc0e80 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::GlobalVariable**) + 1244
15 LLDB                     0x0000000115d2d9bc lldb_private::SwiftExpressionParser::Parse(lldb_private::DiagnosticManager&, unsigned int, unsigned int) + 10272
16 LLDB                     0x0000000115d40c14 lldb_private::SwiftUserExpression::GetTextAndSetExpressionParser(lldb_private::DiagnosticManager&, std::__1::unique_ptr<lldb_private::SwiftExpressionSourceCode, std::__1::default_delete<lldb_private::SwiftExpressionSourceCode>>&, lldb_private::ExecutionContext&, lldb_private::ExecutionContextScope*) + 5480
17 LLDB                     0x0000000115d41950 lldb_private::SwiftUserExpression::Parse(lldb_private::DiagnosticManager&, lldb_private::ExecutionContext&, lldb_private::ExecutionPolicy, bool, bool) + 2172
18 LLDB                     0x0000000115bb2c7c lldb_private::UserExpression::Evaluate(lldb_private::ExecutionContext&, lldb_private::EvaluateExpressionOptions const&, llvm::StringRef, llvm::StringRef, std::__1::shared_ptr<lldb_private::ValueObject>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, lldb_private::ValueObject*) + 3256
19 LLDB                     0x0000000115baff9c lldb_private::REPL::IOHandlerInputComplete(lldb_private::IOHandler&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) + 2472
20 LLDB                     0x0000000115b2e6a0 lldb_private::IOHandlerEditline::Run() + 292
21 LLDB                     0x0000000115b109dc lldb_private::Debugger::RunIOHandlers() + 128
22 LLDB                     0x0000000115b16b84 std::__1::__function::__func<lldb_private::Debugger::StartIOHandlerThread()::$_0, std::__1::allocator<lldb_private::Debugger::StartIOHandlerThread()::$_0>, void* ()>::operator()() + 28
23 LLDB                     0x0000000115bbbd68 lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*) + 132
24 LLDB                     0x0000000115faabac lldb_private::HostThreadMacOSX::ThreadCreateTrampoline(void*) + 32
25 libsystem_pthread.dylib  0x000000018b0d1c0c _pthread_start + 136
26 libsystem_pthread.dylib  0x000000018b0ccb80 thread_start + 8
[1]    87965 segmentation fault  swift repl

Expected behavior

result should just be the encoded array

Environment

Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions