-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove PartialOrd
, Ord
from DefId
#90749
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @cjgillot |
This comment has been minimized.
This comment has been minimized.
a3fcf2c
to
8ede793
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #89550) made this pull request unmergeable. Please resolve the merge conflicts. |
9328f94
to
84c3a03
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6024b94
to
200894f
Compare
This comment has been minimized.
This comment has been minimized.
PartialOrd
, Ord
from DefId
PartialOrd
, Ord
from DefId
☔ The latest upstream changes (presumably #90423) made this pull request unmergeable. Please resolve the merge conflicts. |
200894f
to
8a04b94
Compare
This comment has been minimized.
This comment has been minimized.
@rustbot author |
☔ The latest upstream changes (presumably #91924) made this pull request unmergeable. Please resolve the merge conflicts. |
@rustbot ready I suspect that many of the errors are from removing the various calls to In an earlier iteration of this PR, I tried just replacing everything in sight with Update: I tested each of the calls to |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @pierwill, I expected much less use of these ordering impls.
Could you please reorder/remix your commits into commits that pass x.py check
? This makes it much easier to review and to better see the consequences of each modification.
The main concern is the iteration order in each place where we replace a BTree
by a hash-map.
You can use the internal lint (lint has been removed)rustc::potential_query_instability
to help finding such issues.
@@ -744,12 +743,12 @@ impl<'tcx> TyCtxt<'tcx> { | |||
self, | |||
value: Binder<'tcx, T>, | |||
mut fld_r: F, | |||
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>) | |||
) -> (T, FxHashMap<ty::BoundRegion, ty::Region<'tcx>>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this FxHashMap used anyhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not? 👀 🤔 I'm not entirely sure how to check. The lsp-find-references
command in Emacs shows several places where the returned map is ignored:
compiler/rustc_borrowck/src/universal_regions.rs
736: let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| {
compiler/rustc_middle/src/ty/fold.rs
821: self.replace_late_bound_regions(value, |br| {
911: self.replace_late_bound_regions(value, |_| self.lifetimes.re_erased).0
928: .replace_late_bound_regions(sig, |_| {
compiler/rustc_middle/src/ty/print/pretty.rs
2160: self.tcx.replace_late_bound_regions(value.clone(), |br| {
compiler/rustc_typeck/src/collect.rs
457: .replace_late_bound_regions(poly_trait_ref, |_| {
@@ -796,14 +795,14 @@ impl<'tcx> TyCtxt<'tcx> { | |||
mut fld_r: F, | |||
fld_t: G, | |||
fld_c: H, | |||
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>) | |||
) -> (T, FxHashMap<ty::BoundRegion, ty::Region<'tcx>>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does any use site rely on the iteration order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here?
for &late_bound_region in map.values() { |
@@ -946,7 +945,10 @@ pub trait PrettyPrinter<'tcx>: | |||
&mut self, | |||
trait_ref: ty::PolyTraitRef<'tcx>, | |||
proj_ty: Option<(DefId, ty::Binder<'tcx, Ty<'tcx>>)>, | |||
traits: &mut FxHashMap<ty::PolyTraitRef<'tcx>, BTreeMap<DefId, ty::Binder<'tcx, Ty<'tcx>>>>, | |||
traits: &mut FxHashMap< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this FxHashMap used? Does any code depend on the iteration order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This map is used in two places:
self.insert_trait_and_projection(trait_ref, None, &mut traits, &mut fn_traits); rust/compiler/rustc_middle/src/ty/print/pretty.rs
Lines 806 to 807 in 181e915
self.insert_trait_and_projection( trait_ref,
traits: &mut FxHashMap<ty::PolyTraitRef<'tcx>, BTreeMap<DefId, ty::Binder<'tcx, Ty<'tcx>>>>, | ||
traits: &mut FxHashMap< | ||
ty::PolyTraitRef<'tcx>, | ||
FxHashMap<DefId, ty::Binder<'tcx, Ty<'tcx>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used in the same calls as above #90749 (comment).
@@ -90,7 +89,7 @@ pub type VarInfos = IndexVec<RegionVid, RegionVariableInfo>; | |||
pub struct RegionConstraintData<'tcx> { | |||
/// Constraints of the form `A <= B`, where either `A` or `B` can | |||
/// be a region variable (or neither, as it happens). | |||
pub constraints: BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>, | |||
pub constraints: FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does any code depend on the iteration order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes:
for (idx, (constraint, _)) in self.data.constraints.iter().enumerate() { for constraint in self.data.constraints.keys() { for (constraint, origin) in &self.data.constraints { for constraint in self.data.constraints.keys() { for constraint in regions.constraints.keys() {
mapped_consts: BTreeMap<ty::PlaceholderConst<'tcx>, ty::BoundVar>, | ||
mapped_regions: FxHashMap<ty::PlaceholderRegion, ty::BoundRegion>, | ||
mapped_types: FxHashMap<ty::PlaceholderType, ty::BoundTy>, | ||
mapped_consts: FxHashMap<ty::PlaceholderConst<'tcx>, ty::BoundVar>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does any code depend on the iteration order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly here?
rust/compiler/rustc_trait_selection/src/traits/project.rs
Lines 464 to 484 in f1ce0e6
let data = data.super_fold_with(self); | |
let normalized_ty = opt_normalize_projection_type( | |
self.selcx, | |
self.param_env, | |
data, | |
self.cause.clone(), | |
self.depth, | |
&mut self.obligations, | |
) | |
.ok() | |
.flatten() | |
.map(|normalized_ty| { | |
PlaceholderReplacer::replace_placeholders( | |
infcx, | |
mapped_regions, | |
mapped_types, | |
mapped_consts, | |
&self.universes, | |
normalized_ty, | |
) | |
}) |
let lhs = (other.def_id.krate, other.def_id); | ||
let rhs = (self.def_id.krate, self.def_id); | ||
let (lhs, _) = (other.def_id.krate, other.def_id); | ||
let (rhs, _) = (self.def_id.krate, self.def_id); | ||
lhs.cmp(&rhs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This impl is wrong and will probably produce surprising results.
We implement Eq
, so we expect a real equality, not just CrateNum
.
Is the PartialOrd
/Ord
bound used? Where? Can we live without?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ordering is used here https://github.com/rust-lang/rust/blob/088dd7cb54f57bd1c870a343cb5dc3d3d2703761/compiler/rustc_typeck/src/check/method/suggest.rs#L1651 and in the PartialEq
implementation: https://github.com/rust-lang/rust/blob/088dd7cb54f57bd1c870a343cb5dc3d3d2703761/compiler/rustc_typeck/src/check/method/suggest.rs#L1906
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the Eq
,PartialEq
are currently used for deduplication: https://github.com/rust-lang/rust/blob/088dd7cb54f57bd1c870a343cb5dc3d3d2703761/compiler/rustc_typeck/src/check/method/suggest.rs#L1652
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it work or defeat our purpose to sort the TraitInfo
s by DefIndex
?
@@ -1338,7 +1337,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { | |||
} | |||
|
|||
// Use a `BTreeSet` to keep output in a more consistent order. | |||
let mut associated_types: FxHashMap<Span, BTreeSet<DefId>> = FxHashMap::default(); | |||
let mut associated_types: FxHashMap<Span, FxHashSet<DefId>> = FxHashMap::default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still rely on the iteration order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes:
rust/compiler/rustc_typeck/src/astconv/mod.rs
Line 1403 in 181e915
for def_ids in associated_types.values_mut() { |
|
||
/// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred | ||
/// must be added to the struct header. | ||
pub type RequiredPredicates<'tcx> = | ||
BTreeMap<ty::OutlivesPredicate<GenericArg<'tcx>, ty::Region<'tcx>>, Span>; | ||
FxHashMap<ty::OutlivesPredicate<GenericArg<'tcx>, ty::Region<'tcx>>, Span>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we rely somewhere on the iteration order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes:
for &(predicate, span) in predicates.predicates { |
a3758d2
to
ef06eda
Compare
This comment has been minimized.
This comment has been minimized.
a415d8e
to
088dd7c
Compare
This comment has been minimized.
This comment has been minimized.
088dd7c
to
a75ba63
Compare
This comment has been minimized.
This comment has been minimized.
a75ba63
to
c600b95
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #92844) made this pull request unmergeable. Please resolve the merge conflicts. |
c600b95
to
2b0b438
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #92805) made this pull request unmergeable. Please resolve the merge conflicts. |
2b0b438
to
9f0d58f
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
Remove some unused `Ord` derives based on `Span` Remove some `Ord`, `PartialOrd` derivations that rely on underlying ordering of `Span`. These ordering traits appear to be unused right now. If we're going to attempt to remove ordering traits from `Span` as suggested in rust-lang#90317 (comment), we might want to slowly remove code that depends on this ordering (as opposed to the all-at-once approach in rust-lang#90749 and rust-lang#90408). cc `@tmiasko` `@cjgillot`
Closing this (for now), as I'm looking at making this change in a series of smaller PRs. |
…gillot Remove some unused ordering derivations based on `DefId` Like rust-lang#93018, this removes some unused/unneeded ordering derivations as part of ongoing work on rust-lang#90317. Here, these changes are aimed at making rust-lang#90749 easier to review, test, and merge. r? `@cjgillot`
Part of work on #90317.