提交 e5b36848 编写于 作者: J Jared Roesch

Remove ClosureTyper impl for FnCtxt

上级 480cd8fe
......@@ -25,7 +25,7 @@
use middle::free_region::FreeRegionMap;
use middle::mem_categorization as mc;
use middle::mem_categorization::McResult;
use middle::region::{self, CodeExtent};
use middle::region::CodeExtent;
use middle::subst;
use middle::subst::Substs;
use middle::subst::Subst;
......@@ -40,7 +40,7 @@
use syntax::ast;
use syntax::codemap;
use syntax::codemap::Span;
use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
use util::nodemap::{FnvHashMap, NodeMap};
use self::combine::CombineFields;
use self::region_inference::{RegionVarBindings, RegionSnapshot};
......@@ -524,7 +524,21 @@ fn closure_type(&self,
substs: &subst::Substs<'tcx>)
-> ty::ClosureTy<'tcx>
{
self.tables.borrow().closure_tys.get(&def_id).unwrap().subst(self.tcx, substs)
// the substitutions in `substs` are already monomorphized,
// but we still must normalize associated types
let closure_ty = self.tables
.borrow()
.closure_tys
.get(&def_id)
.unwrap()
.subst(self.tcx, substs);
if self.normalize {
// NOTE: this flag is *always* set to false currently
panic!("issue XXXX: must finish fulfill refactor") // normalize_associated_type(self.param_env.tcx, &closure_ty)
} else {
closure_ty
}
}
fn closure_upvars(&self,
......@@ -532,7 +546,16 @@ fn closure_upvars(&self,
substs: &Substs<'tcx>)
-> Option<Vec<ty::ClosureUpvar<'tcx>>>
{
ty::ctxt::closure_upvars(self, def_id, substs)
// the substitutions in `substs` are already monomorphized,
// but we still must normalize associated types
let result = ty::ctxt::closure_upvars(self, def_id, substs)
if self.normalize {
// NOTE: this flag is *always* set to false currently
panic!("issue XXXX: must finish fulfill refactor") // monomorphize::normalize_associated_type(self.param_env.tcx, &result)
} else {
result
}
}
}
......@@ -1073,6 +1096,11 @@ pub fn resolve_type_vars_if_possible<T:TypeFoldable<'tcx>>(&self, value: &T) ->
value.fold_with(&mut r)
}
/// Resolves all type variables in `t` and then, if any were left
/// unresolved, substitutes an error type. This is used after the
/// main checking when doing a second pass before writeback. The
/// justification is that writeback will produce an error for
/// these unconstrained type variables.
fn resolve_type_vars_or_error(&self, t: &Ty<'tcx>) -> mc::McResult<Ty<'tcx>> {
let ty = self.resolve_type_vars_if_possible(t);
if ty.has_infer_types() || ty.references_error() { Err(()) } else { Ok(ty) }
......
......@@ -137,9 +137,9 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
// Check whether this is a call to a closure where we
// haven't yet decided on whether the closure is fn vs
// fnmut vs fnonce. If so, we have to defer further processing.
if fcx.closure_kind(def_id).is_none() {
if fcx.infcx().closure_kind(def_id).is_none() {
let closure_ty =
fcx.closure_type(def_id, substs);
fcx.infcx().closure_type(def_id, substs);
let fn_sig =
fcx.infcx().replace_late_bound_regions_with_fresh_var(call_expr.span,
infer::FnCall,
......@@ -344,7 +344,7 @@ fn resolve<'a>(&mut self, fcx: &FnCtxt<'a,'tcx>) {
// we should not be invoked until the closure kind has been
// determined by upvar inference
assert!(fcx.closure_kind(self.closure_def_id).is_some());
assert!(fcx.infcx().closure_kind(self.closure_def_id).is_some());
// We may now know enough to figure out fn vs fnmut etc.
match try_overloaded_call_traits(fcx, self.call_expr, self.callee_expr,
......
......@@ -273,7 +273,7 @@ fn coerce_unsized(&self,
};
let source = source.adjust_for_autoref(self.tcx(), reborrow);
let mut selcx = traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
let mut selcx = traits::SelectionContext::new(self.fcx.infcx(), self.fcx.infcx());
// Use a FIFO queue for this custom fulfillment procedure.
let mut queue = VecDeque::new();
......
......@@ -195,7 +195,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
poly_trait_ref.to_predicate());
// Now we want to know if this can be matched
let mut selcx = traits::SelectionContext::new(fcx.infcx(), fcx);
let mut selcx = traits::SelectionContext::new(fcx.infcx(), fcx.infcx());
if !selcx.evaluate_obligation(&obligation) {
debug!("--> Cannot match obligation");
return None; // Cannot be matched, no such method resolution is possible.
......
......@@ -421,7 +421,7 @@ fn assemble_inherent_impl_probe(&mut self, impl_def_id: ast::DefId) {
// We can't use normalize_associated_types_in as it will pollute the
// fcx's fulfillment context after this probe is over.
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx.infcx());
let traits::Normalized { value: xform_self_ty, obligations } =
traits::normalize(selcx, cause, &xform_self_ty);
debug!("assemble_inherent_impl_probe: xform_self_ty = {:?}",
......@@ -681,7 +681,7 @@ fn assemble_extension_candidates_for_trait_impls(&mut self,
// as it will pollute the fcx's fulfillment context after this probe
// is over.
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx.infcx());
let traits::Normalized { value: xform_self_ty, obligations } =
traits::normalize(selcx, cause, &xform_self_ty);
......@@ -1076,7 +1076,7 @@ fn consider_probe(&self, self_ty: Ty<'tcx>, probe: &Candidate<'tcx>,
match probe.kind {
InherentImplCandidate(impl_def_id, ref substs, ref ref_obligations) |
ExtensionImplCandidate(impl_def_id, _, ref substs, _, ref ref_obligations) => {
let selcx = &mut traits::SelectionContext::new(self.infcx(), self.fcx);
let selcx = &mut traits::SelectionContext::new(self.infcx(), self.fcx.infcx());
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
// Check whether the impl imposes obligations we have to worry about.
......
......@@ -102,7 +102,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let obligation = Obligation::misc(span,
fcx.body_id,
poly_trait_ref.to_predicate());
let mut selcx = SelectionContext::new(infcx, fcx);
let mut selcx = SelectionContext::new(infcx, fcx.infcx());
if selcx.evaluate_obligation(&obligation) {
span_stored_function();
......
......@@ -316,65 +316,6 @@ fn node_method_ty(&self, method_call: ty::MethodCall)
.map(|ty| self.infcx().resolve_type_vars_if_possible(&ty))
}
fn node_method_origin(&self, method_call: ty::MethodCall)
-> Option<ty::MethodOrigin<'tcx>>
{
self.inh.tables
.borrow()
.method_map
.get(&method_call)
.map(|method| method.origin.clone())
}
fn adjustments(&self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) -> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
&tables.adjustments
}
Ref::map(self.inh.tables.borrow(), project_adjustments)
}
fn is_method_call(&self, id: ast::NodeId) -> bool {
self.inh.tables.borrow().method_map.contains_key(&ty::MethodCall::expr(id))
}
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<CodeExtent> {
self.param_env().temporary_scope(rvalue_id)
}
fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
self.inh.tables.borrow().upvar_capture_map.get(&upvar_id).cloned()
}
}
impl<'a, 'tcx> ty::ClosureTyper<'tcx> for FnCtxt<'a, 'tcx> {
fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> {
&self.inh.infcx.parameter_environment
}
fn closure_kind(&self,
def_id: ast::DefId)
-> Option<ty::ClosureKind>
{
self.inh.tables.borrow().closure_kinds.get(&def_id).cloned()
}
fn closure_type(&self,
def_id: ast::DefId,
substs: &subst::Substs<'tcx>)
-> ty::ClosureTy<'tcx>
{
self.inh.tables.borrow().closure_tys.get(&def_id).unwrap().subst(self.tcx(), substs)
}
fn closure_upvars(&self,
def_id: ast::DefId,
substs: &Substs<'tcx>)
-> Option<Vec<ty::ClosureUpvar<'tcx>>> {
ty::ctxt::closure_upvars(self, def_id, substs)
}
}
impl<'a, 'tcx> Inherited<'a, 'tcx> {
fn new(tcx: &'a ty::ctxt<'tcx>,
tables: &'a RefCell<ty::Tables<'tcx>>,
......@@ -1473,7 +1414,7 @@ fn instantiate_bounds(&self,
fn normalize_associated_types_in<T>(&self, span: Span, value: &T) -> T
where T : TypeFoldable<'tcx> + HasTypeFlags
{
self.inh.normalize_associated_types_in(self, span, self.body_id, value)
self.inh.normalize_associated_types_in(self.infcx(), span, self.body_id, value)
}
fn normalize_associated_type(&self,
......@@ -1488,7 +1429,7 @@ fn normalize_associated_type(&self,
self.inh.fulfillment_cx
.borrow_mut()
.normalize_projection_type(self.infcx(),
self,
self.infcx(),
ty::ProjectionTy {
trait_ref: trait_ref,
item_name: item_name,
......@@ -1843,7 +1784,7 @@ fn select_all_obligations_or_error(&self) {
self.select_all_obligations_and_apply_defaults();
let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut();
match fulfillment_cx.select_all_or_error(self.infcx(), self) {
match fulfillment_cx.select_all_or_error(self.infcx(), self.infcx()) {
Ok(()) => { }
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
}
......@@ -1854,7 +1795,7 @@ fn select_obligations_where_possible(&self) {
match
self.inh.fulfillment_cx
.borrow_mut()
.select_where_possible(self.infcx(), self)
.select_where_possible(self.infcx(), self.infcx())
{
Ok(()) => { }
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
......@@ -1869,7 +1810,7 @@ fn select_new_obligations(&self) {
match
self.inh.fulfillment_cx
.borrow_mut()
.select_new_obligations(self.infcx(), self)
.select_new_obligations(self.infcx(), self.infcx())
{
Ok(()) => { }
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
......
......@@ -86,6 +86,7 @@
use check::dropck;
use check::FnCtxt;
use middle::free_region::FreeRegionMap;
use middle::infer::InferCtxt;
use middle::implicator;
use middle::mem_categorization as mc;
use middle::region::CodeExtent;
......@@ -353,7 +354,7 @@ fn relate_free_regions(&mut self,
debug!("relate_free_regions(t={:?})", ty);
let body_scope = CodeExtent::from_node_id(body_id);
let body_scope = ty::ReScope(body_scope);
let implications = implicator::implications(self.fcx.infcx(), self.fcx, body_id,
let implications = implicator::implications(self.fcx.infcx(), self.fcx.infcx(), body_id,
ty, body_scope, span);
// 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) {
// If necessary, constrain destructors in the unadjusted form of this
// expression.
let cmt_result = {
let mc = mc::MemCategorizationContext::new(rcx.fcx);
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
mc.cat_expr_unadjusted(expr)
};
match cmt_result {
......@@ -568,7 +569,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
// If necessary, constrain destructors in this expression. This will be
// the adjusted form if there is an adjustment.
let cmt_result = {
let mc = mc::MemCategorizationContext::new(rcx.fcx);
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
mc.cat_expr(expr)
};
match cmt_result {
......@@ -912,7 +913,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
r, m);
{
let mc = mc::MemCategorizationContext::new(rcx.fcx);
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
debug!("constrain_autoderefs: self_cmt={:?}",
self_cmt);
......@@ -1037,7 +1038,7 @@ fn link_addr_of(rcx: &mut Rcx, expr: &ast::Expr,
debug!("link_addr_of(expr={:?}, base={:?})", expr, base);
let cmt = {
let mc = mc::MemCategorizationContext::new(rcx.fcx);
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
ignore_err!(mc.cat_expr(base))
};
......@@ -1055,7 +1056,7 @@ fn link_local(rcx: &Rcx, local: &ast::Local) {
None => { return; }
Some(ref expr) => &**expr,
};
let mc = mc::MemCategorizationContext::new(rcx.fcx);
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let discr_cmt = ignore_err!(mc.cat_expr(init_expr));
link_pattern(rcx, mc, discr_cmt, &*local.pat);
}
......@@ -1065,7 +1066,7 @@ fn link_local(rcx: &Rcx, local: &ast::Local) {
/// linked to the lifetime of its guarantor (if any).
fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
debug!("regionck::for_match()");
let mc = mc::MemCategorizationContext::new(rcx.fcx);
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let discr_cmt = ignore_err!(mc.cat_expr(discr));
debug!("discr_cmt={:?}", discr_cmt);
for arm in arms {
......@@ -1080,7 +1081,7 @@ fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
/// linked to the lifetime of its guarantor (if any).
fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
debug!("regionck::link_fn_args(body_scope={:?})", body_scope);
let mc = mc::MemCategorizationContext::new(rcx.fcx);
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
for arg in args {
let arg_ty = rcx.fcx.node_ty(arg.id);
let re_scope = ty::ReScope(body_scope);
......@@ -1095,7 +1096,7 @@ fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
/// Link lifetimes of any ref bindings in `root_pat` to the pointers found in the discriminant, if
/// needed.
fn link_pattern<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
mc: mc::MemCategorizationContext<FnCtxt<'a, 'tcx>>,
mc: mc::MemCategorizationContext<InferCtxt<'a, 'tcx>>,
discr_cmt: mc::cmt<'tcx>,
root_pat: &ast::Pat) {
debug!("link_pattern(discr_cmt={:?}, root_pat={:?})",
......@@ -1134,7 +1135,7 @@ fn link_autoref(rcx: &Rcx,
autoref: &ty::AutoRef)
{
debug!("link_autoref(autoref={:?})", autoref);
let mc = mc::MemCategorizationContext::new(rcx.fcx);
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let expr_cmt = ignore_err!(mc.cat_expr_autoderefd(expr, autoderefs));
debug!("expr_cmt={:?}", expr_cmt);
......@@ -1158,7 +1159,7 @@ fn link_by_ref(rcx: &Rcx,
callee_scope: CodeExtent) {
debug!("link_by_ref(expr={:?}, callee_scope={:?})",
expr, callee_scope);
let mc = mc::MemCategorizationContext::new(rcx.fcx);
let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let expr_cmt = ignore_err!(mc.cat_expr(expr));
let borrow_region = ty::ReScope(callee_scope);
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>,
ty,
region);
let implications = implicator::implications(rcx.fcx.infcx(), rcx.fcx, rcx.body_id,
let implications = implicator::implications(rcx.fcx.infcx(), rcx.fcx.infcx(), rcx.body_id,
ty, region, origin.span());
for implication in implications {
debug!("implication: {:?}", implication);
......@@ -1443,7 +1444,7 @@ fn closure_must_outlive<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
debug!("closure_must_outlive(region={:?}, def_id={:?}, substs={:?})",
region, def_id, substs);
let upvars = rcx.fcx.closure_upvars(def_id, substs).unwrap();
let upvars = rcx.fcx.infcx().closure_upvars(def_id, substs).unwrap();
for upvar in upvars {
let var_id = upvar.def.def_id().local_id();
type_must_outlive(
......
......@@ -186,7 +186,7 @@ fn analyze_closure(&mut self, id: ast::NodeId, decl: &ast::FnDecl, body: &ast::B
debug!("analyzing closure `{}` with fn body id `{}`", id, body.id);
let mut euv = euv::ExprUseVisitor::new(self, self.fcx);
let mut euv = euv::ExprUseVisitor::new(self, self.fcx.infcx());
euv.walk_fn(decl, body);
// If we had not yet settled on a closure kind for this closure,
......
......@@ -259,7 +259,7 @@ fn check_impl(&mut self,
let predicates = fcx.tcx().lookup_super_predicates(poly_trait_ref.def_id());
let predicates = predicates.instantiate_supertrait(fcx.tcx(), &poly_trait_ref);
let predicates = {
let selcx = &mut traits::SelectionContext::new(fcx.infcx(), fcx);
let selcx = &mut traits::SelectionContext::new(fcx.infcx(), fcx.infcx());
traits::normalize(selcx, cause.clone(), &predicates)
};
for predicate in predicates.value.predicates {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册