From 05c57e0e6a667422c8a9159febbf0476f039f4fc Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Mon, 29 Jun 2015 17:46:24 -0700 Subject: [PATCH] Remove Typer + ClosureTyper impls for BlockS --- src/librustc/middle/check_const.rs | 3 +- src/librustc/middle/check_rvalues.rs | 4 +- src/librustc/middle/expr_use_visitor.rs | 15 ++-- src/librustc/middle/infer/mod.rs | 6 +- src/librustc/middle/mem_categorization.rs | 26 +++---- src/librustc_trans/lib.rs | 1 - src/librustc_trans/trans/_match.rs | 4 +- src/librustc_trans/trans/common.rs | 92 +---------------------- src/librustc_typeck/check/regionck.rs | 4 +- 9 files changed, 32 insertions(+), 123 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 139750af6284..2798cfa43ddb 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -110,8 +110,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { } fn with_euv<'b, F, R>(&'b mut self, item_id: Option, f: F) -> R where - F: for<'t> FnOnce(&mut euv::ExprUseVisitor<'b, 't, 'tcx, - infer::InferCtxt<'a, 'tcx>>) -> R, + F: for<'t> FnOnce(&mut euv::ExprUseVisitor<'b, 't, 'b, 'tcx>) -> R, { let param_env = match item_id { Some(item_id) => ty::ParameterEnvironment::for_item(self.tcx, item_id), diff --git a/src/librustc/middle/check_rvalues.rs b/src/librustc/middle/check_rvalues.rs index 23accf88dc9d..731e49192a82 100644 --- a/src/librustc/middle/check_rvalues.rs +++ b/src/librustc/middle/check_rvalues.rs @@ -41,8 +41,8 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> { { // FIXME (@jroesch) change this to be an inference context let param_env = ParameterEnvironment::for_item(self.tcx, fn_id); - let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env), false); - let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &infcx.parameter_environment }; + let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env.clone()), false); + let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: ¶m_env }; let mut euv = euv::ExprUseVisitor::new(&mut delegate, &infcx); euv.walk_fn(fd, b); } diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 25728c50c61f..c8555d28e40a 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -21,9 +21,10 @@ use self::TrackMatchMode::*; use self::OverloadedCallType::*; use middle::{def, region, pat_util}; +use middle::infer; use middle::mem_categorization as mc; use middle::mem_categorization::Typer; -use middle::ty::{self}; +use middle::ty::{self, ClosureTyper}; use middle::ty::{MethodCall, MethodObject, MethodTraitObject}; use middle::ty::{MethodOrigin, MethodParam, MethodTypeParam}; use middle::ty::{MethodStatic, MethodStaticClosure}; @@ -291,9 +292,9 @@ impl OverloadedCallType { // supplies types from the tree. After type checking is complete, you // can just use the tcx as the typer. -pub struct ExprUseVisitor<'d,'t,'tcx:'t,TYPER:'t> { - typer: &'t TYPER, - mc: mc::MemCategorizationContext<'t,TYPER>, +pub struct ExprUseVisitor<'d,'t,'a: 't, 'tcx:'a> { + typer: &'t infer::InferCtxt<'a, 'tcx>, + mc: mc::MemCategorizationContext<'t, 'a, 'tcx>, delegate: &'d mut (Delegate<'tcx>+'d), } @@ -319,10 +320,10 @@ enum PassArgs { ByRef, } -impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { +impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> { pub fn new(delegate: &'d mut Delegate<'tcx>, - typer: &'t TYPER) - -> ExprUseVisitor<'d,'t,'tcx,TYPER> { + typer: &'t infer::InferCtxt<'a, 'tcx>) + -> ExprUseVisitor<'d,'t,'a, 'tcx> { ExprUseVisitor { typer: typer, mc: mc::MemCategorizationContext::new(typer), diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index 31bfc01886c0..6ca1c22a2c22 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -30,7 +30,7 @@ use middle::region::CodeExtent; use middle::subst; use middle::subst::Substs; use middle::subst::Subst; -use middle::traits::{self, FulfillmentContext, Normalized, MiscObligation, +use middle::traits::{self, FulfillmentContext, Normalized, SelectionContext, ObligationCause}; use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, UnconstrainedNumeric}; use middle::ty::{self, Ty, HasTypeFlags}; @@ -477,7 +477,7 @@ pub struct CombinedSnapshot { impl<'a, 'tcx> mc::Typer<'tcx> for InferCtxt<'a, 'tcx> { fn node_ty(&self, id: ast::NodeId) -> McResult> { - let ty = self.node_ty(id); + let ty = self.node_type(id); self.resolve_type_vars_or_error(&ty) } @@ -1183,7 +1183,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { .map(|method| resolve_ty(method.ty))) } - pub fn node_ty(&self, id: ast::NodeId) -> Ty<'tcx> { + pub fn node_type(&self, id: ast::NodeId) -> Ty<'tcx> { match self.tables.borrow().node_types.get(&id) { Some(&t) => t, // FIXME diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 13e127e91261..867174ffbc5b 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -73,10 +73,11 @@ pub use self::categorization::*; use self::Aliasability::*; use ast_map; +use middle::infer; use middle::check_const; use middle::def; use middle::region; -use middle::ty::{self, Ty}; +use middle::ty::{self, Ty, ClosureTyper}; use util::nodemap::NodeMap; use syntax::ast::{MutImmutable, MutMutable}; @@ -255,13 +256,10 @@ impl ast_node for ast::Pat { fn span(&self) -> Span { self.span } } -pub struct MemCategorizationContext<'t,TYPER:'t> { - typer: &'t TYPER -} - -impl<'t,TYPER:'t> Copy for MemCategorizationContext<'t,TYPER> {} -impl<'t,TYPER:'t> Clone for MemCategorizationContext<'t,TYPER> { - fn clone(&self) -> MemCategorizationContext<'t,TYPER> { *self } +#[derive(Copy, Clone)] +pub struct MemCategorizationContext<'t, 'a: 't, 'tcx : 'a> { + pub typer: &'t infer::InferCtxt<'a, 'tcx>, + // pub monomorphize: bool, } pub type McResult = Result; @@ -391,13 +389,13 @@ impl MutabilityCategory { } } -impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { - pub fn new(typer: &'t TYPER) -> MemCategorizationContext<'t,TYPER> { +impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> { + pub fn new(typer: &'t infer::InferCtxt<'a, 'tcx>) -> MemCategorizationContext<'t, 'a, 'tcx> { MemCategorizationContext { typer: typer } } - fn tcx(&self) -> &'t ty::ctxt<'tcx> { - self.typer.tcx() + fn tcx(&self) -> &'a ty::ctxt<'tcx> { + self.typer.tcx } fn expr_ty(&self, expr: &ast::Expr) -> McResult> { @@ -1175,7 +1173,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { } pub fn cat_pattern(&self, cmt: cmt<'tcx>, pat: &ast::Pat, mut op: F) -> McResult<()> - where F: FnMut(&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat), + where F: FnMut(&MemCategorizationContext<'t, 'a, 'tcx>, cmt<'tcx>, &ast::Pat), { self.cat_pattern_(cmt, pat, &mut op) } @@ -1183,7 +1181,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { // FIXME(#19596) This is a workaround, but there should be a better way to do this fn cat_pattern_(&self, cmt: cmt<'tcx>, pat: &ast::Pat, op: &mut F) -> McResult<()> - where F : FnMut(&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat), + where F : FnMut(&MemCategorizationContext<'t, 'a, 'tcx>, cmt<'tcx>, &ast::Pat), { // Here, `cmt` is the categorization for the value being // matched and pat is the pattern it is being matched against. diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index dc692b0e765d..bb7e95cd4ae4 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -43,7 +43,6 @@ #![feature(unicode)] #![feature(unicode)] #![feature(vec_push_all)] -#![feature(cell_extras)] #![allow(trivial_casts)] diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index 9b293f7b1a78..a9617bd17c09 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -195,6 +195,7 @@ use middle::check_match; use middle::const_eval; use middle::def::{self, DefMap}; use middle::expr_use_visitor as euv; +use middle::infer; use middle::lang_items::StrEqFnLangItem; use middle::mem_categorization as mc; use middle::pat_util::*; @@ -1350,7 +1351,8 @@ fn is_discr_reassigned(bcx: Block, discr: &ast::Expr, body: &ast::Expr) -> bool reassigned: false }; { - let mut visitor = euv::ExprUseVisitor::new(&mut rc, bcx); + let infcx = infer::new_infer_ctxt(bcx.tcx(), &bcx.tcx().tables, None, false); + let mut visitor = euv::ExprUseVisitor::new(&mut rc, &infcx); visitor.walk_expr(body); } rc.reassigned diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index d4f318a4258c..598029b842b6 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -22,7 +22,6 @@ use middle::cfg; use middle::def; use middle::infer; use middle::lang_items::LangItem; -use middle::mem_categorization as mc; use middle::mem_categorization::Typer; use middle::ty::ClosureTyper; use middle::region; @@ -48,7 +47,7 @@ use util::nodemap::{FnvHashMap, NodeMap}; use arena::TypedArena; use libc::{c_uint, c_char}; use std::ffi::CString; -use std::cell::{Cell, RefCell, Ref}; +use std::cell::{Cell, RefCell}; use std::result::Result as StdResult; use std::vec::Vec; use syntax::ast; @@ -577,95 +576,6 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> { } } -impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { - fn node_ty(&self, id: ast::NodeId) -> mc::McResult> { - Ok(node_id_type(self, id)) - } - - fn expr_ty_adjusted(&self, expr: &ast::Expr) -> mc::McResult> { - Ok(expr_ty_adjusted(self, expr)) - } - - fn node_method_ty(&self, method_call: ty::MethodCall) -> Option> { - self.tcx() - .tables - .borrow() - .method_map - .get(&method_call) - .map(|method| monomorphize_type(self, method.ty)) - } - - fn node_method_origin(&self, method_call: ty::MethodCall) - -> Option> - { - self.tcx() - .tables - .borrow() - .method_map - .get(&method_call) - .map(|method| method.origin.clone()) - } - - fn adjustments<'a>(&'a self) -> Ref>> { - // FIXME (@jroesch): this is becuase we currently have a HR inference problem - // in the snapshot that causes this code not to work. - fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) -> - &'a NodeMap> { - &tables.adjustments - } - - Ref::map(self.tcx().tables.borrow(), project_adjustments) - } - - fn is_method_call(&self, id: ast::NodeId) -> bool { - self.tcx().tables.borrow().method_map.contains_key(&ty::MethodCall::expr(id)) - } - - fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option { - self.tcx().region_maps.temporary_scope(rvalue_id) - } - - fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option { - Some(self.tcx().tables.borrow().upvar_capture_map.get(&upvar_id).unwrap().clone()) - } - - fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool { - ty.moves_by_default(&self.fcx.param_env, span) - } -} - -impl<'blk, 'tcx> ty::ClosureTyper<'tcx> for BlockS<'blk, 'tcx> { - fn param_env<'a>(&'a self) -> &'a ty::ParameterEnvironment<'a, 'tcx> { - &self.fcx.param_env - } - - fn closure_kind(&self, - def_id: ast::DefId) - -> Option - { - let infcx = infer::normalizing_infer_ctxt(self.tcx(), &self.tcx().tables); - infcx.closure_kind(def_id) - } - - fn closure_type(&self, - def_id: ast::DefId, - substs: &subst::Substs<'tcx>) - -> ty::ClosureTy<'tcx> - { - let infcx = infer::normalizing_infer_ctxt(self.tcx(), &self.tcx().tables); - infcx.closure_type(def_id, substs) - } - - fn closure_upvars(&self, - def_id: ast::DefId, - substs: &Substs<'tcx>) - -> Option>> - { - let infcx = infer::new_infer_ctxt(self.tcx(), &self.tcx().tables, None, true); - infcx.closure_upvars(def_id, substs) - } -} - pub struct Result<'blk, 'tcx: 'blk> { pub bcx: Block<'blk, 'tcx>, pub val: ValueRef diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 661e1856ce8c..a98bcc247edd 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -1101,8 +1101,8 @@ 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>, +fn link_pattern<'t, 'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, + mc: mc::MemCategorizationContext<'t, 'a, 'tcx>, discr_cmt: mc::cmt<'tcx>, root_pat: &ast::Pat) { debug!("link_pattern(discr_cmt={:?}, root_pat={:?})",