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.
This commit is contained in:
bors 2023-03-07 07:01:57 +00:00
commit 8f9e09ac3e
15 changed files with 66 additions and 61 deletions

View File

@ -4,7 +4,7 @@ use crate::nll::ToRegionVid;
use crate::path_utils::allow_two_phase_borrow; use crate::path_utils::allow_two_phase_borrow;
use crate::place_ext::PlaceExt; use crate::place_ext::PlaceExt;
use crate::BorrowIndex; use crate::BorrowIndex;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_middle::mir::traversal; use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
@ -26,10 +26,10 @@ pub struct BorrowSet<'tcx> {
/// NOTE: a given location may activate more than one borrow in the future /// NOTE: a given location may activate more than one borrow in the future
/// when more general two-phase borrow support is introduced, but for now we /// when more general two-phase borrow support is introduced, but for now we
/// only need to store one borrow index. /// only need to store one borrow index.
pub activation_map: FxHashMap<Location, Vec<BorrowIndex>>, pub activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
/// Map from local to all the borrows on that local. /// Map from local to all the borrows on that local.
pub local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>, pub local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
pub(crate) locals_state_at_exit: LocalsStateAtExit, pub(crate) locals_state_at_exit: LocalsStateAtExit,
} }
@ -175,8 +175,8 @@ struct GatherBorrows<'a, 'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
body: &'a Body<'tcx>, body: &'a Body<'tcx>,
location_map: FxIndexMap<Location, BorrowData<'tcx>>, location_map: FxIndexMap<Location, BorrowData<'tcx>>,
activation_map: FxHashMap<Location, Vec<BorrowIndex>>, activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>, local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
/// When we encounter a 2-phase borrow statement, it will always /// When we encounter a 2-phase borrow statement, it will always
/// be assigning into a temporary TEMP: /// be assigning into a temporary TEMP:
@ -186,7 +186,7 @@ struct GatherBorrows<'a, 'tcx> {
/// We add TEMP into this map with `b`, where `b` is the index of /// We add TEMP into this map with `b`, where `b` is the index of
/// the borrow. When we find a later use of this activation, we /// the borrow. When we find a later use of this activation, we
/// remove from the map (and add to the "tombstone" set below). /// remove from the map (and add to the "tombstone" set below).
pending_activations: FxHashMap<mir::Local, BorrowIndex>, pending_activations: FxIndexMap<mir::Local, BorrowIndex>,
locals_state_at_exit: LocalsStateAtExit, locals_state_at_exit: LocalsStateAtExit,
} }

View File

@ -1,6 +1,6 @@
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_middle::mir::{self, BasicBlock, Body, Location, Place}; use rustc_middle::mir::{self, BasicBlock, Body, Location, Place};
use rustc_middle::ty::RegionVid; use rustc_middle::ty::RegionVid;
@ -124,7 +124,7 @@ pub struct Borrows<'a, 'tcx> {
body: &'a Body<'tcx>, body: &'a Body<'tcx>,
borrow_set: &'a BorrowSet<'tcx>, borrow_set: &'a BorrowSet<'tcx>,
borrows_out_of_scope_at_location: FxHashMap<Location, Vec<BorrowIndex>>, borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
} }
struct StackEntry { struct StackEntry {
@ -138,7 +138,7 @@ struct OutOfScopePrecomputer<'a, 'tcx> {
visit_stack: Vec<StackEntry>, visit_stack: Vec<StackEntry>,
body: &'a Body<'tcx>, body: &'a Body<'tcx>,
regioncx: &'a RegionInferenceContext<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>,
borrows_out_of_scope_at_location: FxHashMap<Location, Vec<BorrowIndex>>, borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
} }
impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> { impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
@ -148,7 +148,7 @@ impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
visit_stack: vec![], visit_stack: vec![],
body, body,
regioncx, regioncx,
borrows_out_of_scope_at_location: FxHashMap::default(), borrows_out_of_scope_at_location: FxIndexMap::default(),
} }
} }
} }

View File

@ -1,7 +1,7 @@
use either::Either; use either::Either;
use rustc_const_eval::util::CallKind; use rustc_const_eval::util::CallKind;
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{ use rustc_errors::{
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
}; };
@ -173,7 +173,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let mut is_loop_move = false; let mut is_loop_move = false;
let mut in_pattern = false; let mut in_pattern = false;
let mut seen_spans = FxHashSet::default(); let mut seen_spans = FxIndexSet::default();
for move_site in &move_site_vec { for move_site in &move_site_vec {
let move_out = self.move_data.moves[(*move_site).moi]; let move_out = self.move_data.moves[(*move_site).moi];
@ -2223,8 +2223,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} }
} }
let mut visited = FxHashSet::default(); let mut visited = FxIndexSet::default();
let mut move_locations = FxHashSet::default(); let mut move_locations = FxIndexSet::default();
let mut reinits = vec![]; let mut reinits = vec![];
let mut result = vec![]; let mut result = vec![];
@ -2351,7 +2351,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let reinits_reachable = reinits let reinits_reachable = reinits
.into_iter() .into_iter()
.filter(|reinit| { .filter(|reinit| {
let mut visited = FxHashSet::default(); let mut visited = FxIndexSet::default();
let mut stack = vec![*reinit]; let mut stack = vec![*reinit];
while let Some(location) = stack.pop() { while let Some(location) = stack.pop() {
if !visited.insert(location) { if !visited.insert(location) {

View File

@ -9,7 +9,7 @@ use crate::{
nll::ToRegionVid, nll::ToRegionVid,
region_infer::{Cause, RegionInferenceContext}, region_infer::{Cause, RegionInferenceContext},
}; };
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxIndexSet;
use rustc_middle::mir::visit::{MirVisitable, PlaceContext, Visitor}; use rustc_middle::mir::visit::{MirVisitable, PlaceContext, Visitor};
use rustc_middle::mir::{Body, Local, Location}; use rustc_middle::mir::{Body, Local, Location};
use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_middle::ty::{RegionVid, TyCtxt};
@ -37,7 +37,7 @@ struct UseFinder<'cx, 'tcx> {
impl<'cx, 'tcx> UseFinder<'cx, 'tcx> { impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
fn find(&mut self) -> Option<Cause> { fn find(&mut self) -> Option<Cause> {
let mut queue = VecDeque::new(); let mut queue = VecDeque::new();
let mut visited = FxHashSet::default(); let mut visited = FxIndexSet::default();
queue.push_back(self.start_point); queue.push_back(self.start_point);
while let Some(p) = queue.pop_front() { while let Some(p) = queue.pop_front() {

View File

@ -1,7 +1,7 @@
//! Contains utilities for generating suggestions for borrowck errors related to unsatisfied //! Contains utilities for generating suggestions for borrowck errors related to unsatisfied
//! outlives constraints. //! outlives constraints.
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::Diagnostic; use rustc_errors::Diagnostic;
use rustc_middle::ty::RegionVid; use rustc_middle::ty::RegionVid;
use smallvec::SmallVec; use smallvec::SmallVec;
@ -87,7 +87,7 @@ impl OutlivesSuggestionBuilder {
// Keep track of variables that we have already suggested unifying so that we don't print // Keep track of variables that we have already suggested unifying so that we don't print
// out silly duplicate messages. // out silly duplicate messages.
let mut unified_already = FxHashSet::default(); let mut unified_already = FxIndexSet::default();
for (fr, outlived) in &self.constraints_to_add { for (fr, outlived) in &self.constraints_to_add {
let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) else { let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) else {

View File

@ -1,6 +1,5 @@
//! This query borrow-checks the MIR to (further) ensure it is not broken. //! This query borrow-checks the MIR to (further) ensure it is not broken.
#![allow(rustc::potential_query_instability)]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(let_chains)] #![feature(let_chains)]
@ -18,7 +17,7 @@ extern crate rustc_middle;
#[macro_use] #[macro_use]
extern crate tracing; extern crate tracing;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::graph::dominators::Dominators;
use rustc_data_structures::vec_map::VecMap; use rustc_data_structures::vec_map::VecMap;
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, SubdiagnosticMessage}; use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, SubdiagnosticMessage};
@ -404,7 +403,7 @@ fn do_mir_borrowck<'tcx>(
// Note that this set is expected to be small - only upvars from closures // Note that this set is expected to be small - only upvars from closures
// would have a chance of erroneously adding non-user-defined mutable vars // would have a chance of erroneously adding non-user-defined mutable vars
// to the set. // to the set.
let temporary_used_locals: FxHashSet<Local> = mbcx let temporary_used_locals: FxIndexSet<Local> = mbcx
.used_mut .used_mut
.iter() .iter()
.filter(|&local| !mbcx.body.local_decls[*local].is_user_variable()) .filter(|&local| !mbcx.body.local_decls[*local].is_user_variable())
@ -491,7 +490,7 @@ pub struct BodyWithBorrowckFacts<'tcx> {
pub struct BorrowckInferCtxt<'cx, 'tcx> { pub struct BorrowckInferCtxt<'cx, 'tcx> {
pub(crate) infcx: &'cx InferCtxt<'tcx>, pub(crate) infcx: &'cx InferCtxt<'tcx>,
pub(crate) reg_var_to_origin: RefCell<FxHashMap<ty::RegionVid, RegionCtxt>>, pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,
} }
impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> { impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
@ -588,7 +587,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
/// borrow errors that is handled by the `reservation_error_reported` field as the inclusion /// borrow errors that is handled by the `reservation_error_reported` field as the inclusion
/// of the `Span` type (while required to mute some errors) stops the muting of the reservation /// of the `Span` type (while required to mute some errors) stops the muting of the reservation
/// errors. /// errors.
access_place_error_reported: FxHashSet<(Place<'tcx>, Span)>, access_place_error_reported: FxIndexSet<(Place<'tcx>, Span)>,
/// This field keeps track of when borrow conflict errors are reported /// This field keeps track of when borrow conflict errors are reported
/// for reservations, so that we don't report seemingly duplicate /// for reservations, so that we don't report seemingly duplicate
/// errors for corresponding activations. /// errors for corresponding activations.
@ -596,17 +595,17 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
// FIXME: ideally this would be a set of `BorrowIndex`, not `Place`s, // FIXME: ideally this would be a set of `BorrowIndex`, not `Place`s,
// but it is currently inconvenient to track down the `BorrowIndex` // but it is currently inconvenient to track down the `BorrowIndex`
// at the time we detect and report a reservation error. // at the time we detect and report a reservation error.
reservation_error_reported: FxHashSet<Place<'tcx>>, reservation_error_reported: FxIndexSet<Place<'tcx>>,
/// This fields keeps track of the `Span`s that we have /// This fields keeps track of the `Span`s that we have
/// used to report extra information for `FnSelfUse`, to avoid /// used to report extra information for `FnSelfUse`, to avoid
/// unnecessarily verbose errors. /// unnecessarily verbose errors.
fn_self_span_reported: FxHashSet<Span>, fn_self_span_reported: FxIndexSet<Span>,
/// This field keeps track of errors reported in the checking of uninitialized variables, /// This field keeps track of errors reported in the checking of uninitialized variables,
/// so that we don't report seemingly duplicate errors. /// so that we don't report seemingly duplicate errors.
uninitialized_error_reported: FxHashSet<PlaceRef<'tcx>>, uninitialized_error_reported: FxIndexSet<PlaceRef<'tcx>>,
/// This field keeps track of all the local variables that are declared mut and are mutated. /// This field keeps track of all the local variables that are declared mut and are mutated.
/// Used for the warning issued by an unused mutable local variable. /// Used for the warning issued by an unused mutable local variable.
used_mut: FxHashSet<Local>, used_mut: FxIndexSet<Local>,
/// If the function we're checking is a closure, then we'll need to report back the list of /// If the function we're checking is a closure, then we'll need to report back the list of
/// mutable upvars that have been used. This field keeps track of them. /// mutable upvars that have been used. This field keeps track of them.
used_mut_upvars: SmallVec<[Field; 8]>, used_mut_upvars: SmallVec<[Field; 8]>,
@ -628,7 +627,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
/// Record the region names generated for each region in the given /// Record the region names generated for each region in the given
/// MIR def so that we can reuse them later in help/error messages. /// MIR def so that we can reuse them later in help/error messages.
region_names: RefCell<FxHashMap<RegionVid, RegionName>>, region_names: RefCell<FxIndexMap<RegionVid, RegionName>>,
/// The counter for generating new region names. /// The counter for generating new region names.
next_region_name: RefCell<usize>, next_region_name: RefCell<usize>,
@ -2329,7 +2328,7 @@ mod error {
/// same primary span come out in a consistent order. /// same primary span come out in a consistent order.
buffered_move_errors: buffered_move_errors:
BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx, ErrorGuaranteed>)>, BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx, ErrorGuaranteed>)>,
buffered_mut_errors: FxHashMap<Span, (DiagnosticBuilder<'tcx, ErrorGuaranteed>, usize)>, buffered_mut_errors: FxIndexMap<Span, (DiagnosticBuilder<'tcx, ErrorGuaranteed>, usize)>,
/// Diagnostics to be reported buffer. /// Diagnostics to be reported buffer.
buffered: Vec<Diagnostic>, buffered: Vec<Diagnostic>,
/// Set to Some if we emit an error during borrowck /// Set to Some if we emit an error during borrowck

View File

@ -1,7 +1,7 @@
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_middle::infer::MemberConstraint; use rustc_middle::infer::MemberConstraint;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
@ -18,7 +18,7 @@ where
{ {
/// Stores the first "member" constraint for a given `R0`. This is an /// Stores the first "member" constraint for a given `R0`. This is an
/// index into the `constraints` vector below. /// index into the `constraints` vector below.
first_constraints: FxHashMap<R, NllMemberConstraintIndex>, first_constraints: FxIndexMap<R, NllMemberConstraintIndex>,
/// Stores the data about each `R0 member of [R1..Rn]` constraint. /// Stores the data about each `R0 member of [R1..Rn]` constraint.
/// These are organized into a linked list, so each constraint /// These are organized into a linked list, so each constraint
@ -132,7 +132,7 @@ where
let MemberConstraintSet { first_constraints, mut constraints, choice_regions } = self; let MemberConstraintSet { first_constraints, mut constraints, choice_regions } = self;
let mut first_constraints2 = FxHashMap::default(); let mut first_constraints2 = FxIndexMap::default();
first_constraints2.reserve(first_constraints.len()); first_constraints2.reserve(first_constraints.len());
for (r1, start1) in first_constraints { for (r1, start1) in first_constraints {

View File

@ -3,7 +3,7 @@ use std::rc::Rc;
use rustc_data_structures::binary_search_util; use rustc_data_structures::binary_search_util;
use rustc_data_structures::frozen::Frozen; use rustc_data_structures::frozen::Frozen;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::scc::Sccs; use rustc_data_structures::graph::scc::Sccs;
use rustc_errors::Diagnostic; use rustc_errors::Diagnostic;
use rustc_hir::def_id::CRATE_DEF_ID; use rustc_hir::def_id::CRATE_DEF_ID;
@ -88,7 +88,7 @@ pub struct RegionInferenceContext<'tcx> {
member_constraints_applied: Vec<AppliedMemberConstraint>, member_constraints_applied: Vec<AppliedMemberConstraint>,
/// Map universe indexes to information on why we created it. /// Map universe indexes to information on why we created it.
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>, universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
/// Contains the minimum universe of any variable within the same /// Contains the minimum universe of any variable within the same
/// SCC. We will ensure that no SCC contains values that are not /// SCC. We will ensure that no SCC contains values that are not
@ -263,7 +263,7 @@ fn sccs_info<'cx, 'tcx>(
debug!(debug_str); debug!(debug_str);
let num_components = sccs.scc_data().ranges().len(); let num_components = sccs.scc_data().ranges().len();
let mut components = vec![FxHashSet::default(); num_components]; let mut components = vec![FxIndexSet::default(); num_components];
for (reg_var_idx, scc_idx) in sccs.scc_indices().iter().enumerate() { for (reg_var_idx, scc_idx) in sccs.scc_indices().iter().enumerate() {
let reg_var = ty::RegionVid::from_usize(reg_var_idx); let reg_var = ty::RegionVid::from_usize(reg_var_idx);
@ -295,9 +295,9 @@ fn sccs_info<'cx, 'tcx>(
(ConstraintSccIndex::from_usize(scc_idx), repr) (ConstraintSccIndex::from_usize(scc_idx), repr)
}) })
.collect::<FxHashMap<_, _>>(); .collect::<FxIndexMap<_, _>>();
let mut scc_node_to_edges = FxHashMap::default(); let mut scc_node_to_edges = FxIndexMap::default();
for (scc_idx, repr) in components_representatives.iter() { for (scc_idx, repr) in components_representatives.iter() {
let edges_range = sccs.scc_data().ranges()[*scc_idx].clone(); let edges_range = sccs.scc_data().ranges()[*scc_idx].clone();
let edges = &sccs.scc_data().all_successors()[edges_range]; let edges = &sccs.scc_data().all_successors()[edges_range];
@ -325,7 +325,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>, universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
outlives_constraints: OutlivesConstraintSet<'tcx>, outlives_constraints: OutlivesConstraintSet<'tcx>,
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>, member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>, universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
type_tests: Vec<TypeTest<'tcx>>, type_tests: Vec<TypeTest<'tcx>>,
liveness_constraints: LivenessValues<RegionVid>, liveness_constraints: LivenessValues<RegionVid>,
elements: &Rc<RegionValueElements>, elements: &Rc<RegionValueElements>,
@ -522,6 +522,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// outlives `'a` and hence contains R0 and R1. /// outlives `'a` and hence contains R0 and R1.
fn init_free_and_bound_regions(&mut self) { fn init_free_and_bound_regions(&mut self) {
// Update the names (if any) // Update the names (if any)
// This iterator has unstable order but we collect it all into an IndexVec
for (external_name, variable) in self.universal_regions.named_universal_regions() { for (external_name, variable) in self.universal_regions.named_universal_regions() {
debug!( debug!(
"init_universal_regions: region {:?} has external name {:?}", "init_universal_regions: region {:?} has external name {:?}",
@ -918,7 +919,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// Sometimes we register equivalent type-tests that would // Sometimes we register equivalent type-tests that would
// result in basically the exact same error being reported to // result in basically the exact same error being reported to
// the user. Avoid that. // the user. Avoid that.
let mut deduplicate_errors = FxHashSet::default(); let mut deduplicate_errors = FxIndexSet::default();
for type_test in &self.type_tests { for type_test in &self.type_tests {
debug!("check_type_test: {:?}", type_test); debug!("check_type_test: {:?}", type_test);
@ -1504,6 +1505,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// the outlives suggestions or the debug output from `#[rustc_regions]` would be // the outlives suggestions or the debug output from `#[rustc_regions]` would be
// duplicated. The polonius subset errors are deduplicated here, while keeping the // duplicated. The polonius subset errors are deduplicated here, while keeping the
// CFG-location ordering. // CFG-location ordering.
// We can iterate the HashMap here because the result is sorted afterwards.
#[allow(rustc::potential_query_instability)]
let mut subset_errors: Vec<_> = polonius_output let mut subset_errors: Vec<_> = polonius_output
.subset_errors .subset_errors
.iter() .iter()

View File

@ -1,4 +1,4 @@
use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::vec_map::VecMap; use rustc_data_structures::vec_map::VecMap;
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
@ -65,7 +65,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
) -> VecMap<LocalDefId, OpaqueHiddenType<'tcx>> { ) -> VecMap<LocalDefId, OpaqueHiddenType<'tcx>> {
let mut result: VecMap<LocalDefId, OpaqueHiddenType<'tcx>> = VecMap::new(); let mut result: VecMap<LocalDefId, OpaqueHiddenType<'tcx>> = VecMap::new();
let member_constraints: FxHashMap<_, _> = self let member_constraints: FxIndexMap<_, _> = self
.member_constraints .member_constraints
.all_indices() .all_indices()
.map(|ci| (self.member_constraints[ci].key, ci)) .map(|ci| (self.member_constraints[ci].key, ci))
@ -364,7 +364,7 @@ fn check_opaque_type_parameter_valid(
OpaqueTyOrigin::TyAlias => {} OpaqueTyOrigin::TyAlias => {}
} }
let opaque_generics = tcx.generics_of(opaque_type_key.def_id); let opaque_generics = tcx.generics_of(opaque_type_key.def_id);
let mut seen_params: FxHashMap<_, Vec<_>> = FxHashMap::default(); let mut seen_params: FxIndexMap<_, Vec<_>> = FxIndexMap::default();
for (i, arg) in opaque_type_key.substs.iter().enumerate() { for (i, arg) in opaque_type_key.substs.iter().enumerate() {
let arg_is_param = match arg.unpack() { let arg_is_param = match arg.unpack() {
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)), GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),

View File

@ -3,7 +3,7 @@
use crate::constraints::ConstraintSccIndex; use crate::constraints::ConstraintSccIndex;
use crate::RegionInferenceContext; use crate::RegionInferenceContext;
use itertools::Itertools; use itertools::Itertools;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::vec_graph::VecGraph; use rustc_data_structures::graph::vec_graph::VecGraph;
use rustc_data_structures::graph::WithSuccessors; use rustc_data_structures::graph::WithSuccessors;
use rustc_middle::ty::RegionVid; use rustc_middle::ty::RegionVid;
@ -14,7 +14,7 @@ pub(crate) struct ReverseSccGraph {
graph: VecGraph<ConstraintSccIndex>, graph: VecGraph<ConstraintSccIndex>,
/// For each SCC, the range of `universal_regions` that use that SCC as /// For each SCC, the range of `universal_regions` that use that SCC as
/// their value. /// their value.
scc_regions: FxHashMap<ConstraintSccIndex, Range<usize>>, scc_regions: FxIndexMap<ConstraintSccIndex, Range<usize>>,
/// All of the universal regions, in grouped so that `scc_regions` can /// All of the universal regions, in grouped so that `scc_regions` can
/// index into here. /// index into here.
universal_regions: Vec<RegionVid>, universal_regions: Vec<RegionVid>,
@ -26,7 +26,7 @@ impl ReverseSccGraph {
&'a self, &'a self,
scc0: ConstraintSccIndex, scc0: ConstraintSccIndex,
) -> impl Iterator<Item = RegionVid> + 'a { ) -> impl Iterator<Item = RegionVid> + 'a {
let mut duplicates = FxHashSet::default(); let mut duplicates = FxIndexSet::default();
self.graph self.graph
.depth_first_search(scc0) .depth_first_search(scc0)
.flat_map(move |scc1| { .flat_map(move |scc1| {
@ -55,7 +55,7 @@ impl RegionInferenceContext<'_> {
paired_scc_regions.sort(); paired_scc_regions.sort();
let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect(); let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect();
let mut scc_regions = FxHashMap::default(); let mut scc_regions = FxIndexMap::default();
let mut start = 0; let mut start = 0;
for (scc, group) in &paired_scc_regions.into_iter().group_by(|(scc, _)| *scc) { for (scc, group) in &paired_scc_regions.into_iter().group_by(|(scc, _)| *scc) {
let group_size = group.count(); let group_size = group.count();

View File

@ -19,7 +19,7 @@ use super::{Locations, TypeChecker};
impl<'a, 'tcx> TypeChecker<'a, 'tcx> { impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
/// Check explicit closure signature annotation, /// Check explicit closure signature annotation,
/// e.g., `|x: FxHashMap<_, &'static u32>| ...`. /// e.g., `|x: FxIndexMap<_, &'static u32>| ...`.
#[instrument(skip(self, body), level = "debug")] #[instrument(skip(self, body), level = "debug")]
pub(super) fn check_signature_annotation(&mut self, body: &Body<'tcx>) { pub(super) fn check_signature_annotation(&mut self, body: &Body<'tcx>) {
let mir_def_id = body.source.def_id().expect_local(); let mir_def_id = body.source.def_id().expect_local();

View File

@ -1,4 +1,4 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_index::bit_set::HybridBitSet; use rustc_index::bit_set::HybridBitSet;
use rustc_index::interval::IntervalSet; use rustc_index::interval::IntervalSet;
use rustc_infer::infer::canonical::QueryRegionConstraints; use rustc_infer::infer::canonical::QueryRegionConstraints;
@ -56,7 +56,7 @@ pub(super) fn trace<'mir, 'tcx>(
elements, elements,
local_use_map, local_use_map,
move_data, move_data,
drop_data: FxHashMap::default(), drop_data: FxIndexMap::default(),
}; };
let mut results = LivenessResults::new(cx); let mut results = LivenessResults::new(cx);
@ -85,7 +85,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
move_data: &'me MoveData<'tcx>, move_data: &'me MoveData<'tcx>,
/// Cache for the results of `dropck_outlives` query. /// Cache for the results of `dropck_outlives` query.
drop_data: FxHashMap<Ty<'tcx>, DropData<'tcx>>, drop_data: FxIndexMap<Ty<'tcx>, DropData<'tcx>>,
/// Results of dataflow tracking which variables (and paths) have been /// Results of dataflow tracking which variables (and paths) have been
/// initialized. /// initialized.
@ -185,7 +185,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
fn add_extra_drop_facts( fn add_extra_drop_facts(
&mut self, &mut self,
drop_used: Vec<(Local, Location)>, drop_used: Vec<(Local, Location)>,
relevant_live_locals: FxHashSet<Local>, relevant_live_locals: FxIndexSet<Local>,
) { ) {
let locations = IntervalSet::new(self.cx.elements.num_points()); let locations = IntervalSet::new(self.cx.elements.num_points());

View File

@ -9,7 +9,7 @@ use either::Either;
use hir::OpaqueTyOrigin; use hir::OpaqueTyOrigin;
use rustc_data_structures::frozen::Frozen; use rustc_data_structures::frozen::Frozen;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::vec_map::VecMap; use rustc_data_structures::vec_map::VecMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
@ -145,7 +145,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
outlives_constraints: OutlivesConstraintSet::default(), outlives_constraints: OutlivesConstraintSet::default(),
member_constraints: MemberConstraintSet::default(), member_constraints: MemberConstraintSet::default(),
type_tests: Vec::default(), type_tests: Vec::default(),
universe_causes: FxHashMap::default(), universe_causes: FxIndexMap::default(),
}; };
let CreateResult { let CreateResult {
@ -875,7 +875,7 @@ struct TypeChecker<'a, 'tcx> {
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>, user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>, region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: ty::Region<'tcx>, implicit_region_bound: ty::Region<'tcx>,
reported_errors: FxHashSet<(Ty<'tcx>, Span)>, reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
} }
@ -925,7 +925,7 @@ pub(crate) struct MirTypeckRegionConstraints<'tcx> {
pub(crate) member_constraints: MemberConstraintSet<'tcx, RegionVid>, pub(crate) member_constraints: MemberConstraintSet<'tcx, RegionVid>,
pub(crate) universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>, pub(crate) universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
pub(crate) type_tests: Vec<TypeTest<'tcx>>, pub(crate) type_tests: Vec<TypeTest<'tcx>>,
} }

View File

@ -312,6 +312,9 @@ impl<'tcx> UniversalRegions<'tcx> {
} }
/// Gets an iterator over all the early-bound regions that have names. /// Gets an iterator over all the early-bound regions that have names.
/// Iteration order may be unstable, so this should only be used when
/// iteration order doesn't affect anything
#[allow(rustc::potential_query_instability)]
pub fn named_universal_regions<'s>( pub fn named_universal_regions<'s>(
&'s self, &'s self,
) -> impl Iterator<Item = (ty::Region<'tcx>, ty::RegionVid)> + 's { ) -> impl Iterator<Item = (ty::Region<'tcx>, ty::RegionVid)> + 's {

View File

@ -1,6 +1,6 @@
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxIndexSet;
use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{ use rustc_middle::mir::{
Local, Location, Place, Statement, StatementKind, Terminator, TerminatorKind, Local, Location, Place, Statement, StatementKind, Terminator, TerminatorKind,
@ -26,8 +26,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// See #55344 for context. /// See #55344 for context.
pub(crate) fn gather_used_muts( pub(crate) fn gather_used_muts(
&mut self, &mut self,
temporary_used_locals: FxHashSet<Local>, temporary_used_locals: FxIndexSet<Local>,
mut never_initialized_mut_locals: FxHashSet<Local>, mut never_initialized_mut_locals: FxIndexSet<Local>,
) { ) {
{ {
let mut visitor = GatherUsedMutsVisitor { let mut visitor = GatherUsedMutsVisitor {
@ -48,8 +48,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// MIR visitor for collecting used mutable variables. /// MIR visitor for collecting used mutable variables.
/// The 'visit lifetime represents the duration of the MIR walk. /// The 'visit lifetime represents the duration of the MIR walk.
struct GatherUsedMutsVisitor<'visit, 'cx, 'tcx> { struct GatherUsedMutsVisitor<'visit, 'cx, 'tcx> {
temporary_used_locals: FxHashSet<Local>, temporary_used_locals: FxIndexSet<Local>,
never_initialized_mut_locals: &'visit mut FxHashSet<Local>, never_initialized_mut_locals: &'visit mut FxIndexSet<Local>,
mbcx: &'visit mut MirBorrowckCtxt<'cx, 'tcx>, mbcx: &'visit mut MirBorrowckCtxt<'cx, 'tcx>,
} }