mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 11:50:13 +01:00
EvalOrAddInst has to create a non-canonical instruction for evaluating a few typed insts, such as LookupImplWitness which uses an InstId to provide a location for diagnostics. But the output of the function is a ConstantId. We do not have access to the non-canonical InstId after the function returns. But if the constant value was symbolic, it was being attached to the inst, and the inst would be added to the eval block of the enclosing generic. This needlessly added semir for a symbolic value. The ConstantId returned by EvalOrAddInst can be used immediately, such as to evaluate an ImplWitnessAccess. In that case, the final evaluated result is all we need to keep in semir. If the ConstantId needs to be replaced by specifics, it is only as part of some other instruction, since ConstantIds themselves are not modified by specifics, instructions are. In that case, the canonical instruction in the constant value would have been added to some other (now symbolic) instruction, which would be replaced by a specific. This has no functional change, but it reduces runtime overhead and semir output for LookupImplWitness and ImplWitnessAccess.