rustc: Change smallintmap to use an ivec and use it for the node type table. 3x typechecking speedup.

This commit is contained in:
Patrick Walton 2011-06-19 18:02:37 -07:00
parent 8cdef277b2
commit 3f7380ccec
4 changed files with 20 additions and 28 deletions

View File

@ -352,7 +352,7 @@ type type_store = interner::interner[raw_t];
type ty_param_substs_opt_and_ty = tup(option::t[vec[ty::t]], ty::t);
type node_type_table =
@mutable vec[mutable option::t[ty::ty_param_substs_opt_and_ty]];
@smallintmap::smallintmap[ty::ty_param_substs_opt_and_ty];
fn populate_type_store(&ctxt cx) {
intern(cx, ty_nil, none[str]);
@ -394,9 +394,8 @@ fn mk_rcache() -> creader_cache {
}
fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs) -> ctxt {
let vec[mutable option::t[ty::ty_param_substs_opt_and_ty]] ntt_sub =
[mutable ];
let node_type_table ntt = @mutable ntt_sub;
let node_type_table ntt =
@smallintmap::mk[ty::ty_param_substs_opt_and_ty]();
auto tcache = new_def_hash[ty::ty_param_count_and_ty]();
auto items = new_def_hash[any_item]();
auto ts = @interner::mk[raw_t](hash_raw_ty, eq_raw_ty);
@ -1597,7 +1596,7 @@ fn ann_to_ty_param_substs_opt_and_ty(&ctxt cx, &ast::ann ann) ->
ty_param_substs_opt_and_ty {
// Pull out the node type table.
alt ({ cx.node_types.(ann.id) }) {
alt (smallintmap::find(*cx.node_types, ann.id)) {
case (none) {
cx.sess.bug("ann_to_ty_param_substs_opt_and_ty() called on an " +
"untyped node");

View File

@ -42,6 +42,7 @@ import std::option;
import std::option::none;
import std::option::some;
import std::option::from_maybe;
import std::smallintmap;
import middle::tstate::ann::ts_ann;
type ty_table = hashmap[ast::def_id, ty::t];
@ -385,12 +386,7 @@ fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast::ty ast_ty) -> ty::t {
mod write {
fn inner(&node_type_table ntt, uint node_id,
&ty_param_substs_opt_and_ty tpot) {
auto ntt_ = *ntt;
vec::grow_set(ntt_,
node_id,
none[ty_param_substs_opt_and_ty],
some[ty_param_substs_opt_and_ty](tpot));
*ntt = ntt_;
smallintmap::insert(*ntt, node_id, tpot);
}
// Writes a type parameter count and type pair into the node type table.
@ -1173,13 +1169,6 @@ fn replace_expr_type(&@fn_ctxt fcx, &@ast::expr expr,
write::ty_fixup(fcx, ty::expr_ann(expr).id, tup(new_tps, new_tyt._1));
}
fn replace_node_type_only(&ty::ctxt tcx, uint fixup, ty::t new_t) {
auto fixup_opt = tcx.node_types.(fixup);
auto tps = option::get[ty::ty_param_substs_opt_and_ty](fixup_opt)._0;
tcx.node_types.(fixup) =
some[ty::ty_param_substs_opt_and_ty](tup(tps, new_t));
}
// AST fragment checking
fn check_lit(@crate_ctxt ccx, &@ast::lit lit) -> ty::t {

View File

@ -2,6 +2,7 @@
import option::none;
import option::some;
import uint::next_power_of_two;
type operator2[T,U,V] = fn(&T, &U) -> V;
@ -110,7 +111,7 @@ fn slice_mut[T](&T[mutable?] v, uint start, uint end) -> T[mutable] {
/// Expands the given vector in-place by appending `n` copies of `initval`.
fn grow[T](&mutable T[] v, uint n, &T initval) {
reserve(v, len(v) + n);
reserve(v, next_power_of_two(len(v) + n));
let uint i = 0u;
while (i < n) {
v += ~[initval];
@ -120,7 +121,7 @@ fn grow[T](&mutable T[] v, uint n, &T initval) {
// TODO: Remove me once we have slots.
fn grow_mut[T](&mutable T[mutable] v, uint n, &T initval) {
reserve(v, len(v) + n);
reserve(v, next_power_of_two(len(v) + n));
let uint i = 0u;
while (i < n) {
v += ~[mutable initval];
@ -131,7 +132,7 @@ fn grow_mut[T](&mutable T[mutable] v, uint n, &T initval) {
/// Calls `f` `n` times and appends the results of these calls to the given
/// vector.
fn grow_fn[T](&mutable T[] v, uint n, fn(uint)->T init_fn) {
reserve(v, len(v) + n);
reserve(v, next_power_of_two(len(v) + n));
let uint i = 0u;
while (i < n) {
v += ~[init_fn(i)];

View File

@ -5,19 +5,21 @@
import option::none;
import option::some;
type smallintmap[T] = rec(mutable vec[mutable option::t[T]] v);
// FIXME: Should not be @; there's a bug somewhere in rustc that requires this
// to be.
type smallintmap[T] = @rec(mutable (option::t[T])[mutable] v);
fn mk[T]() -> smallintmap[T] {
let vec[mutable option::t[T]] v = [mutable ];
ret rec(mutable v=v);
let (option::t[T])[mutable] v = ~[mutable];
ret @rec(mutable v=v);
}
fn insert[T](&smallintmap[T] m, uint key, &T val) {
vec::grow_set[option::t[T]](m.v, key, none[T], some[T](val));
ivec::grow_set[option::t[T]](m.v, key, none[T], some[T](val));
}
fn find[T](&smallintmap[T] m, uint key) -> option::t[T] {
if (key < vec::len[option::t[T]](m.v)) { ret m.v.(key); }
if (key < ivec::len[option::t[T]](m.v)) { ret m.v.(key); }
ret none[T];
}
@ -36,7 +38,8 @@ fn contains_key[T](&smallintmap[T] m, uint key) -> bool {
}
fn truncate[T](&smallintmap[T] m, uint len) {
m.v = vec::slice_mut[option::t[T]](m.v, 0u, len);
m.v = ivec::slice_mut[option::t[T]](m.v, 0u, len);
}
fn max_key[T](&smallintmap[T] m) -> uint { ret vec::len[option::t[T]](m.v); }
fn max_key[T](&smallintmap[T] m) -> uint { ret ivec::len[option::t[T]](m.v); }