From 5d481877f186276ee8cd6f81e6fae350c0526b4e Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 13 Sep 2024 16:15:59 -0700 Subject: [PATCH] Omit a trailing `SpecificId` by default when formatting instruction arguments. (#4315) --- toolchain/sem_ir/formatter.cpp | 50 +++++++--------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/toolchain/sem_ir/formatter.cpp b/toolchain/sem_ir/formatter.cpp index b05a7e2f578f0..9c35e139d48f5 100644 --- a/toolchain/sem_ir/formatter.cpp +++ b/toolchain/sem_ir/formatter.cpp @@ -661,6 +661,16 @@ class FormatterImpl { // By default, an instruction has a comma-separated argument list. using Info = Internal::InstLikeTypeInfo; if constexpr (Info::NumArgs == 2) { + // Several instructions have a second operand that's a specific ID. We + // don't include it in the argument list if there is no corresponding + // specific, that is, when we're not in a generic context. + if constexpr (std::is_same_v, + SemIR::SpecificId>) { + if (!Info::template Get<1>(inst).is_valid()) { + FormatArgs(Info::template Get<0>(inst)); + return; + } + } FormatArgs(Info::template Get<0>(inst), Info::template Get<1>(inst)); } else if constexpr (Info::NumArgs == 1) { FormatArgs(Info::template Get<0>(inst)); @@ -790,35 +800,11 @@ class FormatterImpl { FormatTrailingBlock(inst.decl_block_id); } - auto FormatInstRHS(FunctionType inst) -> void { - if (inst.specific_id.is_valid()) { - FormatArgs(inst.function_id, inst.specific_id); - } else { - FormatArgs(inst.function_id); - } - } - auto FormatInstRHS(ClassDecl inst) -> void { FormatArgs(inst.class_id); FormatTrailingBlock(inst.decl_block_id); } - auto FormatInstRHS(ClassType inst) -> void { - if (inst.specific_id.is_valid()) { - FormatArgs(inst.class_id, inst.specific_id); - } else { - FormatArgs(inst.class_id); - } - } - - auto FormatInstRHS(GenericClassType inst) -> void { - if (inst.enclosing_specific_id.is_valid()) { - FormatArgs(inst.class_id, inst.enclosing_specific_id); - } else { - FormatArgs(inst.class_id); - } - } - auto FormatInstRHS(ImplDecl inst) -> void { FormatArgs(inst.impl_id); FormatTrailingBlock(inst.decl_block_id); @@ -829,22 +815,6 @@ class FormatterImpl { FormatTrailingBlock(inst.decl_block_id); } - auto FormatInstRHS(InterfaceType inst) -> void { - if (inst.specific_id.is_valid()) { - FormatArgs(inst.interface_id, inst.specific_id); - } else { - FormatArgs(inst.interface_id); - } - } - - auto FormatInstRHS(GenericInterfaceType inst) -> void { - if (inst.enclosing_specific_id.is_valid()) { - FormatArgs(inst.interface_id, inst.enclosing_specific_id); - } else { - FormatArgs(inst.interface_id); - } - } - auto FormatInstRHS(IntLiteral inst) -> void { out_ << " "; sem_ir_.ints()