Skip to content

Commit 4ad75b3

Browse files
authored
Rollup merge of #41873 - michaelwoerister:fix-filemap-hash-lookup, r=nikomatsakis
ICH: Handle case of removed FileMaps. This PR fixes a bug introduced in #41709 where removing a source file between compilation sessions would cause an ICE: https://travis-ci.org/rust-icci/crossbeam/jobs/230582234#L633 r? @nikomatsakis
2 parents 183dd9e + 84a40c1 commit 4ad75b3

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/librustc_incremental/persist/hash.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
7979

8080
DepNode::FileMap(def_id, ref name) => {
8181
if def_id.is_local() {
82-
Some(self.incremental_hashes_map[dep_node])
82+
// We will have been able to retrace the DefId (which is
83+
// always the local CRATE_DEF_INDEX), but the file with the
84+
// given name might have been removed, so we use get() in
85+
// order to allow for that case.
86+
self.incremental_hashes_map.get(dep_node).map(|x| *x)
8387
} else {
8488
Some(self.metadata_hash(DepNode::FileMap(def_id, name.clone()),
8589
def_id.krate,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
pub fn print_hello() {
12+
println!("hello");
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 case makes sure that the compiler doesn't crash due to a failing
12+
// table lookup when a source file is removed.
13+
14+
// revisions:rpass1 rpass2
15+
16+
// Note that we specify -g so that the FileMaps actually get referenced by the
17+
// incr. comp. cache:
18+
// compile-flags: -Z query-dep-graph -g
19+
20+
#[cfg(rpass1)]
21+
mod auxiliary;
22+
23+
#[cfg(rpass1)]
24+
fn main() {
25+
auxiliary::print_hello();
26+
}
27+
28+
#[cfg(rpass2)]
29+
fn main() {
30+
println!("hello");
31+
}

0 commit comments

Comments
 (0)