Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Move FulfillmentContext out of InferCtxt
  • Loading branch information
soltanmm-google committed Feb 11, 2016
commit 0ff7021dd372209c5380196ef7f979548c32bab0
5 changes: 1 addition & 4 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ pub struct InferCtxt<'a, 'tcx: 'a> {

pub parameter_environment: ty::ParameterEnvironment<'a, 'tcx>,

pub fulfillment_cx: RefCell<traits::FulfillmentContext<'tcx>>,

// the set of predicates on which errors have been reported, to
// avoid reporting the same error twice.
pub reported_trait_errors: RefCell<FnvHashSet<traits::TraitErrorKey<'tcx>>>,
Expand Down Expand Up @@ -366,7 +364,6 @@ pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>,
float_unification_table: RefCell::new(UnificationTable::new()),
region_vars: RegionVarBindings::new(tcx),
parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()),
fulfillment_cx: RefCell::new(traits::FulfillmentContext::new()),
reported_trait_errors: RefCell::new(FnvHashSet()),
normalize: false,
err_count_on_creation: tcx.sess.err_count()
Expand Down Expand Up @@ -525,7 +522,7 @@ pub fn normalize_associated_type<'tcx,T>(tcx: &ty::ctxt<'tcx>, value: &T) -> T
result,
obligations);

let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
let mut fulfill_cx = traits::FulfillmentContext::new();

for obligation in obligations {
fulfill_cx.register_predicate_obligation(&infcx, obligation);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_passes/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
let ty = self.tcx.node_id_to_type(e.id);
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None);
let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic);
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
match fulfill_cx.select_all_or_error(&infcx) {
let mut fulfillment_cx = traits::FulfillmentContext::new();
fulfillment_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
match fulfillment_cx.select_all_or_error(&infcx) {
Ok(()) => { },
Err(ref errors) => {
traits::report_fulfillment_errors(&infcx, errors);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// Currently, we use a fulfillment context to completely resolve
// all nested obligations. This is because they can inform the
// inference of the impl's type parameters.
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
let mut fulfill_cx = traits::FulfillmentContext::new();
let vtable = selection.map(|predicate| {
fulfill_cx.register_predicate_obligation(&infcx, predicate);
});
Expand Down Expand Up @@ -1188,7 +1188,7 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
let tcx = ccx.tcx();
let infcx = infer::normalizing_infer_ctxt(tcx, &tcx.tables);
let mut selcx = traits::SelectionContext::new(&infcx);
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
let mut fulfill_cx = traits::FulfillmentContext::new();
let cause = traits::ObligationCause::dummy();
let traits::Normalized { value: predicates, obligations } =
traits::normalize(&mut selcx, cause.clone(), &predicates);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn deduce_expectations_from_obligations<'a,'tcx>(
expected_vid: ty::TyVid)
-> (Option<ty::FnSig<'tcx>>, Option<ty::ClosureKind>)
{
let fulfillment_cx = fcx.inh.infcx.fulfillment_cx.borrow();
let fulfillment_cx = fcx.inh.fulfillment_cx.borrow();
// Here `expected_ty` is known to be a type inference variable.

let expected_sig =
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
impl_trait_ref);

let mut infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
let mut fulfillment_cx = infcx.fulfillment_cx.borrow_mut();
let mut fulfillment_cx = traits::FulfillmentContext::new();

let trait_to_impl_substs = &impl_trait_ref.substs;

Expand Down Expand Up @@ -417,7 +417,7 @@ pub fn compare_const_impl<'tcx>(tcx: &ty::ctxt<'tcx>,
impl_trait_ref);

let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
let mut fulfillment_cx = infcx.fulfillment_cx.borrow_mut();
let mut fulfillment_cx = traits::FulfillmentContext::new();

// The below is for the most part highly similar to the procedure
// for methods above. It is simpler in many respects, especially
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_typeck/check/dropck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(

let impl_param_env = ty::ParameterEnvironment::for_item(tcx, self_type_node_id);
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(impl_param_env));
let mut fulfillment_cx = traits::FulfillmentContext::new();

let named_type = tcx.lookup_item_type(self_type_did).ty;
let named_type = named_type.subst(tcx, &infcx.parameter_environment.free_substs);
Expand All @@ -105,7 +106,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
return Err(());
}

if let Err(ref errors) = infcx.fulfillment_cx.borrow_mut().select_all_or_error(&infcx) {
if let Err(ref errors) = fulfillment_cx.select_all_or_error(&infcx) {
// this could be reached when we get lazy normalization
traits::report_fulfillment_errors(&infcx, errors);
return Err(());
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ pub struct Inherited<'a, 'tcx: 'a> {
infcx: infer::InferCtxt<'a, 'tcx>,
locals: RefCell<NodeMap<Ty<'tcx>>>,

fulfillment_cx: RefCell<traits::FulfillmentContext<'tcx>>,

tables: &'a RefCell<ty::Tables<'tcx>>,

// When we process a call like `c()` where `c` is a closure type,
Expand Down Expand Up @@ -306,6 +308,7 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {

Inherited {
infcx: infer::new_infer_ctxt(tcx, tables, Some(param_env)),
fulfillment_cx: RefCell::new(traits::FulfillmentContext::new()),
locals: RefCell::new(NodeMap()),
tables: tables,
deferred_call_resolutions: RefCell::new(DefIdMap()),
Expand All @@ -320,9 +323,8 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
-> T
where T : TypeFoldable<'tcx>
{
let mut fulfillment_cx = self.infcx.fulfillment_cx.borrow_mut();
assoc::normalize_associated_types_in(&self.infcx,
&mut fulfillment_cx,
&mut self.fulfillment_cx.borrow_mut(),
span,
body_id,
value)
Expand Down Expand Up @@ -1370,7 +1372,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.body_id,
traits::ObligationCauseCode::MiscObligation);
self.inh
.infcx
.fulfillment_cx
.borrow_mut()
.normalize_projection_type(self.infcx(),
Expand Down Expand Up @@ -1505,7 +1506,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
builtin_bound: ty::BuiltinBound,
cause: traits::ObligationCause<'tcx>)
{
self.inh.infcx.fulfillment_cx.borrow_mut()
self.inh.fulfillment_cx.borrow_mut()
.register_builtin_bound(self.infcx(), ty, builtin_bound, cause);
}

Expand All @@ -1514,7 +1515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
debug!("register_predicate({:?})",
obligation);
self.inh.infcx.fulfillment_cx
self.inh.fulfillment_cx
.borrow_mut()
.register_predicate_obligation(self.infcx(), obligation);
}
Expand Down Expand Up @@ -1646,7 +1647,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
region: ty::Region,
cause: traits::ObligationCause<'tcx>)
{
let mut fulfillment_cx = self.inh.infcx.fulfillment_cx.borrow_mut();
let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut();
fulfillment_cx.register_region_obligation(ty, region, cause);
}

Expand Down Expand Up @@ -2003,7 +2004,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

self.select_all_obligations_and_apply_defaults();

let mut fulfillment_cx = self.inh.infcx.fulfillment_cx.borrow_mut();
let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut();
match fulfillment_cx.select_all_or_error(self.infcx()) {
Ok(()) => { }
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
Expand All @@ -2013,7 +2014,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Select as many obligations as we can at present.
fn select_obligations_where_possible(&self) {
match
self.inh.infcx.fulfillment_cx
self.inh.fulfillment_cx
.borrow_mut()
.select_where_possible(self.infcx())
{
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
let region_obligations =
self.fcx
.inh
.infcx
.fulfillment_cx
.borrow()
.region_obligations(node_id)
Expand All @@ -369,7 +368,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {

// Processing the region obligations should not cause the list to grow further:
assert_eq!(region_obligations.len(),
self.fcx.inh.infcx.fulfillment_cx.borrow().region_obligations(node_id).len());
self.fcx.inh.fulfillment_cx.borrow().region_obligations(node_id).len());
}

fn code_to_origin(&self,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
}
};

let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
let mut fulfill_cx = traits::FulfillmentContext::new();

// Register an obligation for `A: Trait<B>`.
let cause = traits::ObligationCause::misc(span, impl_node_id);
Expand Down