Skip to content

Commit e5b3684

Browse files
committed
Remove ClosureTyper impl for FnCtxt
1 parent 480cd8f commit e5b3684

File tree

10 files changed

+62
-92
lines changed

10 files changed

+62
-92
lines changed

src/librustc/middle/infer/mod.rs

+32-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use self::region_inference::GenericKind;
2525
use middle::free_region::FreeRegionMap;
2626
use middle::mem_categorization as mc;
2727
use middle::mem_categorization::McResult;
28-
use middle::region::{self, CodeExtent};
28+
use middle::region::CodeExtent;
2929
use middle::subst;
3030
use middle::subst::Substs;
3131
use middle::subst::Subst;
@@ -40,7 +40,7 @@ use std::fmt;
4040
use syntax::ast;
4141
use syntax::codemap;
4242
use syntax::codemap::Span;
43-
use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
43+
use util::nodemap::{FnvHashMap, NodeMap};
4444

4545
use self::combine::CombineFields;
4646
use self::region_inference::{RegionVarBindings, RegionSnapshot};
@@ -524,15 +524,38 @@ impl<'a, 'tcx> ty::ClosureTyper<'tcx> for InferCtxt<'a, 'tcx> {
524524
substs: &subst::Substs<'tcx>)
525525
-> ty::ClosureTy<'tcx>
526526
{
527-
self.tables.borrow().closure_tys.get(&def_id).unwrap().subst(self.tcx, substs)
527+
// the substitutions in `substs` are already monomorphized,
528+
// but we still must normalize associated types
529+
let closure_ty = self.tables
530+
.borrow()
531+
.closure_tys
532+
.get(&def_id)
533+
.unwrap()
534+
.subst(self.tcx, substs);
535+
536+
if self.normalize {
537+
// NOTE: this flag is *always* set to false currently
538+
panic!("issue XXXX: must finish fulfill refactor") // normalize_associated_type(self.param_env.tcx, &closure_ty)
539+
} else {
540+
closure_ty
541+
}
528542
}
529543

530544
fn closure_upvars(&self,
531545
def_id: ast::DefId,
532546
substs: &Substs<'tcx>)
533547
-> Option<Vec<ty::ClosureUpvar<'tcx>>>
534548
{
535-
ty::ctxt::closure_upvars(self, def_id, substs)
549+
// the substitutions in `substs` are already monomorphized,
550+
// but we still must normalize associated types
551+
let result = ty::ctxt::closure_upvars(self, def_id, substs)
552+
553+
if self.normalize {
554+
// NOTE: this flag is *always* set to false currently
555+
panic!("issue XXXX: must finish fulfill refactor") // monomorphize::normalize_associated_type(self.param_env.tcx, &result)
556+
} else {
557+
result
558+
}
536559
}
537560
}
538561

@@ -1073,6 +1096,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10731096
value.fold_with(&mut r)
10741097
}
10751098

1099+
/// Resolves all type variables in `t` and then, if any were left
1100+
/// unresolved, substitutes an error type. This is used after the
1101+
/// main checking when doing a second pass before writeback. The
1102+
/// justification is that writeback will produce an error for
1103+
/// these unconstrained type variables.
10761104
fn resolve_type_vars_or_error(&self, t: &Ty<'tcx>) -> mc::McResult<Ty<'tcx>> {
10771105
let ty = self.resolve_type_vars_if_possible(t);
10781106
if ty.has_infer_types() || ty.references_error() { Err(()) } else { Ok(ty) }

src/librustc_typeck/check/callee.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
137137
// Check whether this is a call to a closure where we
138138
// haven't yet decided on whether the closure is fn vs
139139
// fnmut vs fnonce. If so, we have to defer further processing.
140-
if fcx.closure_kind(def_id).is_none() {
140+
if fcx.infcx().closure_kind(def_id).is_none() {
141141
let closure_ty =
142-
fcx.closure_type(def_id, substs);
142+
fcx.infcx().closure_type(def_id, substs);
143143
let fn_sig =
144144
fcx.infcx().replace_late_bound_regions_with_fresh_var(call_expr.span,
145145
infer::FnCall,
@@ -344,7 +344,7 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
344344

345345
// we should not be invoked until the closure kind has been
346346
// determined by upvar inference
347-
assert!(fcx.closure_kind(self.closure_def_id).is_some());
347+
assert!(fcx.infcx().closure_kind(self.closure_def_id).is_some());
348348

349349
// We may now know enough to figure out fn vs fnmut etc.
350350
match try_overloaded_call_traits(fcx, self.call_expr, self.callee_expr,

src/librustc_typeck/check/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
273273
};
274274
let source = source.adjust_for_autoref(self.tcx(), reborrow);
275275

276-
let mut selcx = traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
276+
let mut selcx = traits::SelectionContext::new(self.fcx.infcx(), self.fcx.infcx());
277277

278278
// Use a FIFO queue for this custom fulfillment procedure.
279279
let mut queue = VecDeque::new();

src/librustc_typeck/check/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
195195
poly_trait_ref.to_predicate());
196196

197197
// Now we want to know if this can be matched
198-
let mut selcx = traits::SelectionContext::new(fcx.infcx(), fcx);
198+
let mut selcx = traits::SelectionContext::new(fcx.infcx(), fcx.infcx());
199199
if !selcx.evaluate_obligation(&obligation) {
200200
debug!("--> Cannot match obligation");
201201
return None; // Cannot be matched, no such method resolution is possible.

src/librustc_typeck/check/method/probe.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
421421
// We can't use normalize_associated_types_in as it will pollute the
422422
// fcx's fulfillment context after this probe is over.
423423
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
424-
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
424+
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx.infcx());
425425
let traits::Normalized { value: xform_self_ty, obligations } =
426426
traits::normalize(selcx, cause, &xform_self_ty);
427427
debug!("assemble_inherent_impl_probe: xform_self_ty = {:?}",
@@ -681,7 +681,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
681681
// as it will pollute the fcx's fulfillment context after this probe
682682
// is over.
683683
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
684-
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
684+
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx.infcx());
685685
let traits::Normalized { value: xform_self_ty, obligations } =
686686
traits::normalize(selcx, cause, &xform_self_ty);
687687

@@ -1076,7 +1076,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
10761076
match probe.kind {
10771077
InherentImplCandidate(impl_def_id, ref substs, ref ref_obligations) |
10781078
ExtensionImplCandidate(impl_def_id, _, ref substs, _, ref ref_obligations) => {
1079-
let selcx = &mut traits::SelectionContext::new(self.infcx(), self.fcx);
1079+
let selcx = &mut traits::SelectionContext::new(self.infcx(), self.fcx.infcx());
10801080
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
10811081

10821082
// Check whether the impl imposes obligations we have to worry about.

src/librustc_typeck/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
102102
let obligation = Obligation::misc(span,
103103
fcx.body_id,
104104
poly_trait_ref.to_predicate());
105-
let mut selcx = SelectionContext::new(infcx, fcx);
105+
let mut selcx = SelectionContext::new(infcx, fcx.infcx());
106106

107107
if selcx.evaluate_obligation(&obligation) {
108108
span_stored_function();

src/librustc_typeck/check/mod.rs

+5-64
Original file line numberDiff line numberDiff line change
@@ -316,65 +316,6 @@ impl<'a, 'tcx> mc::Typer<'tcx> for FnCtxt<'a, 'tcx> {
316316
.map(|ty| self.infcx().resolve_type_vars_if_possible(&ty))
317317
}
318318

319-
fn node_method_origin(&self, method_call: ty::MethodCall)
320-
-> Option<ty::MethodOrigin<'tcx>>
321-
{
322-
self.inh.tables
323-
.borrow()
324-
.method_map
325-
.get(&method_call)
326-
.map(|method| method.origin.clone())
327-
}
328-
329-
fn adjustments(&self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
330-
fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) -> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
331-
&tables.adjustments
332-
}
333-
334-
Ref::map(self.inh.tables.borrow(), project_adjustments)
335-
}
336-
337-
fn is_method_call(&self, id: ast::NodeId) -> bool {
338-
self.inh.tables.borrow().method_map.contains_key(&ty::MethodCall::expr(id))
339-
}
340-
341-
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<CodeExtent> {
342-
self.param_env().temporary_scope(rvalue_id)
343-
}
344-
345-
fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
346-
self.inh.tables.borrow().upvar_capture_map.get(&upvar_id).cloned()
347-
}
348-
}
349-
350-
impl<'a, 'tcx> ty::ClosureTyper<'tcx> for FnCtxt<'a, 'tcx> {
351-
fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> {
352-
&self.inh.infcx.parameter_environment
353-
}
354-
355-
fn closure_kind(&self,
356-
def_id: ast::DefId)
357-
-> Option<ty::ClosureKind>
358-
{
359-
self.inh.tables.borrow().closure_kinds.get(&def_id).cloned()
360-
}
361-
362-
fn closure_type(&self,
363-
def_id: ast::DefId,
364-
substs: &subst::Substs<'tcx>)
365-
-> ty::ClosureTy<'tcx>
366-
{
367-
self.inh.tables.borrow().closure_tys.get(&def_id).unwrap().subst(self.tcx(), substs)
368-
}
369-
370-
fn closure_upvars(&self,
371-
def_id: ast::DefId,
372-
substs: &Substs<'tcx>)
373-
-> Option<Vec<ty::ClosureUpvar<'tcx>>> {
374-
ty::ctxt::closure_upvars(self, def_id, substs)
375-
}
376-
}
377-
378319
impl<'a, 'tcx> Inherited<'a, 'tcx> {
379320
fn new(tcx: &'a ty::ctxt<'tcx>,
380321
tables: &'a RefCell<ty::Tables<'tcx>>,
@@ -1473,7 +1414,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14731414
fn normalize_associated_types_in<T>(&self, span: Span, value: &T) -> T
14741415
where T : TypeFoldable<'tcx> + HasTypeFlags
14751416
{
1476-
self.inh.normalize_associated_types_in(self, span, self.body_id, value)
1417+
self.inh.normalize_associated_types_in(self.infcx(), span, self.body_id, value)
14771418
}
14781419

14791420
fn normalize_associated_type(&self,
@@ -1488,7 +1429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14881429
self.inh.fulfillment_cx
14891430
.borrow_mut()
14901431
.normalize_projection_type(self.infcx(),
1491-
self,
1432+
self.infcx(),
14921433
ty::ProjectionTy {
14931434
trait_ref: trait_ref,
14941435
item_name: item_name,
@@ -1843,7 +1784,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18431784

18441785
self.select_all_obligations_and_apply_defaults();
18451786
let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut();
1846-
match fulfillment_cx.select_all_or_error(self.infcx(), self) {
1787+
match fulfillment_cx.select_all_or_error(self.infcx(), self.infcx()) {
18471788
Ok(()) => { }
18481789
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
18491790
}
@@ -1854,7 +1795,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18541795
match
18551796
self.inh.fulfillment_cx
18561797
.borrow_mut()
1857-
.select_where_possible(self.infcx(), self)
1798+
.select_where_possible(self.infcx(), self.infcx())
18581799
{
18591800
Ok(()) => { }
18601801
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
@@ -1869,7 +1810,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18691810
match
18701811
self.inh.fulfillment_cx
18711812
.borrow_mut()
1872-
.select_new_obligations(self.infcx(), self)
1813+
.select_new_obligations(self.infcx(), self.infcx())
18731814
{
18741815
Ok(()) => { }
18751816
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }

src/librustc_typeck/check/regionck.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ use astconv::AstConv;
8686
use check::dropck;
8787
use check::FnCtxt;
8888
use middle::free_region::FreeRegionMap;
89+
use middle::infer::InferCtxt;
8990
use middle::implicator;
9091
use middle::mem_categorization as mc;
9192
use middle::region::CodeExtent;
@@ -353,7 +354,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
353354
debug!("relate_free_regions(t={:?})", ty);
354355
let body_scope = CodeExtent::from_node_id(body_id);
355356
let body_scope = ty::ReScope(body_scope);
356-
let implications = implicator::implications(self.fcx.infcx(), self.fcx, body_id,
357+
let implications = implicator::implications(self.fcx.infcx(), self.fcx.infcx(), body_id,
357358
ty, body_scope, span);
358359

359360
// Record any relations between free regions that we observe into the free-region-map.
@@ -549,7 +550,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
549550
// If necessary, constrain destructors in the unadjusted form of this
550551
// expression.
551552
let cmt_result = {
552-
let mc = mc::MemCategorizationContext::new(rcx.fcx);
553+
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
553554
mc.cat_expr_unadjusted(expr)
554555
};
555556
match cmt_result {
@@ -568,7 +569,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
568569
// If necessary, constrain destructors in this expression. This will be
569570
// the adjusted form if there is an adjustment.
570571
let cmt_result = {
571-
let mc = mc::MemCategorizationContext::new(rcx.fcx);
572+
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
572573
mc.cat_expr(expr)
573574
};
574575
match cmt_result {
@@ -912,7 +913,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
912913
r, m);
913914

914915
{
915-
let mc = mc::MemCategorizationContext::new(rcx.fcx);
916+
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
916917
let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
917918
debug!("constrain_autoderefs: self_cmt={:?}",
918919
self_cmt);
@@ -1037,7 +1038,7 @@ fn link_addr_of(rcx: &mut Rcx, expr: &ast::Expr,
10371038
debug!("link_addr_of(expr={:?}, base={:?})", expr, base);
10381039

10391040
let cmt = {
1040-
let mc = mc::MemCategorizationContext::new(rcx.fcx);
1041+
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
10411042
ignore_err!(mc.cat_expr(base))
10421043
};
10431044

@@ -1055,7 +1056,7 @@ fn link_local(rcx: &Rcx, local: &ast::Local) {
10551056
None => { return; }
10561057
Some(ref expr) => &**expr,
10571058
};
1058-
let mc = mc::MemCategorizationContext::new(rcx.fcx);
1059+
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
10591060
let discr_cmt = ignore_err!(mc.cat_expr(init_expr));
10601061
link_pattern(rcx, mc, discr_cmt, &*local.pat);
10611062
}
@@ -1065,7 +1066,7 @@ fn link_local(rcx: &Rcx, local: &ast::Local) {
10651066
/// linked to the lifetime of its guarantor (if any).
10661067
fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
10671068
debug!("regionck::for_match()");
1068-
let mc = mc::MemCategorizationContext::new(rcx.fcx);
1069+
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
10691070
let discr_cmt = ignore_err!(mc.cat_expr(discr));
10701071
debug!("discr_cmt={:?}", discr_cmt);
10711072
for arm in arms {
@@ -1080,7 +1081,7 @@ fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
10801081
/// linked to the lifetime of its guarantor (if any).
10811082
fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
10821083
debug!("regionck::link_fn_args(body_scope={:?})", body_scope);
1083-
let mc = mc::MemCategorizationContext::new(rcx.fcx);
1084+
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
10841085
for arg in args {
10851086
let arg_ty = rcx.fcx.node_ty(arg.id);
10861087
let re_scope = ty::ReScope(body_scope);
@@ -1095,7 +1096,7 @@ fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
10951096
/// Link lifetimes of any ref bindings in `root_pat` to the pointers found in the discriminant, if
10961097
/// needed.
10971098
fn link_pattern<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
1098-
mc: mc::MemCategorizationContext<FnCtxt<'a, 'tcx>>,
1099+
mc: mc::MemCategorizationContext<InferCtxt<'a, 'tcx>>,
10991100
discr_cmt: mc::cmt<'tcx>,
11001101
root_pat: &ast::Pat) {
11011102
debug!("link_pattern(discr_cmt={:?}, root_pat={:?})",
@@ -1134,7 +1135,7 @@ fn link_autoref(rcx: &Rcx,
11341135
autoref: &ty::AutoRef)
11351136
{
11361137
debug!("link_autoref(autoref={:?})", autoref);
1137-
let mc = mc::MemCategorizationContext::new(rcx.fcx);
1138+
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
11381139
let expr_cmt = ignore_err!(mc.cat_expr_autoderefd(expr, autoderefs));
11391140
debug!("expr_cmt={:?}", expr_cmt);
11401141

@@ -1158,7 +1159,7 @@ fn link_by_ref(rcx: &Rcx,
11581159
callee_scope: CodeExtent) {
11591160
debug!("link_by_ref(expr={:?}, callee_scope={:?})",
11601161
expr, callee_scope);
1161-
let mc = mc::MemCategorizationContext::new(rcx.fcx);
1162+
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
11621163
let expr_cmt = ignore_err!(mc.cat_expr(expr));
11631164
let borrow_region = ty::ReScope(callee_scope);
11641165
link_region(rcx, expr.span, &borrow_region, ty::ImmBorrow, expr_cmt);
@@ -1402,7 +1403,7 @@ pub fn type_must_outlive<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
14021403
ty,
14031404
region);
14041405

1405-
let implications = implicator::implications(rcx.fcx.infcx(), rcx.fcx, rcx.body_id,
1406+
let implications = implicator::implications(rcx.fcx.infcx(), rcx.fcx.infcx(), rcx.body_id,
14061407
ty, region, origin.span());
14071408
for implication in implications {
14081409
debug!("implication: {:?}", implication);
@@ -1443,7 +1444,7 @@ fn closure_must_outlive<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
14431444
debug!("closure_must_outlive(region={:?}, def_id={:?}, substs={:?})",
14441445
region, def_id, substs);
14451446

1446-
let upvars = rcx.fcx.closure_upvars(def_id, substs).unwrap();
1447+
let upvars = rcx.fcx.infcx().closure_upvars(def_id, substs).unwrap();
14471448
for upvar in upvars {
14481449
let var_id = upvar.def.def_id().local_id();
14491450
type_must_outlive(

src/librustc_typeck/check/upvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
186186

187187
debug!("analyzing closure `{}` with fn body id `{}`", id, body.id);
188188

189-
let mut euv = euv::ExprUseVisitor::new(self, self.fcx);
189+
let mut euv = euv::ExprUseVisitor::new(self, self.fcx.infcx());
190190
euv.walk_fn(decl, body);
191191

192192
// If we had not yet settled on a closure kind for this closure,

src/librustc_typeck/check/wf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
259259
let predicates = fcx.tcx().lookup_super_predicates(poly_trait_ref.def_id());
260260
let predicates = predicates.instantiate_supertrait(fcx.tcx(), &poly_trait_ref);
261261
let predicates = {
262-
let selcx = &mut traits::SelectionContext::new(fcx.infcx(), fcx);
262+
let selcx = &mut traits::SelectionContext::new(fcx.infcx(), fcx.infcx());
263263
traits::normalize(selcx, cause.clone(), &predicates)
264264
};
265265
for predicate in predicates.value.predicates {

0 commit comments

Comments
 (0)