Don't extend hir::Def when there's already a dedicated "function-like" detector
This commit is contained in:
parent
73e2b4662d
commit
b4ee38ede3
6 changed files with 18 additions and 23 deletions
|
|
@ -74,7 +74,6 @@ pub enum Def {
|
|||
SelfCtor(DefId /* impl */), // DefId refers to the impl
|
||||
Method(DefId),
|
||||
AssociatedConst(DefId),
|
||||
Closure(hir::BodyId),
|
||||
|
||||
Local(ast::NodeId),
|
||||
Upvar(ast::NodeId, // node id of closed over local
|
||||
|
|
@ -282,7 +281,6 @@ impl Def {
|
|||
id
|
||||
}
|
||||
|
||||
Def::Closure(_) |
|
||||
Def::Local(..) |
|
||||
Def::Upvar(..) |
|
||||
Def::Label(..) |
|
||||
|
|
@ -321,7 +319,6 @@ impl Def {
|
|||
Def::Trait(..) => "trait",
|
||||
Def::ForeignTy(..) => "foreign type",
|
||||
Def::Method(..) => "method",
|
||||
Def::Closure(_) => "closure",
|
||||
Def::Const(..) => "constant",
|
||||
Def::AssociatedConst(..) => "associated constant",
|
||||
Def::TyParam(..) => "type parameter",
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ pub struct FnLikeNode<'a> { node: Node<'a> }
|
|||
|
||||
/// MaybeFnLike wraps a method that indicates if an object
|
||||
/// corresponds to some FnLikeNode.
|
||||
pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; }
|
||||
trait MaybeFnLike { fn is_fn_like(&self) -> bool; }
|
||||
|
||||
impl MaybeFnLike for ast::Item {
|
||||
fn is_fn_like(&self) -> bool {
|
||||
|
|
|
|||
|
|
@ -340,14 +340,9 @@ impl<'hir> Map<'hir> {
|
|||
let def_id = self.local_def_id(variant.node.data.id());
|
||||
Some(Def::Variant(def_id))
|
||||
}
|
||||
Node::Expr(expr) => {
|
||||
match expr.node {
|
||||
ExprKind::Closure(_, _, body_id, _, _) => Some(Def::Closure(body_id)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
Node::Field(_) |
|
||||
Node::AnonConst(_) |
|
||||
Node::Expr(_) |
|
||||
Node::Stmt(_) |
|
||||
Node::Ty(_) |
|
||||
Node::TraitRef(_) |
|
||||
|
|
|
|||
|
|
@ -1044,7 +1044,6 @@ impl_stable_hash_for!(enum hir::def::Def {
|
|||
SelfCtor(impl_def_id),
|
||||
VariantCtor(def_id, ctor_kind),
|
||||
Method(def_id),
|
||||
Closure(body_id),
|
||||
AssociatedConst(def_id),
|
||||
Local(def_id),
|
||||
Upvar(def_id, index, expr_id),
|
||||
|
|
|
|||
|
|
@ -44,19 +44,24 @@ impl MirPass for ConstProp {
|
|||
if source.promoted.is_some() {
|
||||
return;
|
||||
}
|
||||
match tcx.describe_def(source.def_id) {
|
||||
// Only run const prop on functions, methods, closures and associated constants
|
||||
| Some(Def::Fn(_))
|
||||
| Some(Def::Method(_))
|
||||
| Some(Def::AssociatedConst(_))
|
||||
| Some(Def::Closure(_))
|
||||
=> {}
|
||||
|
||||
use rustc::hir::map::blocks::FnLikeNode;
|
||||
let node_id = tcx.hir.as_local_node_id(source.def_id)
|
||||
.expect("Non-local call to local provider is_const_fn");
|
||||
|
||||
let is_fn_like = FnLikeNode::from_node(tcx.hir.get(node_id)).is_some();
|
||||
let is_assoc_const = match tcx.describe_def(source.def_id) {
|
||||
Some(Def::AssociatedConst(_)) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
// Only run const prop on functions, methods, closures and associated constants
|
||||
if !is_fn_like && !is_assoc_const {
|
||||
// skip anon_const/statics/consts because they'll be evaluated by miri anyway
|
||||
def => {
|
||||
trace!("ConstProp skipped for {:?} ({:?})", source.def_id, def);
|
||||
return
|
||||
},
|
||||
trace!("ConstProp skipped for {:?}", source.def_id);
|
||||
return
|
||||
}
|
||||
|
||||
trace!("ConstProp starting for {:?}", source.def_id);
|
||||
|
||||
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
|
||||
|
|
|
|||
|
|
@ -827,7 +827,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
ref_id: id_from_def_id(def_id),
|
||||
})
|
||||
}
|
||||
HirDef::Closure(_) |
|
||||
HirDef::PrimTy(..) |
|
||||
HirDef::SelfTy(..) |
|
||||
HirDef::Label(..) |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue