mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:54:41 +01:00
Add an EvalOrAddInst function. (#5258)
Use that instead of `AddInstInNoBlock` to get the value of an instruction when evaluation might depend on the `InstId` but only the `ConstantId` of the instruction is desired by the consumer.
This commit is contained in:
@@ -405,15 +405,13 @@ class SubstConstantCallbacks final : public SubstInstCallbacks {
|
||||
// Rebuilds an instruction by building a new constant.
|
||||
auto Rebuild(SemIR::InstId old_inst_id, SemIR::Inst new_inst) const
|
||||
-> SemIR::InstId override {
|
||||
auto result_id = GetOrAddInst(
|
||||
auto const_id = EvalOrAddInst(
|
||||
*context_,
|
||||
SemIR::LocIdAndInst::UncheckedLoc(
|
||||
context_->insts().GetLocId(old_inst_id).ToImplicit(), new_inst));
|
||||
auto const_inst_id =
|
||||
context_->constant_values().GetConstantInstId(result_id);
|
||||
CARBON_CHECK(const_inst_id.has_value(),
|
||||
CARBON_CHECK(const_id.has_value(),
|
||||
"Substitution into constant produced non-constant");
|
||||
return const_inst_id;
|
||||
return context_->constant_values().GetInstId(const_id);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user