From eea916068cc0d0d5d39fc4b02c2c4c88ae9a9138 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 26 Oct 2017 15:50:29 +0200 Subject: [PATCH 1/2] incr.comp.: Fix invalid DepNode assignment in HIR map. --- src/librustc/hir/map/collector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 816793cc1aaa0..2f4b62dcbf782 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -219,7 +219,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { f: F) { let prev_owner = self.current_dep_node_owner; let prev_signature_dep_index = self.current_signature_dep_index; - let prev_full_dep_index = self.current_signature_dep_index; + let prev_full_dep_index = self.current_full_dep_index; let prev_in_body = self.currently_in_body; let def_path_hash = self.definitions.def_path_hash(dep_node_owner); From 10ffff8bc6f073ffe1342ca3fef229cec0d98693 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 26 Oct 2017 16:21:37 +0200 Subject: [PATCH 2/2] incr.comp.: Update overflow-check logic in HIR hashing. --- src/librustc/ich/hcx.rs | 3 +- src/librustc/ich/impls_hir.rs | 34 ++++++++++---- src/test/incremental/hashes/consts.rs | 46 +++++++++++-------- src/test/incremental/hashes/statics.rs | 46 +++++++++++-------- .../incremental/spans_significant_w_panic.rs | 30 ++++++++++++ 5 files changed, 110 insertions(+), 49 deletions(-) create mode 100644 src/test/incremental/spans_significant_w_panic.rs diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index e7a26e14db5bb..f46540114f750 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -206,9 +206,10 @@ impl<'gcx> StableHashingContext<'gcx> { pub fn hash_hir_item_like(&mut self, item_attrs: &[ast::Attribute], + is_const: bool, f: F) { 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; } let prev_hash_node_ids = self.node_id_hashing_mode; diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 994f0bd16b1f8..ff12f7933888b 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -713,7 +713,15 @@ impl<'gcx> HashStable> for hir::TraitItem { span } = *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); attrs.hash_stable(hcx, hasher); generics.hash_stable(hcx, hasher); @@ -750,7 +758,15 @@ impl<'gcx> HashStable> for hir::ImplItem { span } = *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); vis.hash_stable(hcx, hasher); defaultness.hash_stable(hcx, hasher); @@ -869,11 +885,13 @@ impl<'gcx> HashStable> for hir::Item { fn hash_stable(&self, hcx: &mut StableHashingContext<'gcx>, hasher: &mut StableHasher) { - let hash_spans = match self.node { + let (is_const, hash_spans) = match self.node { hir::ItemStatic(..) | - hir::ItemConst(..) | - hir::ItemFn(..) => { - hcx.hash_spans() + hir::ItemConst(..) => { + (true, hcx.hash_spans()) + } + hir::ItemFn(_, _, constness, ..) => { + (constness == hir::Constness::Const, hcx.hash_spans()) } hir::ItemUse(..) | hir::ItemExternCrate(..) | @@ -887,7 +905,7 @@ impl<'gcx> HashStable> for hir::Item { hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) => { - false + (false, false) } }; @@ -901,7 +919,7 @@ impl<'gcx> HashStable> for hir::Item { span } = *self; - hcx.hash_hir_item_like(attrs, |hcx| { + hcx.hash_hir_item_like(attrs, is_const, |hcx| { hcx.while_hashing_spans(hash_spans, |hcx| { name.hash_stable(hcx, hasher); attrs.hash_stable(hcx, hasher); diff --git a/src/test/incremental/hashes/consts.rs b/src/test/incremental/hashes/consts.rs index 35641e978b7fd..65acfb82da66f 100644 --- a/src/test/incremental/hashes/consts.rs +++ b/src/test/incremental/hashes/consts.rs @@ -62,48 +62,54 @@ const CONST_CHANGE_TYPE_2: Option = None; // 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="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 ------------------------------------------- -#[cfg(cfail1)] -const CONST_CHANGE_VALUE_2: i16 = 1 + 1; -#[cfg(not(cfail1))] +// Change value between expressions ------------------------------------------- #[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] -const CONST_CHANGE_VALUE_2: i16 = 1 + 2; - +const CONST_CHANGE_VALUE_2: i16 = { + #[cfg(cfail1)] + { 1 + 1 } -#[cfg(cfail1)] -const CONST_CHANGE_VALUE_3: i16 = 2 + 3; + #[cfg(not(cfail1))] + { 1 + 2 } +}; -#[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] -const CONST_CHANGE_VALUE_3: i16 = 2 * 3; - +const CONST_CHANGE_VALUE_3: i16 = { + #[cfg(cfail1)] + { 2 + 3 } -#[cfg(cfail1)] -const CONST_CHANGE_VALUE_4: i16 = 1 + 2 * 3; + #[cfg(not(cfail1))] + { 2 * 3 } +}; -#[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[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 ----------------------------------------------------- diff --git a/src/test/incremental/hashes/statics.rs b/src/test/incremental/hashes/statics.rs index 4ff80ead89d45..7a4123190dde3 100644 --- a/src/test/incremental/hashes/statics.rs +++ b/src/test/incremental/hashes/statics.rs @@ -115,49 +115,55 @@ static STATIC_CHANGE_TYPE_2: Option = None; // 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="cfail3")] #[rustc_metadata_clean(cfg="cfail2")] #[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 ------------------------------------------- -#[cfg(cfail1)] -static STATIC_CHANGE_VALUE_2: i16 = 1 + 1; -#[cfg(not(cfail1))] +// Change value between expressions ------------------------------------------- #[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] -static STATIC_CHANGE_VALUE_2: i16 = 1 + 2; - +static STATIC_CHANGE_VALUE_2: i16 = { + #[cfg(cfail1)] + { 1 + 1 } -#[cfg(cfail1)] -static STATIC_CHANGE_VALUE_3: i16 = 2 + 3; + #[cfg(not(cfail1))] + { 1 + 2 } +}; -#[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] -static STATIC_CHANGE_VALUE_3: i16 = 2 * 3; - +static STATIC_CHANGE_VALUE_3: i16 = { + #[cfg(cfail1)] + { 2 + 3 } -#[cfg(cfail1)] -static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 3; + #[cfg(not(cfail1))] + { 2 * 3 } +}; -#[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", except="HirBody")] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail2")] #[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 ----------------------------------------------------- diff --git a/src/test/incremental/spans_significant_w_panic.rs b/src/test/incremental/spans_significant_w_panic.rs new file mode 100644 index 0000000000000..c0bf35e781c70 --- /dev/null +++ b/src/test/incremental/spans_significant_w_panic.rs @@ -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 or the MIT license +// , 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; +}