mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 09:58:10 +00:00
When a facet type contains a rewrite constraint like `.(J.J1).(I.I1)` the ImplWitnessAccess should only use its RHS value if it's trying to find `.(J.J1).(I.I1)`. It can't just look at the `.(I.I1)` part or it may grab the RHS for a similar `.(K.K2).(I.I1)` rewrite. While it's not possible to write a nested access on the LHS of a rewrite constraint like `.(J.J1).(I.I1)`, it is possible to construct a facet type that ends up with that as its rewrite using nested facet types: ```carbon T:! J where .J1 impls (I where .I1 = ()) ``` The access `T.(J.J1).(I.I1)` should evaluate to `()`. The ImplWitnessAccess evaluation starts by looking for a rewrite of `.(I.I1)` in the type of the access self, which is `T.(J.J1)`. Then it looks for `.(I.I1)` in the type of that access self, which is `T`. At that point it finds the rewrite of `.(J.J1).(I.I1) = ()` and can use the `()`. However it can also find other rewrites that end in `.(I.I1)`. To do this correctly, when moving through an ImplWitnessAccess to the next nested access self, we record the access (interface, element) pair that we are looking through. And then we require the rewrite constraint to be prefixed by all of the (interface, element) pairs that we have recorded.