rustc: Migrate tag variants to interior vectors
This commit is contained in:
parent
52a7c2b78e
commit
5703bd1760
@ -194,27 +194,27 @@ fn get_symbol(session::session sess, ast::def_id def) -> str {
|
||||
ret item_symbol(lookup_item(def._1, data));
|
||||
}
|
||||
|
||||
fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> vec[ty::variant_info] {
|
||||
fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> ty::variant_info[] {
|
||||
auto external_crate_id = def._0;
|
||||
auto data = tcx.sess.get_external_crate(external_crate_id).data;
|
||||
auto items = ebml::get_doc(ebml::new_doc(data), tag_items);
|
||||
auto item = find_item(def._1, items);
|
||||
let vec[ty::variant_info] infos = [];
|
||||
let ty::variant_info[] infos = ~[];
|
||||
auto variant_ids = tag_variant_ids(item, external_crate_id);
|
||||
for (ast::def_id did in variant_ids) {
|
||||
auto item = find_item(did._1, items);
|
||||
auto ctor_ty = item_type(item, external_crate_id, tcx);
|
||||
let vec[ty::t] arg_tys = [];
|
||||
let ty::t[] arg_tys = ~[];
|
||||
alt (ty::struct(tcx, ctor_ty)) {
|
||||
case (ty::ty_fn(_, ?args, _, _, _)) {
|
||||
for (ty::arg a in args) { arg_tys += [a.ty]; }
|
||||
for (ty::arg a in args) { arg_tys += ~[a.ty]; }
|
||||
}
|
||||
case (_) {
|
||||
// Nullary tag variant.
|
||||
|
||||
}
|
||||
}
|
||||
infos += [rec(args=arg_tys, ctor_ty=ctor_ty, id=did)];
|
||||
infos += ~[rec(args=arg_tys, ctor_ty=ctor_ty, id=did)];
|
||||
}
|
||||
ret infos;
|
||||
}
|
||||
|
@ -903,7 +903,7 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
|
||||
|
||||
fn type_of_tag(&@crate_ctxt cx, &span sp, &ast::def_id did, &ty::t t)
|
||||
-> TypeRef {
|
||||
auto degen = vec::len(ty::tag_variants(cx.tcx, did)) == 1u;
|
||||
auto degen = std::ivec::len(ty::tag_variants(cx.tcx, did)) == 1u;
|
||||
if (ty::type_has_dynamic_size(cx.tcx, t)) {
|
||||
if (degen) { ret T_i8(); }
|
||||
else { ret T_opaque_tag(cx.tn); }
|
||||
@ -1351,7 +1351,7 @@ fn dynamic_size_of(&@block_ctxt cx, ty::t t) -> result {
|
||||
for (ty::variant_info variant in variants) {
|
||||
// Perform type substitution on the raw argument types.
|
||||
|
||||
let vec[ty::t] raw_tys = variant.args;
|
||||
let ty::t[] raw_tys = variant.args;
|
||||
let vec[ty::t] tys = [];
|
||||
for (ty::t raw_ty in raw_tys) {
|
||||
auto t =
|
||||
@ -1366,7 +1366,7 @@ fn dynamic_size_of(&@block_ctxt cx, ty::t t) -> result {
|
||||
bcx.build.Store(umax(bcx, this_size, old_max_size), max_size);
|
||||
}
|
||||
auto max_size_val = bcx.build.Load(max_size);
|
||||
auto total_size = if (vec::len(variants) != 1u) {
|
||||
auto total_size = if (std::ivec::len(variants) != 1u) {
|
||||
bcx.build.Add(max_size_val, llsize_of(T_int()))
|
||||
} else { max_size_val };
|
||||
ret rslt(bcx, total_size);
|
||||
@ -2655,7 +2655,7 @@ fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
|
||||
fn iter_variant(@block_ctxt cx, ValueRef a_tup, ValueRef b_tup,
|
||||
&ty::variant_info variant, &ty::t[] tps,
|
||||
&ast::def_id tid, &val_pair_and_ty_fn f) -> result {
|
||||
if (vec::len[ty::t](variant.args) == 0u) {
|
||||
if (std::ivec::len[ty::t](variant.args) == 0u) {
|
||||
ret rslt(cx, C_nil());
|
||||
}
|
||||
auto fn_ty = variant.ctor_ty;
|
||||
@ -2664,12 +2664,10 @@ fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
|
||||
case (ty::ty_fn(_, ?args, _, _, _)) {
|
||||
auto j = 0;
|
||||
for (ty::arg a in args) {
|
||||
auto rslt = GEP_tag(cx, a_tup, tid,
|
||||
variant.id, tps, j);
|
||||
auto rslt = GEP_tag(cx, a_tup, tid, variant.id, tps, j);
|
||||
auto llfldp_a = rslt.val;
|
||||
cx = rslt.bcx;
|
||||
rslt = GEP_tag(cx, b_tup, tid,
|
||||
variant.id, tps, j);
|
||||
rslt = GEP_tag(cx, b_tup, tid, variant.id, tps, j);
|
||||
auto llfldp_b = rslt.val;
|
||||
cx = rslt.bcx;
|
||||
auto ty_subst =
|
||||
@ -2730,7 +2728,7 @@ fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
|
||||
}
|
||||
case (ty::ty_tag(?tid, ?tps)) {
|
||||
auto variants = ty::tag_variants(cx.fcx.lcx.ccx.tcx, tid);
|
||||
auto n_variants = vec::len(variants);
|
||||
auto n_variants = std::ivec::len(variants);
|
||||
|
||||
// Cast the tags to types we can GEP into.
|
||||
if (n_variants == 1u) {
|
||||
@ -4159,8 +4157,8 @@ fn autoderef_lval(&@block_ctxt cx, ValueRef v, &ty::t t, bool is_lval)
|
||||
}
|
||||
case (ty::ty_tag(?did, ?tps)) {
|
||||
auto variants = ty::tag_variants(ccx.tcx, did);
|
||||
if (vec::len(variants) != 1u ||
|
||||
vec::len(variants.(0).args) != 1u) {
|
||||
if (std::ivec::len(variants) != 1u ||
|
||||
std::ivec::len(variants.(0).args) != 1u) {
|
||||
break;
|
||||
}
|
||||
if (is_lval) { v1 = cx.build.Load(v1); }
|
||||
@ -4700,7 +4698,7 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
|
||||
auto matched_cx = new_sub_block_ctxt(cx, "matched_cx");
|
||||
auto llblobptr = llval;
|
||||
|
||||
if (vec::len(variants) == 1u) {
|
||||
if (std::ivec::len(variants) == 1u) {
|
||||
cx.build.Br(matched_cx.llbb);
|
||||
} else {
|
||||
auto lltagptr =
|
||||
@ -4789,7 +4787,8 @@ fn trans_pat_binding(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
|
||||
"trans_pat_binding: internal error, unbound var"); }
|
||||
}
|
||||
auto llblobptr = llval;
|
||||
if (vec::len(ty::tag_variants(cx.fcx.lcx.ccx.tcx, vdef._0))!=1u) {
|
||||
if (std::ivec::len(ty::tag_variants(cx.fcx.lcx.ccx.tcx, vdef._0))
|
||||
!= 1u) {
|
||||
auto lltagptr = cx.build.PointerCast
|
||||
(llval, T_opaque_tag_ptr(cx.fcx.lcx.ccx.tn));
|
||||
llblobptr = cx.build.GEP(lltagptr, [C_int(0), C_int(1)]);
|
||||
@ -4987,7 +4986,8 @@ fn trans_path(&@block_ctxt cx, &ast::path p, ast::node_id id) -> lval_result {
|
||||
auto bcx = alloc_result.bcx;
|
||||
auto lltagptr = bcx.build.PointerCast
|
||||
(lltagblob, T_ptr(lltagty));
|
||||
if (vec::len(ty::tag_variants(ccx.tcx, tid)) != 1u) {
|
||||
if (std::ivec::len(ty::tag_variants(ccx.tcx, tid))
|
||||
!= 1u) {
|
||||
auto lldiscrim_gv =
|
||||
lookup_discriminant(bcx.fcx.lcx, tid, vid);
|
||||
auto lldiscrim = bcx.build.Load(lldiscrim_gv);
|
||||
|
@ -1288,8 +1288,8 @@ fn type_autoderef(&ctxt cx, &ty::t t) -> ty::t {
|
||||
}
|
||||
case (ty::ty_tag(?did, ?tps)) {
|
||||
auto variants = tag_variants(cx, did);
|
||||
if (vec::len(variants) != 1u ||
|
||||
vec::len(variants.(0).args) != 1u) {
|
||||
if (ivec::len(variants) != 1u ||
|
||||
ivec::len(variants.(0).args) != 1u) {
|
||||
break;
|
||||
}
|
||||
t1 = substitute_type_params(cx, tps, variants.(0).args.(0));
|
||||
@ -2812,12 +2812,10 @@ fn def_has_ty_params(&ast::def def) -> bool {
|
||||
|
||||
|
||||
// Tag information
|
||||
type variant_info = rec(vec[ty::t] args, ty::t ctor_ty, ast::def_id id);
|
||||
type variant_info = rec(ty::t[] args, ty::t ctor_ty, ast::def_id id);
|
||||
|
||||
fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] {
|
||||
if (ast::local_crate != id._0) {
|
||||
ret decoder::get_tag_variants(cx, id);
|
||||
}
|
||||
fn tag_variants(&ctxt cx, &ast::def_id id) -> variant_info[] {
|
||||
if (ast::local_crate != id._0) { ret decoder::get_tag_variants(cx, id); }
|
||||
auto item = alt (cx.items.find(id._1)) {
|
||||
case (some(?i)) { i }
|
||||
case (none) {
|
||||
@ -2828,22 +2826,22 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] {
|
||||
case (ast_map::node_item(?item)) {
|
||||
alt (item.node) {
|
||||
case (ast::item_tag(?variants, _)) {
|
||||
let vec[variant_info] result = [];
|
||||
let variant_info[] result = ~[];
|
||||
for (ast::variant variant in variants) {
|
||||
auto ctor_ty = node_id_to_monotype
|
||||
(cx, variant.node.id);
|
||||
let vec[t] arg_tys = [];
|
||||
let t[] arg_tys = ~[];
|
||||
if (vec::len[ast::variant_arg](variant.node.args) >
|
||||
0u) {
|
||||
for (arg a in ty_fn_args(cx, ctor_ty)) {
|
||||
arg_tys += [a.ty];
|
||||
arg_tys += ~[a.ty];
|
||||
}
|
||||
}
|
||||
auto did = variant.node.id;
|
||||
result +=
|
||||
[rec(args=arg_tys,
|
||||
ctor_ty=ctor_ty,
|
||||
id=ast::local_def(did))];
|
||||
~[rec(args=arg_tys,
|
||||
ctor_ty=ctor_ty,
|
||||
id=ast::local_def(did))];
|
||||
}
|
||||
ret result;
|
||||
}
|
||||
@ -2858,7 +2856,7 @@ fn tag_variant_with_id(&ctxt cx, &ast::def_id tag_id, &ast::def_id variant_id)
|
||||
-> variant_info {
|
||||
auto variants = tag_variants(cx, tag_id);
|
||||
auto i = 0u;
|
||||
while (i < vec::len[variant_info](variants)) {
|
||||
while (i < ivec::len[variant_info](variants)) {
|
||||
auto variant = variants.(i);
|
||||
if (def_eq(variant.id, variant_id)) { ret variant; }
|
||||
i += 1u;
|
||||
|
@ -874,8 +874,8 @@ fn do_autoderef(&@fn_ctxt fcx, &span sp, &ty::t t) -> ty::t {
|
||||
}
|
||||
case (ty::ty_tag(?did, ?tps)) {
|
||||
auto variants = ty::tag_variants(fcx.ccx.tcx, did);
|
||||
if (vec::len(variants) != 1u ||
|
||||
vec::len(variants.(0).args) != 1u) {
|
||||
if (ivec::len(variants) != 1u ||
|
||||
ivec::len(variants.(0).args) != 1u) {
|
||||
ret t1;
|
||||
}
|
||||
t1 = ty::substitute_type_params(fcx.ccx.tcx, tps,
|
||||
@ -1620,8 +1620,8 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
||||
case (ty::ty_res(_, ?inner, _)) { oper_t = inner; }
|
||||
case (ty::ty_tag(?id, ?tps)) {
|
||||
auto variants = ty::tag_variants(fcx.ccx.tcx, id);
|
||||
if (vec::len(variants) != 1u ||
|
||||
vec::len(variants.(0).args) != 1u) {
|
||||
if (ivec::len(variants) != 1u ||
|
||||
ivec::len(variants.(0).args) != 1u) {
|
||||
fcx.ccx.tcx.sess.span_fatal
|
||||
(expr.span, "can only dereference tags " +
|
||||
"with a single variant which has a " +
|
||||
|
Loading…
Reference in New Issue
Block a user