Skip to content

Commit

Permalink
A few cleanups for hir
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Sep 12, 2018
1 parent fdcd4a4 commit 2919ecd
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 155 deletions.
4 changes: 2 additions & 2 deletions src/librustc/hir/check_attr.rs
Expand Up @@ -125,7 +125,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
.iter()
.filter(|attr| attr.name() == "repr")
.filter_map(|attr| attr.meta_item_list())
.flat_map(|hints| hints)
.flatten()
.collect();

let mut int_reprs = 0;
Expand Down Expand Up @@ -185,7 +185,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
continue
}
}
"i8" | "u8" | "i16" | "u16" |
"i8" | "u8" | "i16" | "u16" |
"i32" | "u32" | "i64" | "u64" |
"isize" | "usize" => {
int_reprs += 1;
Expand Down
23 changes: 8 additions & 15 deletions src/librustc/hir/intravisit.rs
Expand Up @@ -50,7 +50,6 @@ use super::itemlikevisit::DeepVisitor;

use std::cmp;
use std::u32;
use std::result::Result::Err;

#[derive(Copy, Clone)]
pub enum FnKind<'a> {
Expand Down Expand Up @@ -1067,31 +1066,26 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
ExprKind::Break(ref destination, ref opt_expr) => {
if let Some(ref label) = destination.label {
visitor.visit_label(label);
match destination.target_id {
Ok(node_id) => visitor.visit_def_mention(Def::Label(node_id)),
Err(_) => {},
};
if let Ok(node_id) = destination.target_id {
visitor.visit_def_mention(Def::Label(node_id))
}
}
walk_list!(visitor, visit_expr, opt_expr);
}
ExprKind::Continue(ref destination) => {
if let Some(ref label) = destination.label {
visitor.visit_label(label);
match destination.target_id {
Ok(node_id) => visitor.visit_def_mention(Def::Label(node_id)),
Err(_) => {},
};
if let Ok(node_id) = destination.target_id {
visitor.visit_def_mention(Def::Label(node_id))
}
}
}
ExprKind::Ret(ref optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression);
}
ExprKind::InlineAsm(_, ref outputs, ref inputs) => {
for output in outputs {
visitor.visit_expr(output)
}
for input in inputs {
visitor.visit_expr(input)
for expr in outputs.iter().chain(inputs.iter()) {
visitor.visit_expr(expr)
}
}
ExprKind::Yield(ref subexpression) => {
Expand Down Expand Up @@ -1156,7 +1150,6 @@ impl IdRange {
self.min = cmp::min(self.min, id);
self.max = cmp::max(self.max, NodeId::from_u32(id.as_u32() + 1));
}

}


Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/lowering.rs
Expand Up @@ -596,7 +596,7 @@ impl<'a> LoweringContext<'a> {
})
}

fn expect_full_def_from_use(&mut self, id: NodeId) -> impl Iterator<Item=Def> {
fn expect_full_def_from_use(&mut self, id: NodeId) -> impl Iterator<Item = Def> {
self.resolver.get_import(id).present_items().map(|pr| {
if pr.unresolved_segments() != 0 {
bug!("path not fully resolved: {:?}", pr);
Expand Down Expand Up @@ -989,7 +989,7 @@ impl<'a> LoweringContext<'a> {
None => {
self.loop_scopes
.last()
.map(|innermost_loop_id| *innermost_loop_id)
.cloned()
.map(|id| Ok(self.lower_node_id(id).node_id))
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope))
.into()
Expand Down
20 changes: 9 additions & 11 deletions src/librustc/hir/map/blocks.rs
Expand Up @@ -161,27 +161,27 @@ impl<'a> FnLikeNode<'a> {
}

pub fn body(self) -> ast::BodyId {
self.handle(|i: ItemFnParts<'a>| i.body,
|_, _, _: &'a ast::MethodSig, _, body: ast::BodyId, _, _| body,
self.handle(|i: ItemFnParts<'a>| i.body,
|_, _, _: &'a ast::MethodSig, _, body: ast::BodyId, _, _| body,
|c: ClosureParts<'a>| c.body)
}

pub fn decl(self) -> &'a FnDecl {
self.handle(|i: ItemFnParts<'a>| &*i.decl,
|_, _, sig: &'a ast::MethodSig, _, _, _, _| &sig.decl,
self.handle(|i: ItemFnParts<'a>| &*i.decl,
|_, _, sig: &'a ast::MethodSig, _, _, _, _| &sig.decl,
|c: ClosureParts<'a>| c.decl)
}

pub fn span(self) -> Span {
self.handle(|i: ItemFnParts| i.span,
self.handle(|i: ItemFnParts| i.span,
|_, _, _: &'a ast::MethodSig, _, _, span, _| span,
|c: ClosureParts| c.span)
|c: ClosureParts| c.span)
}

pub fn id(self) -> NodeId {
self.handle(|i: ItemFnParts| i.id,
self.handle(|i: ItemFnParts| i.id,
|id, _, _: &'a ast::MethodSig, _, _, _, _| id,
|c: ClosureParts| c.id)
|c: ClosureParts| c.id)
}

pub fn constness(self) -> ast::Constness {
Expand Down Expand Up @@ -260,9 +260,7 @@ impl<'a> FnLikeNode<'a> {
ast::ImplItemKind::Method(ref sig, body) => {
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
}
_ => {
bug!("impl method FnLikeNode that is not fn-like")
}
_ => bug!("impl method FnLikeNode that is not fn-like")
}
},
map::Node::Expr(e) => match e.node {
Expand Down
28 changes: 10 additions & 18 deletions src/librustc/hir/map/collector.rs
Expand Up @@ -67,7 +67,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
// them explicitly here.
ref attrs,
span,

// These fields are handled separately:
exported_macros: _,
items: _,
Expand Down Expand Up @@ -128,30 +127,27 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
cstore: &dyn CrateStore,
source_map: &SourceMap,
commandline_args_hash: u64)
-> (Vec<Option<Entry<'hir>>>, Svh) {
self.hir_body_nodes
.sort_unstable_by(|&(ref d1, _), &(ref d2, _)| d1.cmp(d2));
-> (Vec<Option<Entry<'hir>>>, Svh)
{
self.hir_body_nodes.sort_unstable_by_key(|bn| bn.0);

let node_hashes = self
.hir_body_nodes
.iter()
.fold(Fingerprint::ZERO, |fingerprint , &(def_path_hash, dep_node_index)| {
.fold(Fingerprint::ZERO, |fingerprint, &(def_path_hash, dep_node_index)| {
fingerprint.combine(
def_path_hash.0.combine(self.dep_graph.fingerprint_of(dep_node_index))
)
});

let mut upstream_crates: Vec<_> = cstore.crates_untracked().iter().map(|&cnum| {
let name = cstore.crate_name_untracked(cnum).as_str();
let disambiguator = cstore.crate_disambiguator_untracked(cnum)
.to_fingerprint();
let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint();
let hash = cstore.crate_hash_untracked(cnum);
(name, disambiguator, hash)
}).collect();

upstream_crates.sort_unstable_by(|&(name1, dis1, _), &(name2, dis2, _)| {
(name1, dis1).cmp(&(name2, dis2))
});
upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name, dis));

// We hash the final, remapped names of all local source files so we
// don't have to include the path prefix remapping commandline args.
Expand Down Expand Up @@ -229,7 +225,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
}

self.insert_entry(id, entry);

}

fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_id: NodeId, f: F) {
Expand Down Expand Up @@ -311,14 +306,11 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
this.insert(i.id, Node::Item(i));
this.with_parent(i.id, |this| {
match i.node {
ItemKind::Struct(ref struct_def, _) => {
// If this is a tuple-like struct, register the constructor.
if !struct_def.is_struct() {
this.insert(struct_def.id(), Node::StructCtor(struct_def));
}
if let ItemKind::Struct(ref struct_def, _) = i.node {
// If this is a tuple-like struct, register the constructor.
if !struct_def.is_struct() {
this.insert(struct_def.id(), Node::StructCtor(struct_def));
}
_ => {}
}
intravisit::walk_item(this, i);
});
Expand Down
9 changes: 3 additions & 6 deletions src/librustc/hir/map/def_collector.rs
Expand Up @@ -331,13 +331,10 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {

fn visit_token(&mut self, t: Token) {
if let Token::Interpolated(nt) = t {
match nt.0 {
token::NtExpr(ref expr) => {
if let ExprKind::Mac(..) = expr.node {
self.visit_macro_invoc(expr.id);
}
if let token::NtExpr(ref expr) = nt.0 {
if let ExprKind::Mac(..) = expr.node {
self.visit_macro_invoc(expr.id);
}
_ => {}
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/librustc/hir/map/definitions.rs
Expand Up @@ -317,10 +317,8 @@ pub enum DefPathData {
// they are treated specially by the `def_path` function.
/// The crate root (marker)
CrateRoot,

// Catch-all for random DefId things like DUMMY_NODE_ID
Misc,

// Different kinds of items and item-like things:
/// An impl
Impl,
Expand All @@ -342,7 +340,6 @@ pub enum DefPathData {
MacroDef(InternedString),
/// A closure expression
ClosureExpr,

// Subportions of items
/// A type parameter (generic parameter)
TypeParam(InternedString),
Expand All @@ -358,7 +355,6 @@ pub enum DefPathData {
AnonConst,
/// An `impl Trait` type node
ImplTrait,

/// GlobalMetaData identifies a piece of crate metadata that is global to
/// a whole crate (as opposed to just one item). GlobalMetaData components
/// are only supposed to show up right below the crate root.
Expand Down Expand Up @@ -656,10 +652,8 @@ impl DefPathData {
GlobalMetaData(name) => {
return name
}

// note that this does not show up in user printouts
CrateRoot => "{{root}}",

Impl => "{{impl}}",
Misc => "{{?}}",
ClosureExpr => "{{closure}}",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/hir_id_validator.rs
Expand Up @@ -100,8 +100,8 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {

if max != self.hir_ids_seen.len() - 1 {
// Collect the missing ItemLocalIds
let missing: Vec<_> = (0 .. max + 1)
.filter(|&i| !self.hir_ids_seen.contains_key(&ItemLocalId(i as u32)))
let missing: Vec<_> = (0 .. max as u32 + 1)
.filter(|&i| !self.hir_ids_seen.contains_key(&ItemLocalId(i)))
.collect();

// Try to map those to something more useful
Expand Down

0 comments on commit 2919ecd

Please sign in to comment.