Skip to content

Commit

Permalink
Auto merge of #38479 - michaelwoerister:extern_mod_ich, r=nikomatsakis
Browse files Browse the repository at this point in the history
ICH: Fix and test foreign mod hashing.

r? @nikomatsakis
  • Loading branch information
bors committed Dec 28, 2016
2 parents 314c28b + f0a630b commit a9ab778
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 14 deletions.
13 changes: 8 additions & 5 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ pub trait Visitor<'v> : Sized {
fn visit_where_predicate(&mut self, predicate: &'v WherePredicate) {
walk_where_predicate(self, predicate)
}
fn visit_fn_decl(&mut self, fd: &'v FnDecl) {
walk_fn_decl(self, fd)
}
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: ExprId, s: Span, id: NodeId) {
walk_fn(self, fk, fd, b, s, id)
}
Expand Down Expand Up @@ -531,7 +534,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
walk_list!(visitor, visit_ty, tuple_element_types);
}
TyBareFn(ref function_declaration) => {
walk_fn_decl(visitor, &function_declaration.decl);
visitor.visit_fn_decl(&function_declaration.decl);
walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes);
}
TyPath(ref qpath) => {
Expand Down Expand Up @@ -660,7 +663,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v

match foreign_item.node {
ForeignItemFn(ref function_declaration, ref generics) => {
walk_fn_decl(visitor, function_declaration);
visitor.visit_fn_decl(function_declaration);
visitor.visit_generics(generics)
}
ForeignItemStatic(ref typ, _) => visitor.visit_ty(typ),
Expand Down Expand Up @@ -764,7 +767,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
_span: Span,
id: NodeId) {
visitor.visit_id(id);
walk_fn_decl(visitor, function_declaration);
visitor.visit_fn_decl(function_declaration);
walk_fn_kind(visitor, function_kind);
visitor.visit_body(body_id)
}
Expand All @@ -776,7 +779,7 @@ pub fn walk_fn_with_body<'v, V: Visitor<'v>>(visitor: &mut V,
_span: Span,
id: NodeId) {
visitor.visit_id(id);
walk_fn_decl(visitor, function_declaration);
visitor.visit_fn_decl(function_declaration);
walk_fn_kind(visitor, function_kind);
visitor.visit_expr(body)
}
Expand All @@ -793,7 +796,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
MethodTraitItem(ref sig, None) => {
visitor.visit_id(trait_item.id);
visitor.visit_generics(&sig.generics);
walk_fn_decl(visitor, &sig.decl);
visitor.visit_fn_decl(&sig.decl);
}
MethodTraitItem(ref sig, Some(body_id)) => {
visitor.visit_fn(FnKind::Method(trait_item.name,
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_incremental/calculate_svh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,4 @@ impl<'a, 'tcx> Visitor<'tcx> for HashItemsVisitor<'a, 'tcx> {
self.calculate_node_id(impl_item.id, |v| v.visit_impl_item(impl_item));
visit::walk_impl_item(self, impl_item);
}

fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem) {
self.calculate_node_id(item.id, |v| v.visit_foreign_item(item));
visit::walk_foreign_item(self, item);
}
}
31 changes: 27 additions & 4 deletions src/librustc_incremental/calculate_svh/svh_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ enum SawAbiComponent<'a> {
SawLifetimeDef(usize),

SawMod,
SawForeignItem,
SawForeignItem(SawForeignItemComponent),
SawItem(SawItemComponent),
SawTy(SawTyComponent),
SawFnDecl(bool),
SawGenerics,
SawTraitItem(SawTraitOrImplItemComponent),
SawImplItem(SawTraitOrImplItemComponent),
Expand Down Expand Up @@ -363,7 +364,7 @@ enum SawItemComponent {
SawItemConst,
SawItemFn(Unsafety, Constness, Abi),
SawItemMod,
SawItemForeignMod,
SawItemForeignMod(Abi),
SawItemTy,
SawItemEnum,
SawItemStruct,
Expand All @@ -381,7 +382,7 @@ fn saw_item(node: &Item_) -> SawItemComponent {
ItemConst(..) =>SawItemConst,
ItemFn(_, unsafety, constness, abi, _, _) => SawItemFn(unsafety, constness, abi),
ItemMod(..) => SawItemMod,
ItemForeignMod(..) => SawItemForeignMod,
ItemForeignMod(ref fm) => SawItemForeignMod(fm.abi),
ItemTy(..) => SawItemTy,
ItemEnum(..) => SawItemEnum,
ItemStruct(..) => SawItemStruct,
Expand All @@ -392,6 +393,12 @@ fn saw_item(node: &Item_) -> SawItemComponent {
}
}

#[derive(Hash)]
enum SawForeignItemComponent {
Static { mutable: bool },
Fn,
}

#[derive(Hash)]
enum SawPatComponent {
SawPatWild,
Expand Down Expand Up @@ -641,7 +648,17 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
fn visit_foreign_item(&mut self, i: &'tcx ForeignItem) {
debug!("visit_foreign_item: st={:?}", self.st);

SawForeignItem.hash(self.st);
match i.node {
ForeignItemFn(..) => {
SawForeignItem(SawForeignItemComponent::Fn)
}
ForeignItemStatic(_, mutable) => {
SawForeignItem(SawForeignItemComponent::Static {
mutable: mutable
})
}
}.hash(self.st);

hash_span!(self, i.span);
hash_attrs!(self, &i.attrs);
visit::walk_foreign_item(self, i)
Expand Down Expand Up @@ -678,6 +695,12 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
visit::walk_generics(self, g)
}

fn visit_fn_decl(&mut self, fd: &'tcx FnDecl) {
debug!("visit_fn_decl: st={:?}", self.st);
SawFnDecl(fd.variadic).hash(self.st);
visit::walk_fn_decl(self, fd)
}

fn visit_trait_item(&mut self, ti: &'tcx TraitItem) {
debug!("visit_trait_item: st={:?}", self.st);

Expand Down
Loading

0 comments on commit a9ab778

Please sign in to comment.