Skip to content

Commit 552ab37

Browse files
committed
rustc: replace method_map with Def::Method and node_substs entries.
1 parent 9eae6ba commit 552ab37

File tree

20 files changed

+120
-119
lines changed

20 files changed

+120
-119
lines changed

src/librustc/cfg/construct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
355355
}
356356

357357
hir::ExprIndex(ref l, ref r) |
358-
hir::ExprBinary(_, ref l, ref r) if self.tables.is_method_call(expr.id) => {
358+
hir::ExprBinary(_, ref l, ref r) if self.tables.is_method_call(expr) => {
359359
self.call(expr, pred, &l, Some(&**r).into_iter())
360360
}
361361

362-
hir::ExprUnary(_, ref e) if self.tables.is_method_call(expr.id) => {
362+
hir::ExprUnary(_, ref e) if self.tables.is_method_call(expr) => {
363363
self.call(expr, pred, &e, None::<hir::Expr>.iter())
364364
}
365365

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,10 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
598598
hcx: &mut StableHashingContext<'a, 'tcx>,
599599
hasher: &mut StableHasher<W>) {
600600
let ty::TypeckTables {
601-
ref type_relative_path_defs,
601+
ref type_dependent_defs,
602602
ref node_types,
603603
ref node_substs,
604604
ref adjustments,
605-
ref method_map,
606605
ref upvar_capture_map,
607606
ref closure_tys,
608607
ref closure_kinds,
@@ -619,11 +618,10 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
619618
} = *self;
620619

621620
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
622-
ich::hash_stable_nodemap(hcx, hasher, type_relative_path_defs);
621+
ich::hash_stable_nodemap(hcx, hasher, type_dependent_defs);
623622
ich::hash_stable_nodemap(hcx, hasher, node_types);
624623
ich::hash_stable_nodemap(hcx, hasher, node_substs);
625624
ich::hash_stable_nodemap(hcx, hasher, adjustments);
626-
ich::hash_stable_nodemap(hcx, hasher, method_map);
627625
ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
628626
let ty::UpvarId {
629627
var_id,

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
9595
}
9696

9797
fn lookup_and_handle_method(&mut self, id: ast::NodeId) {
98-
self.check_def_id(self.tables.method_map[&id].def_id);
98+
self.check_def_id(self.tables.type_dependent_defs[&id].def_id());
9999
}
100100

101101
fn handle_field_access(&mut self, lhs: &hir::Expr, name: ast::Name) {

src/librustc/middle/effect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
173173
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
174174
match expr.node {
175175
hir::ExprMethodCall(..) => {
176-
let method = self.tables.method_map[&expr.id];
177-
let base_type = self.tcx.type_of(method.def_id);
176+
let def_id = self.tables.type_dependent_defs[&expr.id].def_id();
177+
let base_type = self.tcx.type_of(def_id);
178178
debug!("effect: method call case, base type is {:?}",
179179
base_type);
180180
if type_is_unsafe_function(base_type) {

src/librustc/middle/expr_use_visitor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
563563
}
564564
ty::TyError => { }
565565
_ => {
566-
let method = self.mc.infcx.tables.borrow().method_map[&call.id];
567-
match OverloadedCallType::from_method_id(self.tcx(), method.def_id) {
566+
let def_id = self.mc.infcx.tables.borrow().type_dependent_defs[&call.id].def_id();
567+
match OverloadedCallType::from_method_id(self.tcx(), def_id) {
568568
FnMutOverloadedCall => {
569569
let call_scope_r = self.tcx().node_scope_region(call.id);
570570
self.borrow_expr(callee,
@@ -849,7 +849,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
849849
pass_args: PassArgs)
850850
-> bool
851851
{
852-
if !self.mc.infcx.tables.borrow().is_method_call(expr.id) {
852+
if !self.mc.infcx.tables.borrow().is_method_call(expr) {
853853
return false;
854854
}
855855

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10451045

10461046
hir::ExprAssignOp(_, ref l, ref r) => {
10471047
// an overloaded assign op is like a method call
1048-
if self.tables.is_method_call(expr.id) {
1048+
if self.tables.is_method_call(expr) {
10491049
let succ = self.propagate_through_expr(&l, succ);
10501050
self.propagate_through_expr(&r, succ)
10511051
} else {
@@ -1366,7 +1366,7 @@ fn check_expr<'a, 'tcx>(this: &mut Liveness<'a, 'tcx>, expr: &'tcx Expr) {
13661366
}
13671367

13681368
hir::ExprAssignOp(_, ref l, _) => {
1369-
if !this.tables.is_method_call(expr.id) {
1369+
if !this.tables.is_method_call(expr) {
13701370
this.check_lvalue(&l);
13711371
}
13721372

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
515515
let expr_ty = self.expr_ty(expr)?;
516516
match expr.node {
517517
hir::ExprUnary(hir::UnDeref, ref e_base) => {
518-
if self.infcx.tables.borrow().is_method_call(expr.id) {
518+
if self.infcx.tables.borrow().is_method_call(expr) {
519519
self.cat_overloaded_lvalue(expr, e_base, false)
520520
} else {
521521
let base_cmt = self.cat_expr(&e_base)?;
@@ -538,7 +538,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
538538
}
539539

540540
hir::ExprIndex(ref base, _) => {
541-
if self.infcx.tables.borrow().is_method_call(expr.id()) {
541+
if self.infcx.tables.borrow().is_method_call(expr) {
542542
// If this is an index implemented by a method call, then it
543543
// will include an implicit deref of the result.
544544
// The call to index() returns a `&T` value, which

src/librustc/middle/reachable.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
110110
Some(self.tables.qpath_def(qpath, expr.id))
111111
}
112112
hir::ExprMethodCall(..) => {
113-
let def_id = self.tables.method_map[&expr.id].def_id;
114-
Some(Def::Method(def_id))
113+
Some(self.tables.type_dependent_defs[&expr.id])
115114
}
116115
_ => None
117116
};

src/librustc/ty/context.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ pub struct CommonTypes<'tcx> {
206206

207207
#[derive(RustcEncodable, RustcDecodable)]
208208
pub struct TypeckTables<'tcx> {
209-
/// Resolved definitions for `<T>::X` associated paths.
210-
pub type_relative_path_defs: NodeMap<Def>,
209+
/// Resolved definitions for `<T>::X` associated paths and
210+
/// method calls, including those of overloaded operators.
211+
pub type_dependent_defs: NodeMap<Def>,
211212

212213
/// Stores the types for various nodes in the AST. Note that this table
213214
/// is not guaranteed to be populated until after typeck. See
@@ -222,8 +223,6 @@ pub struct TypeckTables<'tcx> {
222223

223224
pub adjustments: NodeMap<ty::adjustment::Adjustment<'tcx>>,
224225

225-
pub method_map: NodeMap<ty::MethodCallee<'tcx>>,
226-
227226
/// Borrows
228227
pub upvar_capture_map: ty::UpvarCaptureMap<'tcx>,
229228

@@ -271,11 +270,10 @@ pub struct TypeckTables<'tcx> {
271270
impl<'tcx> TypeckTables<'tcx> {
272271
pub fn empty() -> TypeckTables<'tcx> {
273272
TypeckTables {
274-
type_relative_path_defs: NodeMap(),
273+
type_dependent_defs: NodeMap(),
275274
node_types: FxHashMap(),
276275
node_substs: NodeMap(),
277276
adjustments: NodeMap(),
278-
method_map: FxHashMap(),
279277
upvar_capture_map: FxHashMap(),
280278
closure_tys: NodeMap(),
281279
closure_kinds: NodeMap(),
@@ -294,7 +292,7 @@ impl<'tcx> TypeckTables<'tcx> {
294292
match *qpath {
295293
hir::QPath::Resolved(_, ref path) => path.def,
296294
hir::QPath::TypeRelative(..) => {
297-
self.type_relative_path_defs.get(&id).cloned().unwrap_or(Def::Err)
295+
self.type_dependent_defs.get(&id).cloned().unwrap_or(Def::Err)
298296
}
299297
}
300298
}
@@ -357,8 +355,17 @@ impl<'tcx> TypeckTables<'tcx> {
357355
.map(|adj| adj.target).or_else(|| self.expr_ty_opt(expr))
358356
}
359357

360-
pub fn is_method_call(&self, expr_id: NodeId) -> bool {
361-
self.method_map.contains_key(&expr_id)
358+
pub fn is_method_call(&self, expr: &hir::Expr) -> bool {
359+
// Only paths and method calls/overloaded operators have
360+
// entries in type_dependent_defs, ignore the former here.
361+
if let hir::ExprPath(_) = expr.node {
362+
return false;
363+
}
364+
365+
match self.type_dependent_defs.get(&expr.id) {
366+
Some(&Def::Method(_)) => true,
367+
_ => false
368+
}
362369
}
363370

364371
pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture<'tcx>> {

src/librustc/ty/sty.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ pub enum TypeVariants<'tcx> {
141141
TyFnDef(DefId, &'tcx Substs<'tcx>, PolyFnSig<'tcx>),
142142

143143
/// A pointer to a function. Written as `fn() -> i32`.
144-
/// FIXME: This is currently also used to represent the callee of a method;
145-
/// see ty::MethodCallee etc.
146144
TyFnPtr(PolyFnSig<'tcx>),
147145

148146
/// A trait, defined with `trait`.

0 commit comments

Comments
 (0)