Stop substituting into MetaInstId operands. (#5328)

A `MetaInstId` is intended to represent a handle to an instruction in a
generic as an operand to a template action; substituting into the action
should not substitute into the referenced instruction.

Fixing this exposed a bug in `GetOrAddInst` where it would return an
`InstId` of an unattached symbolic constant in some cases, rather than
the `InstId` of an instruction that has the relevant (attached) constant
value. That's fixed for now by turning off the `GetOrAddInst`
optimization in that case, but in future we can refine this by adding
the instruction to the eval block for the generic only, and not to the
body of the generic.
This commit is contained in:
Richard Smith
2025-04-21 21:19:14 +00:00
committed by GitHub
parent b5ae988a08
commit 64baa84e4d
8 changed files with 76 additions and 31 deletions
+6
View File
@@ -112,6 +112,12 @@ auto GetOrAddInst(Context& context, SemIR::LocIdAndInst loc_id_and_inst)
return SemIR::InstId::None;
}
if (const_id.is_symbolic()) {
// TODO: Only add this instruction to the eval block, and don't
// re-evaluate it.
return AddInst(context, loc_id_and_inst);
}
CARBON_VLOG_TO(context.vlog_stream(), "GetOrAddInst: constant: {0}\n",
loc_id_and_inst.inst);
return context.constant_values().GetInstId(const_id);