Automatically update constant_values() when adding a constant to the constant store. (#3618)

As requested in review of #3611.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2024-01-19 16:09:36 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 9e3c4a3ef1
commit 9bd5fbd25c
3 changed files with 25 additions and 19 deletions
+2 -9
View File
@@ -103,15 +103,8 @@ auto Context::AddPlaceholderInst(SemIR::ParseNodeAndInst parse_node_and_inst)
auto Context::AddConstant(SemIR::Inst inst, bool is_symbolic)
-> SemIR::ConstantId {
auto [inst_id, added] = constants().GetOrAdd(inst);
auto const_id = is_symbolic ? SemIR::ConstantId::ForSymbolicConstant(inst_id)
: SemIR::ConstantId::ForTemplateConstant(inst_id);
if (added) {
// TODO: Should `ConstantStore` do this for us?
constant_values().Set(inst_id, const_id);
}
CARBON_VLOG() << "AddConstantInst: " << inst << "\n";
auto const_id = constants().GetOrAdd(inst, is_symbolic);
CARBON_VLOG() << "AddConstant: " << inst << "\n";
return const_id;
}