diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 7da9d6f82bcf..450d4203bae3 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -328,7 +328,7 @@ pub fn phase_3_run_analysis_passes(sess: Session, freevars, region_map, lang_items); // passes are timed inside typeck - let (method_map, vtable_map) = typeck::check_crate(&ty_cx, trait_map, krate); + typeck::check_crate(&ty_cx, trait_map, krate); time(time_passes, "check static items", (), |_| middle::check_static::check_crate(&ty_cx, krate)); @@ -338,56 +338,52 @@ pub fn phase_3_run_analysis_passes(sess: Session, middle::const_eval::process_crate(krate, &ty_cx)); time(time_passes, "const checking", (), |_| - middle::check_const::check_crate(krate, def_map, method_map, &ty_cx)); + middle::check_const::check_crate(krate, &ty_cx)); let maps = (external_exports, last_private_map); let (exported_items, public_items) = time(time_passes, "privacy checking", maps, |(a, b)| - middle::privacy::check_crate(&ty_cx, &method_map, &exp_map2, - a, b, krate)); + middle::privacy::check_crate(&ty_cx, &exp_map2, a, b, krate)); time(time_passes, "effect checking", (), |_| - middle::effect::check_crate(&ty_cx, method_map, krate)); + middle::effect::check_crate(&ty_cx, krate)); let middle::moves::MoveMaps {moves_map, moved_variables_set, capture_map} = time(time_passes, "compute moves", (), |_| - middle::moves::compute_moves(&ty_cx, method_map, krate)); + middle::moves::compute_moves(&ty_cx, krate)); time(time_passes, "match checking", (), |_| - middle::check_match::check_crate(&ty_cx, method_map, - &moves_map, krate)); + middle::check_match::check_crate(&ty_cx, &moves_map, krate)); time(time_passes, "liveness checking", (), |_| - middle::liveness::check_crate(&ty_cx, method_map, - &capture_map, krate)); + middle::liveness::check_crate(&ty_cx, &capture_map, krate)); let root_map = time(time_passes, "borrow checking", (), |_| - middle::borrowck::check_crate(&ty_cx, method_map, - &moves_map, &moved_variables_set, + middle::borrowck::check_crate(&ty_cx, &moves_map, + &moved_variables_set, &capture_map, krate)); drop(moves_map); drop(moved_variables_set); time(time_passes, "kind checking", (), |_| - kind::check_crate(&ty_cx, method_map, krate)); + kind::check_crate(&ty_cx, krate)); let reachable_map = time(time_passes, "reachability checking", (), |_| - reachable::find_reachable(&ty_cx, method_map, &exported_items)); + reachable::find_reachable(&ty_cx, &exported_items)); time(time_passes, "death checking", (), |_| { middle::dead::check_crate(&ty_cx, - method_map, &exported_items, &reachable_map, krate) }); time(time_passes, "lint checking", (), |_| - lint::check_crate(&ty_cx, method_map, &exported_items, krate)); + lint::check_crate(&ty_cx, &exported_items, krate)); CrateAnalysis { exp_map2: exp_map2, @@ -396,8 +392,6 @@ pub fn phase_3_run_analysis_passes(sess: Session, public_items: public_items, maps: astencode::Maps { root_map: root_map, - method_map: method_map, - vtable_map: vtable_map, capture_map: RefCell::new(capture_map) }, reachable: reachable_map diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 49a2b6326c81..0584322ef9e9 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -55,8 +55,6 @@ use writer = serialize::ebml::writer; // Auxiliary maps of things to be encoded pub struct Maps { pub root_map: middle::borrowck::root_map, - pub method_map: middle::typeck::MethodMap, - pub vtable_map: middle::typeck::vtable_map, pub capture_map: RefCell, } @@ -1052,7 +1050,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, } let method_call = MethodCall::expr(id); - for &method in maps.method_map.borrow().find(&method_call).iter() { + for &method in tcx.method_map.borrow().find(&method_call).iter() { ebml_w.tag(c::tag_table_method_map, |ebml_w| { ebml_w.id(id); ebml_w.tag(c::tag_table_val, |ebml_w| { @@ -1061,7 +1059,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, }) } - for &dr in maps.vtable_map.borrow().find(&method_call).iter() { + for &dr in tcx.vtable_map.borrow().find(&method_call).iter() { ebml_w.tag(c::tag_table_vtable_map, |ebml_w| { ebml_w.id(id); ebml_w.tag(c::tag_table_val, |ebml_w| { @@ -1075,7 +1073,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, ty::AutoDerefRef(adj) => { for autoderef in range(0, adj.autoderefs) { let method_call = MethodCall::autoderef(id, autoderef as u32); - for &method in maps.method_map.borrow().find(&method_call).iter() { + for &method in tcx.method_map.borrow().find(&method_call).iter() { ebml_w.tag(c::tag_table_method_map, |ebml_w| { ebml_w.id(id); ebml_w.tag(c::tag_table_val, |ebml_w| { @@ -1084,7 +1082,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, }) } - for &dr in maps.vtable_map.borrow().find(&method_call).iter() { + for &dr in tcx.vtable_map.borrow().find(&method_call).iter() { ebml_w.tag(c::tag_table_vtable_map, |ebml_w| { ebml_w.id(id); ebml_w.tag(c::tag_table_val, |ebml_w| { @@ -1398,7 +1396,7 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext, expr_id: id, autoderef: autoderef }; - dcx.maps.method_map.borrow_mut().insert(method_call, method); + dcx.tcx.method_map.borrow_mut().insert(method_call, method); } c::tag_table_vtable_map => { let (autoderef, vtable_res) = @@ -1408,7 +1406,7 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext, expr_id: id, autoderef: autoderef }; - dcx.maps.vtable_map.borrow_mut().insert(vtable_key, vtable_res); + dcx.tcx.vtable_map.borrow_mut().insert(vtable_key, vtable_res); } c::tag_table_adjustments => { let adj: @ty::AutoAdjustment = @val_dsr.read_auto_adjustment(xcx); diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 5e0425141ac8..848ace40d4da 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -806,7 +806,7 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>, this.check_for_conflicting_loans(expr.id); this.check_move_out_from_expr(expr); - let method_map = this.bccx.method_map.borrow(); + let method_map = this.bccx.tcx.method_map.borrow(); match expr.node { ast::ExprPath(..) => { if !this.move_data.is_assignee(expr.id) { diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index dd9f2eb970be..155f805d2174 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -188,7 +188,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt, } // Special checks for various kinds of expressions: - let method_map = this.bccx.method_map.borrow(); + let method_map = this.bccx.tcx.method_map.borrow(); match ex.node { ast::ExprAddrOf(mutbl, base) => { let base_cmt = this.bccx.cat_expr(base); @@ -375,7 +375,7 @@ impl<'a> GatherLoanCtxt<'a> { pub fn guarantee_autoderefs(&mut self, expr: &ast::Expr, autoderefs: uint) { - let method_map = self.bccx.method_map.borrow(); + let method_map = self.bccx.tcx.method_map.borrow(); for i in range(0, autoderefs) { match method_map.find(&MethodCall::autoderef(expr.id, i as u32)) { Some(method) => { diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 21e68e2724fc..628c41fb6c5e 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -76,7 +76,6 @@ impl<'a> Visitor<()> for BorrowckCtxt<'a> { } pub fn check_crate(tcx: &ty::ctxt, - method_map: typeck::MethodMap, moves_map: &NodeSet, moved_variables_set: &NodeSet, capture_map: &moves::CaptureMap, @@ -84,7 +83,6 @@ pub fn check_crate(tcx: &ty::ctxt, -> root_map { let mut bccx = BorrowckCtxt { tcx: tcx, - method_map: method_map, moves_map: moves_map, moved_variables_set: moved_variables_set, capture_map: capture_map, @@ -149,7 +147,6 @@ fn borrowck_fn(this: &mut BorrowckCtxt, gather_loans::gather_loans_in_fn(this, decl, body); let mut loan_dfcx = DataFlowContext::new(this.tcx, - this.method_map, LoanDataFlowOperator, id_range, all_loans.len()); @@ -161,7 +158,6 @@ fn borrowck_fn(this: &mut BorrowckCtxt, let flowed_moves = move_data::FlowedMoveData::new(move_data, this.tcx, - this.method_map, id_range, body); @@ -176,7 +172,6 @@ fn borrowck_fn(this: &mut BorrowckCtxt, pub struct BorrowckCtxt<'a> { tcx: &'a ty::ctxt, - method_map: typeck::MethodMap, moves_map: &'a NodeSet, moved_variables_set: &'a NodeSet, capture_map: &'a moves::CaptureMap, @@ -437,12 +432,9 @@ impl<'a> BorrowckCtxt<'a> { self.moves_map.contains(&id) } - pub fn mc(&self) -> mc::MemCategorizationContext> { + pub fn mc(&self) -> mc::MemCategorizationContext<&'a ty::ctxt> { mc::MemCategorizationContext { - typer: TcxTyper { - tcx: self.tcx, - method_map: self.method_map - } + typer: self.tcx, } } @@ -572,8 +564,7 @@ impl<'a> BorrowckCtxt<'a> { move_data::MoveExpr => { let (expr_ty, expr_span) = match self.tcx.map.find(move.id) { Some(ast_map::NodeExpr(expr)) => { - (ty::expr_ty_adjusted(self.tcx, expr, - &*self.method_map.borrow()), expr.span) + (ty::expr_ty_adjusted(self.tcx, expr), expr.span) } r => self.tcx.sess.bug(format!("MoveExpr({:?}) maps to {:?}, not Expr", move.id, r)) @@ -599,8 +590,7 @@ impl<'a> BorrowckCtxt<'a> { move_data::Captured => { let (expr_ty, expr_span) = match self.tcx.map.find(move.id) { Some(ast_map::NodeExpr(expr)) => { - (ty::expr_ty_adjusted(self.tcx, expr, - &*self.method_map.borrow()), expr.span) + (ty::expr_ty_adjusted(self.tcx, expr), expr.span) } r => self.tcx.sess.bug(format!("Captured({:?}) maps to {:?}, not Expr", move.id, r)) @@ -915,18 +905,13 @@ impl Repr for LoanPath { /////////////////////////////////////////////////////////////////////////// -pub struct TcxTyper<'a> { - tcx: &'a ty::ctxt, - method_map: typeck::MethodMap, -} - -impl<'a> mc::Typer for TcxTyper<'a> { +impl<'a> mc::Typer for &'a ty::ctxt { fn tcx<'a>(&'a self) -> &'a ty::ctxt { - self.tcx + *self } fn node_ty(&mut self, id: ast::NodeId) -> mc::McResult { - Ok(ty::node_id_to_type(self.tcx, id)) + Ok(ty::node_id_to_type(*self, id)) } fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option { @@ -934,7 +919,7 @@ impl<'a> mc::Typer for TcxTyper<'a> { } fn adjustment(&mut self, id: ast::NodeId) -> Option<@ty::AutoAdjustment> { - self.tcx.adjustments.borrow().find_copy(&id) + self.adjustments.borrow().find_copy(&id) } fn is_method_call(&mut self, id: ast::NodeId) -> bool { @@ -942,10 +927,10 @@ impl<'a> mc::Typer for TcxTyper<'a> { } fn temporary_scope(&mut self, id: ast::NodeId) -> Option { - self.tcx.region_maps.temporary_scope(id) + self.region_maps.temporary_scope(id) } fn upvar_borrow(&mut self, id: ty::UpvarId) -> ty::UpvarBorrow { - self.tcx.upvar_borrow_map.borrow().get_copy(&id) + self.upvar_borrow_map.borrow().get_copy(&id) } } diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index 0e18946a3a10..b35eefcc73fb 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -22,7 +22,6 @@ use middle::borrowck::*; use middle::dataflow::DataFlowContext; use middle::dataflow::DataFlowOperator; use middle::ty; -use middle::typeck; use syntax::ast; use syntax::ast_util; use syntax::codemap::Span; @@ -511,19 +510,16 @@ impl MoveData { impl<'a> FlowedMoveData<'a> { pub fn new(move_data: MoveData, tcx: &'a ty::ctxt, - method_map: typeck::MethodMap, id_range: ast_util::IdRange, body: &ast::Block) -> FlowedMoveData<'a> { let mut dfcx_moves = DataFlowContext::new(tcx, - method_map, MoveDataFlowOperator, id_range, move_data.moves.borrow().len()); let mut dfcx_assign = DataFlowContext::new(tcx, - method_map, AssignDataFlowOperator, id_range, move_data.var_assignments.borrow().len()); diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 67f3b8fe9065..6d6031ed050b 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -21,8 +21,6 @@ use syntax::visit::Visitor; use syntax::visit; pub struct CheckCrateVisitor<'a> { - def_map: resolve::DefMap, - method_map: typeck::MethodMap, tcx: &'a ty::ctxt, } @@ -38,16 +36,8 @@ impl<'a> Visitor for CheckCrateVisitor<'a> { } } -pub fn check_crate(krate: &Crate, - def_map: resolve::DefMap, - method_map: typeck::MethodMap, - tcx: &ty::ctxt) { - let mut v = CheckCrateVisitor { - def_map: def_map, - method_map: method_map, - tcx: tcx, - }; - visit::walk_crate(&mut v, krate, false); +pub fn check_crate(krate: &Crate, tcx: &ty::ctxt) { + visit::walk_crate(&mut CheckCrateVisitor { tcx: tcx }, krate, false); tcx.sess.abort_if_errors(); } @@ -55,7 +45,7 @@ fn check_item(v: &mut CheckCrateVisitor, it: &Item, _is_const: bool) { match it.node { ItemStatic(_, _, ex) => { v.visit_expr(ex, true); - check_item_recursion(&v.tcx.sess, &v.tcx.map, v.def_map, it); + check_item_recursion(&v.tcx.sess, &v.tcx.map, v.tcx.def_map, it); } ItemEnum(ref enum_definition, _) => { for var in (*enum_definition).variants.iter() { @@ -103,7 +93,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) { ExprLit(lit) if ast_util::lit_is_str(lit) => {} ExprBinary(..) | ExprUnary(..) => { let method_call = typeck::MethodCall::expr(e.id); - if v.method_map.borrow().contains_key(&method_call) { + if v.tcx.method_map.borrow().contains_key(&method_call) { v.tcx.sess.span_err(e.span, "user-defined operators are not \ allowed in constant expressions"); } @@ -127,7 +117,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) { "paths in constants may only refer to \ items without type parameters"); } - match v.def_map.borrow().find(&e.id) { + match v.tcx.def_map.borrow().find(&e.id) { Some(&DefStatic(..)) | Some(&DefFn(_, _)) | Some(&DefVariant(_, _, _)) | @@ -145,7 +135,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) { } } ExprCall(callee, _) => { - match v.def_map.borrow().find(&callee.id) { + match v.tcx.def_map.borrow().find(&callee.id) { Some(&DefStruct(..)) => {} // OK. Some(&DefVariant(..)) => {} // OK. _ => { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index db1badb7d598..12d83aa4135d 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -15,7 +15,6 @@ use middle::const_eval::{eval_const_expr, const_val, const_bool, const_float}; use middle::pat_util::*; use middle::ty::*; use middle::ty; -use middle::typeck::MethodMap; use util::nodemap::NodeSet; use util::ppaux::ty_to_str; @@ -30,7 +29,6 @@ use syntax::visit::{Visitor, FnKind}; struct MatchCheckCtxt<'a> { tcx: &'a ty::ctxt, - method_map: MethodMap, moves_map: &'a NodeSet } @@ -47,12 +45,10 @@ impl<'a> Visitor<()> for MatchCheckCtxt<'a> { } pub fn check_crate(tcx: &ty::ctxt, - method_map: MethodMap, moves_map: &NodeSet, krate: &Crate) { let mut cx = MatchCheckCtxt { tcx: tcx, - method_map: method_map, moves_map: moves_map }; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index d39f0721b427..f72555de9887 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -15,7 +15,7 @@ use middle::astencode; use middle::ty; use middle::typeck::astconv; -use util::nodemap::{DefIdMap, FnvHashMap, NodeMap}; +use util::nodemap::{DefIdMap, NodeMap}; use syntax::ast::*; use syntax::parse::token::InternedString; @@ -128,8 +128,6 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt, } let maps = astencode::Maps { root_map: @RefCell::new(HashMap::new()), - method_map: @RefCell::new(FnvHashMap::new()), - vtable_map: @RefCell::new(FnvHashMap::new()), capture_map: RefCell::new(NodeMap::new()) }; let e = match csearch::maybe_get_item_ast(tcx, enum_def, @@ -169,8 +167,6 @@ pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId) } let maps = astencode::Maps { root_map: @RefCell::new(HashMap::new()), - method_map: @RefCell::new(FnvHashMap::new()), - vtable_map: @RefCell::new(FnvHashMap::new()), capture_map: RefCell::new(NodeMap::new()) }; let e = match csearch::maybe_get_item_ast(tcx, def_id, diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 2b79917f9d51..742daa82ecd4 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -32,7 +32,6 @@ use util::nodemap::NodeMap; #[deriving(Clone)] pub struct DataFlowContext<'a, O> { tcx: &'a ty::ctxt, - method_map: typeck::MethodMap, /// the data flow operator oper: O, @@ -123,7 +122,6 @@ impl<'a, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, O> { impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> { pub fn new(tcx: &'a ty::ctxt, - method_map: typeck::MethodMap, oper: O, id_range: IdRange, bits_per_id: uint) -> DataFlowContext<'a, O> { @@ -138,7 +136,6 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> { DataFlowContext { tcx: tcx, - method_map: method_map, words_per_id: words_per_id, nodeid_to_bitset: NodeMap::new(), bits_per_id: bits_per_id, @@ -784,7 +781,7 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> { fn is_method_call(&self, expr: &ast::Expr) -> bool { let method_call = typeck::MethodCall::expr(expr.id); - self.dfcx.method_map.borrow().contains_key(&method_call) + self.dfcx.tcx.method_map.borrow().contains_key(&method_call) } fn reset(&mut self, bits: &mut [uint]) { diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 413c6a4de1d0..e74bef9e95ce 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -50,18 +50,15 @@ fn should_explore(tcx: &ty::ctxt, def_id: ast::DefId) -> bool { struct MarkSymbolVisitor<'a> { worklist: Vec, - method_map: typeck::MethodMap, tcx: &'a ty::ctxt, live_symbols: ~HashSet, } impl<'a> MarkSymbolVisitor<'a> { fn new(tcx: &'a ty::ctxt, - method_map: typeck::MethodMap, worklist: Vec) -> MarkSymbolVisitor<'a> { MarkSymbolVisitor { worklist: worklist, - method_map: method_map, tcx: tcx, live_symbols: ~HashSet::new(), } @@ -93,7 +90,7 @@ impl<'a> MarkSymbolVisitor<'a> { fn lookup_and_handle_method(&mut self, id: ast::NodeId, span: codemap::Span) { let method_call = typeck::MethodCall::expr(id); - match self.method_map.borrow().find(&method_call) { + match self.tcx.method_map.borrow().find(&method_call) { Some(method) => { match method.origin { typeck::MethodStatic(def_id) => { @@ -285,14 +282,13 @@ fn create_and_seed_worklist(tcx: &ty::ctxt, } fn find_live(tcx: &ty::ctxt, - method_map: typeck::MethodMap, exported_items: &privacy::ExportedItems, reachable_symbols: &NodeSet, krate: &ast::Crate) -> ~HashSet { let worklist = create_and_seed_worklist(tcx, exported_items, reachable_symbols, krate); - let mut symbol_visitor = MarkSymbolVisitor::new(tcx, method_map, worklist); + let mut symbol_visitor = MarkSymbolVisitor::new(tcx, worklist); symbol_visitor.mark_live_symbols(); symbol_visitor.live_symbols } @@ -406,11 +402,10 @@ impl<'a> Visitor<()> for DeadVisitor<'a> { } pub fn check_crate(tcx: &ty::ctxt, - method_map: typeck::MethodMap, exported_items: &privacy::ExportedItems, reachable_symbols: &NodeSet, krate: &ast::Crate) { - let live_symbols = find_live(tcx, method_map, exported_items, + let live_symbols = find_live(tcx, exported_items, reachable_symbols, krate); let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols }; visit::walk_crate(&mut visitor, krate, ()); diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index 827d07484b73..ef7c59248449 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -12,7 +12,7 @@ /// `unsafe`. use middle::ty; -use middle::typeck::{MethodCall, MethodMap}; +use middle::typeck::MethodCall; use util::ppaux; use syntax::ast; @@ -38,8 +38,6 @@ fn type_is_unsafe_function(ty: ty::t) -> bool { struct EffectCheckVisitor<'a> { tcx: &'a ty::ctxt, - /// The method map. - method_map: MethodMap, /// Whether we're in an unsafe context. unsafe_context: UnsafeContext, } @@ -138,7 +136,7 @@ impl<'a> Visitor<()> for EffectCheckVisitor<'a> { match expr.node { ast::ExprMethodCall(_, _, _) => { let method_call = MethodCall::expr(expr.id); - let base_type = self.method_map.borrow().get(&method_call).ty; + let base_type = self.tcx.method_map.borrow().get(&method_call).ty; debug!("effect: method call case, base type is {}", ppaux::ty_to_str(self.tcx, base_type)); if type_is_unsafe_function(base_type) { @@ -190,10 +188,9 @@ impl<'a> Visitor<()> for EffectCheckVisitor<'a> { } } -pub fn check_crate(tcx: &ty::ctxt, method_map: MethodMap, krate: &ast::Crate) { +pub fn check_crate(tcx: &ty::ctxt, krate: &ast::Crate) { let mut visitor = EffectCheckVisitor { tcx: tcx, - method_map: method_map, unsafe_context: SafeContext, }; diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index a152e06eb06a..613251df19e9 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -47,7 +47,6 @@ use syntax::visit::Visitor; #[deriving(Clone)] pub struct Context<'a> { tcx: &'a ty::ctxt, - method_map: typeck::MethodMap, } impl<'a> Visitor<()> for Context<'a> { @@ -70,11 +69,9 @@ impl<'a> Visitor<()> for Context<'a> { } pub fn check_crate(tcx: &ty::ctxt, - method_map: typeck::MethodMap, krate: &Crate) { let mut ctx = Context { tcx: tcx, - method_map: method_map, }; visit::walk_crate(&mut ctx, krate, ()); tcx.sess.abort_if_errors(); @@ -240,7 +237,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) { // Handle any kind bounds on type parameters { - let method_map = cx.method_map.borrow(); + let method_map = cx.tcx.method_map.borrow(); let method = method_map.find(&typeck::MethodCall::expr(e.id)); let node_type_substs = cx.tcx.node_type_substs.borrow(); let r = match method { @@ -312,8 +309,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) { match **adjustment { ty::AutoObject(..) => { let source_ty = ty::expr_ty(cx.tcx, e); - let target_ty = ty::expr_ty_adjusted(cx.tcx, e, - &*cx.method_map.borrow()); + let target_ty = ty::expr_ty_adjusted(cx.tcx, e); check_trait_cast(cx, source_ty, target_ty, e.span); } ty::AutoAddEnv(..) | diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 6ce815d9bc46..3707c60ebe02 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -437,9 +437,6 @@ struct Context<'a> { cur: SmallIntMap<(level, LintSource)>, // context we're checking in (used to access fields like sess) tcx: &'a ty::ctxt, - // maps from an expression id that corresponds to a method call to the - // details of the method to be invoked - method_map: typeck::MethodMap, // Items exported by the crate; used by the missing_doc lint. exported_items: &'a privacy::ExportedItems, // The id of the current `ast::StructDef` being walked. @@ -1537,7 +1534,7 @@ fn check_stability(cx: &Context, e: &ast::Expr) { } ast::ExprMethodCall(..) => { let method_call = typeck::MethodCall::expr(e.id); - match cx.method_map.borrow().find(&method_call) { + match cx.tcx.method_map.borrow().find(&method_call) { Some(method) => { match method.origin { typeck::MethodStatic(def_id) => { @@ -1775,14 +1772,12 @@ impl<'a> IdVisitingOperation for Context<'a> { } pub fn check_crate(tcx: &ty::ctxt, - method_map: typeck::MethodMap, exported_items: &privacy::ExportedItems, krate: &ast::Crate) { let mut cx = Context { dict: @get_lint_dict(), cur: SmallIntMap::new(), tcx: tcx, - method_map: method_map, exported_items: exported_items, cur_struct_def_id: -1, is_doc_hidden: false, diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index a189b9776356..32d2a8f9c8f1 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -106,7 +106,6 @@ use middle::lint::{UnusedVariable, DeadAssignment}; use middle::pat_util; use middle::ty; -use middle::typeck; use middle::moves; use util::nodemap::NodeMap; @@ -171,10 +170,9 @@ impl<'a> Visitor<()> for IrMaps<'a> { } pub fn check_crate(tcx: &ty::ctxt, - method_map: typeck::MethodMap, capture_map: &moves::CaptureMap, krate: &Crate) { - visit::walk_crate(&mut IrMaps(tcx, method_map, capture_map), krate, ()); + visit::walk_crate(&mut IrMaps(tcx, capture_map), krate, ()); tcx.sess.abort_if_errors(); } @@ -247,7 +245,6 @@ enum VarKind { struct IrMaps<'a> { tcx: &'a ty::ctxt, - method_map: typeck::MethodMap, capture_map: &'a moves::CaptureMap, num_live_nodes: uint, @@ -260,12 +257,10 @@ struct IrMaps<'a> { } fn IrMaps<'a>(tcx: &'a ty::ctxt, - method_map: typeck::MethodMap, capture_map: &'a moves::CaptureMap) -> IrMaps<'a> { IrMaps { tcx: tcx, - method_map: method_map, capture_map: capture_map, num_live_nodes: 0, num_vars: 0, @@ -366,7 +361,7 @@ fn visit_fn(ir: &mut IrMaps, let _i = ::util::common::indenter(); // swap in a new set of IR maps for this function body: - let mut fn_maps = IrMaps(ir.tcx, ir.method_map, ir.capture_map); + let mut fn_maps = IrMaps(ir.tcx, ir.capture_map); unsafe { debug!("creating fn_maps: {}", transmute::<&IrMaps, *IrMaps>(&fn_maps)); diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 2029df38b100..5d63a05e5606 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -130,7 +130,7 @@ and so on. use middle::pat_util::{pat_bindings}; use middle::freevars; use middle::ty; -use middle::typeck::{MethodCall, MethodMap}; +use middle::typeck::MethodCall; use util::ppaux; use util::ppaux::Repr; use util::common::indenter; @@ -177,7 +177,6 @@ pub struct MoveMaps { #[deriving(Clone)] struct VisitContext<'a> { tcx: &'a ty::ctxt, - method_map: MethodMap, move_maps: MoveMaps } @@ -202,13 +201,9 @@ impl<'a> visit::Visitor<()> for VisitContext<'a> { fn visit_ty(&mut self, _t: &Ty, _: ()) {} } -pub fn compute_moves(tcx: &ty::ctxt, - method_map: MethodMap, - krate: &Crate) -> MoveMaps -{ +pub fn compute_moves(tcx: &ty::ctxt, krate: &Crate) -> MoveMaps { let mut visit_cx = VisitContext { tcx: tcx, - method_map: method_map, move_maps: MoveMaps { moves_map: NodeSet::new(), moved_variables_set: NodeSet::new(), @@ -274,8 +269,7 @@ impl<'a> VisitContext<'a> { debug!("consume_expr(expr={})", expr.repr(self.tcx)); - let expr_ty = ty::expr_ty_adjusted(self.tcx, expr, - &*self.method_map.borrow()); + let expr_ty = ty::expr_ty_adjusted(self.tcx, expr); if ty::type_moves_by_default(self.tcx, expr_ty) { self.move_maps.moves_map.insert(expr.id); self.use_expr(expr, Move); @@ -577,7 +571,7 @@ impl<'a> VisitContext<'a> { arg_exprs: &[@Expr]) -> bool { let method_call = MethodCall::expr(expr.id); - if !self.method_map.borrow().contains_key(&method_call) { + if !self.tcx.method_map.borrow().contains_key(&method_call) { return false; } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 1e160df10612..4877bfc5cce6 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -337,7 +337,6 @@ struct PrivacyVisitor<'a> { curitem: ast::NodeId, in_fn: bool, in_foreign: bool, - method_map: &'a MethodMap, parents: NodeMap, external_exports: resolve::ExternalExports, last_private_map: resolve::LastPrivateMap, @@ -775,8 +774,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { fn visit_expr(&mut self, expr: &ast::Expr, _: ()) { match expr.node { ast::ExprField(base, ident, _) => { - match ty::get(ty::expr_ty_adjusted(self.tcx, base, - &*self.method_map.borrow())).sty { + match ty::get(ty::expr_ty_adjusted(self.tcx, base)).sty { ty::ty_struct(id, _) => { self.check_field(expr.span, id, NamedField(ident)); } @@ -785,7 +783,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { } ast::ExprMethodCall(ident, _, _) => { let method_call = MethodCall::expr(expr.id); - match self.method_map.borrow().find(&method_call) { + match self.tcx.method_map.borrow().find(&method_call) { None => { self.tcx.sess.span_bug(expr.span, "method call not in \ @@ -1404,7 +1402,6 @@ impl<'a> Visitor<()> for VisiblePrivateTypesVisitor<'a> { } pub fn check_crate(tcx: &ty::ctxt, - method_map: &MethodMap, exp_map2: &resolve::ExportMap2, external_exports: resolve::ExternalExports, last_private_map: resolve::LastPrivateMap, @@ -1423,7 +1420,6 @@ pub fn check_crate(tcx: &ty::ctxt, in_foreign: false, tcx: tcx, parents: visitor.parents, - method_map: method_map, external_exports: external_exports, last_private_map: last_private_map, }; diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 839f1d6039c8..6e2edb4e8b2a 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -84,9 +84,6 @@ fn method_might_be_inlined(tcx: &ty::ctxt, method: &ast::Method, struct ReachableContext<'a> { // The type context. tcx: &'a ty::ctxt, - // The method map, which links node IDs of method call expressions to the - // methods they've been resolved to. - method_map: typeck::MethodMap, // The set of items which must be exported in the linkage sense. reachable_symbols: NodeSet, // A worklist of item IDs. Each item ID in this worklist will be inlined @@ -133,7 +130,7 @@ impl<'a> Visitor<()> for ReachableContext<'a> { } ast::ExprMethodCall(..) => { let method_call = typeck::MethodCall::expr(expr.id); - match self.method_map.borrow().get(&method_call).origin { + match self.tcx.method_map.borrow().get(&method_call).origin { typeck::MethodStatic(def_id) => { if is_local(def_id) { if self.def_id_represents_local_inlined_item(def_id) { @@ -159,10 +156,9 @@ impl<'a> Visitor<()> for ReachableContext<'a> { impl<'a> ReachableContext<'a> { // Creates a new reachability computation context. - fn new(tcx: &'a ty::ctxt, method_map: typeck::MethodMap) -> ReachableContext<'a> { + fn new(tcx: &'a ty::ctxt) -> ReachableContext<'a> { ReachableContext { tcx: tcx, - method_map: method_map, reachable_symbols: NodeSet::new(), worklist: Vec::new(), } @@ -339,10 +335,9 @@ impl<'a> ReachableContext<'a> { } pub fn find_reachable(tcx: &ty::ctxt, - method_map: typeck::MethodMap, exported_items: &privacy::ExportedItems) -> NodeSet { - let mut reachable_context = ReachableContext::new(tcx, method_map); + let mut reachable_context = ReachableContext::new(tcx); // Step 1: Seed the worklist with all nodes which were found to be public as // a result of the privacy pass along with all local lang items. If diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 7002d09beca6..7c0f81b16d1e 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -391,7 +391,7 @@ pub fn trans_fn_ref_with_vtables( let ref_ty = match node { ExprId(id) => node_id_type(bcx, id), MethodCall(method_call) => { - let t = bcx.ccx().maps.method_map.borrow().get(&method_call).ty; + let t = bcx.tcx().method_map.borrow().get(&method_call).ty; monomorphize_type(bcx, t) } }; @@ -474,7 +474,7 @@ pub fn trans_method_call<'a>( let _icx = push_ctxt("trans_method_call"); debug!("trans_method_call(call_ex={})", call_ex.repr(bcx.tcx())); let method_call = MethodCall::expr(call_ex.id); - let method_ty = bcx.ccx().maps.method_map.borrow().get(&method_call).ty; + let method_ty = bcx.tcx().method_map.borrow().get(&method_call).ty; trans_call_inner( bcx, Some(common::expr_info(call_ex)), diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 72e716d0c3ca..66e0a35d6383 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -754,9 +754,7 @@ pub fn expr_ty(bcx: &Block, ex: &ast::Expr) -> ty::t { } pub fn expr_ty_adjusted(bcx: &Block, ex: &ast::Expr) -> ty::t { - let tcx = bcx.tcx(); - let t = ty::expr_ty_adjusted(tcx, ex, &*bcx.ccx().maps.method_map.borrow()); - monomorphize_type(bcx, t) + monomorphize_type(bcx, ty::expr_ty_adjusted(bcx.tcx(), ex)) } // Key used to lookup values supplied for type parameters in an expr. @@ -774,7 +772,7 @@ pub fn node_id_type_params(bcx: &Block, node: ExprOrMethodCall) -> Vec { let params = match node { ExprId(id) => ty::node_id_to_type_params(tcx, id), MethodCall(method_call) => { - bcx.ccx().maps.method_map.borrow().get(&method_call).substs.tps.clone() + tcx.method_map.borrow().get(&method_call).substs.tps.clone() } }; @@ -799,7 +797,7 @@ pub fn node_id_type_params(bcx: &Block, node: ExprOrMethodCall) -> Vec { pub fn node_vtables(bcx: &Block, id: typeck::MethodCall) -> Option { - let vtable_map = bcx.ccx().maps.vtable_map.borrow(); + let vtable_map = bcx.tcx().vtable_map.borrow(); let raw_vtables = vtable_map.find(&id); raw_vtables.map(|vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts)) } diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 8848feb88890..cc9029f52864 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -187,8 +187,7 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef let mut llconst = llconst; let mut inlineable = inlineable; let ety = ty::expr_ty(cx.tcx(), e); - let ety_adjusted = ty::expr_ty_adjusted(cx.tcx(), e, - &*cx.maps.method_map.borrow()); + let ety_adjusted = ty::expr_ty_adjusted(cx.tcx(), e); let opt_adj = cx.tcx.adjustments.borrow().find_copy(&e.id); match opt_adj { None => { } @@ -414,8 +413,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, }, true) } ast::ExprField(base, field, _) => { - let bt = ty::expr_ty_adjusted(cx.tcx(), base, - &*cx.maps.method_map.borrow()); + let bt = ty::expr_ty_adjusted(cx.tcx(), base); let brepr = adt::represent_type(cx, bt); let (bv, inlineable) = const_expr(cx, base, is_local); expr::with_field_tys(cx.tcx(), bt, None, |discr, field_tys| { @@ -425,8 +423,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr, } ast::ExprIndex(base, index) => { - let bt = ty::expr_ty_adjusted(cx.tcx(), base, - &*cx.maps.method_map.borrow()); + let bt = ty::expr_ty_adjusted(cx.tcx(), base); let (bv, inlineable) = const_expr(cx, base, is_local); let iv = match const_eval::eval_const_expr(cx.tcx(), index) { const_eval::const_int(i) => i as u64, diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 4e850b8990a1..27b459735721 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -118,7 +118,7 @@ pub fn trans_into<'a>(bcx: &'a Block<'a>, bcx.fcx.push_ast_cleanup_scope(expr.id); - let kind = ty::expr_kind(bcx.tcx(), bcx.ccx().maps.method_map, expr); + let kind = ty::expr_kind(bcx.tcx(), expr); bcx = match kind { ty::LvalueExpr | ty::RvalueDatumExpr => { trans_unadjusted(bcx, expr).store_to_dest(dest, expr.id) @@ -205,8 +205,7 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, }; } AutoObject(..) => { - let adjusted_ty = ty::expr_ty_adjusted(bcx.tcx(), expr, - &*bcx.ccx().maps.method_map.borrow()); + let adjusted_ty = ty::expr_ty_adjusted(bcx.tcx(), expr); let scratch = rvalue_scratch_datum(bcx, adjusted_ty, "__adjust"); bcx = meth::trans_trait_cast( bcx, datum, expr.id, SaveIn(scratch.val)); @@ -323,7 +322,7 @@ fn trans_unadjusted<'a>(bcx: &'a Block<'a>, debuginfo::set_source_location(bcx.fcx, expr.id, expr.span); - return match ty::expr_kind(bcx.tcx(), bcx.ccx().maps.method_map, expr) { + return match ty::expr_kind(bcx.tcx(), expr) { ty::LvalueExpr | ty::RvalueDatumExpr => { let datum = unpack_datum!(bcx, { trans_datum_unadjusted(bcx, expr) @@ -1118,7 +1117,7 @@ fn trans_unary<'a>(bcx: &'a Block<'a>, // Otherwise, we should be in the RvalueDpsExpr path. assert!( op == ast::UnDeref || - !ccx.maps.method_map.borrow().contains_key(&method_call)); + !ccx.tcx.method_map.borrow().contains_key(&method_call)); let un_ty = expr_ty(bcx, expr); @@ -1403,7 +1402,7 @@ fn trans_binary<'a>(bcx: &'a Block<'a>, let ccx = bcx.ccx(); // if overloaded, would be RvalueDpsExpr - assert!(!ccx.maps.method_map.borrow().contains_key(&MethodCall::expr(expr.id))); + assert!(!ccx.tcx.method_map.borrow().contains_key(&MethodCall::expr(expr.id))); match op { ast::BiAnd => { @@ -1443,7 +1442,7 @@ fn trans_overloaded_op<'a, 'b>( rhs: Option<(Datum, ast::NodeId)>, dest: Option) -> Result<'a> { - let method_ty = bcx.ccx().maps.method_map.borrow().get(&method_call).ty; + let method_ty = bcx.tcx().method_map.borrow().get(&method_call).ty; callee::trans_call_inner(bcx, Some(expr_info(expr)), monomorphize_type(bcx, method_ty), @@ -1614,7 +1613,7 @@ fn trans_assign_op<'a>( debug!("trans_assign_op(expr={})", bcx.expr_to_str(expr)); // User-defined operator methods cannot be used with `+=` etc right now - assert!(!bcx.ccx().maps.method_map.borrow().contains_key(&MethodCall::expr(expr.id))); + assert!(!bcx.tcx().method_map.borrow().contains_key(&MethodCall::expr(expr.id))); // Evaluate LHS (destination), which should be an lvalue let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, dst, "assign_op")); @@ -1692,7 +1691,7 @@ fn deref_once<'a>(bcx: &'a Block<'a>, expr_id: expr.id, autoderef: derefs as u32 }; - let method_ty = ccx.maps.method_map.borrow() + let method_ty = ccx.tcx.method_map.borrow() .find(&method_call).map(|method| method.ty); let datum = match method_ty { Some(method_ty) => { diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 851f8207cb68..6ac25cd1f136 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -83,7 +83,7 @@ pub fn trans_method_callee<'a>( -> Callee<'a> { let _icx = push_ctxt("meth::trans_method_callee"); - let (origin, method_ty) = match bcx.ccx().maps.method_map + let (origin, method_ty) = match bcx.tcx().method_map .borrow().find(&method_call) { Some(method) => { debug!("trans_method_callee({:?}, method={})", @@ -193,7 +193,7 @@ pub fn trans_static_method_callee(bcx: &Block, name={}", method_id, expr_id, token::get_name(mname)); let vtable_key = MethodCall::expr(expr_id); - let vtbls = ccx.maps.vtable_map.borrow().get_copy(&vtable_key); + let vtbls = ccx.tcx.vtable_map.borrow().get_copy(&vtable_key); let vtbls = resolve_vtables_in_fn_ctxt(bcx.fcx, vtbls); match vtbls.get(bound_index).get(0) { @@ -576,7 +576,7 @@ pub fn trans_trait_cast<'a>(bcx: &'a Block<'a>, bcx = datum.store_to(bcx, llboxdest); // Store the vtable into the second half of pair. - let res = *ccx.maps.vtable_map.borrow().get(&MethodCall::expr(id)); + let res = *ccx.tcx.vtable_map.borrow().get(&MethodCall::expr(id)); let origins = *resolve_vtables_in_fn_ctxt(bcx.fcx, res).get(0); let vtable = get_vtable(bcx, v_ty, origins); let llvtabledest = GEPi(bcx, lldest, [0u, abi::trt_field_vtable]); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 7745b0cc08fa..ff9ff64397aa 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -22,7 +22,7 @@ use middle::resolve_lifetime; use middle::ty; use middle::subst::Subst; use middle::typeck; -use middle::typeck::{MethodCall, MethodCallee, MethodMap}; +use middle::typeck::MethodCall; use middle::ty_fold; use middle::ty_fold::TypeFolder; use middle; @@ -359,6 +359,9 @@ pub struct ctxt { // and variants that are found. pub extern_const_statics: RefCell>>, pub extern_const_variants: RefCell>>, + + pub method_map: typeck::MethodMap, + pub vtable_map: typeck::vtable_map, } pub enum tbox_flag { @@ -1131,6 +1134,8 @@ pub fn mk_ctxt(s: Session, upvar_borrow_map: RefCell::new(HashMap::new()), extern_const_statics: RefCell::new(DefIdMap::new()), extern_const_variants: RefCell::new(DefIdMap::new()), + method_map: @RefCell::new(FnvHashMap::new()), + vtable_map: @RefCell::new(FnvHashMap::new()), } } @@ -2789,10 +2794,7 @@ pub fn expr_ty_opt(cx: &ctxt, expr: &ast::Expr) -> Option { return node_id_to_type_opt(cx, expr.id); } -pub fn expr_ty_adjusted(cx: &ctxt, - expr: &ast::Expr, - method_map: &FnvHashMap) - -> t { +pub fn expr_ty_adjusted(cx: &ctxt, expr: &ast::Expr) -> t { /*! * * Returns the type of `expr`, considering any `AutoAdjustment` @@ -2809,7 +2811,7 @@ pub fn expr_ty_adjusted(cx: &ctxt, let unadjusted_ty = expr_ty(cx, expr); let adjustment = cx.adjustments.borrow().find_copy(&expr.id); adjust_ty(cx, expr.span, expr.id, unadjusted_ty, adjustment, |method_call| { - method_map.find(&method_call).map(|method| method.ty) + cx.method_map.borrow().find(&method_call).map(|method| method.ty) }) } @@ -2856,7 +2858,7 @@ pub fn adjust_ty(cx: &ctxt, expr_id: ast::NodeId, unadjusted_ty: ty::t, adjustment: Option<@AutoAdjustment>, - method_type: |MethodCall| -> Option) + method_type: |typeck::MethodCall| -> Option) -> ty::t { /*! See `expr_ty_adjusted` */ @@ -2888,7 +2890,8 @@ pub fn adjust_ty(cx: &ctxt, if !ty::type_is_error(adjusted_ty) { for i in range(0, adj.autoderefs) { - match method_type(MethodCall::autoderef(expr_id, i as u32)) { + let method_call = typeck::MethodCall::autoderef(expr_id, i as u32); + match method_type(method_call) { Some(method_ty) => { adjusted_ty = ty_fn_ret(method_ty); } @@ -3066,10 +3069,8 @@ pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> ast::Def { } } -pub fn expr_is_lval(tcx: &ctxt, - method_map: MethodMap, - e: &ast::Expr) -> bool { - match expr_kind(tcx, method_map, e) { +pub fn expr_is_lval(tcx: &ctxt, e: &ast::Expr) -> bool { + match expr_kind(tcx, e) { LvalueExpr => true, RvalueDpsExpr | RvalueDatumExpr | RvalueStmtExpr => false } @@ -3087,10 +3088,8 @@ pub enum ExprKind { RvalueStmtExpr } -pub fn expr_kind(tcx: &ctxt, - method_map: MethodMap, - expr: &ast::Expr) -> ExprKind { - if method_map.borrow().contains_key(&MethodCall::expr(expr.id)) { +pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { + if tcx.method_map.borrow().contains_key(&typeck::MethodCall::expr(expr.id)) { // Overloaded operations are generally calls, and hence they are // generated via DPS, but there are two exceptions: return match expr.node { @@ -3234,7 +3233,7 @@ pub fn expr_kind(tcx: &ctxt, } } - ast::ExprParen(e) => expr_kind(tcx, method_map, e), + ast::ExprParen(e) => expr_kind(tcx, e), ast::ExprMac(..) => { tcx.sess.span_bug( diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index f80b8f2f9e85..476142a415f6 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2688,7 +2688,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, demand::suptype(fcx, expr.span, result_t, lhs_t); let tcx = fcx.tcx(); - if !ty::expr_is_lval(tcx, fcx.ccx.method_map, lhs) { + if !ty::expr_is_lval(tcx, lhs) { tcx.sess.span_err(lhs.span, "illegal left-hand side expression"); } @@ -2865,7 +2865,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, check_expr_with_lvalue_pref(fcx, lhs, PreferMutLvalue); let tcx = fcx.tcx(); - if !ty::expr_is_lval(tcx, fcx.ccx.method_map, lhs) { + if !ty::expr_is_lval(tcx, lhs) { tcx.sess.span_err(lhs.span, "illegal left-hand side expression"); } diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 6ad3d380b286..d7a22e91c5ea 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -93,7 +93,7 @@ fn resolve_method_map_entry(wbcx: &mut WbCtxt, sp: Span, method_call: MethodCall self_ty: None } }; - fcx.ccx.method_map.borrow_mut().insert(method_call, new_method); + tcx.method_map.borrow_mut().insert(method_call, new_method); } None => {} } @@ -104,7 +104,7 @@ fn resolve_vtable_map_entry(fcx: &FnCtxt, sp: Span, vtable_key: MethodCall) { match fcx.inh.vtable_map.borrow().find_copy(&vtable_key) { Some(origins) => { let r_origins = resolve_origins(fcx, sp, origins); - fcx.ccx.vtable_map.borrow_mut().insert(vtable_key, r_origins); + fcx.tcx().vtable_map.borrow_mut().insert(vtable_key, r_origins); debug!("writeback::resolve_vtable_map_entry(vtable_key={}, vtables={:?})", vtable_key, r_origins.repr(fcx.tcx())); } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index f78f0a8f2731..b5fdc492cb40 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -242,8 +242,6 @@ pub type impl_vtable_map = RefCell>; pub struct CrateCtxt<'a> { // A mapping from method call sites to traits that have that method. trait_map: resolve::TraitMap, - method_map: MethodMap, - vtable_map: vtable_map, tcx: &'a ty::ctxt } @@ -445,13 +443,10 @@ fn check_for_entry_fn(ccx: &CrateCtxt) { pub fn check_crate(tcx: &ty::ctxt, trait_map: resolve::TraitMap, - krate: &ast::Crate) - -> (MethodMap, vtable_map) { + krate: &ast::Crate) { let time_passes = tcx.sess.time_passes(); let ccx = CrateCtxt { trait_map: trait_map, - method_map: @RefCell::new(FnvHashMap::new()), - vtable_map: @RefCell::new(FnvHashMap::new()), tcx: tcx }; @@ -473,5 +468,4 @@ pub fn check_crate(tcx: &ty::ctxt, check_for_entry_fn(&ccx); tcx.sess.abort_if_errors(); - (ccx.method_map, ccx.vtable_map) }