Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upincr.comp.: Implement query result cache and use it to cache type checking tables. #46004
Conversation
michaelwoerister
added some commits
Nov 13, 2017
rust-highfive
assigned
nikomatsakis
Nov 15, 2017
This comment has been minimized.
This comment has been minimized.
|
Just found a bug in this: The Please do not merge until this is fixed. |
kennytm
added
the
S-waiting-on-review
label
Nov 15, 2017
nikomatsakis
reviewed
Nov 15, 2017
| let body = Body::decode(&mut decoder).unwrap(); | ||
| body.diagnostics.into_iter().collect() | ||
|
|
||
| let prev_diagnostics: FxHashMap<_, _> = { |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Nov 15, 2017
Contributor
Why do we have this new variable here? It doesn't serve an obvious purpose. =)
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Nov 16, 2017
Author
Contributor
It does in later commits where this block is used to limit the scope of the CacheDecoder.
nikomatsakis
reviewed
Nov 15, 2017
| where E: 'enc + ty_codec::TyEncoder | ||
| { | ||
| fn specialized_encode(&mut self, node_id: &NodeId) -> Result<(), Self::Error> { | ||
| let hir_id = self.definitions.node_to_hir_id(*node_id); |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Nov 15, 2017
Contributor
Is this basically copy-n-paste from the other encoders? (Not criticizing, just trying to understand.)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Nov 15, 2017
Author
Contributor
Yeah, I thought about writing a macro in ty::codec that would instantiate these implementations. Upfront, I wasn't sure though how many of them would end up just being copies.
nikomatsakis
reviewed
Nov 15, 2017
| } | ||
| } | ||
|
|
||
| impl<'a, 'tcx, 'x> SpecializedDecoder<&'tcx Substs<'tcx>> for CacheDecoder<'a, 'tcx, 'x> { |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Nov 15, 2017
Contributor
If we forget one of these impls, what happens? I think it panics? (These impls are copy-n-paste, I assume.)
This comment has been minimized.
This comment has been minimized.
nikomatsakis
reviewed
Nov 15, 2017
| @@ -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>, | |||
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Nov 15, 2017
Contributor
Does this signal a shift away from the "reverse lookup by hash" strategy?
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Nov 16, 2017
Author
Contributor
No, the DefPathTables are stored for facilitating the "reverse lookup by hash". The implementation in this PR does the following:
- Store a
DefIdunmodified in the cache. - When loading, we need to
- map the serialized
DefIdto the session-independentDefPathHashand then - look up the new
DefIdby thisDefPathHash.
- map the serialized
In order to be able to do step (i), we need the old DefPathTable because it maps DefIndices to DefPathHashes.
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 DefIds and DefIndices to DefPathHashes at serialization time and thus get rid of the requirement to store the old DefPathTables. 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.
This comment has been minimized.
This comment has been minimized.
nikomatsakis
reviewed
Nov 15, 2017
|
Did a first pass. Left some drive-by questions. The main "red flag" of sorts was that there seemed to be a bit more code duplication than I expected, though mostly it's just impls calling into common helpers, so perhaps it's fine. Not sure how best to avoid it, perhaps using a macro -- or there might be some specialization tricks we could use with a helper trait. |
michaelwoerister
added some commits
Nov 16, 2017
This comment has been minimized.
This comment has been minimized.
|
OK, this should be up-to-date now. I went ahead and implemented the "map to |
michaelwoerister
referenced this pull request
Nov 16, 2017
Closed
Tracking issue for "Red/Green" Dependency Tracking #42293
nikomatsakis
approved these changes
Nov 16, 2017
|
Lovely. |
|
|
||
|
|
||
| #[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
| pub struct LocalDefId(DefIndex); |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Nov 16, 2017
Contributor
I've wanted to add this type for so long. But can you please add a doc-comment explaining its role and why to use it, and also why it is bad to just use a raw DefIndex.
| self.krate == LOCAL_CRATE | ||
| } | ||
|
|
||
| #[inline] |
This comment has been minimized.
This comment has been minimized.
| prev_cnums: Vec<(u32, String, CrateDisambiguator)>, | ||
| cnum_map: RefCell<Option<IndexVec<CrateNum, Option<CrateNum>>>>, | ||
| prev_def_path_tables: Vec<DefPathTable>, |
This comment has been minimized.
This comment has been minimized.
| ty_codec::decode_const(self) | ||
| } | ||
| } | ||
| implement_ty_decoder!( DecodeContext<'a, 'tcx> ); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Er wait, I wanted something. @bors r- |
This comment has been minimized.
This comment has been minimized.
|
r=me with comment on |
michaelwoerister
force-pushed the
michaelwoerister:cached-mir-wip-3
branch
from
5f4d5d3
to
0a1f6dd
Nov 16, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors r=nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
|
kennytm
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Nov 16, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors p=1 (we'd like to get this tested on rust-icci asap) |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Nov 17, 2017
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit 0a1f6dd
into
rust-lang:master
Nov 17, 2017
This comment has been minimized.
This comment has been minimized.
|
Note, this is not expected to show up in any benchmarks yet since it's behind the |
michaelwoerister commentedNov 15, 2017
This is a spike implementation of caching more than LLVM IR and object files when doing incremental compilation. At the moment, only the
typeck_tables_ofquery is cached but MIR and borrow-check will follow shortly. The feature is activated by running with-Zincremental-queriesin addition to-Zincremental, it is not yet active by default.r? @nikomatsakis