Skip to content

Commit da3c6b7

Browse files
committed
map create numbers between compilations
1 parent b2799a5 commit da3c6b7

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
@@ -18,7 +18,7 @@ use hir::TraitMap;
1818
use hir::def::DefMap;
1919
use hir::def_id::{DefId, DefIndex};
2020
use hir::map as ast_map;
21-
use hir::map::{DefKey, DefPath, DefPathData, DisambiguatedDefPathData};
21+
use hir::map::{DefKey, DefPathData, DisambiguatedDefPathData};
2222
use middle::free_region::FreeRegionMap;
2323
use middle::region::RegionMaps;
2424
use middle::resolve_lifetime;
@@ -538,8 +538,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
538538
}
539539
}
540540

541-
pub fn retrace_path(self, path: &DefPath) -> Option<DefId> {
542-
debug!("retrace_path(path={:?}, krate={:?})", path, self.crate_name(path.krate));
541+
pub fn retrace_path(self,
542+
krate: ast::CrateNum,
543+
path_data: &[DisambiguatedDefPathData])
544+
-> Option<DefId> {
545+
debug!("retrace_path(path={:?}, krate={:?})", path_data, self.crate_name(krate));
543546

544547
let root_key = DefKey {
545548
parent: None,
@@ -549,22 +552,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
549552
},
550553
};
551554

552-
let root_index = self.def_index_for_def_key(path.krate, root_key)
555+
let root_index = self.def_index_for_def_key(krate, root_key)
553556
.expect("no root key?");
554557

555558
debug!("retrace_path: root_index={:?}", root_index);
556559

557560
let mut index = root_index;
558-
for data in &path.data {
561+
for data in path_data {
559562
let key = DefKey { parent: Some(index), disambiguated_data: data.clone() };
560563
debug!("retrace_path: key={:?}", key);
561-
match self.def_index_for_def_key(path.krate, key) {
564+
match self.def_index_for_def_key(krate, key) {
562565
Some(i) => index = i,
563566
None => return None,
564567
}
565568
}
566569

567-
Some(DefId { krate: path.krate, index: index })
570+
Some(DefId { krate: krate, index: index })
568571
}
569572

570573
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
@@ -22,6 +22,7 @@ use rustc::util::nodemap::DefIdMap;
2222
use std::fmt::{self, Debug};
2323
use std::iter::once;
2424
use syntax::ast;
25+
use std::collections::HashMap;
2526

2627
/// Index into the DefIdDirectory
2728
#[derive(Copy, Clone, Debug, PartialOrd, Ord, Hash, PartialEq, Eq,
@@ -92,18 +93,29 @@ impl DefIdDirectory {
9293
}
9394

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

97108
let ids = self.paths.iter()
98109
.map(|path| {
99-
if self.krate_still_valid(tcx, max_current_crate, path.krate) {
100-
tcx.retrace_path(path)
110+
let old_krate_id = path.krate as usize;
111+
assert!(old_krate_id < self.krates.len());
112+
let old_crate_info = &self.krates[old_krate_id];
113+
let old_crate_key = make_key(&old_crate_info.name,
114+
&old_crate_info.disambiguator);
115+
if let Some(&new_crate_key) = new_krates.get(&old_crate_key) {
116+
tcx.retrace_path(new_crate_key, &path.data)
101117
} else {
102-
debug!("crate {} changed from {:?} to {:?}/{:?}",
103-
path.krate,
104-
self.krates[path.krate as usize],
105-
tcx.crate_name(path.krate),
106-
tcx.crate_disambiguator(path.krate));
118+
debug!("crate {:?} no longer exists", old_crate_key);
107119
None
108120
}
109121
})
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)