Skip to content

Commit 2b57a78

Browse files
committed
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.
1 parent 0293827 commit 2b57a78

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use relate::combine::PredicateEmittingRelation;
1818
use rustc_data_structures::captures::Captures;
1919
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
2020
use rustc_data_structures::sync::Lrc;
21-
use rustc_data_structures::undo_log::Rollback;
21+
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
2222
use rustc_data_structures::unify as ut;
2323
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
2424
use rustc_hir as hir;
@@ -50,6 +50,7 @@ use snapshot::undo_log::InferCtxtUndoLogs;
5050
use tracing::{debug, instrument};
5151
use type_variable::TypeVariableOrigin;
5252

53+
use crate::infer::region_constraints::UndoLog;
5354
use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligation, TraitEngine};
5455

5556
pub mod at;
@@ -1043,18 +1044,14 @@ impl<'tcx> InferCtxt<'tcx> {
10431044
/// Clone the list of variable regions. This is used only during NLL processing
10441045
/// to put the set of region variables into the NLL region context.
10451046
pub fn get_region_var_origins(&self) -> VarInfos {
1046-
let mut inner = self.inner.borrow_mut();
1047-
let (var_infos, data) = inner
1048-
.region_constraint_storage
1049-
// We clone instead of taking because borrowck still wants to use
1050-
// the inference context after calling this for diagnostics
1051-
// and the new trait solver.
1052-
.clone()
1053-
.expect("regions already resolved")
1054-
.with_log(&mut inner.undo_log)
1055-
.into_infos_and_data();
1056-
assert!(data.is_empty());
1057-
var_infos
1047+
let inner = self.inner.borrow();
1048+
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log));
1049+
let storage = inner.region_constraint_storage.as_ref().expect("regions already resolved");
1050+
assert!(storage.data.is_empty());
1051+
// We clone instead of taking because borrowck still wants to use the
1052+
// inference context after calling this for diagnostics and the new
1053+
// trait solver.
1054+
storage.var_infos.clone()
10581055
}
10591056

10601057
#[instrument(level = "debug", skip(self), ret)]

compiler/rustc_infer/src/infer/outlives/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! Various code related to computing outlives relations.
22
3+
use rustc_data_structures::undo_log::UndoLogs;
34
use rustc_middle::traits::query::{NoSolution, OutlivesBound};
45
use rustc_middle::ty;
56
use tracing::instrument;
67

78
use self::env::OutlivesEnvironment;
8-
use super::region_constraints::RegionConstraintData;
9+
use super::region_constraints::{RegionConstraintData, UndoLog};
910
use super::{InferCtxt, RegionResolutionError, SubregionOrigin};
1011
use crate::infer::free_regions::RegionRelations;
1112
use crate::infer::lexical_region_resolve;
@@ -63,26 +64,22 @@ impl<'tcx> InferCtxt<'tcx> {
6364
}
6465
};
6566

66-
let (var_infos, data) = {
67+
let storage = {
6768
let mut inner = self.inner.borrow_mut();
6869
let inner = &mut *inner;
6970
assert!(
7071
self.tainted_by_errors().is_some() || inner.region_obligations.is_empty(),
7172
"region_obligations not empty: {:#?}",
7273
inner.region_obligations
7374
);
74-
inner
75-
.region_constraint_storage
76-
.take()
77-
.expect("regions already resolved")
78-
.with_log(&mut inner.undo_log)
79-
.into_infos_and_data()
75+
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log));
76+
inner.region_constraint_storage.take().expect("regions already resolved")
8077
};
8178

8279
let region_rels = &RegionRelations::new(self.tcx, outlives_env.free_region_map());
8380

8481
let (lexical_region_resolutions, errors) =
85-
lexical_region_resolve::resolve(region_rels, var_infos, data);
82+
lexical_region_resolve::resolve(region_rels, storage.var_infos, storage.data);
8683

8784
let old_value = self.lexical_region_resolutions.replace(Some(lexical_region_resolutions));
8885
assert!(old_value.is_none());

compiler/rustc_infer/src/infer/region_constraints/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ pub use rustc_middle::infer::MemberConstraint;
2727
#[derive(Clone, Default)]
2828
pub struct RegionConstraintStorage<'tcx> {
2929
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
30-
var_infos: IndexVec<RegionVid, RegionVariableInfo>,
30+
pub(super) var_infos: IndexVec<RegionVid, RegionVariableInfo>,
3131

32-
data: RegionConstraintData<'tcx>,
32+
pub(super) data: RegionConstraintData<'tcx>,
3333

3434
/// For a given pair of regions (R1, R2), maps to a region R3 that
3535
/// is designated as their LUB (edges R1 <= R3 and R2 <= R3
@@ -354,14 +354,6 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
354354
&self.data
355355
}
356356

357-
/// Once all the constraints have been gathered, extract out the final data.
358-
///
359-
/// Not legal during a snapshot.
360-
pub fn into_infos_and_data(self) -> (VarInfos, RegionConstraintData<'tcx>) {
361-
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&self.undo_log));
362-
(mem::take(&mut self.storage.var_infos), mem::take(&mut self.storage.data))
363-
}
364-
365357
/// Takes (and clears) the current set of constraints. Note that
366358
/// the set of variables remains intact, but all relationships
367359
/// between them are reset. This is used during NLL checking to

0 commit comments

Comments
 (0)