Skip to content

Commit 87fbd78

Browse files
committed
Auto merge of rust-lang#122974 - fmease:rustdoc-auto-trait-experiments, r=<try>
[perf-only] rustdoc: synthetic impls: auto traits: Fx{Hash↦Index}{Map,Set} Part of rust-lang#119597 and rust-lang#113015. r? ghost
2 parents 9b8d12c + 814797d commit 87fbd78

File tree

7 files changed

+70
-152
lines changed

7 files changed

+70
-152
lines changed

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use rustc_infer::infer::DefineOpaqueTypes;
1010
use rustc_middle::mir::interpret::ErrorHandled;
1111
use rustc_middle::ty::{Region, RegionVid};
1212

13-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
13+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet, IndexEntry};
1414

15-
use std::collections::hash_map::Entry;
1615
use std::collections::VecDeque;
1716
use std::iter;
1817

@@ -35,17 +34,10 @@ pub enum AutoTraitResult<A> {
3534
NegativeImpl,
3635
}
3736

38-
#[allow(dead_code)]
39-
impl<A> AutoTraitResult<A> {
40-
fn is_auto(&self) -> bool {
41-
matches!(self, AutoTraitResult::PositiveImpl(_) | AutoTraitResult::NegativeImpl)
42-
}
43-
}
44-
4537
pub struct AutoTraitInfo<'cx> {
4638
pub full_user_env: ty::ParamEnv<'cx>,
4739
pub region_data: RegionConstraintData<'cx>,
48-
pub vid_to_region: FxHashMap<ty::RegionVid, ty::Region<'cx>>,
40+
pub vid_to_region: FxIndexMap<ty::RegionVid, ty::Region<'cx>>,
4941
}
5042

5143
pub struct AutoTraitFinder<'tcx> {
@@ -114,7 +106,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
114106
}
115107

116108
let infcx = tcx.infer_ctxt().build();
117-
let mut fresh_preds = FxHashSet::default();
109+
let mut fresh_preds = FxIndexSet::default();
118110

119111
// Due to the way projections are handled by SelectionContext, we need to run
120112
// evaluate_predicates twice: once on the original param env, and once on the result of
@@ -239,7 +231,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
239231
ty: Ty<'tcx>,
240232
param_env: ty::ParamEnv<'tcx>,
241233
user_env: ty::ParamEnv<'tcx>,
242-
fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
234+
fresh_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
243235
) -> Option<(ty::ParamEnv<'tcx>, ty::ParamEnv<'tcx>)> {
244236
let tcx = infcx.tcx;
245237

@@ -252,7 +244,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
252244

253245
let mut select = SelectionContext::new(infcx);
254246

255-
let mut already_visited = FxHashSet::default();
247+
let mut already_visited = FxHashSet::default(); // NOTE(fmease): not used for iteration
256248
let mut predicates = VecDeque::new();
257249
predicates.push_back(ty::Binder::dummy(ty::TraitPredicate {
258250
trait_ref: ty::TraitRef::new(infcx.tcx, trait_did, [ty]),
@@ -473,9 +465,9 @@ impl<'tcx> AutoTraitFinder<'tcx> {
473465
fn map_vid_to_region<'cx>(
474466
&self,
475467
regions: &RegionConstraintData<'cx>,
476-
) -> FxHashMap<ty::RegionVid, ty::Region<'cx>> {
477-
let mut vid_map: FxHashMap<RegionTarget<'cx>, RegionDeps<'cx>> = FxHashMap::default();
478-
let mut finished_map = FxHashMap::default();
468+
) -> FxIndexMap<ty::RegionVid, ty::Region<'cx>> {
469+
let mut vid_map = FxIndexMap::<RegionTarget<'cx>, RegionDeps<'cx>>::default();
470+
let mut finished_map = FxIndexMap::default();
479471

480472
for (constraint, _) in &regions.constraints {
481473
match constraint {
@@ -513,22 +505,22 @@ impl<'tcx> AutoTraitFinder<'tcx> {
513505
}
514506

515507
while !vid_map.is_empty() {
516-
#[allow(rustc::potential_query_instability)]
517508
let target = *vid_map.keys().next().expect("Keys somehow empty");
518-
let deps = vid_map.remove(&target).expect("Entry somehow missing");
509+
// FIXME(#120456) - is `swap_remove` correct?
510+
let deps = vid_map.swap_remove(&target).expect("Entry somehow missing");
519511

520512
for smaller in deps.smaller.iter() {
521513
for larger in deps.larger.iter() {
522514
match (smaller, larger) {
523515
(&RegionTarget::Region(_), &RegionTarget::Region(_)) => {
524-
if let Entry::Occupied(v) = vid_map.entry(*smaller) {
516+
if let IndexEntry::Occupied(v) = vid_map.entry(*smaller) {
525517
let smaller_deps = v.into_mut();
526518
smaller_deps.larger.insert(*larger);
527519
// FIXME(#120456) - is `swap_remove` correct?
528520
smaller_deps.larger.swap_remove(&target);
529521
}
530522

531-
if let Entry::Occupied(v) = vid_map.entry(*larger) {
523+
if let IndexEntry::Occupied(v) = vid_map.entry(*larger) {
532524
let larger_deps = v.into_mut();
533525
larger_deps.smaller.insert(*smaller);
534526
// FIXME(#120456) - is `swap_remove` correct?
@@ -542,14 +534,14 @@ impl<'tcx> AutoTraitFinder<'tcx> {
542534
// Do nothing; we don't care about regions that are smaller than vids.
543535
}
544536
(&RegionTarget::RegionVid(_), &RegionTarget::RegionVid(_)) => {
545-
if let Entry::Occupied(v) = vid_map.entry(*smaller) {
537+
if let IndexEntry::Occupied(v) = vid_map.entry(*smaller) {
546538
let smaller_deps = v.into_mut();
547539
smaller_deps.larger.insert(*larger);
548540
// FIXME(#120456) - is `swap_remove` correct?
549541
smaller_deps.larger.swap_remove(&target);
550542
}
551543

552-
if let Entry::Occupied(v) = vid_map.entry(*larger) {
544+
if let IndexEntry::Occupied(v) = vid_map.entry(*larger) {
553545
let larger_deps = v.into_mut();
554546
larger_deps.smaller.insert(*smaller);
555547
// FIXME(#120456) - is `swap_remove` correct?
@@ -560,6 +552,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
560552
}
561553
}
562554
}
555+
563556
finished_map
564557
}
565558

@@ -588,7 +581,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
588581
ty: Ty<'_>,
589582
nested: impl Iterator<Item = PredicateObligation<'tcx>>,
590583
computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
591-
fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
584+
fresh_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
592585
predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>,
593586
selcx: &mut SelectionContext<'_, 'tcx>,
594587
) -> bool {

0 commit comments

Comments
 (0)