mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 17:18:10 +00:00
The sort and dedupe operations in facet type resolution explicitly work with `ImplWitnessAccess` instructions as being a reference to an associated constant on some entity. If only one of the instructions is an `ImplWitnessAccess`, we still want to consider that one as such, not get its constant value, which may be some concrete type, and use that for comparison instead. This makes the new test fail (which we don't want) in a consistent way with a similar test of TypeAnd (which we also don't want to fail), making the system more consistent, while leaving some improvements to be done. Avoid inconsistent orderings between instructions, by making the comparison function into a total order. To do so, we sort ImplWitnessAccess instructions first, and sort them by their InstId. Non-ImplWitnessAccess instructions come second, and sort them by their constant InstId. Thanks to jonmeow for figuring out that the function was not producing a total order and why. Since this means the order is no longer relative to source order, we order the two assignments in the diagnostic by source order(ish) by putting the lower InstId first in the diagnostic output. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>