Skip to content

Commit

Permalink
ICH - Include omitted elements in inc. comp. hash rust-lang#36914
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Borderé authored and Mathieu Borderé committed Oct 4, 2016
1 parent 0cfdb2a commit bc382e3
Showing 1 changed file with 146 additions and 16 deletions.
162 changes: 146 additions & 16 deletions src/librustc_incremental/calculate_svh/svh_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

use self::SawExprComponent::*;
use self::SawAbiComponent::*;
use self::SawItemComponent::*;
use self::SawPatComponent::*;
use self::SawTyComponent::*;
use self::SawTraitOrImplItemComponent::*;
use syntax::abi::Abi;
use syntax::ast::{self, Name, NodeId};
use syntax::parse::token;
use syntax_pos::{Span, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos};
Expand Down Expand Up @@ -154,19 +159,19 @@ enum SawAbiComponent<'a> {

SawMod,
SawForeignItem,
SawItem,
SawTy,
SawItem(SawItemComponent),
SawTy(SawTyComponent),
SawGenerics,
SawTraitItem,
SawImplItem,
SawTraitItem(SawTraitOrImplItemComponent),
SawImplItem(SawTraitOrImplItemComponent),
SawStructField,
SawVariant,
SawPath(bool),
SawPathSegment,
SawPathParameters,
SawPathListItem,
SawBlock,
SawPat,
SawPat(SawPatComponent),
SawLocal,
SawArm,
SawExpr(SawExprComponent<'a>),
Expand Down Expand Up @@ -197,6 +202,9 @@ enum SawAbiComponent<'a> {
/// because the SVH is just a developer convenience; there is no
/// guarantee of collision-freedom, hash collisions are just
/// (hopefully) unlikely.)
///
/// The xxxComponent enums and saw_xxx functions for Item, Pat,
/// Ty, TraitItem and ImplItem follow the same methodology.
#[derive(Hash)]
enum SawExprComponent<'a> {

Expand Down Expand Up @@ -266,6 +274,134 @@ fn saw_expr<'a>(node: &'a Expr_) -> SawExprComponent<'a> {
}
}

#[derive(Hash)]
enum SawItemComponent {
SawItemExternCrate,
SawItemUse,
SawItemStatic(Mutability),
SawItemConst,
SawItemFn(Unsafety, Constness, Abi),
SawItemMod,
SawItemForeignMod,
SawItemTy,
SawItemEnum,
SawItemStruct,
SawItemUnion,
SawItemTrait(Unsafety),
SawItemDefaultImpl(Unsafety),
SawItemImpl(Unsafety, ImplPolarity)
}

fn saw_item(node: &Item_) -> SawItemComponent {
match *node {
ItemExternCrate(..) => SawItemExternCrate,
ItemUse(..) => SawItemUse,
ItemStatic(_, mutability, _) => SawItemStatic(mutability),
ItemConst(..) =>SawItemConst,
ItemFn(_, unsafety, constness, abi, _, _) => SawItemFn(unsafety, constness, abi),
ItemMod(..) => SawItemMod,
ItemForeignMod(..) => SawItemForeignMod,
ItemTy(..) => SawItemTy,
ItemEnum(..) => SawItemEnum,
ItemStruct(..) => SawItemStruct,
ItemUnion(..) => SawItemUnion,
ItemTrait(unsafety, ..) => SawItemTrait(unsafety),
ItemDefaultImpl(unsafety, _) => SawItemDefaultImpl(unsafety),
ItemImpl(unsafety, implpolarity, ..) => SawItemImpl(unsafety, implpolarity)
}
}

#[derive(Hash)]
enum SawPatComponent {
SawPatWild,
SawPatBinding(BindingMode),
SawPatStruct,
SawPatTupleStruct,
SawPatPath,
SawPatTuple,
SawPatBox,
SawPatRef(Mutability),
SawPatLit,
SawPatRange,
SawPathVec
}

fn saw_pat(node: &PatKind) -> SawPatComponent {
match *node {
PatKind::Wild => SawPatWild,
PatKind::Binding(bindingmode, ..) => SawPatBinding(bindingmode),
PatKind::Struct(..) => SawPatStruct,
PatKind::TupleStruct(..) => SawPatTupleStruct,
PatKind::Path(..) => SawPatPath,
PatKind::Tuple(..) => SawPatTuple,
PatKind::Box(..) => SawPatBox,
PatKind::Ref(_, mutability) => SawPatRef(mutability),
PatKind::Lit(..) => SawPatLit,
PatKind::Range(..) => SawPatRange,
PatKind::Vec(..) => SawPathVec
}
}

#[derive(Hash)]
enum SawTyComponent {
SawTyVec,
SawTyFixedLengthVec,
SawTyPtr(Mutability),
SawTyRptr(Mutability),
SawTyBareFn,
SawTyNever,
SawTyTup,
SawTyPath,
SawTyObjectSum,
SawTyPolyTraitRef,
SawTyImplTrait,
SawTyTypeof,
SawTyInfer
}

fn saw_ty(node: &Ty_) -> SawTyComponent {
match *node {
TyVec(..) => SawTyVec,
TyFixedLengthVec(..) => SawTyFixedLengthVec,
TyPtr(ref mty) => SawTyPtr(mty.mutbl),
TyRptr(_, ref mty) => SawTyRptr(mty.mutbl),
TyBareFn(..) => SawTyBareFn,
TyNever => SawTyNever,
TyTup(..) => SawTyTup,
TyPath(..) => SawTyPath,
TyObjectSum(..) => SawTyObjectSum,
TyPolyTraitRef(..) => SawTyPolyTraitRef,
TyImplTrait(..) => SawTyImplTrait,
TyTypeof(..) => SawTyTypeof,
TyInfer => SawTyInfer
}
}

#[derive(Hash)]
enum SawTraitOrImplItemComponent {
SawTraitOrImplItemConst,
SawTraitOrImplItemMethod(Unsafety, Constness, Abi),
SawTraitOrImplItemType
}

fn saw_trait_item(ti: &TraitItem_) -> SawTraitOrImplItemComponent {
match *ti {
ConstTraitItem(..) => SawTraitOrImplItemConst,
MethodTraitItem(ref sig, _) =>
SawTraitOrImplItemMethod(sig.unsafety, sig.constness, sig.abi),
TypeTraitItem(..) => SawTraitOrImplItemType
}
}

fn saw_impl_item(ii: &ImplItemKind) -> SawTraitOrImplItemComponent {
match *ii {
ImplItemKind::Const(..) => SawTraitOrImplItemConst,
ImplItemKind::Method(ref sig, _) =>
SawTraitOrImplItemMethod(sig.unsafety, sig.constness, sig.abi),
ImplItemKind::Type(..) => SawTraitOrImplItemType
}
}

#[derive(Clone, Copy, Hash, Eq, PartialEq)]
enum SawSpanExpnKind {
NoExpansion,
Expand Down Expand Up @@ -382,10 +518,7 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has

fn visit_item(&mut self, i: &'tcx Item) {
debug!("visit_item: {:?} st={:?}", i, self.st);

SawItem.hash(self.st);
// Hash the value of the discriminant of the Item variant.
self.hash_discriminant(&i.node);
SawItem(saw_item(&i.node)).hash(self.st);
hash_span!(self, i.span);
hash_attrs!(self, &i.attrs);
visit::walk_item(self, i)
Expand All @@ -398,7 +531,7 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has

fn visit_ty(&mut self, t: &'tcx Ty) {
debug!("visit_ty: st={:?}", self.st);
SawTy.hash(self.st);
SawTy(saw_ty(&t.node)).hash(self.st);
hash_span!(self, t.span);
visit::walk_ty(self, t)
}
Expand All @@ -411,17 +544,15 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has

fn visit_trait_item(&mut self, ti: &'tcx TraitItem) {
debug!("visit_trait_item: st={:?}", self.st);
SawTraitItem.hash(self.st);
self.hash_discriminant(&ti.node);
SawTraitItem(saw_trait_item(&ti.node)).hash(self.st);
hash_span!(self, ti.span);
hash_attrs!(self, &ti.attrs);
visit::walk_trait_item(self, ti)
}

fn visit_impl_item(&mut self, ii: &'tcx ImplItem) {
debug!("visit_impl_item: st={:?}", self.st);
SawImplItem.hash(self.st);
self.hash_discriminant(&ii.node);
SawImplItem(saw_impl_item(&ii.node)).hash(self.st);
hash_span!(self, ii.span);
hash_attrs!(self, &ii.attrs);
visit::walk_impl_item(self, ii)
Expand Down Expand Up @@ -451,8 +582,7 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has

fn visit_pat(&mut self, p: &'tcx Pat) {
debug!("visit_pat: st={:?}", self.st);
SawPat.hash(self.st);
self.hash_discriminant(&p.node);
SawPat(saw_pat(&p.node)).hash(self.st);
hash_span!(self, p.span);
visit::walk_pat(self, p)
}
Expand Down

0 comments on commit bc382e3

Please sign in to comment.