Skip to content

Remove PartialOrd/Ord impls for DefId and CrateNum #83006

@Aaron1011

Description

@Aaron1011
Member

Both DefId and CrateNum are not stable across compilation sessions - the associated DefPathHash is a stable cross-session ID. However, both DefId and CrateNum have Ord impls, which makes it easy to accidentally sort something by the unstable DefID/CrateNum value. If this sorted result makes its way into a query result, it can lead to unstable hash values across compilation sessions. See #82920 for an example of this occuring.

My initial attempt to remove these impls encountered a large number of usages across multiple crates.

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 11, 2021
added
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.
on Mar 12, 2021
JohnTitor

JohnTitor commented on Jun 19, 2021

@JohnTitor
Member

#85829 refactored CrateNum so DefId is the only item here.

My initial attempt to remove these impls encountered a large number of usages across multiple crates.

Hmm, yes, for example, we use DefId within BTreeMap or FxHashMap. So, is the rough fix to store DefPathHash instead of it?

pierwill

pierwill commented on Nov 5, 2021

@pierwill
Member

@rustbot claim

pierwill

pierwill commented on Nov 5, 2021

@pierwill
Member

This issue is part of #90317.

pierwill

pierwill commented on Nov 5, 2021

@pierwill
Member

@Aaron1011 Looks like we can close this in favor of #90317, yes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-incr-compArea: Incremental compilationC-cleanupCategory: PRs that clean code up or issues documenting cleanup.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

      Participants

      @Aaron1011@jonas-schievink@pierwill@JohnTitor@camelid

      Issue actions

        Remove `PartialOrd`/`Ord` impls for `DefId` and `CrateNum` · Issue #83006 · rust-lang/rust