diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2020-08-04 04:53:28 -0400 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2020-08-04 04:53:28 -0400 |
| commit | 955aebf529787fd49b05f07346e3de97da31cb09 (patch) | |
| tree | 1a571abe3a63eebc224512172f6d9b4b8427134c | |
| parent | 40857b9453a80801fc51b606b0d7532efedad42b (diff) | |
| download | rust-955aebf529787fd49b05f07346e3de97da31cb09.tar.gz rust-955aebf529787fd49b05f07346e3de97da31cb09.zip | |
Don't serialize ExpnData for foreign crates
When we encode an ExpnId into the crate metadata, we write out the CrateNum of the crate that 'owns' the corresponding `ExpnData`, which is later used to decode the `ExpnData` from its owning crate. However, we current serialize the `ExpnData` for all `ExpnIds` that we serialize, even if the `ExpnData` was already serialized into a foreign crate. This commit skips encoding this kind of `ExpnData`, which should hopefully speed up metadata encoding and reduce the total metadata size.
| -rw-r--r-- | src/librustc_span/hygiene.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/librustc_span/hygiene.rs b/src/librustc_span/hygiene.rs index a03ac4e1fdb..87c2c1e6bd0 100644 --- a/src/librustc_span/hygiene.rs +++ b/src/librustc_span/hygiene.rs @@ -1170,13 +1170,27 @@ pub fn raw_encode_expn_id<E: Encoder>( mode: ExpnDataEncodeMode, e: &mut E, ) -> Result<(), E::Error> { - if !context.serialized_expns.lock().contains(&expn) { - context.latest_expns.lock().insert(expn); - } + // Record the fact that we need to serialize the corresponding + // `ExpnData` + let needs_data = || { + if !context.serialized_expns.lock().contains(&expn) { + context.latest_expns.lock().insert(expn); + } + }; + match mode { - ExpnDataEncodeMode::IncrComp => expn.0.encode(e), + ExpnDataEncodeMode::IncrComp => { + // Always serialize the `ExpnData` in incr comp mode + needs_data(); + expn.0.encode(e) + } ExpnDataEncodeMode::Metadata => { let data = expn.expn_data(); + // We only need to serialize the ExpnData + // if it comes from this crate. + if data.krate == LOCAL_CRATE { + needs_data(); + } data.orig_id.expect("Missing orig_id").encode(e)?; data.krate.encode(e) } |
