librustc: Stop calling each_path
in coherence.
10% win or so for small crates.
This commit is contained in:
parent
4f32a2d854
commit
d9bb78efdf
@ -182,6 +182,9 @@ pub static tag_misc_info_crate_items: uint = 0x80;
|
|||||||
pub static tag_item_method_provided_source: uint = 0x81;
|
pub static tag_item_method_provided_source: uint = 0x81;
|
||||||
pub static tag_item_impl_vtables: uint = 0x82;
|
pub static tag_item_impl_vtables: uint = 0x82;
|
||||||
|
|
||||||
|
pub static tag_impls: uint = 0x83;
|
||||||
|
pub static tag_impls_impl: uint = 0x84;
|
||||||
|
|
||||||
pub struct LinkMeta {
|
pub struct LinkMeta {
|
||||||
name: @str,
|
name: @str,
|
||||||
vers: @str,
|
vers: @str,
|
||||||
|
@ -246,3 +246,11 @@ pub fn get_link_args_for_crate(cstore: @mut cstore::CStore,
|
|||||||
let cdata = cstore::get_crate_data(cstore, crate_num);
|
let cdata = cstore::get_crate_data(cstore, crate_num);
|
||||||
decoder::get_link_args_for_crate(cdata)
|
decoder::get_link_args_for_crate(cdata)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn each_impl(cstore: @mut cstore::CStore,
|
||||||
|
crate_num: ast::CrateNum,
|
||||||
|
callback: &fn(ast::def_id)) {
|
||||||
|
let cdata = cstore::get_crate_data(cstore, crate_num);
|
||||||
|
decoder::each_impl(cdata, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1316,3 +1316,13 @@ pub fn get_link_args_for_crate(cdata: cmd) -> ~[~str] {
|
|||||||
};
|
};
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn each_impl(cdata: cmd, callback: &fn(ast::def_id)) {
|
||||||
|
let impls_doc = reader::get_doc(reader::Doc(cdata.data), tag_impls);
|
||||||
|
let _ = do reader::tagged_docs(impls_doc, tag_impls_impl) |impl_doc| {
|
||||||
|
callback(item_def_id(impl_doc, cdata));
|
||||||
|
true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ use syntax::attr::AttrMetaMethods;
|
|||||||
use syntax::diagnostic::span_handler;
|
use syntax::diagnostic::span_handler;
|
||||||
use syntax::parse::token::special_idents;
|
use syntax::parse::token::special_idents;
|
||||||
use syntax::ast_util;
|
use syntax::ast_util;
|
||||||
|
use syntax::visit::Visitor;
|
||||||
use syntax::visit;
|
use syntax::visit;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
use syntax;
|
use syntax;
|
||||||
@ -72,6 +73,7 @@ struct Stats {
|
|||||||
dep_bytes: uint,
|
dep_bytes: uint,
|
||||||
lang_item_bytes: uint,
|
lang_item_bytes: uint,
|
||||||
link_args_bytes: uint,
|
link_args_bytes: uint,
|
||||||
|
impl_bytes: uint,
|
||||||
misc_bytes: uint,
|
misc_bytes: uint,
|
||||||
item_bytes: uint,
|
item_bytes: uint,
|
||||||
index_bytes: uint,
|
index_bytes: uint,
|
||||||
@ -1221,7 +1223,10 @@ struct EncodeVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl visit::Visitor<()> for EncodeVisitor {
|
impl visit::Visitor<()> for EncodeVisitor {
|
||||||
fn visit_expr(&mut self, ex:@expr, _:()) { my_visit_expr(ex); }
|
fn visit_expr(&mut self, ex:@expr, _:()) {
|
||||||
|
visit::walk_expr(self, ex, ());
|
||||||
|
my_visit_expr(ex);
|
||||||
|
}
|
||||||
fn visit_item(&mut self, i:@item, _:()) {
|
fn visit_item(&mut self, i:@item, _:()) {
|
||||||
visit::walk_item(self, i, ());
|
visit::walk_item(self, i, ());
|
||||||
my_visit_item(i,
|
my_visit_item(i,
|
||||||
@ -1510,6 +1515,41 @@ fn encode_link_args(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
|
|||||||
ebml_w.end_tag();
|
ebml_w.end_tag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ImplVisitor<'self> {
|
||||||
|
ecx: &'self EncodeContext<'self>,
|
||||||
|
ebml_w: &'self mut writer::Encoder,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'self> Visitor<()> for ImplVisitor<'self> {
|
||||||
|
fn visit_item(&mut self, item: @item, _: ()) {
|
||||||
|
match item.node {
|
||||||
|
item_impl(*) => {
|
||||||
|
self.ebml_w.start_tag(tag_impls_impl);
|
||||||
|
encode_def_id(self.ebml_w, local_def(item.id));
|
||||||
|
self.ebml_w.end_tag();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
visit::walk_item(self, item, ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encode_impls(ecx: &EncodeContext,
|
||||||
|
crate: &Crate,
|
||||||
|
ebml_w: &mut writer::Encoder) {
|
||||||
|
ebml_w.start_tag(tag_impls);
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut visitor = ImplVisitor {
|
||||||
|
ecx: ecx,
|
||||||
|
ebml_w: ebml_w,
|
||||||
|
};
|
||||||
|
visit::walk_crate(&mut visitor, crate, ());
|
||||||
|
}
|
||||||
|
|
||||||
|
ebml_w.end_tag();
|
||||||
|
}
|
||||||
|
|
||||||
fn encode_misc_info(ecx: &EncodeContext,
|
fn encode_misc_info(ecx: &EncodeContext,
|
||||||
crate: &Crate,
|
crate: &Crate,
|
||||||
ebml_w: &mut writer::Encoder) {
|
ebml_w: &mut writer::Encoder) {
|
||||||
@ -1574,6 +1614,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
|
|||||||
dep_bytes: 0,
|
dep_bytes: 0,
|
||||||
lang_item_bytes: 0,
|
lang_item_bytes: 0,
|
||||||
link_args_bytes: 0,
|
link_args_bytes: 0,
|
||||||
|
impl_bytes: 0,
|
||||||
misc_bytes: 0,
|
misc_bytes: 0,
|
||||||
item_bytes: 0,
|
item_bytes: 0,
|
||||||
index_bytes: 0,
|
index_bytes: 0,
|
||||||
@ -1632,6 +1673,11 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
|
|||||||
encode_link_args(&ecx, &mut ebml_w);
|
encode_link_args(&ecx, &mut ebml_w);
|
||||||
ecx.stats.link_args_bytes = *wr.pos - i;
|
ecx.stats.link_args_bytes = *wr.pos - i;
|
||||||
|
|
||||||
|
// Encode the def IDs of impls, for coherence checking.
|
||||||
|
i = *wr.pos;
|
||||||
|
encode_impls(&ecx, crate, &mut ebml_w);
|
||||||
|
ecx.stats.impl_bytes = *wr.pos - i;
|
||||||
|
|
||||||
// Encode miscellaneous info.
|
// Encode miscellaneous info.
|
||||||
i = *wr.pos;
|
i = *wr.pos;
|
||||||
encode_misc_info(&ecx, crate, &mut ebml_w);
|
encode_misc_info(&ecx, crate, &mut ebml_w);
|
||||||
@ -1664,6 +1710,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
|
|||||||
printfln!(" dep bytes: %u", ecx.stats.dep_bytes);
|
printfln!(" dep bytes: %u", ecx.stats.dep_bytes);
|
||||||
printfln!(" lang item bytes: %u", ecx.stats.lang_item_bytes);
|
printfln!(" lang item bytes: %u", ecx.stats.lang_item_bytes);
|
||||||
printfln!(" link args bytes: %u", ecx.stats.link_args_bytes);
|
printfln!(" link args bytes: %u", ecx.stats.link_args_bytes);
|
||||||
|
printfln!(" impl bytes: %u", ecx.stats.impl_bytes);
|
||||||
printfln!(" misc bytes: %u", ecx.stats.misc_bytes);
|
printfln!(" misc bytes: %u", ecx.stats.misc_bytes);
|
||||||
printfln!(" item bytes: %u", ecx.stats.item_bytes);
|
printfln!(" item bytes: %u", ecx.stats.item_bytes);
|
||||||
printfln!(" index bytes: %u", ecx.stats.index_bytes);
|
printfln!(" index bytes: %u", ecx.stats.index_bytes);
|
||||||
|
@ -15,10 +15,9 @@
|
|||||||
// each trait in the system to its implementations.
|
// each trait in the system to its implementations.
|
||||||
|
|
||||||
|
|
||||||
use metadata::csearch::{each_path, get_impl_trait};
|
use metadata::csearch::{each_impl, get_impl_trait};
|
||||||
use metadata::csearch;
|
use metadata::csearch;
|
||||||
use metadata::cstore::iter_crate_data;
|
use metadata::cstore::iter_crate_data;
|
||||||
use metadata::decoder::{dl_def, dl_field, dl_impl};
|
|
||||||
use middle::ty::get;
|
use middle::ty::get;
|
||||||
use middle::ty::{lookup_item_type, subst};
|
use middle::ty::{lookup_item_type, subst};
|
||||||
use middle::ty::{substs, t, ty_bool, ty_bot, ty_box, ty_enum, ty_err};
|
use middle::ty::{substs, t, ty_bool, ty_bot, ty_box, ty_enum, ty_err};
|
||||||
@ -680,9 +679,6 @@ impl CoherenceChecker {
|
|||||||
let tcx = self.crate_context.tcx;
|
let tcx = self.crate_context.tcx;
|
||||||
let implementation = @csearch::get_impl(tcx, impl_def_id);
|
let implementation = @csearch::get_impl(tcx, impl_def_id);
|
||||||
|
|
||||||
debug!("coherence: adding impl from external crate: %s",
|
|
||||||
ty::item_path_str(tcx, implementation.did));
|
|
||||||
|
|
||||||
// Make sure we don't visit the same implementation multiple times.
|
// Make sure we don't visit the same implementation multiple times.
|
||||||
if !impls_seen.insert(implementation.did) {
|
if !impls_seen.insert(implementation.did) {
|
||||||
// Skip this one.
|
// Skip this one.
|
||||||
@ -752,15 +748,10 @@ impl CoherenceChecker {
|
|||||||
|
|
||||||
let crate_store = self.crate_context.tcx.sess.cstore;
|
let crate_store = self.crate_context.tcx.sess.cstore;
|
||||||
do iter_crate_data(crate_store) |crate_number, _crate_metadata| {
|
do iter_crate_data(crate_store) |crate_number, _crate_metadata| {
|
||||||
do each_path(crate_store, crate_number) |_, def_like, _| {
|
do each_impl(crate_store, crate_number) |def_id| {
|
||||||
match def_like {
|
assert_eq!(crate_number, def_id.crate);
|
||||||
dl_impl(def_id) => {
|
self.add_external_impl(&mut impls_seen, def_id)
|
||||||
self.add_external_impl(&mut impls_seen, def_id)
|
}
|
||||||
}
|
|
||||||
dl_def(_) | dl_field => (), // Skip this.
|
|
||||||
}
|
|
||||||
true
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ pub struct BorrowRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn try_take_task_borrow_list() -> Option<~[BorrowRecord]> {
|
fn try_take_task_borrow_list() -> Option<~[BorrowRecord]> {
|
||||||
do Local::borrow::<Task, Option<~[BorrowRecord]>> |task| {
|
do Local::borrow |task: &mut Task| {
|
||||||
task.borrow_list.take()
|
task.borrow_list.take()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) {
|
|||||||
};
|
};
|
||||||
let borrows = f(borrows);
|
let borrows = f(borrows);
|
||||||
let borrows = Cell::new(borrows);
|
let borrows = Cell::new(borrows);
|
||||||
do Local::borrow::<Task, ()> |task| {
|
do Local::borrow |task: &mut Task| {
|
||||||
task.borrow_list = Some(borrows.take());
|
task.borrow_list = Some(borrows.take());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -555,7 +555,7 @@ impl Scheduler {
|
|||||||
let current_task: &mut Task = match sched.cleanup_job {
|
let current_task: &mut Task = match sched.cleanup_job {
|
||||||
Some(CleanupJob { task: ref task, _ }) => {
|
Some(CleanupJob { task: ref task, _ }) => {
|
||||||
let task_ptr: *~Task = task;
|
let task_ptr: *~Task = task;
|
||||||
transmute_mut_region(*transmute_mut_unsafe(task))
|
transmute_mut_region(*transmute_mut_unsafe(task_ptr))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
rtabort!("no cleanup job");
|
rtabort!("no cleanup job");
|
||||||
|
Loading…
Reference in New Issue
Block a user