Skip to content

Commit

Permalink
Omit a trailing SpecificId by default when formatting instruction a…
Browse files Browse the repository at this point in the history
…rguments. (#4315)
  • Loading branch information
zygoloid authored Sep 13, 2024
1 parent 02950e4 commit 5d48187
Showing 1 changed file with 10 additions and 40 deletions.
50 changes: 10 additions & 40 deletions toolchain/sem_ir/formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,16 @@ class FormatterImpl {
// By default, an instruction has a comma-separated argument list.
using Info = Internal::InstLikeTypeInfo<InstT>;
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<typename Info::template ArgType<1>,
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));
Expand Down Expand Up @@ -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);
Expand All @@ -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()
Expand Down

0 comments on commit 5d48187

Please sign in to comment.