-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
incr.comp.: Implement query result cache and use it to cache type checking tables. #46004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8cbc022
c08e03a
bc96d9d
9ac1026
3bd333c
15db165
bedb44c
de0317e
2087d5e
4bfab89
0b14383
2c1aedd
279b6df
13582c6
2f50e62
24e54dd
2f44ef2
723028f
cb1ff24
4c4f7a3
0a1f6dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ pub struct OnDiskCache<'sess> { | |
|
|
||
| prev_cnums: Vec<(u32, String, CrateDisambiguator)>, | ||
| cnum_map: RefCell<Option<IndexVec<CrateNum, Option<CrateNum>>>>, | ||
| prev_def_path_tables: Vec<DefPathTable>, | ||
|
|
||
| _prev_filemap_starts: BTreeMap<BytePos, StableFilemapId>, | ||
| codemap: &'sess CodeMap, | ||
|
|
@@ -73,9 +74,12 @@ impl<'sess> OnDiskCache<'sess> { | |
| debug_assert!(sess.opts.incremental.is_some()); | ||
|
|
||
| let mut decoder = opaque::Decoder::new(&data[..], start_pos); | ||
|
|
||
|
|
||
| // Decode the header | ||
| let header = Header::decode(&mut decoder).unwrap(); | ||
|
|
||
| let prev_diagnostics = { | ||
| let (prev_diagnostics, prev_def_path_tables) = { | ||
| let mut decoder = CacheDecoder { | ||
| tcx: None, | ||
| opaque: decoder, | ||
|
|
@@ -85,21 +89,28 @@ impl<'sess> OnDiskCache<'sess> { | |
| prev_def_path_tables: &Vec::new(), | ||
| }; | ||
|
|
||
| // Decode Diagnostics | ||
| let prev_diagnostics: FxHashMap<_, _> = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have this new variable here? It doesn't serve an obvious purpose. =)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does in later commits where this block is used to limit the scope of the |
||
| let diagnostics = EncodedPrevDiagnostics::decode(&mut decoder) | ||
| .expect("Error while trying to decode prev. diagnostics \ | ||
| from incr. comp. cache."); | ||
| diagnostics.into_iter().collect() | ||
| }; | ||
|
|
||
| prev_diagnostics | ||
| // Decode DefPathTables | ||
| let prev_def_path_tables: Vec<DefPathTable> = | ||
| Decodable::decode(&mut decoder) | ||
| .expect("Error while trying to decode cached DefPathTables"); | ||
|
|
||
| (prev_diagnostics, prev_def_path_tables) | ||
| }; | ||
|
|
||
| OnDiskCache { | ||
| prev_diagnostics, | ||
| _prev_filemap_starts: header.prev_filemap_starts, | ||
| prev_cnums: header.prev_cnums, | ||
| cnum_map: RefCell::new(None), | ||
| prev_def_path_tables, | ||
| codemap: sess.codemap(), | ||
| current_diagnostics: RefCell::new(FxHashMap()), | ||
| } | ||
|
|
@@ -111,6 +122,7 @@ impl<'sess> OnDiskCache<'sess> { | |
| _prev_filemap_starts: BTreeMap::new(), | ||
| prev_cnums: vec![], | ||
| cnum_map: RefCell::new(None), | ||
| prev_def_path_tables: Vec::new(), | ||
| codemap, | ||
| current_diagnostics: RefCell::new(FxHashMap()), | ||
| } | ||
|
|
@@ -166,6 +178,22 @@ impl<'sess> OnDiskCache<'sess> { | |
|
|
||
| diagnostics.encode(&mut encoder)?; | ||
|
|
||
|
|
||
| // Encode all DefPathTables | ||
| let upstream_def_path_tables = tcx.all_crate_nums(LOCAL_CRATE) | ||
| .iter() | ||
| .map(|&cnum| (cnum, cstore.def_path_table(cnum))) | ||
| .collect::<FxHashMap<_,_>>(); | ||
| let def_path_tables: Vec<&DefPathTable> = sorted_cnums.into_iter().map(|cnum| { | ||
| if cnum == LOCAL_CRATE { | ||
| tcx.hir.definitions().def_path_table() | ||
| } else { | ||
| &*upstream_def_path_tables[&cnum] | ||
| } | ||
| }).collect(); | ||
|
|
||
| def_path_tables.encode(&mut encoder)?; | ||
|
|
||
| return Ok(()); | ||
|
|
||
| fn sorted_cnums_including_local_crate(cstore: &CrateStore) -> Vec<CrateNum> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this signal a shift away from the "reverse lookup by hash" strategy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the
DefPathTablesare stored for facilitating the "reverse lookup by hash". The implementation in this PR does the following:DefIdunmodified in the cache.DefIdto the session-independentDefPathHashand thenDefIdby thisDefPathHash.In order to be able to do step (i), we need the old
DefPathTablebecause it mapsDefIndicestoDefPathHashes.But,... I'm not surprised that this caught your eye. There is an alternative approach that is simpler to implement and maybe more robust: Map
DefIdsandDefIndicestoDefPathHashesat serialization time and thus get rid of the requirement to store the oldDefPathTables. I'm not sure if this affects performance and space requirements in a good or in a bad way. But I'd like to implement it soonish and measure the impact.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see.