mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 23:18:14 +00:00
We were explicitly marking the specifics of `require` decls as `identified` when creating them during identify. But the require may contain calls to other generics internally. And forming the specific for the `require` can also form new specifics for those calls, if they depend on `Self`. The resulting specific can have `IdentifiedWitness` instructions in its arguments, in accesses or FacetValues, etc. Or they may appear in the decl block as it's resolved. So it's very important that the specifics be marked `identified`, as those witnesses may only appear in `identified` specifics. This allows the new `access_through_nested_specific_in_named_constraint.carbon` test to succeed without any poisoning errors. SemIR formatting is changed so that `identified` specifics are more clearly differentiated where they are used, so that we can see if `identified` specifics are misused outside of identifying. Now that we construct more `identified` specifics, we also need to ensure we remove the `identified` state from specifics that come out of `EvaluateIdentifiedWitnesses` and `SubstIdentifiedWitnesses`. To do that we add a new callback method on `SubstInstCallbacks` that we use to build specifics during subst. Then during those operations, we drop the `identified` flag from any specific that we form, because we know that we have also removed any `IdentifiedWitness` instructions because: - We replace them all from arguments during subst. - We CHECK that we're not in the middle of identifying before starting the subst. However now an `IdentifiedFacetType` is not fully deduped, because it may contain a non-identified specific that comes from a `DeclaredFacetType` along with an identified specific that comes from a named constraint, where they have the same arguments. That results in the `IdentifiedFacetType` having two specific interfaces when it really only refers to one. The `fail_todo_impl_as_constraint_duplicates_interface.carbon` test demonstrates this, and that we then diagnose an `impl` as invalid since we find more than one specific interface being extended. To fix this we need to dedupe and count specific interfaces _after_ substituting/evaluating away the IdentifiedWitnesses. This is left to future work.