mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-23 17:02:39 +00:00
New specifics formed during identify need to be marked identified (#8003)
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.
This commit is contained in:
1 parent
2e21255855
commit
eb66bebc35
15 files changed
+323
-155
No files matched your search
@@ -685,8 +685,15 @@ static auto GetConstantValue(EvalContext& eval_context,
|
||||
if (args_id == specific.args_id) {
|
||||
return specific_id;
|
||||
}
|
||||
return eval_context.context().specifics().GetOrAdd(
|
||||
specific.generic_id, args_id, specific.identified);
|
||||
// When modifying a non-`identified` specific during identify, mark the new
|
||||
// specific as `identified` too. If modifying an `identified` specific outside
|
||||
// of identify, it may contain `IdentifiedWitness` insts so the new specific
|
||||
// must keep the `identified` marker.
|
||||
bool identified =
|
||||
eval_context.context().eval_impl_lookup_to_identified_witness() ||
|
||||
specific.identified;
|
||||
return eval_context.context().specifics().GetOrAdd(specific.generic_id,
|
||||
args_id, identified);
|
||||
}
|
||||
|
||||
static auto GetConstantValue(EvalContext& eval_context,
|
||||
|
||||
Reference in new issue
Block a user