Skip to content

Commit 8f9e09a

Browse files
committed
Auto merge of #108735 - clubby789:borrowck-unstable, r=Nilstrieb
Remove `allow(potential_query_instability)` from `borrowck` cc #84447 Replace uses of `FxHash*` with `FxIndex*`. One `#[allow]` for a HashMap in an external crate but the output is sorted afterwards.
2 parents 8824994 + 3eeb3fd commit 8f9e09a

15 files changed

+66
-61
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::nll::ToRegionVid;
44
use crate::path_utils::allow_two_phase_borrow;
55
use crate::place_ext::PlaceExt;
66
use crate::BorrowIndex;
7-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
7+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
88
use rustc_index::bit_set::BitSet;
99
use rustc_middle::mir::traversal;
1010
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
@@ -26,10 +26,10 @@ pub struct BorrowSet<'tcx> {
2626
/// NOTE: a given location may activate more than one borrow in the future
2727
/// when more general two-phase borrow support is introduced, but for now we
2828
/// only need to store one borrow index.
29-
pub activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
29+
pub activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
3030

3131
/// Map from local to all the borrows on that local.
32-
pub local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>,
32+
pub local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
3333

3434
pub(crate) locals_state_at_exit: LocalsStateAtExit,
3535
}
@@ -175,8 +175,8 @@ struct GatherBorrows<'a, 'tcx> {
175175
tcx: TyCtxt<'tcx>,
176176
body: &'a Body<'tcx>,
177177
location_map: FxIndexMap<Location, BorrowData<'tcx>>,
178-
activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
179-
local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>,
178+
activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
179+
local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
180180

181181
/// When we encounter a 2-phase borrow statement, it will always
182182
/// be assigning into a temporary TEMP:
@@ -186,7 +186,7 @@ struct GatherBorrows<'a, 'tcx> {
186186
/// We add TEMP into this map with `b`, where `b` is the index of
187187
/// the borrow. When we find a later use of this activation, we
188188
/// remove from the map (and add to the "tombstone" set below).
189-
pending_activations: FxHashMap<mir::Local, BorrowIndex>,
189+
pending_activations: FxIndexMap<mir::Local, BorrowIndex>,
190190

191191
locals_state_at_exit: LocalsStateAtExit,
192192
}

compiler/rustc_borrowck/src/dataflow.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![deny(rustc::untranslatable_diagnostic)]
22
#![deny(rustc::diagnostic_outside_of_impl)]
3-
use rustc_data_structures::fx::FxHashMap;
3+
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_index::bit_set::BitSet;
55
use rustc_middle::mir::{self, BasicBlock, Body, Location, Place};
66
use rustc_middle::ty::RegionVid;
@@ -124,7 +124,7 @@ pub struct Borrows<'a, 'tcx> {
124124
body: &'a Body<'tcx>,
125125

126126
borrow_set: &'a BorrowSet<'tcx>,
127-
borrows_out_of_scope_at_location: FxHashMap<Location, Vec<BorrowIndex>>,
127+
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
128128
}
129129

130130
struct StackEntry {
@@ -138,7 +138,7 @@ struct OutOfScopePrecomputer<'a, 'tcx> {
138138
visit_stack: Vec<StackEntry>,
139139
body: &'a Body<'tcx>,
140140
regioncx: &'a RegionInferenceContext<'tcx>,
141-
borrows_out_of_scope_at_location: FxHashMap<Location, Vec<BorrowIndex>>,
141+
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
142142
}
143143

144144
impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
@@ -148,7 +148,7 @@ impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
148148
visit_stack: vec![],
149149
body,
150150
regioncx,
151-
borrows_out_of_scope_at_location: FxHashMap::default(),
151+
borrows_out_of_scope_at_location: FxIndexMap::default(),
152152
}
153153
}
154154
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use either::Either;
22
use rustc_const_eval::util::CallKind;
33
use rustc_data_structures::captures::Captures;
4-
use rustc_data_structures::fx::FxHashSet;
4+
use rustc_data_structures::fx::FxIndexSet;
55
use rustc_errors::{
66
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
77
};
@@ -173,7 +173,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
173173

174174
let mut is_loop_move = false;
175175
let mut in_pattern = false;
176-
let mut seen_spans = FxHashSet::default();
176+
let mut seen_spans = FxIndexSet::default();
177177

178178
for move_site in &move_site_vec {
179179
let move_out = self.move_data.moves[(*move_site).moi];
@@ -2223,8 +2223,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22232223
}
22242224
}
22252225

2226-
let mut visited = FxHashSet::default();
2227-
let mut move_locations = FxHashSet::default();
2226+
let mut visited = FxIndexSet::default();
2227+
let mut move_locations = FxIndexSet::default();
22282228
let mut reinits = vec![];
22292229
let mut result = vec![];
22302230

@@ -2351,7 +2351,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
23512351
let reinits_reachable = reinits
23522352
.into_iter()
23532353
.filter(|reinit| {
2354-
let mut visited = FxHashSet::default();
2354+
let mut visited = FxIndexSet::default();
23552355
let mut stack = vec![*reinit];
23562356
while let Some(location) = stack.pop() {
23572357
if !visited.insert(location) {

compiler/rustc_borrowck/src/diagnostics/find_use.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
nll::ToRegionVid,
1010
region_infer::{Cause, RegionInferenceContext},
1111
};
12-
use rustc_data_structures::fx::FxHashSet;
12+
use rustc_data_structures::fx::FxIndexSet;
1313
use rustc_middle::mir::visit::{MirVisitable, PlaceContext, Visitor};
1414
use rustc_middle::mir::{Body, Local, Location};
1515
use rustc_middle::ty::{RegionVid, TyCtxt};
@@ -37,7 +37,7 @@ struct UseFinder<'cx, 'tcx> {
3737
impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
3838
fn find(&mut self) -> Option<Cause> {
3939
let mut queue = VecDeque::new();
40-
let mut visited = FxHashSet::default();
40+
let mut visited = FxIndexSet::default();
4141

4242
queue.push_back(self.start_point);
4343
while let Some(p) = queue.pop_front() {

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Contains utilities for generating suggestions for borrowck errors related to unsatisfied
22
//! outlives constraints.
33
4-
use rustc_data_structures::fx::FxHashSet;
4+
use rustc_data_structures::fx::FxIndexSet;
55
use rustc_errors::Diagnostic;
66
use rustc_middle::ty::RegionVid;
77
use smallvec::SmallVec;
@@ -87,7 +87,7 @@ impl OutlivesSuggestionBuilder {
8787

8888
// Keep track of variables that we have already suggested unifying so that we don't print
8989
// out silly duplicate messages.
90-
let mut unified_already = FxHashSet::default();
90+
let mut unified_already = FxIndexSet::default();
9191

9292
for (fr, outlived) in &self.constraints_to_add {
9393
let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) else {

compiler/rustc_borrowck/src/lib.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! This query borrow-checks the MIR to (further) ensure it is not broken.
22
3-
#![allow(rustc::potential_query_instability)]
43
#![feature(associated_type_bounds)]
54
#![feature(box_patterns)]
65
#![feature(let_chains)]
@@ -18,7 +17,7 @@ extern crate rustc_middle;
1817
#[macro_use]
1918
extern crate tracing;
2019

21-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
20+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2221
use rustc_data_structures::graph::dominators::Dominators;
2322
use rustc_data_structures::vec_map::VecMap;
2423
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, SubdiagnosticMessage};
@@ -404,7 +403,7 @@ fn do_mir_borrowck<'tcx>(
404403
// Note that this set is expected to be small - only upvars from closures
405404
// would have a chance of erroneously adding non-user-defined mutable vars
406405
// to the set.
407-
let temporary_used_locals: FxHashSet<Local> = mbcx
406+
let temporary_used_locals: FxIndexSet<Local> = mbcx
408407
.used_mut
409408
.iter()
410409
.filter(|&local| !mbcx.body.local_decls[*local].is_user_variable())
@@ -491,7 +490,7 @@ pub struct BodyWithBorrowckFacts<'tcx> {
491490

492491
pub struct BorrowckInferCtxt<'cx, 'tcx> {
493492
pub(crate) infcx: &'cx InferCtxt<'tcx>,
494-
pub(crate) reg_var_to_origin: RefCell<FxHashMap<ty::RegionVid, RegionCtxt>>,
493+
pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,
495494
}
496495

497496
impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
@@ -588,25 +587,25 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
588587
/// borrow errors that is handled by the `reservation_error_reported` field as the inclusion
589588
/// of the `Span` type (while required to mute some errors) stops the muting of the reservation
590589
/// errors.
591-
access_place_error_reported: FxHashSet<(Place<'tcx>, Span)>,
590+
access_place_error_reported: FxIndexSet<(Place<'tcx>, Span)>,
592591
/// This field keeps track of when borrow conflict errors are reported
593592
/// for reservations, so that we don't report seemingly duplicate
594593
/// errors for corresponding activations.
595594
//
596595
// FIXME: ideally this would be a set of `BorrowIndex`, not `Place`s,
597596
// but it is currently inconvenient to track down the `BorrowIndex`
598597
// at the time we detect and report a reservation error.
599-
reservation_error_reported: FxHashSet<Place<'tcx>>,
598+
reservation_error_reported: FxIndexSet<Place<'tcx>>,
600599
/// This fields keeps track of the `Span`s that we have
601600
/// used to report extra information for `FnSelfUse`, to avoid
602601
/// unnecessarily verbose errors.
603-
fn_self_span_reported: FxHashSet<Span>,
602+
fn_self_span_reported: FxIndexSet<Span>,
604603
/// This field keeps track of errors reported in the checking of uninitialized variables,
605604
/// so that we don't report seemingly duplicate errors.
606-
uninitialized_error_reported: FxHashSet<PlaceRef<'tcx>>,
605+
uninitialized_error_reported: FxIndexSet<PlaceRef<'tcx>>,
607606
/// This field keeps track of all the local variables that are declared mut and are mutated.
608607
/// Used for the warning issued by an unused mutable local variable.
609-
used_mut: FxHashSet<Local>,
608+
used_mut: FxIndexSet<Local>,
610609
/// If the function we're checking is a closure, then we'll need to report back the list of
611610
/// mutable upvars that have been used. This field keeps track of them.
612611
used_mut_upvars: SmallVec<[Field; 8]>,
@@ -628,7 +627,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
628627

629628
/// Record the region names generated for each region in the given
630629
/// MIR def so that we can reuse them later in help/error messages.
631-
region_names: RefCell<FxHashMap<RegionVid, RegionName>>,
630+
region_names: RefCell<FxIndexMap<RegionVid, RegionName>>,
632631

633632
/// The counter for generating new region names.
634633
next_region_name: RefCell<usize>,
@@ -2329,7 +2328,7 @@ mod error {
23292328
/// same primary span come out in a consistent order.
23302329
buffered_move_errors:
23312330
BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx, ErrorGuaranteed>)>,
2332-
buffered_mut_errors: FxHashMap<Span, (DiagnosticBuilder<'tcx, ErrorGuaranteed>, usize)>,
2331+
buffered_mut_errors: FxIndexMap<Span, (DiagnosticBuilder<'tcx, ErrorGuaranteed>, usize)>,
23332332
/// Diagnostics to be reported buffer.
23342333
buffered: Vec<Diagnostic>,
23352334
/// Set to Some if we emit an error during borrowck

compiler/rustc_borrowck/src/member_constraints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![deny(rustc::untranslatable_diagnostic)]
22
#![deny(rustc::diagnostic_outside_of_impl)]
33
use rustc_data_structures::captures::Captures;
4-
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_data_structures::fx::FxIndexMap;
55
use rustc_index::vec::IndexVec;
66
use rustc_middle::infer::MemberConstraint;
77
use rustc_middle::ty::{self, Ty};
@@ -18,7 +18,7 @@ where
1818
{
1919
/// Stores the first "member" constraint for a given `R0`. This is an
2020
/// index into the `constraints` vector below.
21-
first_constraints: FxHashMap<R, NllMemberConstraintIndex>,
21+
first_constraints: FxIndexMap<R, NllMemberConstraintIndex>,
2222

2323
/// Stores the data about each `R0 member of [R1..Rn]` constraint.
2424
/// These are organized into a linked list, so each constraint
@@ -132,7 +132,7 @@ where
132132

133133
let MemberConstraintSet { first_constraints, mut constraints, choice_regions } = self;
134134

135-
let mut first_constraints2 = FxHashMap::default();
135+
let mut first_constraints2 = FxIndexMap::default();
136136
first_constraints2.reserve(first_constraints.len());
137137

138138
for (r1, start1) in first_constraints {

compiler/rustc_borrowck/src/region_infer/mod.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::rc::Rc;
33

44
use rustc_data_structures::binary_search_util;
55
use rustc_data_structures::frozen::Frozen;
6-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
77
use rustc_data_structures::graph::scc::Sccs;
88
use rustc_errors::Diagnostic;
99
use rustc_hir::def_id::CRATE_DEF_ID;
@@ -88,7 +88,7 @@ pub struct RegionInferenceContext<'tcx> {
8888
member_constraints_applied: Vec<AppliedMemberConstraint>,
8989

9090
/// Map universe indexes to information on why we created it.
91-
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
91+
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
9292

9393
/// Contains the minimum universe of any variable within the same
9494
/// SCC. We will ensure that no SCC contains values that are not
@@ -263,7 +263,7 @@ fn sccs_info<'cx, 'tcx>(
263263
debug!(debug_str);
264264

265265
let num_components = sccs.scc_data().ranges().len();
266-
let mut components = vec![FxHashSet::default(); num_components];
266+
let mut components = vec![FxIndexSet::default(); num_components];
267267

268268
for (reg_var_idx, scc_idx) in sccs.scc_indices().iter().enumerate() {
269269
let reg_var = ty::RegionVid::from_usize(reg_var_idx);
@@ -295,9 +295,9 @@ fn sccs_info<'cx, 'tcx>(
295295

296296
(ConstraintSccIndex::from_usize(scc_idx), repr)
297297
})
298-
.collect::<FxHashMap<_, _>>();
298+
.collect::<FxIndexMap<_, _>>();
299299

300-
let mut scc_node_to_edges = FxHashMap::default();
300+
let mut scc_node_to_edges = FxIndexMap::default();
301301
for (scc_idx, repr) in components_representatives.iter() {
302302
let edges_range = sccs.scc_data().ranges()[*scc_idx].clone();
303303
let edges = &sccs.scc_data().all_successors()[edges_range];
@@ -325,7 +325,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
325325
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
326326
outlives_constraints: OutlivesConstraintSet<'tcx>,
327327
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
328-
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
328+
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
329329
type_tests: Vec<TypeTest<'tcx>>,
330330
liveness_constraints: LivenessValues<RegionVid>,
331331
elements: &Rc<RegionValueElements>,
@@ -522,6 +522,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
522522
/// outlives `'a` and hence contains R0 and R1.
523523
fn init_free_and_bound_regions(&mut self) {
524524
// Update the names (if any)
525+
// This iterator has unstable order but we collect it all into an IndexVec
525526
for (external_name, variable) in self.universal_regions.named_universal_regions() {
526527
debug!(
527528
"init_universal_regions: region {:?} has external name {:?}",
@@ -918,7 +919,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
918919
// Sometimes we register equivalent type-tests that would
919920
// result in basically the exact same error being reported to
920921
// the user. Avoid that.
921-
let mut deduplicate_errors = FxHashSet::default();
922+
let mut deduplicate_errors = FxIndexSet::default();
922923

923924
for type_test in &self.type_tests {
924925
debug!("check_type_test: {:?}", type_test);
@@ -1504,6 +1505,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
15041505
// the outlives suggestions or the debug output from `#[rustc_regions]` would be
15051506
// duplicated. The polonius subset errors are deduplicated here, while keeping the
15061507
// CFG-location ordering.
1508+
// We can iterate the HashMap here because the result is sorted afterwards.
1509+
#[allow(rustc::potential_query_instability)]
15071510
let mut subset_errors: Vec<_> = polonius_output
15081511
.subset_errors
15091512
.iter()

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
22
use rustc_data_structures::vec_map::VecMap;
33
use rustc_errors::ErrorGuaranteed;
44
use rustc_hir::def_id::LocalDefId;
@@ -65,7 +65,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6565
) -> VecMap<LocalDefId, OpaqueHiddenType<'tcx>> {
6666
let mut result: VecMap<LocalDefId, OpaqueHiddenType<'tcx>> = VecMap::new();
6767

68-
let member_constraints: FxHashMap<_, _> = self
68+
let member_constraints: FxIndexMap<_, _> = self
6969
.member_constraints
7070
.all_indices()
7171
.map(|ci| (self.member_constraints[ci].key, ci))
@@ -364,7 +364,7 @@ fn check_opaque_type_parameter_valid(
364364
OpaqueTyOrigin::TyAlias => {}
365365
}
366366
let opaque_generics = tcx.generics_of(opaque_type_key.def_id);
367-
let mut seen_params: FxHashMap<_, Vec<_>> = FxHashMap::default();
367+
let mut seen_params: FxIndexMap<_, Vec<_>> = FxIndexMap::default();
368368
for (i, arg) in opaque_type_key.substs.iter().enumerate() {
369369
let arg_is_param = match arg.unpack() {
370370
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),

compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::constraints::ConstraintSccIndex;
44
use crate::RegionInferenceContext;
55
use itertools::Itertools;
6-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
77
use rustc_data_structures::graph::vec_graph::VecGraph;
88
use rustc_data_structures::graph::WithSuccessors;
99
use rustc_middle::ty::RegionVid;
@@ -14,7 +14,7 @@ pub(crate) struct ReverseSccGraph {
1414
graph: VecGraph<ConstraintSccIndex>,
1515
/// For each SCC, the range of `universal_regions` that use that SCC as
1616
/// their value.
17-
scc_regions: FxHashMap<ConstraintSccIndex, Range<usize>>,
17+
scc_regions: FxIndexMap<ConstraintSccIndex, Range<usize>>,
1818
/// All of the universal regions, in grouped so that `scc_regions` can
1919
/// index into here.
2020
universal_regions: Vec<RegionVid>,
@@ -26,7 +26,7 @@ impl ReverseSccGraph {
2626
&'a self,
2727
scc0: ConstraintSccIndex,
2828
) -> impl Iterator<Item = RegionVid> + 'a {
29-
let mut duplicates = FxHashSet::default();
29+
let mut duplicates = FxIndexSet::default();
3030
self.graph
3131
.depth_first_search(scc0)
3232
.flat_map(move |scc1| {
@@ -55,7 +55,7 @@ impl RegionInferenceContext<'_> {
5555
paired_scc_regions.sort();
5656
let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect();
5757

58-
let mut scc_regions = FxHashMap::default();
58+
let mut scc_regions = FxIndexMap::default();
5959
let mut start = 0;
6060
for (scc, group) in &paired_scc_regions.into_iter().group_by(|(scc, _)| *scc) {
6161
let group_size = group.count();

0 commit comments

Comments
 (0)