summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_borrowck/src/region_infer
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /compiler/rustc_borrowck/src/region_infer
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_borrowck/src/region_infer')
-rw-r--r--compiler/rustc_borrowck/src/region_infer/mod.rs61
-rw-r--r--compiler/rustc_borrowck/src/region_infer/opaque_types.rs17
-rw-r--r--compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs8
3 files changed, 43 insertions, 43 deletions
diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs
index e6195de40..729f3dbff 100644
--- a/compiler/rustc_borrowck/src/region_infer/mod.rs
+++ b/compiler/rustc_borrowck/src/region_infer/mod.rs
@@ -3,11 +3,11 @@ 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;
-use rustc_index::vec::IndexVec;
+use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_infer::infer::outlives::test_type_match;
use rustc_infer::infer::region_constraints::{GenericKind, VarInfos, VerifyBound, VerifyIfEq};
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin};
@@ -27,7 +27,7 @@ use crate::{
},
diagnostics::{RegionErrorKind, RegionErrors, UniverseInfo},
member_constraints::{MemberConstraintSet, NllMemberConstraintIndex},
- nll::{PoloniusOutput, ToRegionVid},
+ nll::PoloniusOutput,
region_infer::reverse_sccs::ReverseSccGraph,
region_infer::values::{
LivenessValues, PlaceholderIndices, RegionElement, RegionValueElements, RegionValues,
@@ -88,7 +88,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
@@ -255,15 +255,16 @@ fn sccs_info<'cx, 'tcx>(
let var_to_origin = infcx.reg_var_to_origin.borrow();
let mut var_to_origin_sorted = var_to_origin.clone().into_iter().collect::<Vec<_>>();
- var_to_origin_sorted.sort_by(|a, b| a.0.cmp(&b.0));
- let mut debug_str = "region variables to origins:\n".to_string();
+ var_to_origin_sorted.sort_by_key(|vto| vto.0);
+
+ let mut reg_vars_to_origins_str = "region variables to origins:\n".to_string();
for (reg_var, origin) in var_to_origin_sorted.into_iter() {
- debug_str.push_str(&format!("{:?}: {:?}\n", reg_var, origin));
+ reg_vars_to_origins_str.push_str(&format!("{:?}: {:?}\n", reg_var, origin));
}
- debug!(debug_str);
+ debug!("{}", reg_vars_to_origins_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);
@@ -275,12 +276,12 @@ fn sccs_info<'cx, 'tcx>(
for (scc_idx, reg_vars_origins) in components.iter().enumerate() {
let regions_info = reg_vars_origins.clone().into_iter().collect::<Vec<_>>();
components_str.push_str(&format!(
- "{:?}: {:?})",
+ "{:?}: {:?},\n)",
ConstraintSccIndex::from_usize(scc_idx),
regions_info,
))
}
- debug!(components_str);
+ debug!("{}", components_str);
// calculate the best representative for each component
let components_representatives = components
@@ -295,9 +296,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];
@@ -325,7 +326,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>,
@@ -398,7 +399,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// the minimum, or narrowest, universe.
fn compute_scc_universes(
constraint_sccs: &Sccs<RegionVid, ConstraintSccIndex>,
- definitions: &IndexVec<RegionVid, RegionDefinition<'tcx>>,
+ definitions: &IndexSlice<RegionVid, RegionDefinition<'tcx>>,
) -> IndexVec<ConstraintSccIndex, ty::UniverseIndex> {
let num_sccs = constraint_sccs.num_sccs();
let mut scc_universes = IndexVec::from_elem_n(ty::UniverseIndex::MAX, num_sccs);
@@ -485,7 +486,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// more details.
fn compute_scc_representatives(
constraints_scc: &Sccs<RegionVid, ConstraintSccIndex>,
- definitions: &IndexVec<RegionVid, RegionDefinition<'tcx>>,
+ definitions: &IndexSlice<RegionVid, RegionDefinition<'tcx>>,
) -> IndexVec<ConstraintSccIndex, ty::RegionVid> {
let num_sccs = constraints_scc.num_sccs();
let next_region_vid = definitions.next_index();
@@ -522,6 +523,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 {:?}",
@@ -591,14 +593,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// Returns `true` if the region `r` contains the point `p`.
///
/// Panics if called before `solve()` executes,
- pub(crate) fn region_contains(&self, r: impl ToRegionVid, p: impl ToElementIndex) -> bool {
- let scc = self.constraint_sccs.scc(r.to_region_vid());
+ pub(crate) fn region_contains(&self, r: RegionVid, p: impl ToElementIndex) -> bool {
+ let scc = self.constraint_sccs.scc(r);
self.scc_values.contains(scc, p)
}
/// Returns access to the value of `r` for debugging purposes.
pub(crate) fn region_value_str(&self, r: RegionVid) -> String {
- let scc = self.constraint_sccs.scc(r.to_region_vid());
+ let scc = self.constraint_sccs.scc(r);
self.scc_values.region_value_str(scc)
}
@@ -606,24 +608,21 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&'a self,
r: RegionVid,
) -> impl Iterator<Item = ty::PlaceholderRegion> + 'a {
- let scc = self.constraint_sccs.scc(r.to_region_vid());
+ let scc = self.constraint_sccs.scc(r);
self.scc_values.placeholders_contained_in(scc)
}
/// Returns access to the value of `r` for debugging purposes.
pub(crate) fn region_universe(&self, r: RegionVid) -> ty::UniverseIndex {
- let scc = self.constraint_sccs.scc(r.to_region_vid());
+ let scc = self.constraint_sccs.scc(r);
self.scc_universes[scc]
}
/// Once region solving has completed, this function will return
/// the member constraints that were applied to the value of a given
/// region `r`. See `AppliedMemberConstraint`.
- pub(crate) fn applied_member_constraints(
- &self,
- r: impl ToRegionVid,
- ) -> &[AppliedMemberConstraint] {
- let scc = self.constraint_sccs.scc(r.to_region_vid());
+ pub(crate) fn applied_member_constraints(&self, r: RegionVid) -> &[AppliedMemberConstraint] {
+ let scc = self.constraint_sccs.scc(r);
binary_search_util::binary_search_slice(
&self.member_constraints_applied,
|applied| applied.member_region_scc,
@@ -918,7 +917,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);
@@ -1131,7 +1130,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let r_vid = self.to_region_vid(r);
let r_scc = self.constraint_sccs.scc(r_vid);
- // The challenge if this. We have some region variable `r`
+ // The challenge is this. We have some region variable `r`
// whose value is a set of CFG points and universal
// regions. We want to find if that set is *equivalent* to
// any of the named regions found in the closure.
@@ -1504,6 +1503,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()
@@ -2213,7 +2214,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// is in the same SCC or something. In that case, find what
// appears to be the most interesting point to report to the
// user via an even more ad-hoc guess.
- categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
+ categorized_path.sort_by_key(|p| p.category);
debug!("sorted_path={:#?}", categorized_path);
(categorized_path.remove(0), extra_info)
@@ -2230,7 +2231,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
r: RegionVid,
body: &Body<'_>,
) -> Option<Location> {
- let scc = self.constraint_sccs.scc(r.to_region_vid());
+ let scc = self.constraint_sccs.scc(r);
let locations = self.scc_values.locations_outlived_by(scc);
for location in locations {
let bb = &body[location.block];
diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs
index c550e37c6..2b16655cf 100644
--- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs
+++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs
@@ -1,5 +1,4 @@
-use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
-use rustc_data_structures::vec_map::VecMap;
+use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::OpaqueTyOrigin;
@@ -61,11 +60,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
pub(crate) fn infer_opaque_types(
&self,
infcx: &InferCtxt<'tcx>,
- opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
- ) -> VecMap<LocalDefId, OpaqueHiddenType<'tcx>> {
- let mut result: VecMap<LocalDefId, OpaqueHiddenType<'tcx>> = VecMap::new();
+ opaque_ty_decls: FxIndexMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
+ ) -> FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> {
+ let mut result: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> = FxIndexMap::default();
- let member_constraints: FxHashMap<_, _> = self
+ let member_constraints: FxIndexMap<_, _> = self
.member_constraints
.all_indices()
.map(|ci| (self.member_constraints[ci].key, ci))
@@ -284,7 +283,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
// hidden type is well formed even without those bounds.
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()));
- let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
+ let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id);
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
// the bounds that the function supplies.
@@ -325,7 +324,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
if errors.is_empty() {
definition_ty
} else {
- let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
+ let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
self.tcx.ty_error(reported)
}
}
@@ -364,7 +363,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(_)),
diff --git a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
index 167f66460..23a59c128 100644
--- a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
+++ b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
@@ -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;
@@ -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>,
@@ -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| {
@@ -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();