Skip to content

Commit 6713736

Browse files
committed
Auto merge of #45551 - michaelwoerister:fix-hir-depnodes-and-ich, r=nikomatsakis
incr.comp.: Fix two problems with HIR hashing. Fixes #45469. This PR fixes two small problems: * Overflow checks are always enabled in a constant context, so we need to hash spans of potentially overflowing operations. (Eventually I'd like to handle spans differently so we don't have to make HIR hashing know so much about things like this.) * The HIR map collector had a bug where it would assign the `DepNode::Hir` instead of the corresponding `DepNode::HirBody` in some nested contexts. r? @nikomatsakis
2 parents f57c55d + 10ffff8 commit 6713736

File tree

6 files changed

+111
-50
lines changed

6 files changed

+111
-50
lines changed

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
219219
f: F) {
220220
let prev_owner = self.current_dep_node_owner;
221221
let prev_signature_dep_index = self.current_signature_dep_index;
222-
let prev_full_dep_index = self.current_signature_dep_index;
222+
let prev_full_dep_index = self.current_full_dep_index;
223223
let prev_in_body = self.currently_in_body;
224224

225225
let def_path_hash = self.definitions.def_path_hash(dep_node_owner);

src/librustc/ich/hcx.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ impl<'gcx> StableHashingContext<'gcx> {
206206

207207
pub fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self,
208208
item_attrs: &[ast::Attribute],
209+
is_const: bool,
209210
f: F) {
210211
let prev_overflow_checks = self.overflow_checks_enabled;
211-
if attr::contains_name(item_attrs, "rustc_inherit_overflow_checks") {
212+
if is_const || attr::contains_name(item_attrs, "rustc_inherit_overflow_checks") {
212213
self.overflow_checks_enabled = true;
213214
}
214215
let prev_hash_node_ids = self.node_id_hashing_mode;

src/librustc/ich/impls_hir.rs

+26-8
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,15 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::TraitItem {
713713
span
714714
} = *self;
715715

716-
hcx.hash_hir_item_like(attrs, |hcx| {
716+
let is_const = match *node {
717+
hir::TraitItemKind::Const(..) |
718+
hir::TraitItemKind::Type(..) => true,
719+
hir::TraitItemKind::Method(hir::MethodSig { constness, .. }, _) => {
720+
constness == hir::Constness::Const
721+
}
722+
};
723+
724+
hcx.hash_hir_item_like(attrs, is_const, |hcx| {
717725
name.hash_stable(hcx, hasher);
718726
attrs.hash_stable(hcx, hasher);
719727
generics.hash_stable(hcx, hasher);
@@ -750,7 +758,15 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::ImplItem {
750758
span
751759
} = *self;
752760

753-
hcx.hash_hir_item_like(attrs, |hcx| {
761+
let is_const = match *node {
762+
hir::ImplItemKind::Const(..) |
763+
hir::ImplItemKind::Type(..) => true,
764+
hir::ImplItemKind::Method(hir::MethodSig { constness, .. }, _) => {
765+
constness == hir::Constness::Const
766+
}
767+
};
768+
769+
hcx.hash_hir_item_like(attrs, is_const, |hcx| {
754770
name.hash_stable(hcx, hasher);
755771
vis.hash_stable(hcx, hasher);
756772
defaultness.hash_stable(hcx, hasher);
@@ -869,11 +885,13 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::Item {
869885
fn hash_stable<W: StableHasherResult>(&self,
870886
hcx: &mut StableHashingContext<'gcx>,
871887
hasher: &mut StableHasher<W>) {
872-
let hash_spans = match self.node {
888+
let (is_const, hash_spans) = match self.node {
873889
hir::ItemStatic(..) |
874-
hir::ItemConst(..) |
875-
hir::ItemFn(..) => {
876-
hcx.hash_spans()
890+
hir::ItemConst(..) => {
891+
(true, hcx.hash_spans())
892+
}
893+
hir::ItemFn(_, _, constness, ..) => {
894+
(constness == hir::Constness::Const, hcx.hash_spans())
877895
}
878896
hir::ItemUse(..) |
879897
hir::ItemExternCrate(..) |
@@ -887,7 +905,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::Item {
887905
hir::ItemEnum(..) |
888906
hir::ItemStruct(..) |
889907
hir::ItemUnion(..) => {
890-
false
908+
(false, false)
891909
}
892910
};
893911

@@ -901,7 +919,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::Item {
901919
span
902920
} = *self;
903921

904-
hcx.hash_hir_item_like(attrs, |hcx| {
922+
hcx.hash_hir_item_like(attrs, is_const, |hcx| {
905923
hcx.while_hashing_spans(hash_spans, |hcx| {
906924
name.hash_stable(hcx, hasher);
907925
attrs.hash_stable(hcx, hasher);

src/test/incremental/hashes/consts.rs

+26-20
Original file line numberDiff line numberDiff line change
@@ -62,48 +62,54 @@ const CONST_CHANGE_TYPE_2: Option<u64> = None;
6262

6363

6464
// Change value between simple literals ---------------------------------------
65-
#[cfg(cfail1)]
66-
const CONST_CHANGE_VALUE_1: i16 = 1;
67-
68-
#[cfg(not(cfail1))]
6965
#[rustc_clean(cfg="cfail2", except="HirBody")]
7066
#[rustc_clean(cfg="cfail3")]
7167
#[rustc_metadata_clean(cfg="cfail3")]
72-
const CONST_CHANGE_VALUE_1: i16 = 2;
68+
const CONST_CHANGE_VALUE_1: i16 = {
69+
#[cfg(cfail1)]
70+
{ 1 }
7371

72+
#[cfg(not(cfail1))]
73+
{ 2 }
74+
};
7475

75-
// Change value between expressions -------------------------------------------
76-
#[cfg(cfail1)]
77-
const CONST_CHANGE_VALUE_2: i16 = 1 + 1;
7876

79-
#[cfg(not(cfail1))]
77+
// Change value between expressions -------------------------------------------
8078
#[rustc_clean(cfg="cfail2", except="HirBody")]
8179
#[rustc_clean(cfg="cfail3")]
8280
#[rustc_metadata_dirty(cfg="cfail2")]
8381
#[rustc_metadata_clean(cfg="cfail3")]
84-
const CONST_CHANGE_VALUE_2: i16 = 1 + 2;
85-
82+
const CONST_CHANGE_VALUE_2: i16 = {
83+
#[cfg(cfail1)]
84+
{ 1 + 1 }
8685

87-
#[cfg(cfail1)]
88-
const CONST_CHANGE_VALUE_3: i16 = 2 + 3;
86+
#[cfg(not(cfail1))]
87+
{ 1 + 2 }
88+
};
8989

90-
#[cfg(not(cfail1))]
9190
#[rustc_clean(cfg="cfail2", except="HirBody")]
9291
#[rustc_clean(cfg="cfail3")]
9392
#[rustc_metadata_dirty(cfg="cfail2")]
9493
#[rustc_metadata_clean(cfg="cfail3")]
95-
const CONST_CHANGE_VALUE_3: i16 = 2 * 3;
96-
94+
const CONST_CHANGE_VALUE_3: i16 = {
95+
#[cfg(cfail1)]
96+
{ 2 + 3 }
9797

98-
#[cfg(cfail1)]
99-
const CONST_CHANGE_VALUE_4: i16 = 1 + 2 * 3;
98+
#[cfg(not(cfail1))]
99+
{ 2 * 3 }
100+
};
100101

101-
#[cfg(not(cfail1))]
102102
#[rustc_clean(cfg="cfail2", except="HirBody")]
103103
#[rustc_clean(cfg="cfail3")]
104104
#[rustc_metadata_dirty(cfg="cfail2")]
105105
#[rustc_metadata_clean(cfg="cfail3")]
106-
const CONST_CHANGE_VALUE_4: i16 = 1 + 2 * 4;
106+
const CONST_CHANGE_VALUE_4: i16 = {
107+
#[cfg(cfail1)]
108+
{ 1 + 2 * 3 }
109+
110+
#[cfg(not(cfail1))]
111+
{ 1 + 2 * 4 }
112+
};
107113

108114

109115
// Change type indirectly -----------------------------------------------------

src/test/incremental/hashes/statics.rs

+26-20
Original file line numberDiff line numberDiff line change
@@ -115,49 +115,55 @@ static STATIC_CHANGE_TYPE_2: Option<u16> = None;
115115

116116

117117
// Change value between simple literals ---------------------------------------
118-
#[cfg(cfail1)]
119-
static STATIC_CHANGE_VALUE_1: i16 = 1;
120-
121-
#[cfg(not(cfail1))]
122118
#[rustc_clean(cfg="cfail2", except="HirBody")]
123119
#[rustc_clean(cfg="cfail3")]
124120
#[rustc_metadata_clean(cfg="cfail2")]
125121
#[rustc_metadata_clean(cfg="cfail3")]
126-
static STATIC_CHANGE_VALUE_1: i16 = 2;
122+
static STATIC_CHANGE_VALUE_1: i16 = {
123+
#[cfg(cfail1)]
124+
{ 1 }
127125

126+
#[cfg(not(cfail1))]
127+
{ 2 }
128+
};
128129

129-
// Change value between expressions -------------------------------------------
130-
#[cfg(cfail1)]
131-
static STATIC_CHANGE_VALUE_2: i16 = 1 + 1;
132130

133-
#[cfg(not(cfail1))]
131+
// Change value between expressions -------------------------------------------
134132
#[rustc_clean(cfg="cfail2", except="HirBody")]
135133
#[rustc_clean(cfg="cfail3")]
136134
#[rustc_metadata_clean(cfg="cfail2")]
137135
#[rustc_metadata_clean(cfg="cfail3")]
138-
static STATIC_CHANGE_VALUE_2: i16 = 1 + 2;
139-
136+
static STATIC_CHANGE_VALUE_2: i16 = {
137+
#[cfg(cfail1)]
138+
{ 1 + 1 }
140139

141-
#[cfg(cfail1)]
142-
static STATIC_CHANGE_VALUE_3: i16 = 2 + 3;
140+
#[cfg(not(cfail1))]
141+
{ 1 + 2 }
142+
};
143143

144-
#[cfg(not(cfail1))]
145144
#[rustc_clean(cfg="cfail2", except="HirBody")]
146145
#[rustc_clean(cfg="cfail3")]
147146
#[rustc_metadata_clean(cfg="cfail2")]
148147
#[rustc_metadata_clean(cfg="cfail3")]
149-
static STATIC_CHANGE_VALUE_3: i16 = 2 * 3;
150-
148+
static STATIC_CHANGE_VALUE_3: i16 = {
149+
#[cfg(cfail1)]
150+
{ 2 + 3 }
151151

152-
#[cfg(cfail1)]
153-
static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 3;
152+
#[cfg(not(cfail1))]
153+
{ 2 * 3 }
154+
};
154155

155-
#[cfg(not(cfail1))]
156156
#[rustc_clean(cfg="cfail2", except="HirBody")]
157157
#[rustc_clean(cfg="cfail3")]
158158
#[rustc_metadata_clean(cfg="cfail2")]
159159
#[rustc_metadata_clean(cfg="cfail3")]
160-
static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 4;
160+
static STATIC_CHANGE_VALUE_4: i16 = {
161+
#[cfg(cfail1)]
162+
{ 1 + 2 * 3 }
163+
164+
#[cfg(not(cfail1))]
165+
{ 1 + 2 * 4 }
166+
};
161167

162168

163169
// Change type indirectly -----------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This test makes sure that just changing a definition's location in the
12+
// source file also changes its incr. comp. hash, if debuginfo is enabled.
13+
14+
// revisions:rpass1 rpass2
15+
16+
// compile-flags: -C overflow-checks=on
17+
18+
#![feature(rustc_attrs)]
19+
20+
#[cfg(rpass1)]
21+
pub fn main() {
22+
let _ = 0u8 + 1;
23+
}
24+
25+
#[cfg(rpass2)]
26+
#[rustc_clean(label="Hir", cfg="rpass2")]
27+
#[rustc_dirty(label="HirBody", cfg="rpass2")]
28+
pub fn main() {
29+
let _ = 0u8 + 1;
30+
}

0 commit comments

Comments
 (0)