Skip to content

Commit 3919374

Browse files
committed
Auto merge of #59953 - eddyb:soa-metadata, r=<try>
rustc_metadata: replace Entry table with one table for each of its fields (AoS -> SoA). In #59789 (comment) I noticed that for many cross-crate queries (e.g. `predicates_of(def_id)`), we were deserializing the `rustc_metadata::schema::Entry` for `def_id` *only* to read one field (i.e. `predicates`). But there are several such queries, and `Entry` is not particularly small (in terms of number of fields, the encoding itself is quite compact), so there is a large (and unnecessary) constant factor. This PR replaces the (random-access) array¹ of `Entry` structures ("AoS"), with many separate arrays¹, one for each field that used to be in `Entry` ("SoA"), resulting in the ability to read individual fields separately, with negligible time overhead (in thoery), and some size overhead (as these arrays are not sparse). For stage1 `libcore`'s metadata blob, the size overhead is `8.44%`, and I have another commit (not initially included in this PR because I want to do perf runs with both) that brings it down to `5.88%`. ¹(in the source, these arrays are called "tables", but perhaps they could use a better name)
2 parents 0085672 + 1ab0e24 commit 3919374

11 files changed

+1306
-1732
lines changed

src/librustc_metadata/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a> CrateLoader<'a> {
162162

163163
fn verify_no_symbol_conflicts(&self,
164164
span: Span,
165-
root: &CrateRoot) {
165+
root: &CrateRoot<'_>) {
166166
// Check for (potential) conflicts with the local crate
167167
if self.local_crate_name == root.name &&
168168
self.sess.local_crate_disambiguator() == root.disambiguator {
@@ -467,7 +467,7 @@ impl<'a> CrateLoader<'a> {
467467
// Go through the crate metadata and load any crates that it references
468468
fn resolve_crate_deps(&mut self,
469469
root: &Option<CratePaths>,
470-
crate_root: &CrateRoot,
470+
crate_root: &CrateRoot<'_>,
471471
metadata: &MetadataBlob,
472472
krate: CrateNum,
473473
span: Span,
@@ -573,7 +573,7 @@ impl<'a> CrateLoader<'a> {
573573
/// implemented as dynamic libraries, but we have a possible future where
574574
/// custom derive (and other macro-1.1 style features) are implemented via
575575
/// executables and custom IPC.
576-
fn load_derive_macros(&mut self, root: &CrateRoot, dylib: Option<PathBuf>, span: Span)
576+
fn load_derive_macros(&mut self, root: &CrateRoot<'_>, dylib: Option<PathBuf>, span: Span)
577577
-> Vec<(ast::Name, Lrc<SyntaxExtension>)> {
578578
use std::{env, mem};
579579
use crate::dynamic_lib::DynamicLibrary;

src/librustc_metadata/cstore.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ pub struct CrateMetadata {
6464
/// Used for decoding interpret::AllocIds in a cached & thread-safe manner.
6565
pub alloc_decoding_state: AllocDecodingState,
6666

67-
pub root: schema::CrateRoot,
67+
// NOTE(eddyb) we pass `'static` to a `'tcx` parameter because this
68+
// lifetime is only used behind `Lazy`, and therefore acts like an
69+
// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
70+
// is being used to decode those values.
71+
pub root: schema::CrateRoot<'static>,
6872

6973
/// For each public item in this crate, we encode a key. When the
7074
/// crate is loaded, we read all the keys and put them in this
@@ -73,7 +77,7 @@ pub struct CrateMetadata {
7377
/// compilation support.
7478
pub def_path_table: Lrc<DefPathTable>,
7579

76-
pub trait_impls: FxHashMap<(u32, DefIndex), schema::LazySeq<DefIndex>>,
80+
pub trait_impls: FxHashMap<(u32, DefIndex), schema::Lazy<[DefIndex]>>,
7781

7882
pub dep_kind: Lock<DepKind>,
7983
pub source: CrateSource,

src/librustc_metadata/cstore_impl.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
244244

245245
used_crate_source => { Lrc::new(cdata.source.clone()) }
246246

247-
exported_symbols => {
248-
let cnum = cdata.cnum;
249-
assert!(cnum != LOCAL_CRATE);
250-
251-
Arc::new(cdata.exported_symbols(tcx))
252-
}
247+
exported_symbols => { Arc::new(cdata.exported_symbols(tcx)) }
253248
}
254249

255250
pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {

0 commit comments

Comments
 (0)