From 1d7d78c6dac770060787a1d46bbb59dcc7d77863 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 26 Mar 2025 15:59:32 -0700 Subject: [PATCH] Add more output in dump for generics, impls (#5190) --- toolchain/check/dump.cpp | 7 +++++++ toolchain/sem_ir/dump.cpp | 29 ++++++++++++++++++++++++----- toolchain/sem_ir/impl.h | 3 ++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/toolchain/check/dump.cpp b/toolchain/check/dump.cpp index 330251b256c4..3abeea2c0381 100644 --- a/toolchain/check/dump.cpp +++ b/toolchain/check/dump.cpp @@ -99,6 +99,13 @@ LLVM_DUMP_METHOD static auto Dump(const Context& context, LLVM_DUMP_METHOD static auto Dump(const Context& context, SemIR::ImplId impl_id) -> void { SemIR::Dump(context.sem_ir(), impl_id); + if (impl_id.has_value()) { + const auto& impl = context.sem_ir().impls().Get(impl_id); + auto loc_id = context.sem_ir().insts().GetLocId(impl.witness_id); + llvm::errs() << "witness loc: "; + DumpNoNewline(context, loc_id); + llvm::errs() << '\n'; + } } LLVM_DUMP_METHOD static auto Dump(const Context& context, diff --git a/toolchain/sem_ir/dump.cpp b/toolchain/sem_ir/dump.cpp index c80be9363c80..5cc8eb3690cc 100644 --- a/toolchain/sem_ir/dump.cpp +++ b/toolchain/sem_ir/dump.cpp @@ -19,6 +19,9 @@ static auto DumpNameIfValid(const File& file, NameId name_id) -> void { static auto DumpNoNewline(const File& file, ConstantId const_id) -> void { llvm::errs() << const_id; + if (!const_id.has_value()) { + return; + } if (const_id.is_symbolic()) { llvm::errs() << ": " << file.constant_values().GetSymbolicConstant(const_id); @@ -121,18 +124,34 @@ LLVM_DUMP_METHOD auto Dump(const File& file, FunctionId function_id) -> void { LLVM_DUMP_METHOD auto Dump(const File& file, GenericId generic_id) -> void { llvm::errs() << generic_id; - if (generic_id.has_value()) { - llvm::errs() << ": " << file.generics().Get(generic_id); + if (!generic_id.has_value()) { + llvm::errs() << '\n'; + return; } - llvm::errs() << '\n'; + llvm::errs() << ": " << file.generics().Get(generic_id) << '\n'; + Dump(file, file.generics().Get(generic_id).bindings_id); } LLVM_DUMP_METHOD auto Dump(const File& file, ImplId impl_id) -> void { llvm::errs() << impl_id; - if (impl_id.has_value()) { - llvm::errs() << ": " << file.impls().Get(impl_id); + if (!impl_id.has_value()) { + llvm::errs() << '\n'; + return; } + + const auto& impl = file.impls().Get(impl_id); + llvm::errs() << ": " << impl << '\n'; + llvm::errs() << " - interface_id: "; + DumpNoNewline(file, impl.interface.interface_id); llvm::errs() << '\n'; + llvm::errs() << " - specific_id: "; + DumpNoNewline(file, impl.interface.specific_id); + llvm::errs() << '\n'; + if (impl.interface.specific_id.has_value()) { + auto inst_block_id = + file.specifics().Get(impl.interface.specific_id).args_id; + Dump(file, inst_block_id); + } } LLVM_DUMP_METHOD auto Dump(const File& file, InstBlockId inst_block_id) diff --git a/toolchain/sem_ir/impl.h b/toolchain/sem_ir/impl.h index 6c006190c043..ed39f488c082 100644 --- a/toolchain/sem_ir/impl.h +++ b/toolchain/sem_ir/impl.h @@ -49,7 +49,8 @@ struct Impl : public EntityWithParamsBase, public ImplFields, public Printable { auto Print(llvm::raw_ostream& out) const -> void { - out << "{self: " << self_id << ", constraint: " << constraint_id << "}"; + out << "{self: " << self_id << ", constraint: " << constraint_id + << ", witness: " << witness_id << "}"; } // Determines whether this impl has been fully defined. This is false until we