Skip to content

Remove allow(potential_query_instability) from borrowck #108735

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

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::nll::ToRegionVid;
use crate::path_utils::allow_two_phase_borrow;
use crate::place_ext::PlaceExt;
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_middle::mir::traversal;
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
Expand All @@ -26,10 +26,10 @@ pub struct BorrowSet<'tcx> {
/// 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
/// 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.
pub local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>,
pub local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,

pub(crate) locals_state_at_exit: LocalsStateAtExit,
}
Expand Down Expand Up @@ -175,8 +175,8 @@ struct GatherBorrows<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
body: &'a Body<'tcx>,
location_map: FxIndexMap<Location, BorrowData<'tcx>>,
activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>,
activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,

/// When we encounter a 2-phase borrow statement, it will always
/// be assigning into a temporary TEMP:
Expand All @@ -186,7 +186,7 @@ struct GatherBorrows<'a, 'tcx> {
/// 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
/// 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,
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![deny(rustc::untranslatable_diagnostic)]
#![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_middle::mir::{self, BasicBlock, Body, Location, Place};
use rustc_middle::ty::RegionVid;
Expand Down Expand Up @@ -124,7 +124,7 @@ pub struct Borrows<'a, 'tcx> {
body: &'a Body<'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 {
Expand All @@ -138,7 +138,7 @@ struct OutOfScopePrecomputer<'a, 'tcx> {
visit_stack: Vec<StackEntry>,
body: &'a Body<'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> {
Expand All @@ -148,7 +148,7 @@ impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
visit_stack: vec![],
body,
regioncx,
borrows_out_of_scope_at_location: FxHashMap::default(),
borrows_out_of_scope_at_location: FxIndexMap::default(),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use either::Either;
use rustc_const_eval::util::CallKind;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
};
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

let mut is_loop_move = 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 {
let move_out = self.move_data.moves[(*move_site).moi];
Expand Down Expand Up @@ -2197,8 +2197,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}

let mut visited = FxHashSet::default();
let mut move_locations = FxHashSet::default();
let mut visited = FxIndexSet::default();
let mut move_locations = FxIndexSet::default();
let mut reinits = vec![];
let mut result = vec![];

Expand Down Expand Up @@ -2325,7 +2325,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let reinits_reachable = reinits
.into_iter()
.filter(|reinit| {
let mut visited = FxHashSet::default();
let mut visited = FxIndexSet::default();
let mut stack = vec![*reinit];
while let Some(location) = stack.pop() {
if !visited.insert(location) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/find_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
nll::ToRegionVid,
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::{Body, Local, Location};
use rustc_middle::ty::{RegionVid, TyCtxt};
Expand Down Expand Up @@ -37,7 +37,7 @@ struct UseFinder<'cx, 'tcx> {
impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
fn find(&mut self) -> Option<Cause> {
let mut queue = VecDeque::new();
let mut visited = FxHashSet::default();
let mut visited = FxIndexSet::default();

queue.push_back(self.start_point);
while let Some(p) = queue.pop_front() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Contains utilities for generating suggestions for borrowck errors related to unsatisfied
//! outlives constraints.

use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::Diagnostic;
use rustc_middle::ty::RegionVid;
use smallvec::SmallVec;
Expand Down Expand Up @@ -87,7 +87,7 @@ impl OutlivesSuggestionBuilder {

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

for (fr, outlived) in &self.constraints_to_add {
let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) else {
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! This query borrow-checks the MIR to (further) ensure it is not broken.

#![allow(rustc::potential_query_instability)]
#![feature(associated_type_bounds)]
#![feature(box_patterns)]
#![feature(let_chains)]
Expand All @@ -18,7 +17,7 @@ extern crate rustc_middle;
#[macro_use]
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::vec_map::VecMap;
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, SubdiagnosticMessage};
Expand Down Expand Up @@ -404,7 +403,7 @@ fn do_mir_borrowck<'tcx>(
// 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
// to the set.
let temporary_used_locals: FxHashSet<Local> = mbcx
let temporary_used_locals: FxIndexSet<Local> = mbcx
.used_mut
.iter()
.filter(|&local| !mbcx.body.local_decls[*local].is_user_variable())
Expand Down Expand Up @@ -491,7 +490,7 @@ pub struct BodyWithBorrowckFacts<'tcx> {

pub struct BorrowckInferCtxt<'cx, '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> {
Expand Down Expand Up @@ -588,25 +587,25 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
/// 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
/// 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
/// for reservations, so that we don't report seemingly duplicate
/// errors for corresponding activations.
//
// FIXME: ideally this would be a set of `BorrowIndex`, not `Place`s,
// but it is currently inconvenient to track down the `BorrowIndex`
// 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
/// used to report extra information for `FnSelfUse`, to avoid
/// 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,
/// 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.
/// 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
/// mutable upvars that have been used. This field keeps track of them.
used_mut_upvars: SmallVec<[Field; 8]>,
Expand All @@ -628,7 +627,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {

/// Record the region names generated for each region in the given
/// 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.
next_region_name: RefCell<usize>,
Expand Down Expand Up @@ -2334,7 +2333,7 @@ mod error {
/// same primary span come out in a consistent order.
buffered_move_errors:
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.
buffered: Vec<Diagnostic>,
/// Set to Some if we emit an error during borrowck
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/member_constraints.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
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_middle::infer::MemberConstraint;
use rustc_middle::ty::{self, Ty};
Expand All @@ -18,7 +18,7 @@ where
{
/// Stores the first "member" constraint for a given `R0`. This is an
/// 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.
/// These are organized into a linked list, so each constraint
Expand Down Expand Up @@ -132,7 +132,7 @@ where

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());

for (r1, start1) in first_constraints {
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::rc::Rc;

use rustc_data_structures::binary_search_util;
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_errors::Diagnostic;
use rustc_hir::def_id::CRATE_DEF_ID;
Expand Down Expand Up @@ -87,7 +87,7 @@ pub struct RegionInferenceContext<'tcx> {
member_constraints_applied: Vec<AppliedMemberConstraint>,

/// 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
/// SCC. We will ensure that no SCC contains values that are not
Expand Down Expand Up @@ -262,7 +262,7 @@ fn sccs_info<'cx, 'tcx>(
debug!(debug_str);

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() {
let reg_var = ty::RegionVid::from_usize(reg_var_idx);
Expand Down Expand Up @@ -294,9 +294,9 @@ fn sccs_info<'cx, 'tcx>(

(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() {
let edges_range = sccs.scc_data().ranges()[*scc_idx].clone();
let edges = &sccs.scc_data().all_successors()[edges_range];
Expand Down Expand Up @@ -324,7 +324,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
outlives_constraints: OutlivesConstraintSet<'tcx>,
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>>,
liveness_constraints: LivenessValues<RegionVid>,
elements: &Rc<RegionValueElements>,
Expand Down Expand Up @@ -521,6 +521,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// outlives `'a` and hence contains R0 and R1.
fn init_free_and_bound_regions(&mut self) {
// 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() {
debug!(
"init_universal_regions: region {:?} has external name {:?}",
Expand Down Expand Up @@ -917,7 +918,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// Sometimes we register equivalent type-tests that would
// result in basically the exact same error being reported to
// the user. Avoid that.
let mut deduplicate_errors = FxHashSet::default();
let mut deduplicate_errors = FxIndexSet::default();

for type_test in &self.type_tests {
debug!("check_type_test: {:?}", type_test);
Expand Down Expand Up @@ -1539,6 +1540,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// the outlives suggestions or the debug output from `#[rustc_regions]` would be
// duplicated. The polonius subset errors are deduplicated here, while keeping the
// 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
.subset_errors
.iter()
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
@@ -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_errors::ErrorGuaranteed;
use rustc_hir::def_id::LocalDefId;
Expand Down Expand Up @@ -65,7 +65,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
) -> VecMap<LocalDefId, OpaqueHiddenType<'tcx>> {
let mut result: VecMap<LocalDefId, OpaqueHiddenType<'tcx>> = VecMap::new();

let member_constraints: FxHashMap<_, _> = self
let member_constraints: FxIndexMap<_, _> = self
.member_constraints
.all_indices()
.map(|ci| (self.member_constraints[ci].key, ci))
Expand Down Expand Up @@ -364,7 +364,7 @@ fn check_opaque_type_parameter_valid(
OpaqueTyOrigin::TyAlias => {}
}
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() {
let arg_is_param = match arg.unpack() {
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::constraints::ConstraintSccIndex;
use crate::RegionInferenceContext;
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::WithSuccessors;
use rustc_middle::ty::RegionVid;
Expand All @@ -14,7 +14,7 @@ pub(crate) struct ReverseSccGraph {
graph: VecGraph<ConstraintSccIndex>,
/// For each SCC, the range of `universal_regions` that use that SCC as
/// 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
/// index into here.
universal_regions: Vec<RegionVid>,
Expand All @@ -26,7 +26,7 @@ impl ReverseSccGraph {
&'a self,
scc0: ConstraintSccIndex,
) -> impl Iterator<Item = RegionVid> + 'a {
let mut duplicates = FxHashSet::default();
let mut duplicates = FxIndexSet::default();
self.graph
.depth_first_search(scc0)
.flat_map(move |scc1| {
Expand Down Expand Up @@ -55,7 +55,7 @@ impl RegionInferenceContext<'_> {
paired_scc_regions.sort();
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;
for (scc, group) in &paired_scc_regions.into_iter().group_by(|(scc, _)| *scc) {
let group_size = group.count();
Expand Down
Loading