Skip to content

Commit cde09e7

Browse files
author
Ariel Ben-Yehuda
committed
rewrite metadata indexing
this improves the compilation time for small crates by ~20%
1 parent fcad49e commit cde09e7

File tree

9 files changed

+322
-244
lines changed

9 files changed

+322
-244
lines changed

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#![feature(rustc_diagnostic_macros)]
5252
#![feature(rustc_private)]
5353
#![feature(scoped_tls)]
54-
#![feature(slice_bytes)]
5554
#![feature(slice_splits)]
5655
#![feature(slice_patterns)]
5756
#![feature(staged_api)]

src/librustc/metadata/common.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ pub const tag_items_data_item_is_tuple_struct_ctor: usize = 0x29;
4545

4646
pub const tag_index: usize = 0x2a;
4747

48-
pub const tag_index_buckets: usize = 0x2b;
49-
50-
pub const tag_index_buckets_bucket: usize = 0x2c;
51-
52-
pub const tag_index_buckets_bucket_elt: usize = 0x2d;
53-
54-
pub const tag_index_table: usize = 0x2e;
48+
// GAP 0x2b, 0x2c, 0x2d, 0x2e
5549

5650
pub const tag_meta_item_name_value: usize = 0x2f;
5751

src/librustc/metadata/creader.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ impl<'a> CrateReader<'a> {
304304
let cmeta = Rc::new(cstore::crate_metadata {
305305
name: name.to_string(),
306306
local_path: RefCell::new(SmallVector::zero()),
307+
index: decoder::load_index(metadata.as_slice()),
307308
data: metadata,
308309
cnum_map: RefCell::new(cnum_map),
309310
cnum: cnum,
@@ -521,7 +522,7 @@ impl<'a> CrateReader<'a> {
521522
}
522523

523524
let registrar = decoder::get_plugin_registrar_fn(ekrate.metadata.as_slice())
524-
.map(|id| decoder::get_symbol(ekrate.metadata.as_slice(), id));
525+
.map(|id| decoder::get_symbol_from_buf(ekrate.metadata.as_slice(), id));
525526

526527
match (ekrate.dylib.as_ref(), registrar) {
527528
(Some(dylib), Some(reg)) => Some((dylib.to_path_buf(), reg)),

src/librustc/metadata/csearch.rs

+3-33
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,18 @@
1111
// Searching for information from the cstore
1212

1313
use front::map as ast_map;
14-
use metadata::common::*;
1514
use metadata::cstore;
1615
use metadata::decoder;
1716
use metadata::inline::InlinedItem;
1817
use middle::def_id::DefId;
1918
use middle::lang_items;
2019
use middle::ty;
20+
use util::nodemap::FnvHashMap;
2121

22-
use rbml;
23-
use rbml::reader;
2422
use std::rc::Rc;
2523
use syntax::ast;
2624
use rustc_front::attr;
2725
use rustc_front::hir;
28-
use syntax::diagnostic::expect;
29-
30-
use std::collections::hash_map::HashMap;
3126

3227
#[derive(Copy, Clone)]
3328
pub struct MethodInfo {
@@ -38,7 +33,7 @@ pub struct MethodInfo {
3833

3934
pub fn get_symbol(cstore: &cstore::CStore, def: DefId) -> String {
4035
let cdata = cstore.get_crate_data(def.krate);
41-
decoder::get_symbol(cdata.data(), def.node)
36+
decoder::get_symbol(&cdata, def.node)
4237
}
4338

4439
/// Iterates over all the language items in the given crate.
@@ -201,7 +196,7 @@ pub fn get_struct_field_names(cstore: &cstore::CStore, def: DefId) -> Vec<ast::N
201196
decoder::get_struct_field_names(&cstore.intr, &*cdata, def.node)
202197
}
203198

204-
pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: DefId) -> HashMap<ast::NodeId,
199+
pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: DefId) -> FnvHashMap<ast::NodeId,
205200
Vec<hir::Attribute>> {
206201
let cdata = cstore.get_crate_data(def.krate);
207202
decoder::get_struct_field_attrs(&*cdata)
@@ -243,31 +238,6 @@ pub fn get_super_predicates<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId)
243238
decoder::get_super_predicates(&*cdata, def.node, tcx)
244239
}
245240

246-
pub fn get_field_type<'tcx>(tcx: &ty::ctxt<'tcx>, class_id: DefId,
247-
def: DefId) -> ty::TypeScheme<'tcx> {
248-
let cstore = &tcx.sess.cstore;
249-
let cdata = cstore.get_crate_data(class_id.krate);
250-
let all_items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items);
251-
let class_doc = expect(tcx.sess.diagnostic(),
252-
decoder::maybe_find_item(class_id.node, all_items),
253-
|| {
254-
(format!("get_field_type: class ID {:?} not found",
255-
class_id)).to_string()
256-
});
257-
let the_field = expect(tcx.sess.diagnostic(),
258-
decoder::maybe_find_item(def.node, class_doc),
259-
|| {
260-
(format!("get_field_type: in class {:?}, field ID {:?} not found",
261-
class_id,
262-
def)).to_string()
263-
});
264-
let ty = decoder::item_type(def, the_field, tcx, &*cdata);
265-
ty::TypeScheme {
266-
generics: ty::Generics::empty(),
267-
ty: ty,
268-
}
269-
}
270-
271241
pub fn get_impl_polarity<'tcx>(tcx: &ty::ctxt<'tcx>,
272242
def: DefId)
273243
-> Option<hir::ImplPolarity>

src/librustc/metadata/cstore.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use self::LinkagePreference::*;
1818
pub use self::NativeLibraryKind::*;
1919

2020
use back::svh::Svh;
21-
use metadata::{creader, decoder, loader};
21+
use metadata::{creader, decoder, index, loader};
2222
use session::search_paths::PathKind;
2323
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
2424

@@ -65,6 +65,7 @@ pub struct crate_metadata {
6565
pub codemap_import_info: RefCell<Vec<ImportedFileMap>>,
6666
pub span: codemap::Span,
6767
pub staged_api: bool,
68+
pub index: index::Index,
6869

6970
/// Flag if this crate is required by an rlib version of this crate, or in
7071
/// other words whether it was explicitly linked to. An example of a crate

0 commit comments

Comments
 (0)