Skip to content

Commit 6947948

Browse files
committed
Move FufillmentContext into InferContext
1 parent e6596d0 commit 6947948

File tree

13 files changed

+48
-29
lines changed

13 files changed

+48
-29
lines changed

src/librustc/middle/infer/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ pub struct InferCtxt<'a, 'tcx: 'a> {
8787

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

90+
pub fulfillment_cx: RefCell<traits::FulfillmentContext<'tcx>>,
91+
9092
// This is a temporary field used for toggling on normalization in the inference context,
9193
// as we move towards the approach described here:
9294
// https://internals.rust-lang.org/t/flattening-the-contexts-for-fun-and-profit/2293
@@ -327,9 +329,16 @@ pub fn fixup_err_to_string(f: fixup_err) -> String {
327329
}
328330
}
329331

332+
/// errors_will_be_reported is required to proxy to the fulfillment context
333+
/// FIXME -- a better option would be to hold back on modifying
334+
/// the global cache until we know that all dependent obligations
335+
/// are also satisfied. In that case, we could actually remove
336+
/// this boolean flag, and we'd also avoid the problem of squelching
337+
/// duplicate errors that occur across fns.
330338
pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>,
331339
tables: &'a RefCell<ty::Tables<'tcx>>,
332-
param_env: Option<ty::ParameterEnvironment<'a, 'tcx>>)
340+
param_env: Option<ty::ParameterEnvironment<'a, 'tcx>>,
341+
errors_will_be_reported: bool)
333342
-> InferCtxt<'a, 'tcx> {
334343
InferCtxt {
335344
tcx: tcx,
@@ -339,6 +348,7 @@ pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>,
339348
float_unification_table: RefCell::new(UnificationTable::new()),
340349
region_vars: RegionVarBindings::new(tcx),
341350
parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()),
351+
fulfillment_cx: RefCell::new(traits::FulfillmentContext::new(errors_will_be_reported)),
342352
normalize: false,
343353
err_count_on_creation: tcx.sess.err_count()
344354
}
@@ -1009,6 +1019,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10091019
raw_ty.adjust(self.tcx,
10101020
expr.span,
10111021
expr.id,
1022+
raw_ty,
10121023
adjustment,
10131024
|method_call| self.tables
10141025
.borrow()

src/librustc/middle/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi
397397

398398
let elaborated_env = unnormalized_env.with_caller_bounds(predicates);
399399

400-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(elaborated_env));
400+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(elaborated_env), false);
401401
let predicates = match fully_normalize(&infcx, &infcx.parameter_environment, cause,
402402
&infcx.parameter_environment.caller_bounds) {
403403
Ok(predicates) => predicates,

src/librustc_trans/trans/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
957957
trait_ref, trait_ref.def_id());
958958

959959
tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id());
960-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
960+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, true);
961961

962962
// Do the initial selection for the obligation. This yields the
963963
// shallow result we are looking for -- that is, what specific impl.
@@ -1019,7 +1019,7 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
10191019
predicates);
10201020

10211021
let tcx = ccx.tcx();
1022-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
1022+
let mut infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, false);
10231023
let typer = NormalizingClosureTyper::new(tcx);
10241024
let mut selcx = traits::SelectionContext::new(&infcx, &typer);
10251025
let mut fulfill_cx = traits::FulfillmentContext::new(false);

src/librustc_trans/trans/monomorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub fn normalize_associated_type<'tcx,T>(tcx: &ty::ctxt<'tcx>, value: &T) -> T
324324
// FIXME(#20304) -- cache
325325
// NOTE: @jroesch
326326
// Here is of an example where we do not use a param_env but use a typer instead.
327-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
327+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, true);
328328
let typer = NormalizingClosureTyper::new(tcx);
329329
let mut selcx = traits::SelectionContext::new(&infcx, &typer);
330330
let cause = traits::ObligationCause::dummy();

src/librustc_typeck/check/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn deduce_expectations_from_obligations<'a,'tcx>(
125125
expected_vid: ty::TyVid)
126126
-> (Option<ty::FnSig<'tcx>>, Option<ty::ClosureKind>)
127127
{
128-
let fulfillment_cx = fcx.inh.fulfillment_cx.borrow();
128+
let fulfillment_cx = fcx.inh.infcx.fulfillment_cx.borrow();
129129
// Here `expected_ty` is known to be a type inference variable.
130130

131131
let expected_sig =

src/librustc_typeck/check/compare_method.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
4343
debug!("compare_impl_method: impl_trait_ref (liberated) = {:?}",
4444
impl_trait_ref);
4545

46-
let mut infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
46+
let mut infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, true);
4747
let mut fulfillment_cx = traits::FulfillmentContext::new(true);
4848

4949
let trait_to_impl_substs = &impl_trait_ref.substs;
@@ -419,7 +419,7 @@ pub fn compare_const_impl<'tcx>(tcx: &ty::ctxt<'tcx>,
419419
debug!("compare_const_impl(impl_trait_ref={:?})",
420420
impl_trait_ref);
421421

422-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
422+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, true);
423423
let mut fulfillment_cx = traits::FulfillmentContext::new(true);
424424

425425
// The below is for the most part highly similar to the procedure

src/librustc_typeck/check/dropck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
9393
ty: named_type } =
9494
tcx.lookup_item_type(self_type_did);
9595

96-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
96+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, false);
9797

9898
infcx.commit_if_ok(|snapshot| {
9999
let (named_type_to_skolem, skol_map) =

src/librustc_typeck/check/mod.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub struct Inherited<'a, 'tcx: 'a> {
159159
fn_sig_map: RefCell<NodeMap<Vec<Ty<'tcx>>>>,
160160

161161
// Tracks trait obligations incurred during this function body.
162-
fulfillment_cx: RefCell<traits::FulfillmentContext<'tcx>>,
162+
// fulfillment_cx: RefCell<traits::FulfillmentContext<'tcx>>,
163163

164164
// When we process a call like `c()` where `c` is a closure type,
165165
// we may not have decided yet whether `c` is a `Fn`, `FnMut`, or
@@ -295,11 +295,11 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
295295
-> Inherited<'a, 'tcx> {
296296

297297
Inherited {
298-
infcx: infer::new_infer_ctxt(tcx, tables, Some(param_env)),
298+
// I'm probably screwed here ... more boolean prop ...
299+
infcx: infer::new_infer_ctxt(tcx, tables, Some(param_env), false),
299300
locals: RefCell::new(NodeMap()),
300301
tables: tables,
301302
fn_sig_map: RefCell::new(NodeMap()),
302-
fulfillment_cx: RefCell::new(traits::FulfillmentContext::new(true)),
303303
deferred_call_resolutions: RefCell::new(DefIdMap()),
304304
deferred_cast_checks: RefCell::new(Vec::new()),
305305
}
@@ -313,7 +313,7 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
313313
-> T
314314
where T : TypeFoldable<'tcx> + HasTypeFlags
315315
{
316-
let mut fulfillment_cx = self.fulfillment_cx.borrow_mut();
316+
let mut fulfillment_cx = self.infcx.fulfillment_cx.borrow_mut();
317317
assoc::normalize_associated_types_in(&self.infcx,
318318
typer,
319319
&mut *fulfillment_cx, span,
@@ -1389,7 +1389,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13891389
let cause = traits::ObligationCause::new(span,
13901390
self.body_id,
13911391
traits::ObligationCauseCode::MiscObligation);
1392-
self.inh.fulfillment_cx
1392+
self.inh
1393+
.infcx
1394+
.fulfillment_cx
13931395
.borrow_mut()
13941396
.normalize_projection_type(self.infcx(),
13951397
self.infcx(),
@@ -1513,7 +1515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15131515
builtin_bound: ty::BuiltinBound,
15141516
cause: traits::ObligationCause<'tcx>)
15151517
{
1516-
self.inh.fulfillment_cx.borrow_mut()
1518+
self.inh.infcx.fulfillment_cx.borrow_mut()
15171519
.register_builtin_bound(self.infcx(), ty, builtin_bound, cause);
15181520
}
15191521

@@ -1522,7 +1524,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15221524
{
15231525
debug!("register_predicate({:?})",
15241526
obligation);
1525-
self.inh.fulfillment_cx
1527+
self.inh.infcx.fulfillment_cx
15261528
.borrow_mut()
15271529
.register_predicate_obligation(self.infcx(), obligation);
15281530
}
@@ -1558,6 +1560,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15581560
let raw_ty = self.infcx().shallow_resolve(raw_ty);
15591561
let resolve_ty = |ty: Ty<'tcx>| self.infcx().resolve_type_vars_if_possible(&ty);
15601562
raw_ty.adjust(self.tcx(), expr.span, expr.id, adjustment, |method_call| {
1563+
.method_map
15611564
self.inh.tables.borrow().method_map.get(&method_call)
15621565
.map(|method| resolve_ty(method.ty))
15631566
})
@@ -1648,7 +1651,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16481651
region: ty::Region,
16491652
cause: traits::ObligationCause<'tcx>)
16501653
{
1651-
let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut();
1654+
let mut fulfillment_cx = self.inh.infcx.fulfillment_cx.borrow_mut();
16521655
fulfillment_cx.register_region_obligation(ty, region, cause);
16531656
}
16541657

@@ -1747,7 +1750,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17471750
assert!(self.inh.deferred_call_resolutions.borrow().is_empty());
17481751

17491752
self.select_all_obligations_and_apply_defaults();
1750-
let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut();
1753+
let mut fulfillment_cx = self.inh.infcx.fulfillment_cx.borrow_mut();
17511754
match fulfillment_cx.select_all_or_error(self.infcx(), self.infcx()) {
17521755
Ok(()) => { }
17531756
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
@@ -1757,7 +1760,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17571760
/// Select as many obligations as we can at present.
17581761
fn select_obligations_where_possible(&self) {
17591762
match
1760-
self.inh.fulfillment_cx
1763+
self.inh.infcx.fulfillment_cx
17611764
.borrow_mut()
17621765
.select_where_possible(self.infcx(), self.infcx())
17631766
{
@@ -1772,7 +1775,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17721775
/// work.
17731776
fn select_new_obligations(&self) {
17741777
match
1775-
self.inh.fulfillment_cx
1778+
self.inh.infcx.fulfillment_cx
17761779
.borrow_mut()
17771780
.select_new_obligations(self.infcx(), self.infcx())
17781781
{

src/librustc_typeck/check/regionck.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,13 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
318318
// Make a copy of the region obligations vec because we'll need
319319
// to be able to borrow the fulfillment-cx below when projecting.
320320
let region_obligations =
321-
self.fcx.inh.fulfillment_cx.borrow()
322-
.region_obligations(node_id)
323-
.to_vec();
321+
self.fcx
322+
.inh
323+
.infcx
324+
.fulfillment_cx
325+
.borrow()
326+
.region_obligations(node_id)
327+
.to_vec();
324328

325329
for r_o in &region_obligations {
326330
debug!("visit_region_obligations: r_o={:?}",
@@ -332,7 +336,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
332336

333337
// Processing the region obligations should not cause the list to grow further:
334338
assert_eq!(region_obligations.len(),
335-
self.fcx.inh.fulfillment_cx.borrow().region_obligations(node_id).len());
339+
self.fcx.inh.infcx.fulfillment_cx.borrow().region_obligations(node_id).len());
336340
}
337341

338342
/// This method populates the region map's `free_region_map`. It walks over the transformed

src/librustc_typeck/coherence/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
448448
debug!("check_implementations_of_coerce_unsized: {:?} -> {:?} (free)",
449449
source, target);
450450

451-
let infcx = new_infer_ctxt(tcx, &tcx.tables, Some(param_env));
451+
let infcx = new_infer_ctxt(tcx, &tcx.tables, Some(param_env), true);
452452

453453
let check_mutbl = |mt_a: ty::mt<'tcx>, mt_b: ty::mt<'tcx>,
454454
mk_ptr: &Fn(Ty<'tcx>) -> Ty<'tcx>| {
@@ -632,7 +632,8 @@ fn subst_receiver_types_in_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
632632
pub fn check_coherence(crate_context: &CrateCtxt) {
633633
CoherenceChecker {
634634
crate_context: crate_context,
635-
inference_context: new_infer_ctxt(crate_context.tcx, &crate_context.tcx.tables, None),
635+
// XXXJAREDXXX: not sure if the bool is right here?
636+
inference_context: new_infer_ctxt(crate_context.tcx, &crate_context.tcx.tables, None, false),
636637
inherent_impls: RefCell::new(FnvHashMap()),
637638
}.check(crate_context.tcx.map.krate());
638639
unsafety::check(crate_context.tcx);

src/librustc_typeck/coherence/overlap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
133133
impl1_def_id,
134134
impl2_def_id);
135135

136-
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None);
136+
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None, false);
137137
if traits::overlapping_impls(&infcx, impl1_def_id, impl2_def_id) {
138138
self.report_overlap_error(trait_def_id, impl1_def_id, impl2_def_id);
139139
}

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>(
22112211
base_type,
22122212
base_type_free);
22132213

2214-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
2214+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, false);
22152215
drop(::require_same_types(tcx,
22162216
Some(&infcx),
22172217
false,

src/librustc_typeck/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>,
188188
{
189189
let result = match maybe_infcx {
190190
None => {
191-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
191+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, false);
192192
infer::mk_eqty(&infcx, t1_is_expected, infer::Misc(span), t1, t2)
193193
}
194194
Some(infcx) => {

0 commit comments

Comments
 (0)