Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove oldmaps, season 2 #5470

Merged
merged 4 commits into from
Mar 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -164,16 +164,6 @@ pub fn parse_input(sess: Session, +cfg: ast::crate_cfg, input: input)
}
}

pub fn time<T>(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,
Expand Down Expand Up @@ -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", ||
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/typeck/check/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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| {
Expand All @@ -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
Expand Down
17 changes: 8 additions & 9 deletions src/librustc/middle/typeck/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<def_id,@mut ~[@Impl]>,
inherent_methods: @mut LinearMap<def_id, @mut ~[@Impl]>,

// Contains implementations of methods associated with a trait. For these,
// the associated trait must be imported at the call site.
extension_methods: HashMap<def_id,@mut ~[@Impl]>,

extension_methods: @mut LinearMap<def_id, @mut ~[@Impl]>,
}

pub fn CoherenceInfo() -> CoherenceInfo {
CoherenceInfo {
inherent_methods: HashMap(),
extension_methods: HashMap(),
inherent_methods: @mut LinearMap::new(),
extension_methods: @mut LinearMap::new(),
}
}

Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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]);
}
Expand Down
14 changes: 11 additions & 3 deletions src/librustc/middle/typeck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -329,17 +330,24 @@ 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(),
vtable_map: oldmap::HashMap(),
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)
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ use syntax::visit;

use core::str;
use std::oldmap::HashMap;
use std;

pub fn time<T>(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<R>(op: &fn() -> R) -> R {
// Use in conjunction with the log post-processor like `src/etc/indenter`
Expand Down