Repository: carbon-language/carbon-lang
File: toolchain/lower/context.cpp (C++)

Code before:
  auto insert_result = file_contexts_.Insert(file->check_ir_id(), [&] {
    auto file_context =
        std::make_unique<FileContext>(*this, *file, inst_namer, vlog_stream_);
    file_context->PrepareToLower();
    return file_context;
  });
  return *insert_result.value();
}

auto Context::LowerPendingDefinitions() -> void {
  // Lower function definitions for generics.
  for (auto [file_context, function_id, specific_id] :
       GrowingRange(specific_function_definitions_)) {
    file_context->BuildFunctionDefinition(function_id, specific_id);
  }
}

auto Context::Finalize() && -> std::unique_ptr<llvm::Module> {
  LowerPendingDefinitions();

  file_contexts_.ForEach(
      [](auto, auto& file_context) { file_context->Finalize(); });

  RawStringOstream errs;
  CARBON_CHECK(!llvm::verifyModule(*llvm_module_, &errs),
               "Verifier errors: {0}", errs.TakeStr());
  return std::move(llvm_module_);
}

auto Context::BuildDICompileUnit(llvm::StringRef module_name,
                                 llvm::Module& llvm_module,
                                 llvm::DIBuilder& di_builder)
    -> llvm::DICompileUnit* {
  llvm_module.addModuleFlag(llvm::Module::Max, "Dwarf Version", 5);
  llvm_module.addModuleFlag(llvm::Module::Warning, "Debug Info Version",
                            llvm::DEBUG_METADATA_VERSION);
  // TODO: Include directory path in the compile_unit_file.
  llvm::DIFile* compile_unit_file = di_builder.createFile(module_name, "");
  // TODO: Introduce a new language code for Carbon. C works well for now since
  // it's something debuggers will already know/have support for at least.
  // Probably have to bump to C++ at some point for virtual functions,
  // templates, etc.
  return di_builder.createCompileUnit(llvm::dwarf::DW_LANG_C, compile_unit_file,
                                      "carbon",
                                      /*isOptimized=*/false, /*Flags=*/"",
                                      /*RV=*/0);
}

auto Context::GetLocForDI(SemIR::AbsoluteNodeId abs_node_id) -> LocForDI {
  const auto& tree_and_subtrees =
      tree_and_subtrees_getters()[abs_node_id.check_ir_id().index]();

Review comment (suggestion):
```suggestion
               "Verifier errors:\n{0}", errs.TakeStr());
```

Code after:
  auto insert_result = file_contexts_.Insert(file->check_ir_id(), [&] {
    auto file_context =
        std::make_unique<FileContext>(*this, *file, inst_namer, vlog_stream_);
    file_context->PrepareToLower();
    return file_context;
  });
  return *insert_result.value();
}

auto Context::LowerPendingDefinitions() -> void {
  // Lower function definitions for generics.
  for (auto [file_context, function_id, specific_id] :
       GrowingRange(specific_function_definitions_)) {
    file_context->BuildFunctionDefinition(function_id, specific_id);
  }
}

auto Context::Finalize(
    llvm::raw_ostream*
        llvm_verifier_stream) && -> std::unique_ptr<llvm::Module> {
  LowerPendingDefinitions();

  file_contexts_.ForEach(
      [](auto, auto& file_context) { file_context->Finalize(); });

  if (llvm_verifier_stream) {
    CARBON_CHECK(!llvm::verifyModule(*llvm_module_, llvm_verifier_stream));
  }
  return std::move(llvm_module_);
}

auto Context::BuildDICompileUnit(llvm::StringRef module_name,
                                 llvm::Module& llvm_module,
                                 llvm::DIBuilder& di_builder)
    -> llvm::DICompileUnit* {
  llvm_module.addModuleFlag(llvm::Module::Max, "Dwarf Version", 5);
  llvm_module.addModuleFlag(llvm::Module::Warning, "Debug Info Version",
                            llvm::DEBUG_METADATA_VERSION);
  // TODO: Include directory path in the compile_unit_file.
  llvm::DIFile* compile_unit_file = di_builder.createFile(module_name, "");
  // TODO: Introduce a new language code for Carbon. C works well for now since
  // it's something debuggers will already know/have support for at least.
  // Probably have to bump to C++ at some point for virtual functions,
  // templates, etc.
  return di_builder.createCompileUnit(llvm::dwarf::DW_LANG_C, compile_unit_file,
                                      "carbon",
                                      /*isOptimized=*/false, /*Flags=*/"",
                                      /*RV=*/0);
}

auto Context::GetLocForDI(SemIR::AbsoluteNodeId abs_node_id) -> LocForDI {