Просмотр исходного кода

Add more output in dump for generics, impls (#5190)

Dana Jansens 1 год назад
Родитель
Сommit
1d7d78c6da
3 измененных файлов с 33 добавлено и 6 удалено
  1. 7 0
      toolchain/check/dump.cpp
  2. 24 5
      toolchain/sem_ir/dump.cpp
  3. 2 1
      toolchain/sem_ir/impl.h

+ 7 - 0
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,

+ 24 - 5
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)

+ 2 - 1
toolchain/sem_ir/impl.h

@@ -49,7 +49,8 @@ struct Impl : public EntityWithParamsBase,
               public ImplFields,
               public Printable<Impl> {
   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