Auto merge of #87044 - cjgillot:expnhash, r=petrochenkov
Cache expansion hash globally ... instead of computing it multiple times. Split from #86676 r? `@petrochenkov`
This commit is contained in:
commit
c7d6bcc788
12 changed files with 285 additions and 240 deletions
|
@ -393,12 +393,19 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnId {
|
|||
} else {
|
||||
local_cdata.cstore.get_crate_data(cnum)
|
||||
};
|
||||
Ok(crate_data
|
||||
let expn_data = crate_data
|
||||
.root
|
||||
.expn_data
|
||||
.get(&crate_data, index)
|
||||
.unwrap()
|
||||
.decode((&crate_data, sess)))
|
||||
.decode((&crate_data, sess));
|
||||
let expn_hash = crate_data
|
||||
.root
|
||||
.expn_hashes
|
||||
.get(&crate_data, index)
|
||||
.unwrap()
|
||||
.decode((&crate_data, sess));
|
||||
Ok((expn_data, expn_hash))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -653,7 +653,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
// Therefore, we need to encode the hygiene data last to ensure that we encode
|
||||
// any `SyntaxContext`s that might be used.
|
||||
i = self.position();
|
||||
let (syntax_contexts, expn_data) = self.encode_hygiene();
|
||||
let (syntax_contexts, expn_data, expn_hashes) = self.encode_hygiene();
|
||||
let hygiene_bytes = self.position() - i;
|
||||
|
||||
// Encode source_map. This needs to be done last,
|
||||
|
@ -701,6 +701,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
tables,
|
||||
syntax_contexts,
|
||||
expn_data,
|
||||
expn_hashes,
|
||||
});
|
||||
|
||||
let total_bytes = self.position();
|
||||
|
@ -1583,23 +1584,29 @@ impl EncodeContext<'a, 'tcx> {
|
|||
self.lazy(foreign_modules.iter().map(|(_, m)| m).cloned())
|
||||
}
|
||||
|
||||
fn encode_hygiene(&mut self) -> (SyntaxContextTable, ExpnDataTable) {
|
||||
fn encode_hygiene(&mut self) -> (SyntaxContextTable, ExpnDataTable, ExpnHashTable) {
|
||||
let mut syntax_contexts: TableBuilder<_, _> = Default::default();
|
||||
let mut expn_data_table: TableBuilder<_, _> = Default::default();
|
||||
let mut expn_hash_table: TableBuilder<_, _> = Default::default();
|
||||
|
||||
let _: Result<(), !> = self.hygiene_ctxt.encode(
|
||||
&mut (&mut *self, &mut syntax_contexts, &mut expn_data_table),
|
||||
|(this, syntax_contexts, _), index, ctxt_data| {
|
||||
&mut (&mut *self, &mut syntax_contexts, &mut expn_data_table, &mut expn_hash_table),
|
||||
|(this, syntax_contexts, _, _), index, ctxt_data| {
|
||||
syntax_contexts.set(index, this.lazy(ctxt_data));
|
||||
Ok(())
|
||||
},
|
||||
|(this, _, expn_data_table), index, expn_data| {
|
||||
|(this, _, expn_data_table, expn_hash_table), index, expn_data, hash| {
|
||||
expn_data_table.set(index, this.lazy(expn_data));
|
||||
expn_hash_table.set(index, this.lazy(hash));
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
|
||||
(syntax_contexts.encode(&mut self.opaque), expn_data_table.encode(&mut self.opaque))
|
||||
(
|
||||
syntax_contexts.encode(&mut self.opaque),
|
||||
expn_data_table.encode(&mut self.opaque),
|
||||
expn_hash_table.encode(&mut self.opaque),
|
||||
)
|
||||
}
|
||||
|
||||
fn encode_proc_macros(&mut self) -> Option<ProcMacroData> {
|
||||
|
|
|
@ -21,7 +21,7 @@ use rustc_session::config::SymbolManglingVersion;
|
|||
use rustc_span::edition::Edition;
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::{self, ExpnData, ExpnId, Span};
|
||||
use rustc_span::{self, ExpnData, ExpnHash, ExpnId, Span};
|
||||
use rustc_target::spec::{PanicStrategy, TargetTriple};
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
@ -171,6 +171,7 @@ macro_rules! Lazy {
|
|||
|
||||
type SyntaxContextTable = Lazy<Table<u32, Lazy<SyntaxContextData>>>;
|
||||
type ExpnDataTable = Lazy<Table<u32, Lazy<ExpnData>>>;
|
||||
type ExpnHashTable = Lazy<Table<u32, Lazy<ExpnHash>>>;
|
||||
|
||||
#[derive(MetadataEncodable, MetadataDecodable)]
|
||||
crate struct ProcMacroData {
|
||||
|
@ -226,6 +227,7 @@ crate struct CrateRoot<'tcx> {
|
|||
|
||||
syntax_contexts: SyntaxContextTable,
|
||||
expn_data: ExpnDataTable,
|
||||
expn_hashes: ExpnHashTable,
|
||||
|
||||
source_map: Lazy<[rustc_span::SourceFile]>,
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue