Skip to content

Commit 9462226

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#36460 - mikhail-m1:35123-map3, r=nikomatsakis
map crate numbers between compilations ?r nikomatsakis issue rust-lang#35123
2 parents 55c9bc2 + 20c1091 commit 9462226

File tree

5 files changed

+92
-15
lines changed

5 files changed

+92
-15
lines changed

src/librustc/ty/context.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use hir::TraitMap;
1717
use hir::def::DefMap;
1818
use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
1919
use hir::map as ast_map;
20-
use hir::map::{DefKey, DefPath, DefPathData, DisambiguatedDefPathData};
20+
use hir::map::{DefKey, DefPathData, DisambiguatedDefPathData};
2121
use middle::free_region::FreeRegionMap;
2222
use middle::region::RegionMaps;
2323
use middle::resolve_lifetime;
@@ -546,8 +546,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
546546
}
547547
}
548548

549-
pub fn retrace_path(self, path: &DefPath) -> Option<DefId> {
550-
debug!("retrace_path(path={:?}, krate={:?})", path, self.crate_name(path.krate));
549+
pub fn retrace_path(self,
550+
krate: CrateNum,
551+
path_data: &[DisambiguatedDefPathData])
552+
-> Option<DefId> {
553+
debug!("retrace_path(path={:?}, krate={:?})", path_data, self.crate_name(krate));
551554

552555
let root_key = DefKey {
553556
parent: None,
@@ -557,22 +560,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
557560
},
558561
};
559562

560-
let root_index = self.def_index_for_def_key(path.krate, root_key)
563+
let root_index = self.def_index_for_def_key(krate, root_key)
561564
.expect("no root key?");
562565

563566
debug!("retrace_path: root_index={:?}", root_index);
564567

565568
let mut index = root_index;
566-
for data in &path.data {
569+
for data in path_data {
567570
let key = DefKey { parent: Some(index), disambiguated_data: data.clone() };
568571
debug!("retrace_path: key={:?}", key);
569-
match self.def_index_for_def_key(path.krate, key) {
572+
match self.def_index_for_def_key(krate, key) {
570573
Some(i) => index = i,
571574
None => return None,
572575
}
573576
}
574577

575-
Some(DefId { krate: path.krate, index: index })
578+
Some(DefId { krate: krate, index: index })
576579
}
577580

578581
pub fn type_parameter_def(self,

src/librustc_incremental/persist/directory.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc::ty::TyCtxt;
2020
use rustc::util::nodemap::DefIdMap;
2121
use std::fmt::{self, Debug};
2222
use std::iter::once;
23+
use std::collections::HashMap;
2324

2425
/// Index into the DefIdDirectory
2526
#[derive(Copy, Clone, Debug, PartialOrd, Ord, Hash, PartialEq, Eq,
@@ -90,18 +91,29 @@ impl DefIdDirectory {
9091
}
9192

9293
pub fn retrace(&self, tcx: TyCtxt) -> RetracedDefIdDirectory {
93-
let max_current_crate = self.max_current_crate(tcx);
94+
95+
fn make_key(name: &str, disambiguator: &str) -> String {
96+
format!("{}/{}", name, disambiguator)
97+
}
98+
99+
let new_krates: HashMap<_, _> =
100+
once(LOCAL_CRATE)
101+
.chain(tcx.sess.cstore.crates())
102+
.map(|krate| (make_key(&tcx.crate_name(krate),
103+
&tcx.crate_disambiguator(krate)), krate))
104+
.collect();
94105

95106
let ids = self.paths.iter()
96107
.map(|path| {
97-
if self.krate_still_valid(tcx, max_current_crate, path.krate) {
98-
tcx.retrace_path(path)
108+
let old_krate_id = path.krate.as_usize();
109+
assert!(old_krate_id < self.krates.len());
110+
let old_crate_info = &self.krates[old_krate_id];
111+
let old_crate_key = make_key(&old_crate_info.name,
112+
&old_crate_info.disambiguator);
113+
if let Some(&new_crate_key) = new_krates.get(&old_crate_key) {
114+
tcx.retrace_path(new_crate_key, &path.data)
99115
} else {
100-
debug!("crate {} changed from {:?} to {:?}/{:?}",
101-
path.krate,
102-
self.krates[path.krate.as_usize()],
103-
tcx.crate_name(path.krate),
104-
tcx.crate_disambiguator(path.krate));
116+
debug!("crate {:?} no longer exists", old_crate_key);
105117
None
106118
}
107119
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 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+
#![crate_type="rlib"]
12+
13+
pub static A : u32 = 32;
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 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+
#![crate_type="rlib"]
12+
13+
pub static B: u32 = 32;
14+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2014 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+
// aux-build:a.rs
12+
// aux-build:b.rs
13+
// revisions:rpass1 rpass2
14+
15+
#![feature(rustc_attrs)]
16+
17+
18+
#[cfg(rpass1)]
19+
extern crate a;
20+
#[cfg(rpass1)]
21+
extern crate b;
22+
23+
#[cfg(rpass2)]
24+
extern crate b;
25+
#[cfg(rpass2)]
26+
extern crate a;
27+
28+
use a::A;
29+
use b::B;
30+
31+
//? #[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
32+
pub fn main() {
33+
A + B;
34+
}

0 commit comments

Comments
 (0)