mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
During impl lookup, for each (generic) impl candidate, we form a specific for that impl by deducing its generic arguments. Then we compare the query interface against the impl's specific interface. That comparison needs the deduced arguments applied to the impl's specific interface. Previously we were doing this by getting the impl's constraint facet type with the impl's specific applied (via `GetConstantValueInSpecific()`) and then identifying that facet type with the impl's deduced self. Identify is a fairly expensive operation. It runs subst, trying to replace `.Self` references. It walks named constraints. It collects require declarations. We're looking at making it do _more_ in the future too, including rewrite constraint resolution and collecting rewrite and same-type constraints. For this reason we have a cache to make it cheap on the second run, but it's still a very heavyweight operation to involve in impl lookup, when all we want is to apply the impl's specific to its target interface. We almost have all the information we need to avoid the identification step. We have the impl's specific after deduction. And we have the SpecificInterface that the impl is targeting in the `Impl` struct. When we form the specific for the impl itself, we resolve the declaration block and form new constant values for all instructions in there, but that does not cover the SpecificInterface that we're storing in the `Impl` struct. So we add a new instruction to the impl's eval block, which will be symbolic when the impl is generic and the target interface depends on a generic parameter. And we store the `InstId` in the `Impl` struct. This allows us to gets its constant value later with the impl's specific applied. From that constant value we can then pull out the SpecificInterface that the impl is targeting.