Skip to content

Generalize StableHashingContext as a trait #53084

Open
@brunocodutra

Description

@brunocodutra

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 AllocIds 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 AllocIds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions