Skip to content

Commit de0317e

Browse files
incr.comp.: Encode DefPathTables for reconstructing DefIds.
1 parent bedb44c commit de0317e

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/librustc/ty/maps/on_disk_cache.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct OnDiskCache<'sess> {
4949

5050
prev_cnums: Vec<(u32, String, CrateDisambiguator)>,
5151
cnum_map: RefCell<Option<IndexVec<CrateNum, Option<CrateNum>>>>,
52+
prev_def_path_tables: Vec<DefPathTable>,
5253

5354
_prev_filemap_starts: BTreeMap<BytePos, StableFilemapId>,
5455
codemap: &'sess CodeMap,
@@ -73,9 +74,12 @@ impl<'sess> OnDiskCache<'sess> {
7374
debug_assert!(sess.opts.incremental.is_some());
7475

7576
let mut decoder = opaque::Decoder::new(&data[..], start_pos);
77+
78+
79+
// Decode the header
7680
let header = Header::decode(&mut decoder).unwrap();
7781

78-
let prev_diagnostics = {
82+
let (prev_diagnostics, prev_def_path_tables) = {
7983
let mut decoder = CacheDecoder {
8084
tcx: None,
8185
opaque: decoder,
@@ -85,21 +89,28 @@ impl<'sess> OnDiskCache<'sess> {
8589
prev_def_path_tables: &Vec::new(),
8690
};
8791

92+
// Decode Diagnostics
8893
let prev_diagnostics: FxHashMap<_, _> = {
8994
let diagnostics = EncodedPrevDiagnostics::decode(&mut decoder)
9095
.expect("Error while trying to decode prev. diagnostics \
9196
from incr. comp. cache.");
9297
diagnostics.into_iter().collect()
9398
};
9499

95-
prev_diagnostics
100+
// Decode DefPathTables
101+
let prev_def_path_tables: Vec<DefPathTable> =
102+
Decodable::decode(&mut decoder)
103+
.expect("Error while trying to decode cached DefPathTables");
104+
105+
(prev_diagnostics, prev_def_path_tables)
96106
};
97107

98108
OnDiskCache {
99109
prev_diagnostics,
100110
_prev_filemap_starts: header.prev_filemap_starts,
101111
prev_cnums: header.prev_cnums,
102112
cnum_map: RefCell::new(None),
113+
prev_def_path_tables,
103114
codemap: sess.codemap(),
104115
current_diagnostics: RefCell::new(FxHashMap()),
105116
}
@@ -111,6 +122,7 @@ impl<'sess> OnDiskCache<'sess> {
111122
_prev_filemap_starts: BTreeMap::new(),
112123
prev_cnums: vec![],
113124
cnum_map: RefCell::new(None),
125+
prev_def_path_tables: Vec::new(),
114126
codemap,
115127
current_diagnostics: RefCell::new(FxHashMap()),
116128
}
@@ -166,6 +178,22 @@ impl<'sess> OnDiskCache<'sess> {
166178

167179
diagnostics.encode(&mut encoder)?;
168180

181+
182+
// Encode all DefPathTables
183+
let upstream_def_path_tables = tcx.all_crate_nums(LOCAL_CRATE)
184+
.iter()
185+
.map(|&cnum| (cnum, cstore.def_path_table(cnum)))
186+
.collect::<FxHashMap<_,_>>();
187+
let def_path_tables: Vec<&DefPathTable> = sorted_cnums.into_iter().map(|cnum| {
188+
if cnum == LOCAL_CRATE {
189+
tcx.hir.definitions().def_path_table()
190+
} else {
191+
&*upstream_def_path_tables[&cnum]
192+
}
193+
}).collect();
194+
195+
def_path_tables.encode(&mut encoder)?;
196+
169197
return Ok(());
170198

171199
fn sorted_cnums_including_local_crate(cstore: &CrateStore) -> Vec<CrateNum> {

0 commit comments

Comments
 (0)