Inline and remove RegionConstraintCollector::into_infos_and_data
.
It's a weird method, and used weirdly: - It's on `RegionConstraintCollector` but operates on `RegionConstraintStorage`. So at both call sites we create a temporary `RegionConstraintCollector`, using `with_log`, to call it. - It `take`s just two of the six fields in `RegionConstraintStorage`. At one of the two call sites we unnecessarily clone the entire `RegionConstraintStorage` just to take those two fields. This commit just inlines and removes it. We no longer need to `take` the two fields, we can just use them directly.
This commit is contained in:
parent
0293827e09
commit
2b57a785a9
3 changed files with 18 additions and 32 deletions
|
@ -18,7 +18,7 @@ pub use relate::combine::PredicateEmittingRelation;
|
||||||
use rustc_data_structures::captures::Captures;
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_data_structures::undo_log::Rollback;
|
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
|
||||||
use rustc_data_structures::unify as ut;
|
use rustc_data_structures::unify as ut;
|
||||||
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
|
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -50,6 +50,7 @@ use snapshot::undo_log::InferCtxtUndoLogs;
|
||||||
use tracing::{debug, instrument};
|
use tracing::{debug, instrument};
|
||||||
use type_variable::TypeVariableOrigin;
|
use type_variable::TypeVariableOrigin;
|
||||||
|
|
||||||
|
use crate::infer::region_constraints::UndoLog;
|
||||||
use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligation, TraitEngine};
|
use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligation, TraitEngine};
|
||||||
|
|
||||||
pub mod at;
|
pub mod at;
|
||||||
|
@ -1043,18 +1044,14 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
/// Clone the list of variable regions. This is used only during NLL processing
|
/// Clone the list of variable regions. This is used only during NLL processing
|
||||||
/// to put the set of region variables into the NLL region context.
|
/// to put the set of region variables into the NLL region context.
|
||||||
pub fn get_region_var_origins(&self) -> VarInfos {
|
pub fn get_region_var_origins(&self) -> VarInfos {
|
||||||
let mut inner = self.inner.borrow_mut();
|
let inner = self.inner.borrow();
|
||||||
let (var_infos, data) = inner
|
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log));
|
||||||
.region_constraint_storage
|
let storage = inner.region_constraint_storage.as_ref().expect("regions already resolved");
|
||||||
// We clone instead of taking because borrowck still wants to use
|
assert!(storage.data.is_empty());
|
||||||
// the inference context after calling this for diagnostics
|
// We clone instead of taking because borrowck still wants to use the
|
||||||
// and the new trait solver.
|
// inference context after calling this for diagnostics and the new
|
||||||
.clone()
|
// trait solver.
|
||||||
.expect("regions already resolved")
|
storage.var_infos.clone()
|
||||||
.with_log(&mut inner.undo_log)
|
|
||||||
.into_infos_and_data();
|
|
||||||
assert!(data.is_empty());
|
|
||||||
var_infos
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
//! Various code related to computing outlives relations.
|
//! Various code related to computing outlives relations.
|
||||||
|
|
||||||
|
use rustc_data_structures::undo_log::UndoLogs;
|
||||||
use rustc_middle::traits::query::{NoSolution, OutlivesBound};
|
use rustc_middle::traits::query::{NoSolution, OutlivesBound};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use self::env::OutlivesEnvironment;
|
use self::env::OutlivesEnvironment;
|
||||||
use super::region_constraints::RegionConstraintData;
|
use super::region_constraints::{RegionConstraintData, UndoLog};
|
||||||
use super::{InferCtxt, RegionResolutionError, SubregionOrigin};
|
use super::{InferCtxt, RegionResolutionError, SubregionOrigin};
|
||||||
use crate::infer::free_regions::RegionRelations;
|
use crate::infer::free_regions::RegionRelations;
|
||||||
use crate::infer::lexical_region_resolve;
|
use crate::infer::lexical_region_resolve;
|
||||||
|
@ -63,7 +64,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (var_infos, data) = {
|
let storage = {
|
||||||
let mut inner = self.inner.borrow_mut();
|
let mut inner = self.inner.borrow_mut();
|
||||||
let inner = &mut *inner;
|
let inner = &mut *inner;
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -71,18 +72,14 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
"region_obligations not empty: {:#?}",
|
"region_obligations not empty: {:#?}",
|
||||||
inner.region_obligations
|
inner.region_obligations
|
||||||
);
|
);
|
||||||
inner
|
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log));
|
||||||
.region_constraint_storage
|
inner.region_constraint_storage.take().expect("regions already resolved")
|
||||||
.take()
|
|
||||||
.expect("regions already resolved")
|
|
||||||
.with_log(&mut inner.undo_log)
|
|
||||||
.into_infos_and_data()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let region_rels = &RegionRelations::new(self.tcx, outlives_env.free_region_map());
|
let region_rels = &RegionRelations::new(self.tcx, outlives_env.free_region_map());
|
||||||
|
|
||||||
let (lexical_region_resolutions, errors) =
|
let (lexical_region_resolutions, errors) =
|
||||||
lexical_region_resolve::resolve(region_rels, var_infos, data);
|
lexical_region_resolve::resolve(region_rels, storage.var_infos, storage.data);
|
||||||
|
|
||||||
let old_value = self.lexical_region_resolutions.replace(Some(lexical_region_resolutions));
|
let old_value = self.lexical_region_resolutions.replace(Some(lexical_region_resolutions));
|
||||||
assert!(old_value.is_none());
|
assert!(old_value.is_none());
|
||||||
|
|
|
@ -27,9 +27,9 @@ pub use rustc_middle::infer::MemberConstraint;
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct RegionConstraintStorage<'tcx> {
|
pub struct RegionConstraintStorage<'tcx> {
|
||||||
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
|
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
|
||||||
var_infos: IndexVec<RegionVid, RegionVariableInfo>,
|
pub(super) var_infos: IndexVec<RegionVid, RegionVariableInfo>,
|
||||||
|
|
||||||
data: RegionConstraintData<'tcx>,
|
pub(super) data: RegionConstraintData<'tcx>,
|
||||||
|
|
||||||
/// For a given pair of regions (R1, R2), maps to a region R3 that
|
/// For a given pair of regions (R1, R2), maps to a region R3 that
|
||||||
/// is designated as their LUB (edges R1 <= R3 and R2 <= R3
|
/// is designated as their LUB (edges R1 <= R3 and R2 <= R3
|
||||||
|
@ -354,14 +354,6 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
||||||
&self.data
|
&self.data
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Once all the constraints have been gathered, extract out the final data.
|
|
||||||
///
|
|
||||||
/// Not legal during a snapshot.
|
|
||||||
pub fn into_infos_and_data(self) -> (VarInfos, RegionConstraintData<'tcx>) {
|
|
||||||
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&self.undo_log));
|
|
||||||
(mem::take(&mut self.storage.var_infos), mem::take(&mut self.storage.data))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Takes (and clears) the current set of constraints. Note that
|
/// Takes (and clears) the current set of constraints. Note that
|
||||||
/// the set of variables remains intact, but all relationships
|
/// the set of variables remains intact, but all relationships
|
||||||
/// between them are reset. This is used during NLL checking to
|
/// between them are reset. This is used during NLL checking to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue