incr.comp.: Update overflow-check logic in HIR hashing.

This commit is contained in:
Michael Woerister 2017-10-26 16:21:37 +02:00
parent eea916068c
commit 10ffff8bc6
5 changed files with 110 additions and 49 deletions

View File

@ -206,9 +206,10 @@ impl<'gcx> StableHashingContext<'gcx> {
pub fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, pub fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self,
item_attrs: &[ast::Attribute], item_attrs: &[ast::Attribute],
is_const: bool,
f: F) { f: F) {
let prev_overflow_checks = self.overflow_checks_enabled; let prev_overflow_checks = self.overflow_checks_enabled;
if attr::contains_name(item_attrs, "rustc_inherit_overflow_checks") { if is_const || attr::contains_name(item_attrs, "rustc_inherit_overflow_checks") {
self.overflow_checks_enabled = true; self.overflow_checks_enabled = true;
} }
let prev_hash_node_ids = self.node_id_hashing_mode; let prev_hash_node_ids = self.node_id_hashing_mode;

View File

@ -713,7 +713,15 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::TraitItem {
span span
} = *self; } = *self;
hcx.hash_hir_item_like(attrs, |hcx| { let is_const = match *node {
hir::TraitItemKind::Const(..) |
hir::TraitItemKind::Type(..) => true,
hir::TraitItemKind::Method(hir::MethodSig { constness, .. }, _) => {
constness == hir::Constness::Const
}
};
hcx.hash_hir_item_like(attrs, is_const, |hcx| {
name.hash_stable(hcx, hasher); name.hash_stable(hcx, hasher);
attrs.hash_stable(hcx, hasher); attrs.hash_stable(hcx, hasher);
generics.hash_stable(hcx, hasher); generics.hash_stable(hcx, hasher);
@ -750,7 +758,15 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::ImplItem {
span span
} = *self; } = *self;
hcx.hash_hir_item_like(attrs, |hcx| { let is_const = match *node {
hir::ImplItemKind::Const(..) |
hir::ImplItemKind::Type(..) => true,
hir::ImplItemKind::Method(hir::MethodSig { constness, .. }, _) => {
constness == hir::Constness::Const
}
};
hcx.hash_hir_item_like(attrs, is_const, |hcx| {
name.hash_stable(hcx, hasher); name.hash_stable(hcx, hasher);
vis.hash_stable(hcx, hasher); vis.hash_stable(hcx, hasher);
defaultness.hash_stable(hcx, hasher); defaultness.hash_stable(hcx, hasher);
@ -869,11 +885,13 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::Item {
fn hash_stable<W: StableHasherResult>(&self, fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'gcx>, hcx: &mut StableHashingContext<'gcx>,
hasher: &mut StableHasher<W>) { hasher: &mut StableHasher<W>) {
let hash_spans = match self.node { let (is_const, hash_spans) = match self.node {
hir::ItemStatic(..) | hir::ItemStatic(..) |
hir::ItemConst(..) | hir::ItemConst(..) => {
hir::ItemFn(..) => { (true, hcx.hash_spans())
hcx.hash_spans() }
hir::ItemFn(_, _, constness, ..) => {
(constness == hir::Constness::Const, hcx.hash_spans())
} }
hir::ItemUse(..) | hir::ItemUse(..) |
hir::ItemExternCrate(..) | hir::ItemExternCrate(..) |
@ -887,7 +905,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::Item {
hir::ItemEnum(..) | hir::ItemEnum(..) |
hir::ItemStruct(..) | hir::ItemStruct(..) |
hir::ItemUnion(..) => { hir::ItemUnion(..) => {
false (false, false)
} }
}; };
@ -901,7 +919,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::Item {
span span
} = *self; } = *self;
hcx.hash_hir_item_like(attrs, |hcx| { hcx.hash_hir_item_like(attrs, is_const, |hcx| {
hcx.while_hashing_spans(hash_spans, |hcx| { hcx.while_hashing_spans(hash_spans, |hcx| {
name.hash_stable(hcx, hasher); name.hash_stable(hcx, hasher);
attrs.hash_stable(hcx, hasher); attrs.hash_stable(hcx, hasher);

View File

@ -62,48 +62,54 @@ const CONST_CHANGE_TYPE_2: Option<u64> = None;
// Change value between simple literals --------------------------------------- // Change value between simple literals ---------------------------------------
#[cfg(cfail1)]
const CONST_CHANGE_VALUE_1: i16 = 1;
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
#[rustc_metadata_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail3")]
const CONST_CHANGE_VALUE_1: i16 = 2; const CONST_CHANGE_VALUE_1: i16 = {
#[cfg(cfail1)]
{ 1 }
#[cfg(not(cfail1))]
{ 2 }
};
// Change value between expressions ------------------------------------------- // Change value between expressions -------------------------------------------
#[cfg(cfail1)]
const CONST_CHANGE_VALUE_2: i16 = 1 + 1;
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
#[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail3")]
const CONST_CHANGE_VALUE_2: i16 = 1 + 2; const CONST_CHANGE_VALUE_2: i16 = {
#[cfg(cfail1)]
{ 1 + 1 }
#[cfg(not(cfail1))]
{ 1 + 2 }
};
#[cfg(cfail1)]
const CONST_CHANGE_VALUE_3: i16 = 2 + 3;
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
#[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail3")]
const CONST_CHANGE_VALUE_3: i16 = 2 * 3; const CONST_CHANGE_VALUE_3: i16 = {
#[cfg(cfail1)]
{ 2 + 3 }
#[cfg(not(cfail1))]
{ 2 * 3 }
};
#[cfg(cfail1)]
const CONST_CHANGE_VALUE_4: i16 = 1 + 2 * 3;
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
#[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_dirty(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail3")]
const CONST_CHANGE_VALUE_4: i16 = 1 + 2 * 4; const CONST_CHANGE_VALUE_4: i16 = {
#[cfg(cfail1)]
{ 1 + 2 * 3 }
#[cfg(not(cfail1))]
{ 1 + 2 * 4 }
};
// Change type indirectly ----------------------------------------------------- // Change type indirectly -----------------------------------------------------

View File

@ -115,49 +115,55 @@ static STATIC_CHANGE_TYPE_2: Option<u16> = None;
// Change value between simple literals --------------------------------------- // Change value between simple literals ---------------------------------------
#[cfg(cfail1)]
static STATIC_CHANGE_VALUE_1: i16 = 1;
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
#[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail3")]
static STATIC_CHANGE_VALUE_1: i16 = 2; static STATIC_CHANGE_VALUE_1: i16 = {
#[cfg(cfail1)]
{ 1 }
#[cfg(not(cfail1))]
{ 2 }
};
// Change value between expressions ------------------------------------------- // Change value between expressions -------------------------------------------
#[cfg(cfail1)]
static STATIC_CHANGE_VALUE_2: i16 = 1 + 1;
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
#[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail3")]
static STATIC_CHANGE_VALUE_2: i16 = 1 + 2; static STATIC_CHANGE_VALUE_2: i16 = {
#[cfg(cfail1)]
{ 1 + 1 }
#[cfg(not(cfail1))]
{ 1 + 2 }
};
#[cfg(cfail1)]
static STATIC_CHANGE_VALUE_3: i16 = 2 + 3;
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
#[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail3")]
static STATIC_CHANGE_VALUE_3: i16 = 2 * 3; static STATIC_CHANGE_VALUE_3: i16 = {
#[cfg(cfail1)]
{ 2 + 3 }
#[cfg(not(cfail1))]
{ 2 * 3 }
};
#[cfg(cfail1)]
static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 3;
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
#[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail2")]
#[rustc_metadata_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail3")]
static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 4; static STATIC_CHANGE_VALUE_4: i16 = {
#[cfg(cfail1)]
{ 1 + 2 * 3 }
#[cfg(not(cfail1))]
{ 1 + 2 * 4 }
};
// Change type indirectly ----------------------------------------------------- // Change type indirectly -----------------------------------------------------

View File

@ -0,0 +1,30 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This test makes sure that just changing a definition's location in the
// source file also changes its incr. comp. hash, if debuginfo is enabled.
// revisions:rpass1 rpass2
// compile-flags: -C overflow-checks=on
#![feature(rustc_attrs)]
#[cfg(rpass1)]
pub fn main() {
let _ = 0u8 + 1;
}
#[cfg(rpass2)]
#[rustc_clean(label="Hir", cfg="rpass2")]
#[rustc_dirty(label="HirBody", cfg="rpass2")]
pub fn main() {
let _ = 0u8 + 1;
}