Remove offsets from InstId formatting, trying to name more (#4645)

The offsets were originally added to deal with churn from builtins in
the raw semir. In textual semir, we mostly see instruction IDs for
imports, and builtins have also settled down more.

On imports, where possible, use the `EntityNameId` for an import instead
of printing an instruction. Next, show the source location if we have a
node. Only show the instruction if there's no location.

This also exposes `Parse::Tree` and `TokenizedBuffer`, so that we can
pass a `SemIR::File` without the component parts. In particular this
allows us to get the `TokenizedBuffer` for import IRs without
substantial structural modifications. We may want to make these optional
for serialized `SemIR` later, but the nodes/tokens contain source
location, which we'd need for debug information -- so it's not clear how
much we can really make them optional without substantial information
loss.

Reduce arguments to just `File` in a few spots, as a result of the
accompanying `TokenizedBuffer` and `Parse::Tree`. Also updates style to
pass around `const File*` where the reference is maintained, instead of
`const File&`.

I was considering keeping a direct reference to the tree and tokens on
`Context`, but initially my thought was it wouldn't make much
difference. I can re-add those if desired, just as direct caching of the
`File` fields.
This commit is contained in:
Jon Ross-Perkins
2024-12-06 21:17:24 +00:00
committed by GitHub
parent a2c939a2a2
commit e7a86b03c6
148 changed files with 2171 additions and 2173 deletions
+4 -7
View File
@@ -440,8 +440,8 @@ class CompilationUnit {
CARBON_CHECK(node_converter_, "Must call PreCheck first");
CARBON_CHECK(!sem_ir_converter_, "Called GetCheckUnit twice");
sem_ir_.emplace(check_ir_id, parse_tree_->packaging_decl(), value_stores_,
input_filename_);
sem_ir_.emplace(&*parse_tree_, check_ir_id, parse_tree_->packaging_decl(),
value_stores_, input_filename_);
if (mem_usage_) {
mem_usage_->Collect("sem_ir_", *sem_ir_);
}
@@ -450,8 +450,6 @@ class CompilationUnit {
return {.consumer = consumer_,
.value_stores = &value_stores_,
.timings = timings_ ? &*timings_ : nullptr,
.tokens = &*tokens_,
.parse_tree = &*parse_tree_,
.get_parse_tree_and_subtrees = *get_parse_tree_and_subtrees_,
.sem_ir = &*sem_ir_,
.node_converter = &*node_converter_,
@@ -500,8 +498,7 @@ class CompilationUnit {
}
};
SemIR::Formatter formatter(*tokens_, *parse_tree_, *sem_ir_,
should_format_entity);
SemIR::Formatter formatter(&*sem_ir_, should_format_entity);
if (vlog_stream_) {
CARBON_VLOG("*** SemIR::File ***\n");
formatter.Print(*vlog_stream_);
@@ -524,7 +521,7 @@ class CompilationUnit {
llvm_context_ = std::make_unique<llvm::LLVMContext>();
// TODO: Consider disabling instruction naming by default if we're not
// producing textual LLVM IR.
SemIR::InstNamer inst_namer(*tokens_, *parse_tree_, *sem_ir_);
SemIR::InstNamer inst_namer(&*sem_ir_);
module_ = Lower::LowerToLLVM(*llvm_context_, options_.include_debug_info,
*sem_ir_converter_, input_filename_,
*sem_ir_, &inst_namer, vlog_stream_);