mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 22:02:51 +01:00
Reduce the size of formatted SemIR. (#4534)
- Do not include entities imported from files that we are not dumping. - Do not include constants and import_refs that are not referenced by something that we are including in the formatted output. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
Carbon Infra Bot
parent
3c18a6c477
commit
4ee65ef58a
@@ -455,7 +455,22 @@ class CompilationUnit {
|
||||
|
||||
bool print = options_.dump_sem_ir && IncludeInDumps();
|
||||
if (vlog_stream_ || print) {
|
||||
SemIR::Formatter formatter(*tokens_, *parse_tree_, *sem_ir_);
|
||||
// Omit entities imported from files that we are not dumping.
|
||||
auto should_format_entity = [&](SemIR::InstId entity_inst_id) -> bool {
|
||||
auto loc_id = sem_ir_->insts().GetLocId(entity_inst_id);
|
||||
if (!loc_id.is_import_ir_inst_id()) {
|
||||
return true;
|
||||
}
|
||||
auto import_ir_id =
|
||||
sem_ir_->import_ir_insts().Get(loc_id.import_ir_inst_id()).ir_id;
|
||||
const auto* import_file =
|
||||
sem_ir_->import_irs().Get(import_ir_id).sem_ir;
|
||||
CARBON_CHECK(import_file);
|
||||
return IncludeInDumps(import_file->filename());
|
||||
};
|
||||
|
||||
SemIR::Formatter formatter(*tokens_, *parse_tree_, *sem_ir_,
|
||||
should_format_entity);
|
||||
if (vlog_stream_) {
|
||||
CARBON_VLOG("*** SemIR::File ***\n");
|
||||
formatter.Print(*vlog_stream_);
|
||||
@@ -624,10 +639,15 @@ class CompilationUnit {
|
||||
CARBON_VLOG("*** {0} done ***\n", logging_label);
|
||||
}
|
||||
|
||||
// Returns true if the file can be dumped.
|
||||
// Returns true if the current input file can be dumped.
|
||||
auto IncludeInDumps() const -> bool {
|
||||
return IncludeInDumps(input_filename_);
|
||||
}
|
||||
|
||||
// Returns true if the specified input file can be dumped.
|
||||
auto IncludeInDumps(llvm::StringRef filename) const -> bool {
|
||||
return options_.exclude_dump_file_prefix.empty() ||
|
||||
!input_filename_.starts_with(options_.exclude_dump_file_prefix);
|
||||
!filename.starts_with(options_.exclude_dump_file_prefix);
|
||||
}
|
||||
|
||||
DriverEnv* driver_env_;
|
||||
|
||||
Reference in New Issue
Block a user