Skip to content

Commit 0b4f268

Browse files
committed
auto merge of #5470 : sanxiyn/rust/remove-oldmap-2, r=sanxiyn
Referencing #4986.
2 parents 1fa2b99 + e2b9cdd commit 0b4f268

File tree

5 files changed

+38
-33
lines changed

5 files changed

+38
-33
lines changed

src/librustc/driver/driver.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use metadata::{creader, cstore, filesearch};
2121
use metadata;
2222
use middle::{trans, freevars, kind, ty, typeck, lint, astencode};
2323
use middle;
24+
use util::common::time;
2425
use util::ppaux;
2526

2627
use core::int;
@@ -32,7 +33,6 @@ use core::vec;
3233
use std::getopts::groups::{optopt, optmulti, optflag, optflagopt, getopts};
3334
use std::getopts::{opt_present};
3435
use std::getopts;
35-
use std;
3636
use syntax::ast;
3737
use syntax::attr;
3838
use syntax::codemap;
@@ -161,16 +161,6 @@ pub fn parse_input(sess: Session, +cfg: ast::crate_cfg, input: input)
161161
}
162162
}
163163

164-
pub fn time<T>(do_it: bool, what: ~str, thunk: &fn() -> T) -> T {
165-
if !do_it { return thunk(); }
166-
let start = std::time::precise_time_s();
167-
let rv = thunk();
168-
let end = std::time::precise_time_s();
169-
io::stdout().write_str(fmt!("time: %3.3f s\t%s\n",
170-
end - start, what));
171-
rv
172-
}
173-
174164
#[deriving_eq]
175165
pub enum compile_upto {
176166
cu_parse,
@@ -251,11 +241,9 @@ pub fn compile_rest(sess: Session, cfg: ast::crate_cfg,
251241
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
252242
region_map, rp_set, lang_items, crate);
253243

254-
let (method_map, vtable_map) =
255-
time(time_passes, ~"typechecking", ||
256-
typeck::check_crate(ty_cx,
257-
trait_map,
258-
crate));
244+
// passes are timed inside typeck
245+
let (method_map, vtable_map) = typeck::check_crate(
246+
ty_cx, trait_map, crate);
259247

260248
// These next two const passes can probably be merged
261249
time(time_passes, ~"const marking", ||

src/librustc/middle/typeck/check/vtable.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use core::result::{Result, Ok, Err};
2828
use core::result;
2929
use core::uint;
3030
use core::vec;
31-
use std::oldmap::HashMap;
31+
use core::hashmap::linear::LinearSet;
3232
use syntax::ast;
3333
use syntax::ast_util;
3434
use syntax::codemap::span;
@@ -234,14 +234,14 @@ pub fn lookup_vtable(vcx: &VtableContext,
234234
_ => {
235235
let mut found = ~[];
236236
237-
let mut impls_seen = HashMap();
237+
let mut impls_seen = LinearSet::new();
238238
239239
match vcx.ccx.coherence_info.extension_methods.find(&trait_id) {
240240
None => {
241241
// Nothing found. Continue.
242242
}
243243
Some(implementations) => {
244-
let implementations: &mut ~[@Impl] = implementations;
244+
let implementations: &mut ~[@Impl] = *implementations;
245245
// implementations is the list of all impls in scope for
246246
// trait_ty. (Usually, there's just one.)
247247
for uint::range(0, implementations.len()) |i| {
@@ -250,10 +250,10 @@ pub fn lookup_vtable(vcx: &VtableContext,
250250
// im is one specific impl of trait_ty.
251251
252252
// First, ensure we haven't processed this impl yet.
253-
if impls_seen.contains_key(&im.did) {
253+
if impls_seen.contains(&im.did) {
254254
loop;
255255
}
256-
impls_seen.insert(im.did, ());
256+
impls_seen.insert(im.did);
257257
258258
// ty::impl_traits gives us the list of all
259259
// traits that im implements. Again, usually

src/librustc/middle/typeck/coherence.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use syntax::visit::{visit_mod};
5656
use util::ppaux::ty_to_str;
5757

5858
use core::result::Ok;
59-
use core::hashmap::linear::LinearSet;
59+
use core::hashmap::linear::{LinearMap, LinearSet};
6060
use core::uint;
6161
use std::oldmap::HashMap;
6262

@@ -142,18 +142,17 @@ pub fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
142142
pub struct CoherenceInfo {
143143
// Contains implementations of methods that are inherent to a type.
144144
// Methods in these implementations don't need to be exported.
145-
inherent_methods: HashMap<def_id,@mut ~[@Impl]>,
145+
inherent_methods: @mut LinearMap<def_id, @mut ~[@Impl]>,
146146
147147
// Contains implementations of methods associated with a trait. For these,
148148
// the associated trait must be imported at the call site.
149-
extension_methods: HashMap<def_id,@mut ~[@Impl]>,
150-
149+
extension_methods: @mut LinearMap<def_id, @mut ~[@Impl]>,
151150
}
152151
153152
pub fn CoherenceInfo() -> CoherenceInfo {
154153
CoherenceInfo {
155-
inherent_methods: HashMap(),
156-
extension_methods: HashMap(),
154+
inherent_methods: @mut LinearMap::new(),
155+
extension_methods: @mut LinearMap::new(),
157156
}
158157
}
159158
@@ -380,7 +379,7 @@ pub impl CoherenceChecker {
380379
.insert(base_def_id, implementation_list);
381380
}
382381
Some(existing_implementation_list) => {
383-
implementation_list = existing_implementation_list;
382+
implementation_list = *existing_implementation_list;
384383
}
385384
}
386385

@@ -397,7 +396,7 @@ pub impl CoherenceChecker {
397396
.insert(trait_id, implementation_list);
398397
}
399398
Some(existing_implementation_list) => {
400-
implementation_list = existing_implementation_list;
399+
implementation_list = *existing_implementation_list;
401400
}
402401
}
403402

@@ -472,7 +471,7 @@ pub impl CoherenceChecker {
472471

473472
match extension_methods.find(&trait_def_id) {
474473
Some(impls) => {
475-
let impls: &mut ~[@Impl] = impls;
474+
let impls: &mut ~[@Impl] = *impls;
476475
for uint::range(0, impls.len()) |i| {
477476
f(impls[i]);
478477
}

src/librustc/middle/typeck/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use core::prelude::*;
5353
use middle::resolve;
5454
use middle::ty::{ty_param_substs_and_ty, vstore_uniq};
5555
use middle::ty;
56+
use util::common::time;
5657
use util::ppaux;
5758

5859
use core::result;
@@ -329,17 +330,24 @@ pub fn check_crate(tcx: ty::ctxt,
329330
trait_map: resolve::TraitMap,
330331
crate: @ast::crate)
331332
-> (method_map, vtable_map) {
333+
let time_passes = tcx.sess.time_passes();
332334
let ccx = @mut CrateCtxt {
333335
trait_map: trait_map,
334336
method_map: oldmap::HashMap(),
335337
vtable_map: oldmap::HashMap(),
336338
coherence_info: @coherence::CoherenceInfo(),
337339
tcx: tcx
338340
};
339-
collect::collect_item_types(ccx, crate);
340-
coherence::check_coherence(ccx, crate);
341341

342-
check::check_item_types(ccx, crate);
342+
time(time_passes, ~"type collecting", ||
343+
collect::collect_item_types(ccx, crate));
344+
345+
time(time_passes, ~"method resolution", ||
346+
coherence::check_coherence(ccx, crate));
347+
348+
time(time_passes, ~"type checking", ||
349+
check::check_item_types(ccx, crate));
350+
343351
check_for_main_fn(ccx);
344352
tcx.sess.abort_if_errors();
345353
(ccx.method_map, ccx.vtable_map)

src/librustc/util/common.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ use syntax::visit;
1616

1717
use core::str;
1818
use std::oldmap::HashMap;
19+
use std;
20+
21+
pub fn time<T>(do_it: bool, what: ~str, thunk: &fn() -> T) -> T {
22+
if !do_it { return thunk(); }
23+
let start = std::time::precise_time_s();
24+
let rv = thunk();
25+
let end = std::time::precise_time_s();
26+
io::println(fmt!("time: %3.3f s\t%s", end - start, what));
27+
rv
28+
}
1929

2030
pub fn indent<R>(op: &fn() -> R) -> R {
2131
// Use in conjunction with the log post-processor like `src/etc/indenter`

0 commit comments

Comments
 (0)