rustc: Use a set-based approach to unification; remove ty_bound_param and ty_local.

Sorry, big perf regression; will fix soon.
This commit is contained in:
Patrick Walton 2011-05-20 18:36:35 -07:00
parent 721c5bbee8
commit ddec6b5f47
10 changed files with 1119 additions and 1198 deletions

View File

@ -125,7 +125,7 @@ fn pretty_print_input(session::session sess, eval::env env, str input,
pp_mode ppm) {
auto def = tup(ast::local_crate, 0);
auto p = front::parser::new_parser(sess, env, def, input, 0u, 0u);
auto crate = front::parser::parse_crate_from_source_file(p);
auto crate = parse_input(sess, p, input);
auto mode;
alt (ppm) {

View File

@ -230,17 +230,6 @@ mod Encode {
}
case (ty::ty_type) {w.write_char('Y');}
case (ty::ty_task) {w.write_char('a');}
// These two don't appear in crate metadata, but are here because
// `hash_ty()` uses this function.
case (ty::ty_bound_param(?id)) {
w.write_char('o');
w.write_str(common::uistr(id));
}
case (ty::ty_local(?def)) {
w.write_char('L');
w.write_str(cx.ds(def));
}
}
}

View File

@ -904,10 +904,6 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
case (ty::ty_param(_)) {
llty = T_i8();
}
case (ty::ty_bound_param(_)) {
cx.tcx.sess.span_err(sp,
"trans::type_of called on ty_bound_param");
}
case (ty::ty_type) { llty = T_ptr(T_tydesc(cx.tn)); }
}
@ -1299,7 +1295,6 @@ fn static_size_of_tag(&@crate_ctxt cx, &span sp, &ty::t t) -> uint {
auto tup_ty = simplify_type(cx, ty::mk_imm_tup(cx.tcx, variant.args));
// Perform any type parameter substitutions.
tup_ty = ty::bind_params_in_type(cx.tcx, tup_ty);
tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty);
// Here we possibly do a recursive call.
@ -1373,10 +1368,8 @@ fn dynamic_size_of(&@block_ctxt cx, ty::t t) -> result {
let vec[ty::t] raw_tys = variant.args;
let vec[ty::t] tys = [];
for (ty::t raw_ty in raw_tys) {
auto t = ty::bind_params_in_type(cx.fcx.lcx.ccx.tcx,
raw_ty);
t = ty::substitute_type_params(cx.fcx.lcx.ccx.tcx, tps,
t);
auto t = ty::substitute_type_params(cx.fcx.lcx.ccx.tcx,
tps, raw_ty);
tys += [t];
}
@ -1553,9 +1546,8 @@ fn GEP_tag(@block_ctxt cx,
auto i = 0;
let vec[ty::t] true_arg_tys = [];
for (ty::t aty in arg_tys) {
auto arg_ty = ty::bind_params_in_type(cx.fcx.lcx.ccx.tcx, aty);
arg_ty = ty::substitute_type_params(cx.fcx.lcx.ccx.tcx, ty_substs,
arg_ty);
auto arg_ty = ty::substitute_type_params(cx.fcx.lcx.ccx.tcx,
ty_substs, aty);
true_arg_tys += [arg_ty];
if (i == ix) {
elem_ty = arg_ty;
@ -2745,10 +2737,8 @@ fn iter_structural_ty_full(&@block_ctxt cx,
auto llfldp_b = rslt.val;
variant_cx = rslt.bcx;
auto ty_subst = ty::bind_params_in_type(
cx.fcx.lcx.ccx.tcx, a.ty);
ty_subst = ty::substitute_type_params(
cx.fcx.lcx.ccx.tcx, tps, ty_subst);
auto ty_subst = ty::substitute_type_params(
cx.fcx.lcx.ccx.tcx, tps, a.ty);
auto llfld_a =
load_if_immediate(variant_cx,
@ -5308,6 +5298,7 @@ fn trans_call(&@block_ctxt cx, &@ast::expr f,
}
auto ret_ty = ty::ann_to_type(cx.fcx.lcx.ccx.tcx, ann);
auto args_res = trans_args(f_res.res.bcx,
llenv, f_res.llobj,
f_res.generic,
@ -7552,6 +7543,7 @@ fn decl_native_fn_and_pair(&@crate_ctxt ccx,
// Declare the wrapper.
auto t = node_ann_type(ccx, ann);
auto wrapper_type = native_fn_wrapper_type(ccx, sp, num_ty_param, t);
let str s = mangle_internal_name_by_path(ccx, path);
let ValueRef wrapper_fn = decl_internal_fastcall_fn(ccx.llmod, s,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -38,3 +38,7 @@ fn truncate[T](&smallintmap[T] m, uint len) {
m.v = vec::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);
}

View File

@ -20,6 +20,12 @@ fn make_set(&ufind ufnd) -> uint {
ret idx;
}
/// Creates sets as necessary to ensure that least `n` sets are present in the
/// data structure.
fn grow(&ufind ufnd, uint n) {
while (set_count(ufnd) < n) { make_set(ufnd); }
}
fn find(&ufind ufnd, uint n) -> uint {
alt (ufnd.nodes.(n)) {
case (none) { ret n; }
@ -37,12 +43,17 @@ fn union(&ufind ufnd, uint m, uint n) {
}
}
fn set_count(&ufind ufnd) -> uint {
ret vec::len[node](ufnd.nodes);
}
// Removes all sets with IDs greater than or equal to the given value.
fn prune(&ufind ufnd, uint n) {
// TODO: Use "slice" once we get rid of "mutable?"
while (n != 0u) {
auto len = vec::len[node](ufnd.nodes);
while (len != n) {
vec::pop[node](ufnd.nodes);
n -= 1u;
len -= 1u;
}
}

View File

@ -12,6 +12,11 @@ fn ne(uint x, uint y) -> bool { ret x != y; }
fn ge(uint x, uint y) -> bool { ret x >= y; }
fn gt(uint x, uint y) -> bool { ret x > y; }
fn max(uint x, uint y) -> uint {
if (x > y) { ret x; }
ret y;
}
iter range(uint lo, uint hi) -> uint {
auto lo_ = lo;
while (lo_ < hi) {

View File

@ -210,7 +210,7 @@ fn unshift[T](&mutable array[T] v, &T t) {
v = res;
}
fn grow[T](&array[T] v, uint n, &T initval) {
fn grow[T](&mutable array[T] v, uint n, &T initval) {
let uint i = n;
while (i > 0u) {
i -= 1u;
@ -218,7 +218,7 @@ fn grow[T](&array[T] v, uint n, &T initval) {
}
}
fn grow_set[T](&vec[mutable T] v, uint index, &T initval, &T val) {
fn grow_set[T](&mutable vec[mutable T] v, uint index, &T initval, &T val) {
auto length = vec::len(v);
if (index >= length) {
grow(v, index - length + 1u, initval);
@ -393,6 +393,12 @@ fn reversed[T](vec[T] v) -> vec[T] {
ret res;
}
/// Truncates the vector to length `new_len`.
/// FIXME: This relies on a typechecker bug (covariance vs. invariance).
fn truncate[T](&mutable vec[mutable? T] v, uint new_len) {
v = slice[T](v, 0u, new_len);
}
// Local Variables:
// mode: rust;
// fill-column: 78;

View File

@ -1,5 +1,4 @@
// error-pattern:unknown syntax expander
fn main() {
#iamnotanextensionthatexists("");
}
}