mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-22 03:46:42 +00:00
When we find a named constraint during identity, we recurse into it. The specific args of the named constraint may contain references to `.Self` which can then make `.Self` appear inside the named constraint, which was making us replace `.Self` at multiple levels and incorrectly. The first specific argument replaces `Self` in the named constraint, and we pass in the self-type of the identify operation. This may contain `.Self` and we should _not_ be replacing the `.Self` references with the self-type that they are contained within. This led to infinite cycles. In the meantime, we have made the toolchain reject any ambiguous `.Self` from being constructed. So we know there is only one value of `.Self` around in a facet type. So now we replace `.Self` only in the top level facet type during identity. That means replacing `.Self` in the specifics of the named constraints that we recurse into. But we do _not_ replace `.Self` anymore inside those named constraints. This resolves the infinite loop. At the same time, when we are identifying an `impls` constraint from earlier in the same facet type, like `C impls Z(.Self)` we are identifying with a self-type of `C`. We want the output to use `C` as the self-type since we should get back an identified facet type that says `C impls Z(.Self)`. But we do _not_ want to replace the `.Self` there since we're inside a facet type and the `.Self` does not refer to `C`. So we parameterize `TryToIdentifyFacetType` to not replace `.Self` when identifying an `impls` constraint from the `where_stack()`. This resolves a large number of `fail_todo_` tests.