Skip to content

Commit e1d2bc2

Browse files
authored
Auto merge of #35166 - nikomatsakis:incr-comp-ice-34991-2, r=mw
Address ICEs running w/ incremental compilation and building glium Fixes for various ICEs I encountered trying to build glium with incremental compilation enabled. Building glium now works. Of the 4 ICEs, I have test cases for 3 of them -- I didn't isolate a test for the last commit and kind of want to go do other things -- most notably, figuring out why incremental isn't saving much *effort*. But if it seems worthwhile and I can come back and try to narrow down the problem. r? @michaelwoerister Fixes #34991 Fixes #32015
2 parents f013914 + e0b82d5 commit e1d2bc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1117
-579
lines changed

src/librustc/dep_graph/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ to read from it. Similarly, reading from the `tcache` map for item `X`
134134
(which is a `DepTrackingMap`, described below) automatically invokes
135135
`dep_graph.read(ItemSignature(X))`.
136136

137+
**Note:** adding `Hir` nodes requires a bit of caution due to the
138+
"inlining" that old trans and constant evaluation still use. See the
139+
section on inlining below.
140+
137141
To make this strategy work, a certain amount of indirection is
138142
required. For example, modules in the HIR do not have direct pointers
139143
to the items that they contain. Rather, they contain node-ids -- one
@@ -387,3 +391,24 @@ RUST_DEP_GRAPH_FILTER='Hir&foo -> TypeckItemBody & bar'
387391
This will dump out all the nodes that lead from `Hir(foo)` to
388392
`TypeckItemBody(bar)`, from which you can (hopefully) see the source
389393
of the erroneous edge.
394+
395+
### Inlining of HIR nodes
396+
397+
For the time being, at least, we still sometimes "inline" HIR nodes
398+
from other crates into the current HIR map. This creates a weird
399+
scenario where the same logical item (let's call it `X`) has two
400+
def-ids: the original def-id `X` and a new, inlined one `X'`. `X'` is
401+
in the current crate, but it's not like other HIR nodes: in
402+
particular, when we restart compilation, it will not be available to
403+
hash. Therefore, we do not want `Hir(X')` nodes appearing in our
404+
graph. Instead, we want a "read" of `Hir(X')` to be represented as a
405+
read of `MetaData(X)`, since the metadata for `X` is where the inlined
406+
representation originated in the first place.
407+
408+
To achieve this, the HIR map will detect if the def-id originates in
409+
an inlined node and add a dependency to a suitable `MetaData` node
410+
instead. If you are reading a HIR node and are not sure if it may be
411+
inlined or not, you can use `tcx.map.read(node_id)` and it will detect
412+
whether the node is inlined or not and do the right thing. You can
413+
also use `tcx.map.is_inlined_def_id()` and
414+
`tcx.map.is_inlined_node_id()` to test.

src/librustc/dep_graph/dep_node.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ macro_rules! try_opt {
2020
)
2121
}
2222

23-
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
23+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
2424
pub enum DepNode<D: Clone + Debug> {
2525
// The `D` type is "how definitions are identified".
2626
// During compilation, it is always `DefId`, but when serializing
@@ -82,9 +82,11 @@ pub enum DepNode<D: Clone + Debug> {
8282
Privacy,
8383
IntrinsicCheck(D),
8484
MatchCheck(D),
85-
MirMapConstruction(D),
86-
MirPass(D),
87-
MirTypeck(D),
85+
86+
// Represents the MIR for a fn; also used as the task node for
87+
// things read/modify that MIR.
88+
Mir(D),
89+
8890
BorrowCheck(D),
8991
RvalueCheck(D),
9092
Reachability,
@@ -214,9 +216,7 @@ impl<D: Clone + Debug> DepNode<D> {
214216
CheckConst(ref d) => op(d).map(CheckConst),
215217
IntrinsicCheck(ref d) => op(d).map(IntrinsicCheck),
216218
MatchCheck(ref d) => op(d).map(MatchCheck),
217-
MirMapConstruction(ref d) => op(d).map(MirMapConstruction),
218-
MirPass(ref d) => op(d).map(MirPass),
219-
MirTypeck(ref d) => op(d).map(MirTypeck),
219+
Mir(ref d) => op(d).map(Mir),
220220
BorrowCheck(ref d) => op(d).map(BorrowCheck),
221221
RvalueCheck(ref d) => op(d).map(RvalueCheck),
222222
TransCrateItem(ref d) => op(d).map(TransCrateItem),
@@ -245,6 +245,6 @@ impl<D: Clone + Debug> DepNode<D> {
245245
/// some independent path or string that persists between runs without
246246
/// the need to be mapped or unmapped. (This ensures we can serialize
247247
/// them even in the absence of a tcx.)
248-
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
248+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
249249
pub struct WorkProductId(pub String);
250250

src/librustc/dep_graph/dep_tracking_map.rs

+10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
6161
self.map.get(k)
6262
}
6363

64+
pub fn get_mut(&mut self, k: &M::Key) -> Option<&mut M::Value> {
65+
self.read(k);
66+
self.write(k);
67+
self.map.get_mut(k)
68+
}
69+
6470
pub fn insert(&mut self, k: M::Key, v: M::Value) -> Option<M::Value> {
6571
self.write(&k);
6672
self.map.insert(k, v)
@@ -70,6 +76,10 @@ impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
7076
self.read(k);
7177
self.map.contains_key(k)
7278
}
79+
80+
pub fn keys(&self) -> Vec<M::Key> {
81+
self.map.keys().cloned().collect()
82+
}
7383
}
7484

7585
impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {

src/librustc/dep_graph/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub fn visit_all_items_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4141
let task_id = (self.dep_node_fn)(item_def_id);
4242
let _task = self.tcx.dep_graph.in_task(task_id.clone());
4343
debug!("Started task {:?}", task_id);
44+
assert!(!self.tcx.map.is_inlined_def_id(item_def_id));
4445
self.tcx.dep_graph.read(DepNode::Hir(item_def_id));
4546
self.visitor.visit_item(i);
4647
debug!("Ended task {:?}", task_id);

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ impl<'a> LoweringContext<'a> {
18541854

18551855
let parent_def = self.parent_def;
18561856
let def = self.resolver.definitions().map(|defs| {
1857-
let def_path_data = DefPathData::Binding(name);
1857+
let def_path_data = DefPathData::Binding(name.as_str());
18581858
let def_index = defs.create_def_with_parent(parent_def, pat.id, def_path_data);
18591859
Def::Local(DefId::local(def_index), pat.id)
18601860
}).unwrap_or(Def::Err);

src/librustc/hir/map/def_collector.rs

+35-33
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
135135
DefPathData::Impl,
136136
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..) |
137137
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
138-
DefPathData::TypeNs(i.ident.name),
139-
ItemKind::Mod(..) => DefPathData::Module(i.ident.name),
138+
DefPathData::TypeNs(i.ident.name.as_str()),
139+
ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
140140
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
141-
DefPathData::ValueNs(i.ident.name),
142-
ItemKind::Mac(..) => DefPathData::MacroDef(i.ident.name),
141+
DefPathData::ValueNs(i.ident.name.as_str()),
142+
ItemKind::Mac(..) => DefPathData::MacroDef(i.ident.name.as_str()),
143143
ItemKind::Use(..) => DefPathData::Misc,
144144
};
145145
let def = self.create_def(i.id, def_data);
@@ -150,12 +150,12 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
150150
for v in &enum_definition.variants {
151151
let variant_def_index =
152152
this.create_def(v.node.data.id(),
153-
DefPathData::EnumVariant(v.node.name.name));
153+
DefPathData::EnumVariant(v.node.name.name.as_str()));
154154
this.with_parent(variant_def_index, |this| {
155155
for (index, field) in v.node.data.fields().iter().enumerate() {
156156
let name = field.ident.map(|ident| ident.name)
157157
.unwrap_or_else(|| token::intern(&index.to_string()));
158-
this.create_def(field.id, DefPathData::Field(name));
158+
this.create_def(field.id, DefPathData::Field(name.as_str()));
159159
}
160160

161161
if let Some(ref expr) = v.node.disr_expr {
@@ -172,8 +172,8 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
172172
}
173173

174174
for (index, field) in struct_def.fields().iter().enumerate() {
175-
let name = field.ident.map(|ident| ident.name)
176-
.unwrap_or(token::intern(&index.to_string()));
175+
let name = field.ident.map(|ident| ident.name.as_str())
176+
.unwrap_or(token::intern(&index.to_string()).as_str());
177177
this.create_def(field.id, DefPathData::Field(name));
178178
}
179179
}
@@ -184,7 +184,8 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
184184
}
185185

186186
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
187-
let def = self.create_def(foreign_item.id, DefPathData::ValueNs(foreign_item.ident.name));
187+
let def = self.create_def(foreign_item.id,
188+
DefPathData::ValueNs(foreign_item.ident.name.as_str()));
188189

189190
self.with_parent(def, |this| {
190191
visit::walk_foreign_item(this, foreign_item);
@@ -193,7 +194,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
193194

194195
fn visit_generics(&mut self, generics: &Generics) {
195196
for ty_param in generics.ty_params.iter() {
196-
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name));
197+
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name.as_str()));
197198
}
198199

199200
visit::walk_generics(self, generics);
@@ -202,9 +203,9 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
202203
fn visit_trait_item(&mut self, ti: &TraitItem) {
203204
let def_data = match ti.node {
204205
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
205-
DefPathData::ValueNs(ti.ident.name),
206-
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name),
207-
TraitItemKind::Macro(..) => DefPathData::MacroDef(ti.ident.name),
206+
DefPathData::ValueNs(ti.ident.name.as_str()),
207+
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name.as_str()),
208+
TraitItemKind::Macro(..) => DefPathData::MacroDef(ti.ident.name.as_str()),
208209
};
209210

210211
let def = self.create_def(ti.id, def_data);
@@ -220,9 +221,9 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
220221
fn visit_impl_item(&mut self, ii: &ImplItem) {
221222
let def_data = match ii.node {
222223
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
223-
DefPathData::ValueNs(ii.ident.name),
224-
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name),
225-
ImplItemKind::Macro(..) => DefPathData::MacroDef(ii.ident.name),
224+
DefPathData::ValueNs(ii.ident.name.as_str()),
225+
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name.as_str()),
226+
ImplItemKind::Macro(..) => DefPathData::MacroDef(ii.ident.name.as_str()),
226227
};
227228

228229
let def = self.create_def(ii.id, def_data);
@@ -239,7 +240,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
239240
let parent_def = self.parent_def;
240241

241242
if let PatKind::Ident(_, id, _) = pat.node {
242-
let def = self.create_def(pat.id, DefPathData::Binding(id.node.name));
243+
let def = self.create_def(pat.id, DefPathData::Binding(id.node.name.as_str()));
243244
self.parent_def = Some(def);
244245
}
245246

@@ -271,11 +272,11 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
271272
}
272273

273274
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
274-
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name));
275+
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str()));
275276
}
276277

277278
fn visit_macro_def(&mut self, macro_def: &MacroDef) {
278-
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name));
279+
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name.as_str()));
279280
}
280281
}
281282

@@ -301,9 +302,9 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
301302
hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemTrait(..) |
302303
hir::ItemExternCrate(..) | hir::ItemMod(..) | hir::ItemForeignMod(..) |
303304
hir::ItemTy(..) =>
304-
DefPathData::TypeNs(i.name),
305+
DefPathData::TypeNs(i.name.as_str()),
305306
hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) =>
306-
DefPathData::ValueNs(i.name),
307+
DefPathData::ValueNs(i.name.as_str()),
307308
hir::ItemUse(..) => DefPathData::Misc,
308309
};
309310
let def = self.create_def(i.id, def_data);
@@ -314,12 +315,12 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
314315
for v in &enum_definition.variants {
315316
let variant_def_index =
316317
this.create_def(v.node.data.id(),
317-
DefPathData::EnumVariant(v.node.name));
318+
DefPathData::EnumVariant(v.node.name.as_str()));
318319

319320
this.with_parent(variant_def_index, |this| {
320321
for field in v.node.data.fields() {
321322
this.create_def(field.id,
322-
DefPathData::Field(field.name));
323+
DefPathData::Field(field.name.as_str()));
323324
}
324325
if let Some(ref expr) = v.node.disr_expr {
325326
this.visit_hir_const_integer(expr);
@@ -335,7 +336,7 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
335336
}
336337

337338
for field in struct_def.fields() {
338-
this.create_def(field.id, DefPathData::Field(field.name));
339+
this.create_def(field.id, DefPathData::Field(field.name.as_str()));
339340
}
340341
}
341342
_ => {}
@@ -345,7 +346,8 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
345346
}
346347

347348
fn visit_foreign_item(&mut self, foreign_item: &'ast hir::ForeignItem) {
348-
let def = self.create_def(foreign_item.id, DefPathData::ValueNs(foreign_item.name));
349+
let def = self.create_def(foreign_item.id,
350+
DefPathData::ValueNs(foreign_item.name.as_str()));
349351

350352
self.with_parent(def, |this| {
351353
intravisit::walk_foreign_item(this, foreign_item);
@@ -354,7 +356,7 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
354356

355357
fn visit_generics(&mut self, generics: &'ast hir::Generics) {
356358
for ty_param in generics.ty_params.iter() {
357-
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.name));
359+
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.name.as_str()));
358360
}
359361

360362
intravisit::walk_generics(self, generics);
@@ -363,8 +365,8 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
363365
fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
364366
let def_data = match ti.node {
365367
hir::MethodTraitItem(..) | hir::ConstTraitItem(..) =>
366-
DefPathData::ValueNs(ti.name),
367-
hir::TypeTraitItem(..) => DefPathData::TypeNs(ti.name),
368+
DefPathData::ValueNs(ti.name.as_str()),
369+
hir::TypeTraitItem(..) => DefPathData::TypeNs(ti.name.as_str()),
368370
};
369371

370372
let def = self.create_def(ti.id, def_data);
@@ -380,8 +382,8 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
380382
fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
381383
let def_data = match ii.node {
382384
hir::ImplItemKind::Method(..) | hir::ImplItemKind::Const(..) =>
383-
DefPathData::ValueNs(ii.name),
384-
hir::ImplItemKind::Type(..) => DefPathData::TypeNs(ii.name),
385+
DefPathData::ValueNs(ii.name.as_str()),
386+
hir::ImplItemKind::Type(..) => DefPathData::TypeNs(ii.name.as_str()),
385387
};
386388

387389
let def = self.create_def(ii.id, def_data);
@@ -398,7 +400,7 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
398400
let parent_def = self.parent_def;
399401

400402
if let hir::PatKind::Binding(_, name, _) = pat.node {
401-
let def = self.create_def(pat.id, DefPathData::Binding(name.node));
403+
let def = self.create_def(pat.id, DefPathData::Binding(name.node.as_str()));
402404
self.parent_def = Some(def);
403405
}
404406

@@ -430,10 +432,10 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
430432
}
431433

432434
fn visit_lifetime_def(&mut self, def: &'ast hir::LifetimeDef) {
433-
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name));
435+
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str()));
434436
}
435437

436438
fn visit_macro_def(&mut self, macro_def: &'ast hir::MacroDef) {
437-
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.name));
439+
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.name.as_str()));
438440
}
439441
}

0 commit comments

Comments
 (0)