Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rustc: replace method_map with Def::Method and node_substs entries.
  • Loading branch information
eddyb committed Jun 1, 2017
1 parent 9eae6ba commit 552ab37
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 119 deletions.
4 changes: 2 additions & 2 deletions src/librustc/cfg/construct.rs
Expand Up @@ -355,11 +355,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

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

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

Expand Down
6 changes: 2 additions & 4 deletions src/librustc/ich/impls_ty.rs
Expand Up @@ -598,11 +598,10 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
hcx: &mut StableHashingContext<'a, 'tcx>,
hasher: &mut StableHasher<W>) {
let ty::TypeckTables {
ref type_relative_path_defs,
ref type_dependent_defs,
ref node_types,
ref node_substs,
ref adjustments,
ref method_map,
ref upvar_capture_map,
ref closure_tys,
ref closure_kinds,
Expand All @@ -619,11 +618,10 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
} = *self;

hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
ich::hash_stable_nodemap(hcx, hasher, type_relative_path_defs);
ich::hash_stable_nodemap(hcx, hasher, type_dependent_defs);
ich::hash_stable_nodemap(hcx, hasher, node_types);
ich::hash_stable_nodemap(hcx, hasher, node_substs);
ich::hash_stable_nodemap(hcx, hasher, adjustments);
ich::hash_stable_nodemap(hcx, hasher, method_map);
ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
let ty::UpvarId {
var_id,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Expand Up @@ -95,7 +95,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}

fn lookup_and_handle_method(&mut self, id: ast::NodeId) {
self.check_def_id(self.tables.method_map[&id].def_id);
self.check_def_id(self.tables.type_dependent_defs[&id].def_id());
}

fn handle_field_access(&mut self, lhs: &hir::Expr, name: ast::Name) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/effect.rs
Expand Up @@ -173,8 +173,8 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
match expr.node {
hir::ExprMethodCall(..) => {
let method = self.tables.method_map[&expr.id];
let base_type = self.tcx.type_of(method.def_id);
let def_id = self.tables.type_dependent_defs[&expr.id].def_id();
let base_type = self.tcx.type_of(def_id);
debug!("effect: method call case, base type is {:?}",
base_type);
if type_is_unsafe_function(base_type) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -563,8 +563,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
}
ty::TyError => { }
_ => {
let method = self.mc.infcx.tables.borrow().method_map[&call.id];
match OverloadedCallType::from_method_id(self.tcx(), method.def_id) {
let def_id = self.mc.infcx.tables.borrow().type_dependent_defs[&call.id].def_id();
match OverloadedCallType::from_method_id(self.tcx(), def_id) {
FnMutOverloadedCall => {
let call_scope_r = self.tcx().node_scope_region(call.id);
self.borrow_expr(callee,
Expand Down Expand Up @@ -849,7 +849,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
pass_args: PassArgs)
-> bool
{
if !self.mc.infcx.tables.borrow().is_method_call(expr.id) {
if !self.mc.infcx.tables.borrow().is_method_call(expr) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/liveness.rs
Expand Up @@ -1045,7 +1045,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {

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

hir::ExprAssignOp(_, ref l, _) => {
if !this.tables.is_method_call(expr.id) {
if !this.tables.is_method_call(expr) {
this.check_lvalue(&l);
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -515,7 +515,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
let expr_ty = self.expr_ty(expr)?;
match expr.node {
hir::ExprUnary(hir::UnDeref, ref e_base) => {
if self.infcx.tables.borrow().is_method_call(expr.id) {
if self.infcx.tables.borrow().is_method_call(expr) {
self.cat_overloaded_lvalue(expr, e_base, false)
} else {
let base_cmt = self.cat_expr(&e_base)?;
Expand All @@ -538,7 +538,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
}

hir::ExprIndex(ref base, _) => {
if self.infcx.tables.borrow().is_method_call(expr.id()) {
if self.infcx.tables.borrow().is_method_call(expr) {
// If this is an index implemented by a method call, then it
// will include an implicit deref of the result.
// The call to index() returns a `&T` value, which
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/reachable.rs
Expand Up @@ -110,8 +110,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
Some(self.tables.qpath_def(qpath, expr.id))
}
hir::ExprMethodCall(..) => {
let def_id = self.tables.method_map[&expr.id].def_id;
Some(Def::Method(def_id))
Some(self.tables.type_dependent_defs[&expr.id])
}
_ => None
};
Expand Down
25 changes: 16 additions & 9 deletions src/librustc/ty/context.rs
Expand Up @@ -206,8 +206,9 @@ pub struct CommonTypes<'tcx> {

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

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

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

pub method_map: NodeMap<ty::MethodCallee<'tcx>>,

/// Borrows
pub upvar_capture_map: ty::UpvarCaptureMap<'tcx>,

Expand Down Expand Up @@ -271,11 +270,10 @@ pub struct TypeckTables<'tcx> {
impl<'tcx> TypeckTables<'tcx> {
pub fn empty() -> TypeckTables<'tcx> {
TypeckTables {
type_relative_path_defs: NodeMap(),
type_dependent_defs: NodeMap(),
node_types: FxHashMap(),
node_substs: NodeMap(),
adjustments: NodeMap(),
method_map: FxHashMap(),
upvar_capture_map: FxHashMap(),
closure_tys: NodeMap(),
closure_kinds: NodeMap(),
Expand All @@ -294,7 +292,7 @@ impl<'tcx> TypeckTables<'tcx> {
match *qpath {
hir::QPath::Resolved(_, ref path) => path.def,
hir::QPath::TypeRelative(..) => {
self.type_relative_path_defs.get(&id).cloned().unwrap_or(Def::Err)
self.type_dependent_defs.get(&id).cloned().unwrap_or(Def::Err)
}
}
}
Expand Down Expand Up @@ -357,8 +355,17 @@ impl<'tcx> TypeckTables<'tcx> {
.map(|adj| adj.target).or_else(|| self.expr_ty_opt(expr))
}

pub fn is_method_call(&self, expr_id: NodeId) -> bool {
self.method_map.contains_key(&expr_id)
pub fn is_method_call(&self, expr: &hir::Expr) -> bool {
// Only paths and method calls/overloaded operators have
// entries in type_dependent_defs, ignore the former here.
if let hir::ExprPath(_) = expr.node {
return false;
}

match self.type_dependent_defs.get(&expr.id) {
Some(&Def::Method(_)) => true,
_ => false
}
}

pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture<'tcx>> {
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/ty/sty.rs
Expand Up @@ -141,8 +141,6 @@ pub enum TypeVariants<'tcx> {
TyFnDef(DefId, &'tcx Substs<'tcx>, PolyFnSig<'tcx>),

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

/// A trait, defined with `trait`.
Expand Down
29 changes: 19 additions & 10 deletions src/librustc_lint/builtin.rs
Expand Up @@ -881,17 +881,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
-> bool {
use rustc::ty::adjustment::*;

// Check for method calls and overloaded operators.
if let Some(m) = cx.tables.method_map.get(&id).cloned() {
if method_call_refers_to_method(cx.tcx, method, m.def_id, m.substs, id) {
return true;
}
}
// Ignore non-expressions.
let expr = if let hir_map::NodeExpr(e) = cx.tcx.hir.get(id) {
e
} else {
return false;
};

// Check for overloaded autoderef method calls.
if let Some(Adjustment {
if let Some(&Adjustment {
kind: Adjust::DerefRef { ref autoderefs, .. }, ..
}) = cx.tables.adjustments.get(&id).cloned() {
}) = cx.tables.adjustments.get(&id) {
for &overloaded in autoderefs {
if let Some(m) = overloaded {
if method_call_refers_to_method(cx.tcx, method, m.def_id, m.substs, id) {
Expand All @@ -901,9 +901,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
}
}

// Check for method calls and overloaded operators.
if cx.tables.is_method_call(expr) {
let def_id = cx.tables.type_dependent_defs[&id].def_id();
let substs = cx.tables.node_substs(id);
if method_call_refers_to_method(cx.tcx, method, def_id, substs, id) {
return true;
}
}

// Check for calls to methods via explicit paths (e.g. `T::method()`).
match cx.tcx.hir.get(id) {
hir_map::NodeExpr(&hir::Expr { node: hir::ExprCall(ref callee, _), .. }) => {
match expr.node {
hir::ExprCall(ref callee, _) => {
let def = if let hir::ExprPath(ref qpath) = callee.node {
cx.tables.qpath_def(qpath, callee.id)
} else {
Expand Down

0 comments on commit 552ab37

Please sign in to comment.