Description
Background
PR #52475 improves the infinite loop detection algorithm during compile time evaluation, the algorithm relies on HashStable
to detect whether two evaluation contexts are potentially identical as an optimization to avoid unnecessarily cloning the entire evaluation context.
The Problem
The current implementation of HashStable
throughout the compiler relies on a hashing context represented by StableHashingContext
. This context however provides no way to resolve AllocId
s to Allocations
, so the implementation of HashStable
for AllocId
relies on the
global TyCtxt::alloc_map
, thus bypassing the current transient allocations in Memory
. This has the inconvenient side effect of increasing the probability of hash conflicts, thus increasing the probability of unnecessarily cloning the evaluation context.
The Solution
@oli-obk suggested StableHashingContext
could be generalized as a trait that could be implemented for Memory
, which would provide a way to directly resolve AllocId
s.