mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 14:54:05 +00:00
Disable global state that modifies eval while resolving a specific (#7923)
We set the `declaring_impl_decls` state to modify the evaluation of LookupImplWitness instructions formed inside an `impl as` decl's constraint. However while checking that constraint, we may form other specifics through calls to generic classes, etc. Specifics are canonical and are keyed by their arguments and the generic ID. This means every time we see the same arguments for a specific, we must produce the same instructions. The `declaring_impl_decls` state can break that, causing instructions inside the specific to be formed in a way they wouldn't at another time. To fix this, remove the effect of `declaring_impl_decls` while resolving a specific. This keeps the specific's evaluation consistent so that the key truly represents the canonical specific for its arguments. This doesn't break anything. Existing LookupImplWitnesses (such as in a class decl) are not guaranteed to point to an `impl as` when they are modified by a specific. It is designators in the `impl as` constraint that are guaranteed as such. Designators in an `extend require impls` statement in a named constraint will be pointed to the `impl as` through another mechanism in a followup, which will make the `impl_as_named_constraint.carbon` test pass again.
This commit is contained in:
1 parent
1429d1566e
commit
71af207401
2 files changed
+54
-1
No files matched your search
@@ -3588,6 +3588,14 @@ auto TryEvalBlockForSpecific(Context& context, SemIR::LocId loc_id,
|
||||
builder.Context(loc_id, ResolvingSpecificHere, specific_id);
|
||||
});
|
||||
|
||||
// The `declaring_impl_decls` is a global state that modifies the evaluation
|
||||
// of LookupImplWitness. As a global state, it should only affect new
|
||||
// instructions introduced during a given state. When we are evaluating for a
|
||||
// specific, we are resolving existing instructions in the eval block for a
|
||||
// generic. The global state should not apply to anything done while resolving
|
||||
// a specific.
|
||||
auto declaring = std::exchange(context.declaring_impl_decls(), {});
|
||||
|
||||
for (auto [i, inst_id, result_id] :
|
||||
llvm::enumerate(eval_block, value_block)) {
|
||||
auto const_id = TryEvalInstInContext(eval_context, inst_id,
|
||||
@@ -3599,6 +3607,9 @@ auto TryEvalBlockForSpecific(Context& context, SemIR::LocId loc_id,
|
||||
}
|
||||
result_id = context.constant_values().GetInstId(const_id);
|
||||
}
|
||||
|
||||
CARBON_CHECK(context.declaring_impl_decls().empty());
|
||||
context.declaring_impl_decls() = std::move(declaring);
|
||||
}
|
||||
|
||||
// Information about the function call we are currently executing. Unlike
|
||||
|
||||
Reference in new issue
Block a user