From c929dec43e335b4342d87cf4e2397753d7510a68 Mon Sep 17 00:00:00 2001 From: jonmeow Date: Tue, 5 Nov 2024 14:20:22 -0800 Subject: [PATCH] Remove verbose formatting of instructions on crash messages. --- toolchain/check/BUILD | 1 - toolchain/check/context.cpp | 11 +++-- toolchain/check/inst_block_stack.cpp | 12 ++--- toolchain/check/inst_block_stack.h | 3 +- toolchain/check/node_stack.cpp | 13 +++--- toolchain/check/node_stack.h | 4 +- toolchain/check/param_and_arg_refs_stack.h | 5 +-- toolchain/sem_ir/formatter.cpp | 52 +++++----------------- toolchain/sem_ir/formatter.h | 8 ---- 9 files changed, 32 insertions(+), 77 deletions(-) diff --git a/toolchain/check/BUILD b/toolchain/check/BUILD index 0f7f755b4780d..1250f96fa9eff 100644 --- a/toolchain/check/BUILD +++ b/toolchain/check/BUILD @@ -205,7 +205,6 @@ cc_library( "//common:vlog", "//toolchain/parse:node_kind", "//toolchain/parse:tree", - "//toolchain/sem_ir:formatter", "//toolchain/sem_ir:ids", "@llvm-project//llvm:Support", ], diff --git a/toolchain/check/context.cpp b/toolchain/check/context.cpp index 1161e2d5ad163..d63cd1f853e19 100644 --- a/toolchain/check/context.cpp +++ b/toolchain/check/context.cpp @@ -1299,12 +1299,11 @@ auto Context::PrintForStackDump(llvm::raw_ostream& output) const -> void { // spaces then add a couple to indent past the Context label. constexpr int Indent = 10; - SemIR::Formatter formatter(*tokens_, *parse_tree_, *sem_ir_); - node_stack_.PrintForStackDump(formatter, Indent, output); - inst_block_stack_.PrintForStackDump(formatter, Indent, output); - pattern_block_stack_.PrintForStackDump(formatter, Indent, output); - param_and_arg_refs_stack_.PrintForStackDump(formatter, Indent, output); - args_type_info_stack_.PrintForStackDump(formatter, Indent, output); + node_stack_.PrintForStackDump(Indent, output); + inst_block_stack_.PrintForStackDump(Indent, output); + pattern_block_stack_.PrintForStackDump(Indent, output); + param_and_arg_refs_stack_.PrintForStackDump(Indent, output); + args_type_info_stack_.PrintForStackDump(Indent, output); } auto Context::DumpFormattedFile() const -> void { diff --git a/toolchain/check/inst_block_stack.cpp b/toolchain/check/inst_block_stack.cpp index d225c05383cbc..4b47d08913967 100644 --- a/toolchain/check/inst_block_stack.cpp +++ b/toolchain/check/inst_block_stack.cpp @@ -61,17 +61,19 @@ auto InstBlockStack::PopAndDiscard() -> void { CARBON_VLOG("{0} PopAndDiscard {1}\n", name_, id_stack_.size()); } -auto InstBlockStack::PrintForStackDump(SemIR::Formatter& formatter, int indent, +auto InstBlockStack::PrintForStackDump(int indent, llvm::raw_ostream& output) const -> void { output.indent(indent); output << name_ << ":\n"; for (const auto& [i, id] : llvm::enumerate(id_stack_)) { output.indent(indent + 2); - output << i << ". " << id; - formatter.PrintPartialTrailingCodeBlock(insts_stack_.PeekArrayAt(i), - indent + 4, output); - output << "\n"; + output << i << ".\t" << id << "\t{"; + llvm::ListSeparator sep; + for (auto id : insts_stack_.PeekArrayAt(i)) { + output << sep << id; + } + output << "}\n"; } } diff --git a/toolchain/check/inst_block_stack.h b/toolchain/check/inst_block_stack.h index fab55c51e4e62..87c84ef93ea05 100644 --- a/toolchain/check/inst_block_stack.h +++ b/toolchain/check/inst_block_stack.h @@ -77,8 +77,7 @@ class InstBlockStack { } // Prints the stack for a stack dump. - auto PrintForStackDump(SemIR::Formatter& formatter, int indent, - llvm::raw_ostream& output) const -> void; + auto PrintForStackDump(int indent, llvm::raw_ostream& output) const -> void; // Runs verification that the processing cleanly finished. auto VerifyOnFinish() const -> void { diff --git a/toolchain/check/node_stack.cpp b/toolchain/check/node_stack.cpp index 3d7ca19cecdd8..e4123f94a6a37 100644 --- a/toolchain/check/node_stack.cpp +++ b/toolchain/check/node_stack.cpp @@ -8,19 +8,15 @@ namespace Carbon::Check { -auto NodeStack::PrintForStackDump(SemIR::Formatter& formatter, int indent, - llvm::raw_ostream& output) const -> void { +auto NodeStack::PrintForStackDump(int indent, llvm::raw_ostream& output) const + -> void { auto print_id = [&](Id id) { if constexpr (Kind == Id::Kind::None) { - output << "no value\n"; + output << "no value"; } else if constexpr (Kind == Id::Kind::Invalid) { CARBON_FATAL("Should not be in node stack"); - } else if constexpr (Kind == Id::KindFor()) { - output << "\n"; - formatter.PrintInst(id.As()>(), indent + 4, - output); } else { - output << id.As() << "\n"; + output << id.As(); } }; @@ -37,6 +33,7 @@ auto NodeStack::PrintForStackDump(SemIR::Formatter& formatter, int indent, break; #include "toolchain/parse/node_kind.def" } + output << "\n"; } } diff --git a/toolchain/check/node_stack.h b/toolchain/check/node_stack.h index 6a5642925d600..c405a35f45272 100644 --- a/toolchain/check/node_stack.h +++ b/toolchain/check/node_stack.h @@ -11,7 +11,6 @@ #include "toolchain/parse/node_kind.h" #include "toolchain/parse/tree.h" #include "toolchain/parse/typed_nodes.h" -#include "toolchain/sem_ir/formatter.h" #include "toolchain/sem_ir/id_kind.h" #include "toolchain/sem_ir/ids.h" @@ -335,8 +334,7 @@ class NodeStack { } // Prints the stack for a stack dump. - auto PrintForStackDump(SemIR::Formatter& formatter, int indent, - llvm::raw_ostream& output) const -> void; + auto PrintForStackDump(int indent, llvm::raw_ostream& output) const -> void; auto empty() const -> bool { return stack_.empty(); } auto size() const -> size_t { return stack_.size(); } diff --git a/toolchain/check/param_and_arg_refs_stack.h b/toolchain/check/param_and_arg_refs_stack.h index 1905926572b1c..44b28e931d41f 100644 --- a/toolchain/check/param_and_arg_refs_stack.h +++ b/toolchain/check/param_and_arg_refs_stack.h @@ -72,9 +72,8 @@ class ParamAndArgRefsStack { auto VerifyOnFinish() -> void { stack_.VerifyOnFinish(); } // Prints the stack for a stack dump. - auto PrintForStackDump(SemIR::Formatter& formatter, int indent, - llvm::raw_ostream& output) const -> void { - return stack_.PrintForStackDump(formatter, indent, output); + auto PrintForStackDump(int indent, llvm::raw_ostream& output) const -> void { + return stack_.PrintForStackDump(indent, output); } private: diff --git a/toolchain/sem_ir/formatter.cpp b/toolchain/sem_ir/formatter.cpp index f54530d27d90b..ffcffad06835a 100644 --- a/toolchain/sem_ir/formatter.cpp +++ b/toolchain/sem_ir/formatter.cpp @@ -78,34 +78,6 @@ class FormatterImpl { out_ << "\n"; } - // Prints a code block. - auto FormatPartialTrailingCodeBlock(llvm::ArrayRef block) - -> void { - out_ << ' '; - OpenBrace(); - constexpr int NumPrintedOnSkip = 9; - // Avoid only skipping one item. - if (block.size() > NumPrintedOnSkip + 1) { - Indent(); - out_ << "... skipping " << (block.size() - NumPrintedOnSkip) - << " insts ...\n"; - block = block.take_back(NumPrintedOnSkip); - } - FormatCodeBlock(block); - CloseBrace(); - } - - // Prints a single instruction. - auto FormatInst(InstId inst_id) -> void { - if (!inst_id.is_valid()) { - Indent(); - out_ << "invalid\n"; - return; - } - - FormatInst(inst_id, sem_ir_.insts().Get(inst_id)); - } - private: enum class AddSpace : bool { Before, After }; @@ -568,6 +540,17 @@ class FormatterImpl { } } + // Prints a single instruction. + auto FormatInst(InstId inst_id) -> void { + if (!inst_id.is_valid()) { + Indent(); + out_ << "invalid\n"; + return; + } + + FormatInst(inst_id, sem_ir_.insts().Get(inst_id)); + } + auto FormatInst(InstId inst_id, Inst inst) -> void { CARBON_KIND_SWITCH(inst) { #define CARBON_SEM_IR_INST_KIND(InstT) \ @@ -1192,17 +1175,4 @@ auto Formatter::Print(llvm::raw_ostream& out) -> void { formatter.Format(); } -auto Formatter::PrintPartialTrailingCodeBlock( - llvm::ArrayRef block, int indent, llvm::raw_ostream& out) - -> void { - FormatterImpl formatter(sem_ir_, &inst_namer_, out, indent); - formatter.FormatPartialTrailingCodeBlock(block); -} - -auto Formatter::PrintInst(SemIR::InstId inst_id, int indent, - llvm::raw_ostream& out) -> void { - FormatterImpl formatter(sem_ir_, &inst_namer_, out, indent); - formatter.FormatInst(inst_id); -} - } // namespace Carbon::SemIR diff --git a/toolchain/sem_ir/formatter.h b/toolchain/sem_ir/formatter.h index 7a2ff326159b9..82dc0053d2fb4 100644 --- a/toolchain/sem_ir/formatter.h +++ b/toolchain/sem_ir/formatter.h @@ -22,14 +22,6 @@ class Formatter { // Prints the full IR. auto Print(llvm::raw_ostream& out) -> void; - // Prints a single code block. Only prints the last several instructions of - // large blocks. - auto PrintPartialTrailingCodeBlock(llvm::ArrayRef block, - int indent, llvm::raw_ostream& out) - -> void; - // Prints a single instruction. - auto PrintInst(SemIR::InstId inst_id, int indent, llvm::raw_ostream& out) - -> void; private: const File& sem_ir_;