Skip to content
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

Reduce the number of RefCells in InferCtxt. #68694

Merged
merged 1 commit into from
Feb 10, 2020
Merged
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
6 changes: 4 additions & 2 deletions src/librustc/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
@@ -317,7 +317,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
let r = self
.infcx
.unwrap()
.borrow_region_constraints()
.inner
.borrow_mut()
.unwrap_region_constraints()
.opportunistic_resolve_var(self.tcx, vid);
debug!(
"canonical: region var found with vid {:?}, \
@@ -621,7 +623,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {

/// Returns the universe in which `vid` is defined.
fn region_var_universe(&self, vid: ty::RegionVid) -> ty::UniverseIndex {
self.infcx.unwrap().borrow_region_constraints().var_universe(vid)
self.infcx.unwrap().inner.borrow_mut().unwrap_region_constraints().var_universe(vid)
}

/// Creates a canonical variable (with the given `info`)
50 changes: 30 additions & 20 deletions src/librustc/infer/combine.rs
Original file line number Diff line number Diff line change
@@ -74,8 +74,9 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
match (&a.kind, &b.kind) {
// Relate integral variables to other types
(&ty::Infer(ty::IntVar(a_id)), &ty::Infer(ty::IntVar(b_id))) => {
self.int_unification_table
self.inner
.borrow_mut()
.int_unification_table
.unify_var_var(a_id, b_id)
.map_err(|e| int_unification_error(a_is_expected, e))?;
Ok(a)
@@ -95,8 +96,9 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {

// Relate floating-point variables to other types
(&ty::Infer(ty::FloatVar(a_id)), &ty::Infer(ty::FloatVar(b_id))) => {
self.float_unification_table
self.inner
.borrow_mut()
.float_unification_table
.unify_var_var(a_id, b_id)
.map_err(|e| float_unification_error(relation.a_is_expected(), e))?;
Ok(a)
@@ -131,8 +133,8 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
return Ok(a);
}

let a = replace_if_possible(self.const_unification_table.borrow_mut(), a);
let b = replace_if_possible(self.const_unification_table.borrow_mut(), b);
let a = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table, a);
let b = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table, b);

let a_is_expected = relation.a_is_expected();

@@ -141,8 +143,9 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
ty::ConstKind::Infer(InferConst::Var(a_vid)),
ty::ConstKind::Infer(InferConst::Var(b_vid)),
) => {
self.const_unification_table
self.inner
.borrow_mut()
.const_unification_table
.unify_var_var(a_vid, b_vid)
.map_err(|e| const_unification_error(a_is_expected, e))?;
return Ok(a);
@@ -174,8 +177,9 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
vid: ty::ConstVid<'tcx>,
value: &'tcx ty::Const<'tcx>,
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
self.const_unification_table
self.inner
.borrow_mut()
.const_unification_table
.unify_var_value(
vid,
ConstVarValue {
@@ -196,8 +200,9 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
vid: ty::IntVid,
val: ty::IntVarValue,
) -> RelateResult<'tcx, Ty<'tcx>> {
self.int_unification_table
self.inner
.borrow_mut()
.int_unification_table
.unify_var_value(vid, Some(val))
.map_err(|e| int_unification_error(vid_is_expected, e))?;
match val {
@@ -212,8 +217,9 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
vid: ty::FloatVid,
val: ast::FloatTy,
) -> RelateResult<'tcx, Ty<'tcx>> {
self.float_unification_table
self.inner
.borrow_mut()
.float_unification_table
.unify_var_value(vid, Some(ty::FloatVarValue(val)))
.map_err(|e| float_unification_error(vid_is_expected, e))?;
Ok(self.tcx.mk_mach_float(val))
@@ -260,7 +266,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
use self::RelationDir::*;

// Get the actual variable that b_vid has been inferred to
debug_assert!(self.infcx.type_variables.borrow_mut().probe(b_vid).is_unknown());
debug_assert!(self.infcx.inner.borrow_mut().type_variables.probe(b_vid).is_unknown());

debug!("instantiate(a_ty={:?} dir={:?} b_vid={:?})", a_ty, dir, b_vid);

@@ -280,7 +286,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
"instantiate(a_ty={:?}, dir={:?}, b_vid={:?}, generalized b_ty={:?})",
a_ty, dir, b_vid, b_ty
);
self.infcx.type_variables.borrow_mut().instantiate(b_vid, b_ty);
self.infcx.inner.borrow_mut().type_variables.instantiate(b_vid, b_ty);

if needs_wf {
self.obligations.push(Obligation::new(
@@ -338,7 +344,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {

debug!("generalize: ambient_variance = {:?}", ambient_variance);

let for_universe = match self.infcx.type_variables.borrow_mut().probe(for_vid) {
let for_universe = match self.infcx.inner.borrow_mut().type_variables.probe(for_vid) {
v @ TypeVariableValue::Known { .. } => {
panic!("instantiating {:?} which has a known value {:?}", for_vid, v,)
}
@@ -350,7 +356,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
let mut generalize = Generalizer {
infcx: self.infcx,
span: self.trace.cause.span,
for_vid_sub_root: self.infcx.type_variables.borrow_mut().sub_root_var(for_vid),
for_vid_sub_root: self.infcx.inner.borrow_mut().type_variables.sub_root_var(for_vid),
for_universe,
ambient_variance,
needs_wf: false,
@@ -502,17 +508,16 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
// us from creating infinitely sized types.
match t.kind {
ty::Infer(ty::TyVar(vid)) => {
let mut variables = self.infcx.type_variables.borrow_mut();
let vid = variables.root_var(vid);
let sub_vid = variables.sub_root_var(vid);
let vid = self.infcx.inner.borrow_mut().type_variables.root_var(vid);
let sub_vid = self.infcx.inner.borrow_mut().type_variables.sub_root_var(vid);
if sub_vid == self.for_vid_sub_root {
// If sub-roots are equal, then `for_vid` and
// `vid` are related via subtyping.
Err(TypeError::CyclicTy(self.root_ty))
} else {
match variables.probe(vid) {
let probe = self.infcx.inner.borrow_mut().type_variables.probe(vid);
match probe {
TypeVariableValue::Known { value: u } => {
drop(variables);
debug!("generalize: known value {:?}", u);
self.relate(&u, &u)
}
@@ -536,8 +541,13 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
ty::Covariant | ty::Contravariant => (),
}

let origin = *variables.var_origin(vid);
let new_var_id = variables.new_var(self.for_universe, false, origin);
let origin =
*self.infcx.inner.borrow_mut().type_variables.var_origin(vid);
let new_var_id = self.infcx.inner.borrow_mut().type_variables.new_var(
self.for_universe,
false,
origin,
);
let u = self.tcx().mk_ty_var(new_var_id);
debug!("generalize: replacing original vid={:?} with new={:?}", vid, u);
Ok(u)
@@ -612,7 +622,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {

match c.val {
ty::ConstKind::Infer(InferConst::Var(vid)) => {
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
let variable_table = &mut self.infcx.inner.borrow_mut().const_unification_table;
let var_value = variable_table.probe_value(vid);
match var_value.val {
ConstVariableValue::Known { value: u } => self.relate(&u, &u),
13 changes: 9 additions & 4 deletions src/librustc/infer/equate.rs
Original file line number Diff line number Diff line change
@@ -72,14 +72,14 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
}

let infcx = self.fields.infcx;
let a = infcx.type_variables.borrow_mut().replace_if_possible(a);
let b = infcx.type_variables.borrow_mut().replace_if_possible(b);
let a = infcx.inner.borrow_mut().type_variables.replace_if_possible(a);
let b = infcx.inner.borrow_mut().type_variables.replace_if_possible(b);

debug!("{}.tys: replacements ({:?}, {:?})", self.tag(), a, b);

match (&a.kind, &b.kind) {
(&ty::Infer(TyVar(a_id)), &ty::Infer(TyVar(b_id))) => {
infcx.type_variables.borrow_mut().equate(a_id, b_id);
infcx.inner.borrow_mut().type_variables.equate(a_id, b_id);
}

(&ty::Infer(TyVar(a_id)), _) => {
@@ -105,7 +105,12 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
) -> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
let origin = Subtype(box self.fields.trace.clone());
self.fields.infcx.borrow_region_constraints().make_eqregion(origin, a, b);
self.fields
.infcx
.inner
.borrow_mut()
.unwrap_region_constraints()
.make_eqregion(origin, a, b);
Ok(a)
}

13 changes: 8 additions & 5 deletions src/librustc/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
@@ -47,9 +47,12 @@ impl<'a, 'tcx> FindLocalByTypeVisitor<'a, 'tcx> {
if ty.walk().any(|inner_ty| {
inner_ty == self.target_ty
|| match (&inner_ty.kind, &self.target_ty.kind) {
(&Infer(TyVar(a_vid)), &Infer(TyVar(b_vid))) => {
self.infcx.type_variables.borrow_mut().sub_unified(a_vid, b_vid)
}
(&Infer(TyVar(a_vid)), &Infer(TyVar(b_vid))) => self
.infcx
.inner
.borrow_mut()
.type_variables
.sub_unified(a_vid, b_vid),
_ => false,
}
}) {
@@ -166,7 +169,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
highlight: Option<ty::print::RegionHighlightMode>,
) -> (String, Option<Span>, Cow<'static, str>, Option<String>, Option<&'static str>) {
if let ty::Infer(ty::TyVar(ty_vid)) = ty.kind {
let ty_vars = self.type_variables.borrow();
let ty_vars = &self.inner.borrow().type_variables;
let var_origin = ty_vars.var_origin(ty_vid);
if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind {
let parent_def_id = def_id.and_then(|def_id| self.tcx.parent(def_id));
@@ -224,7 +227,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let ty_to_string = |ty: Ty<'tcx>| -> String {
let mut s = String::new();
let mut printer = ty::print::FmtPrinter::new(self.tcx, &mut s, Namespace::TypeNS);
let ty_vars = self.type_variables.borrow();
let ty_vars = &self.inner.borrow().type_variables;
let getter = move |ty_vid| {
let var_origin = ty_vars.var_origin(ty_vid);
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) = var_origin.kind {
18 changes: 13 additions & 5 deletions src/librustc/infer/freshen.rs
Original file line number Diff line number Diff line change
@@ -154,14 +154,15 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {

match t.kind {
ty::Infer(ty::TyVar(v)) => {
let opt_ty = self.infcx.type_variables.borrow_mut().probe(v).known();
let opt_ty = self.infcx.inner.borrow_mut().type_variables.probe(v).known();
self.freshen_ty(opt_ty, ty::TyVar(v), ty::FreshTy)
}

ty::Infer(ty::IntVar(v)) => self.freshen_ty(
self.infcx
.int_unification_table
.inner
.borrow_mut()
.int_unification_table
.probe_value(v)
.map(|v| v.to_type(tcx)),
ty::IntVar(v),
@@ -170,8 +171,9 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {

ty::Infer(ty::FloatVar(v)) => self.freshen_ty(
self.infcx
.float_unification_table
.inner
.borrow_mut()
.float_unification_table
.probe_value(v)
.map(|v| v.to_type(tcx)),
ty::FloatVar(v),
@@ -225,8 +227,14 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
match ct.val {
ty::ConstKind::Infer(ty::InferConst::Var(v)) => {
let opt_ct =
self.infcx.const_unification_table.borrow_mut().probe_value(v).val.known();
let opt_ct = self
.infcx
.inner
.borrow_mut()
.const_unification_table
.probe_value(v)
.val
.known();
return self.freshen_const(
opt_ct,
ty::InferConst::Var(v),
32 changes: 14 additions & 18 deletions src/librustc/infer/fudge.rs
Original file line number Diff line number Diff line change
@@ -8,11 +8,10 @@ use super::{ConstVariableOrigin, RegionVariableOrigin};
use rustc_data_structures::unify as ut;
use ut::UnifyKey;

use std::cell::RefMut;
use std::ops::Range;

fn const_vars_since_snapshot<'tcx>(
mut table: RefMut<'_, ut::UnificationTable<ut::InPlace<ConstVid<'tcx>>>>,
table: &mut ut::UnificationTable<ut::InPlace<ConstVid<'tcx>>>,
snapshot: &ut::Snapshot<ut::InPlace<ConstVid<'tcx>>>,
) -> (Range<ConstVid<'tcx>>, Vec<ConstVariableOrigin>) {
let range = table.vars_since_snapshot(snapshot);
@@ -82,23 +81,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// going to be popped, so we will have to
// eliminate any references to them.

let type_vars = self
.type_variables
.borrow_mut()
.vars_since_snapshot(&snapshot.type_snapshot);
let int_vars = self
.int_unification_table
.borrow_mut()
.vars_since_snapshot(&snapshot.int_snapshot);
let float_vars = self
.float_unification_table
.borrow_mut()
.vars_since_snapshot(&snapshot.float_snapshot);
let region_vars = self
.borrow_region_constraints()
let mut inner = self.inner.borrow_mut();
let type_vars =
inner.type_variables.vars_since_snapshot(&snapshot.type_snapshot);
let int_vars =
inner.int_unification_table.vars_since_snapshot(&snapshot.int_snapshot);
let float_vars =
inner.float_unification_table.vars_since_snapshot(&snapshot.float_snapshot);
let region_vars = inner
.unwrap_region_constraints()
.vars_since_snapshot(&snapshot.region_constraints_snapshot);
let const_vars = const_vars_since_snapshot(
self.const_unification_table.borrow_mut(),
&mut inner.const_unification_table,
&snapshot.const_snapshot,
);

@@ -166,7 +160,9 @@ impl<'a, 'tcx> TypeFolder<'tcx> for InferenceFudger<'a, 'tcx> {
// variables to their binding anyhow, we know
// that it is unbound, so we can just return
// it.
debug_assert!(self.infcx.type_variables.borrow_mut().probe(vid).is_unknown());
debug_assert!(
self.infcx.inner.borrow_mut().type_variables.probe(vid).is_unknown()
);
ty
}
}
7 changes: 6 additions & 1 deletion src/librustc/infer/glb.rs
Original file line number Diff line number Diff line change
@@ -66,7 +66,12 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);

let origin = Subtype(box self.fields.trace.clone());
Ok(self.fields.infcx.borrow_region_constraints().glb_regions(self.tcx(), origin, a, b))
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().glb_regions(
self.tcx(),
origin,
a,
b,
))
}

fn consts(
2 changes: 1 addition & 1 deletion src/librustc/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
return Ok(());
}

self.borrow_region_constraints().leak_check(
self.inner.borrow_mut().unwrap_region_constraints().leak_check(
self.tcx,
overly_polymorphic,
placeholder_map,
4 changes: 2 additions & 2 deletions src/librustc/infer/lattice.rs
Original file line number Diff line number Diff line change
@@ -56,8 +56,8 @@ where
}

let infcx = this.infcx();
let a = infcx.type_variables.borrow_mut().replace_if_possible(a);
let b = infcx.type_variables.borrow_mut().replace_if_possible(b);
let a = infcx.inner.borrow_mut().type_variables.replace_if_possible(a);
let b = infcx.inner.borrow_mut().type_variables.replace_if_possible(b);
match (&a.kind, &b.kind) {
// If one side is known to be a variable and one is not,
// create a variable (`v`) to represent the LUB. Make sure to
7 changes: 6 additions & 1 deletion src/librustc/infer/lub.rs
Original file line number Diff line number Diff line change
@@ -66,7 +66,12 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);

let origin = Subtype(box self.fields.trace.clone());
Ok(self.fields.infcx.borrow_region_constraints().lub_regions(self.tcx(), origin, a, b))
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().lub_regions(
self.tcx(),
origin,
a,
b,
))
}

fn consts(
336 changes: 181 additions & 155 deletions src/librustc/infer/mod.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/librustc/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
@@ -322,7 +322,7 @@ where
match value_ty.kind {
ty::Infer(ty::TyVar(value_vid)) => {
// Two type variables: just equate them.
self.infcx.type_variables.borrow_mut().equate(vid, value_vid);
self.infcx.inner.borrow_mut().type_variables.equate(vid, value_vid);
return Ok(value_ty);
}

@@ -343,7 +343,7 @@ where
assert!(!generalized_ty.has_infer_types());
}

self.infcx.type_variables.borrow_mut().instantiate(vid, generalized_ty);
self.infcx.inner.borrow_mut().type_variables.instantiate(vid, generalized_ty);

// The generalized values we extract from `canonical_var_values` have
// been fully instantiated and hence the set of scopes we have
@@ -373,7 +373,7 @@ where
delegate: &mut self.delegate,
first_free_index: ty::INNERMOST,
ambient_variance: self.ambient_variance,
for_vid_sub_root: self.infcx.type_variables.borrow_mut().sub_root_var(for_vid),
for_vid_sub_root: self.infcx.inner.borrow_mut().type_variables.sub_root_var(for_vid),
universe,
};

@@ -870,7 +870,7 @@ where
}

ty::Infer(ty::TyVar(vid)) => {
let mut variables = self.infcx.type_variables.borrow_mut();
let variables = &mut self.infcx.inner.borrow_mut().type_variables;
let vid = variables.root_var(vid);
let sub_vid = variables.sub_root_var(vid);
if sub_vid == self.for_vid_sub_root {
@@ -972,7 +972,7 @@ where
bug!("unexpected inference variable encountered in NLL generalization: {:?}", a);
}
ty::ConstKind::Infer(InferConst::Var(vid)) => {
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
let variable_table = &mut self.infcx.inner.borrow_mut().const_unification_table;
let var_value = variable_table.probe_value(vid);
match var_value.val.known() {
Some(u) => self.relate(&u, &u),
4 changes: 2 additions & 2 deletions src/librustc/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
) {
debug!("register_region_obligation(body_id={:?}, obligation={:?})", body_id, obligation);

self.region_obligations.borrow_mut().push((body_id, obligation));
self.inner.borrow_mut().region_obligations.push((body_id, obligation));
}

pub fn register_region_obligation_with_cause(
@@ -103,7 +103,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {

/// Trait queries just want to pass back type obligations "as is"
pub fn take_registered_region_obligations(&self) -> Vec<(hir::HirId, RegionObligation<'tcx>)> {
::std::mem::take(&mut *self.region_obligations.borrow_mut())
::std::mem::take(&mut self.inner.borrow_mut().region_obligations)
}

/// Process the region obligations that must be proven (during
11 changes: 7 additions & 4 deletions src/librustc/infer/resolve.rs
Original file line number Diff line number Diff line change
@@ -75,9 +75,12 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticTypeAndRegionResolver<'a, 'tcx>

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
ty::ReVar(rid) => {
self.infcx.borrow_region_constraints().opportunistic_resolve_var(self.tcx(), rid)
}
ty::ReVar(rid) => self
.infcx
.inner
.borrow_mut()
.unwrap_region_constraints()
.opportunistic_resolve_var(self.tcx(), rid),
_ => r,
}
}
@@ -120,7 +123,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
// Since we called `shallow_resolve` above, this must
// be an (as yet...) unresolved inference variable.
let ty_var_span = if let ty::TyVar(ty_vid) = infer_ty {
let ty_vars = self.infcx.type_variables.borrow();
let ty_vars = &self.infcx.inner.borrow().type_variables;
if let TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeParameterDefinition(_, _),
span,
13 changes: 9 additions & 4 deletions src/librustc/infer/sub.rs
Original file line number Diff line number Diff line change
@@ -80,8 +80,8 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
}

let infcx = self.fields.infcx;
let a = infcx.type_variables.borrow_mut().replace_if_possible(a);
let b = infcx.type_variables.borrow_mut().replace_if_possible(b);
let a = infcx.inner.borrow_mut().type_variables.replace_if_possible(a);
let b = infcx.inner.borrow_mut().type_variables.replace_if_possible(b);
match (&a.kind, &b.kind) {
(&ty::Infer(TyVar(a_vid)), &ty::Infer(TyVar(b_vid))) => {
// Shouldn't have any LBR here, so we can safely put
@@ -95,7 +95,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
// have to record in the `type_variables` tracker that
// the two variables are equal modulo subtyping, which
// is important to the occurs check later on.
infcx.type_variables.borrow_mut().sub(a_vid, b_vid);
infcx.inner.borrow_mut().type_variables.sub(a_vid, b_vid);
self.fields.obligations.push(Obligation::new(
self.fields.trace.cause.clone(),
self.fields.param_env,
@@ -140,7 +140,12 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
// from the "cause" field, we could perhaps give more tailored
// error messages.
let origin = SubregionOrigin::Subtype(box self.fields.trace.clone());
self.fields.infcx.borrow_region_constraints().make_subregion(origin, a, b);
self.fields
.infcx
.inner
.borrow_mut()
.unwrap_region_constraints()
.make_subregion(origin, a, b);

Ok(a)
}
3 changes: 1 addition & 2 deletions src/librustc/infer/unify_key.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ use rustc_data_structures::unify::{EqUnifyValue, NoError, UnificationTable, Unif
use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};

use std::cell::RefMut;
use std::cmp;
use std::marker::PhantomData;

@@ -214,7 +213,7 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
impl<'tcx> EqUnifyValue for &'tcx ty::Const<'tcx> {}

pub fn replace_if_possible(
mut table: RefMut<'_, UnificationTable<InPlace<ty::ConstVid<'tcx>>>>,
table: &mut UnificationTable<InPlace<ty::ConstVid<'tcx>>>,
c: &'tcx ty::Const<'tcx>,
) -> &'tcx ty::Const<'tcx> {
if let ty::Const { val: ty::ConstKind::Infer(InferConst::Var(vid)), .. } = c {
16 changes: 13 additions & 3 deletions src/librustc/traits/auto_trait.rs
Original file line number Diff line number Diff line change
@@ -199,12 +199,22 @@ impl<'tcx> AutoTraitFinder<'tcx> {
panic!("Unable to fulfill trait {:?} for '{:?}': {:?}", trait_did, ty, e)
});

let body_id_map: FxHashMap<_, _> =
infcx.region_obligations.borrow().iter().map(|&(id, _)| (id, vec![])).collect();
let body_id_map: FxHashMap<_, _> = infcx
.inner
.borrow()
.region_obligations
.iter()
.map(|&(id, _)| (id, vec![]))
.collect();

infcx.process_registered_region_obligations(&body_id_map, None, full_env);

let region_data = infcx.borrow_region_constraints().region_constraint_data().clone();
let region_data = infcx
.inner
.borrow_mut()
.unwrap_region_constraints()
.region_constraint_data()
.clone();

let vid_to_region = self.map_vid_to_region(&region_data);

12 changes: 6 additions & 6 deletions src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
@@ -454,7 +454,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
// bounds. It might be the case that we want two distinct caches,
// or else another kind of cache entry.

let cache_result = infcx.projection_cache.borrow_mut().try_start(cache_key);
let cache_result = infcx.inner.borrow_mut().projection_cache.try_start(cache_key);
match cache_result {
Ok(()) => {}
Err(ProjectionCacheEntry::Ambiguous) => {
@@ -528,7 +528,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
// Once we have inferred everything we need to know, we
// can ignore the `obligations` from that point on.
if infcx.unresolved_type_vars(&ty.value).is_none() {
infcx.projection_cache.borrow_mut().complete_normalized(cache_key, &ty);
infcx.inner.borrow_mut().projection_cache.complete_normalized(cache_key, &ty);
// No need to extend `obligations`.
} else {
obligations.extend(ty.obligations);
@@ -590,7 +590,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
};

let cache_value = prune_cache_value_obligations(infcx, &result);
infcx.projection_cache.borrow_mut().insert_ty(cache_key, cache_value);
infcx.inner.borrow_mut().projection_cache.insert_ty(cache_key, cache_value);
obligations.extend(result.obligations);
Some(result.value)
}
@@ -601,7 +601,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
projected_ty
);
let result = Normalized { value: projected_ty, obligations: vec![] };
infcx.projection_cache.borrow_mut().insert_ty(cache_key, result.clone());
infcx.inner.borrow_mut().projection_cache.insert_ty(cache_key, result.clone());
// No need to extend `obligations`.
Some(result.value)
}
@@ -610,7 +610,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
"opt_normalize_projection_type: \
too many candidates"
);
infcx.projection_cache.borrow_mut().ambiguous(cache_key);
infcx.inner.borrow_mut().projection_cache.ambiguous(cache_key);
None
}
Err(ProjectionTyError::TraitSelectionError(_)) => {
@@ -620,7 +620,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
// Trait`, which when processed will cause the error to be
// reported later

infcx.projection_cache.borrow_mut().error(cache_key);
infcx.inner.borrow_mut().projection_cache.error(cache_key);
let result = normalize_to_error(selcx, param_env, projection_ty, cause, depth);
obligations.extend(result.obligations);
Some(result.value)
2 changes: 1 addition & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
@@ -511,7 +511,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if let Some(key) =
ProjectionCacheKey::from_poly_projection_predicate(self, data)
{
self.infcx.projection_cache.borrow_mut().complete(key);
self.infcx.inner.borrow_mut().projection_cache.complete(key);
}
result
}
4 changes: 3 additions & 1 deletion src/librustc_traits/chalk_context/resolvent_ops.rs
Original file line number Diff line number Diff line change
@@ -226,7 +226,9 @@ impl TypeRelation<'tcx> for AnswerSubstitutor<'cx, 'tcx> {
let b = match b {
&ty::ReVar(vid) => self
.infcx
.borrow_region_constraints()
.inner
.borrow_mut()
.unwrap_region_constraints()
.opportunistic_resolve_var(self.infcx.tcx, vid),

other => other,