diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index c4db61842a584..37f9bc7dd6f54 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -21,6 +21,7 @@ use metadata::{creader, cstore, filesearch}; use metadata; use middle::{trans, freevars, kind, ty, typeck, lint, astencode}; use middle; +use util::common::time; use util::ppaux; use core::int; @@ -32,7 +33,6 @@ use core::vec; use std::getopts::groups::{optopt, optmulti, optflag, optflagopt, getopts}; use std::getopts::{opt_present}; use std::getopts; -use std; use syntax::ast; use syntax::attr; use syntax::codemap; @@ -164,16 +164,6 @@ pub fn parse_input(sess: Session, +cfg: ast::crate_cfg, input: input) } } -pub fn time(do_it: bool, what: ~str, thunk: &fn() -> T) -> T { - if !do_it { return thunk(); } - let start = std::time::precise_time_s(); - let rv = thunk(); - let end = std::time::precise_time_s(); - io::stdout().write_str(fmt!("time: %3.3f s\t%s\n", - end - start, what)); - rv -} - #[deriving_eq] pub enum compile_upto { cu_parse, @@ -254,11 +244,9 @@ pub fn compile_rest(sess: Session, cfg: ast::crate_cfg, let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars, region_map, rp_set, lang_items, crate); - let (method_map, vtable_map) = - time(time_passes, ~"typechecking", || - typeck::check_crate(ty_cx, - trait_map, - crate)); + // passes are timed inside typeck + let (method_map, vtable_map) = typeck::check_crate( + ty_cx, trait_map, crate); // These next two const passes can probably be merged time(time_passes, ~"const marking", || diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 6e86bbca0d1c3..2a705a8feb8b8 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -28,7 +28,7 @@ use core::result::{Result, Ok, Err}; use core::result; use core::uint; use core::vec; -use std::oldmap::HashMap; +use core::hashmap::linear::LinearSet; use syntax::ast; use syntax::ast_util; use syntax::codemap::span; @@ -234,14 +234,14 @@ pub fn lookup_vtable(vcx: &VtableContext, _ => { let mut found = ~[]; - let mut impls_seen = HashMap(); + let mut impls_seen = LinearSet::new(); match vcx.ccx.coherence_info.extension_methods.find(&trait_id) { None => { // Nothing found. Continue. } Some(implementations) => { - let implementations: &mut ~[@Impl] = implementations; + let implementations: &mut ~[@Impl] = *implementations; // implementations is the list of all impls in scope for // trait_ty. (Usually, there's just one.) for uint::range(0, implementations.len()) |i| { @@ -250,10 +250,10 @@ pub fn lookup_vtable(vcx: &VtableContext, // im is one specific impl of trait_ty. // First, ensure we haven't processed this impl yet. - if impls_seen.contains_key(&im.did) { + if impls_seen.contains(&im.did) { loop; } - impls_seen.insert(im.did, ()); + impls_seen.insert(im.did); // ty::impl_traits gives us the list of all // traits that im implements. Again, usually diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 699b8ad74e4ce..a9d00eb985b31 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -56,7 +56,7 @@ use syntax::visit::{visit_mod}; use util::ppaux::ty_to_str; use core::result::Ok; -use core::hashmap::linear::LinearSet; +use core::hashmap::linear::{LinearMap, LinearSet}; use core::uint; use std::oldmap::HashMap; @@ -142,18 +142,17 @@ pub fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo { pub struct CoherenceInfo { // Contains implementations of methods that are inherent to a type. // Methods in these implementations don't need to be exported. - inherent_methods: HashMap, + inherent_methods: @mut LinearMap, // Contains implementations of methods associated with a trait. For these, // the associated trait must be imported at the call site. - extension_methods: HashMap, - + extension_methods: @mut LinearMap, } pub fn CoherenceInfo() -> CoherenceInfo { CoherenceInfo { - inherent_methods: HashMap(), - extension_methods: HashMap(), + inherent_methods: @mut LinearMap::new(), + extension_methods: @mut LinearMap::new(), } } @@ -380,7 +379,7 @@ pub impl CoherenceChecker { .insert(base_def_id, implementation_list); } Some(existing_implementation_list) => { - implementation_list = existing_implementation_list; + implementation_list = *existing_implementation_list; } } @@ -397,7 +396,7 @@ pub impl CoherenceChecker { .insert(trait_id, implementation_list); } Some(existing_implementation_list) => { - implementation_list = existing_implementation_list; + implementation_list = *existing_implementation_list; } } @@ -472,7 +471,7 @@ pub impl CoherenceChecker { match extension_methods.find(&trait_def_id) { Some(impls) => { - let impls: &mut ~[@Impl] = impls; + let impls: &mut ~[@Impl] = *impls; for uint::range(0, impls.len()) |i| { f(impls[i]); } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index ed1a3d33f4cc1..1787c733ed54b 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -53,6 +53,7 @@ use core::prelude::*; use middle::resolve; use middle::ty::{ty_param_substs_and_ty, vstore_uniq}; use middle::ty; +use util::common::time; use util::ppaux; use core::result; @@ -329,6 +330,7 @@ pub fn check_crate(tcx: ty::ctxt, trait_map: resolve::TraitMap, crate: @ast::crate) -> (method_map, vtable_map) { + let time_passes = tcx.sess.time_passes(); let ccx = @mut CrateCtxt { trait_map: trait_map, method_map: oldmap::HashMap(), @@ -336,10 +338,16 @@ pub fn check_crate(tcx: ty::ctxt, coherence_info: @coherence::CoherenceInfo(), tcx: tcx }; - collect::collect_item_types(ccx, crate); - coherence::check_coherence(ccx, crate); - check::check_item_types(ccx, crate); + time(time_passes, ~"type collecting", || + collect::collect_item_types(ccx, crate)); + + time(time_passes, ~"method resolution", || + coherence::check_coherence(ccx, crate)); + + time(time_passes, ~"type checking", || + check::check_item_types(ccx, crate)); + check_for_main_fn(ccx); tcx.sess.abort_if_errors(); (ccx.method_map, ccx.vtable_map) diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index c7945f74f55a5..1cd3982c7e84b 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -16,6 +16,16 @@ use syntax::visit; use core::str; use std::oldmap::HashMap; +use std; + +pub fn time(do_it: bool, what: ~str, thunk: &fn() -> T) -> T { + if !do_it { return thunk(); } + let start = std::time::precise_time_s(); + let rv = thunk(); + let end = std::time::precise_time_s(); + io::println(fmt!("time: %3.3f s\t%s", end - start, what)); + rv +} pub fn indent(op: &fn() -> R) -> R { // Use in conjunction with the log post-processor like `src/etc/indenter`