1
Fork 0

rustc: Remove the overly complex variant_indices and n_ary_variant_indices tables

This commit is contained in:
Patrick Walton 2010-12-02 11:00:10 -08:00
parent eeecc8d061
commit 376b35e618

View file

@ -44,9 +44,9 @@ type glue_fns = rec(ValueRef activate_glue,
ValueRef exit_task_glue, ValueRef exit_task_glue,
vec[ValueRef] upcall_glues); vec[ValueRef] upcall_glues);
tag arity { nullary; n_ary(uint); }
type tag_info = rec(type_handle th, type tag_info = rec(type_handle th,
hashmap[ast.def_id, uint] variant_indices, mutable vec[tup(ast.def_id,arity)] variants);
hashmap[ast.def_id, uint] n_ary_variant_indices);
state type crate_ctxt = rec(session.session sess, state type crate_ctxt = rec(session.session sess,
ModuleRef llmod, ModuleRef llmod,
@ -55,7 +55,7 @@ state type crate_ctxt = rec(session.session sess,
hashmap[str, ValueRef] fn_names, hashmap[str, ValueRef] fn_names,
hashmap[ast.def_id, ValueRef] fn_ids, hashmap[ast.def_id, ValueRef] fn_ids,
hashmap[ast.def_id, @ast.item] items, hashmap[ast.def_id, @ast.item] items,
hashmap[ast.def_id, tag_info] tags, hashmap[ast.def_id, @tag_info] tags,
@glue_fns glues, @glue_fns glues,
namegen names, namegen names,
str path); str path);
@ -1133,14 +1133,22 @@ fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt)
case (ast.def_variant(?tid, ?vid)) { case (ast.def_variant(?tid, ?vid)) {
check (cx.fcx.ccx.tags.contains_key(tid)); check (cx.fcx.ccx.tags.contains_key(tid));
auto info = cx.fcx.ccx.tags.get(tid); auto info = cx.fcx.ccx.tags.get(tid);
if (info.n_ary_variant_indices.contains_key(vid)) { auto i = 0;
cx.fcx.ccx.sess.unimpl("n-ary tag constructors in " + for (tup(ast.def_id,arity) v in info.variants) {
"trans"); if (vid == v._0) {
} else { alt (v._1) {
// Nullary tag variant case. case (nullary) {
auto idx = info.variant_indices.get(vid); auto elems = vec(C_int(i));
auto elems = vec(C_int(idx as int)); ret tup(res(cx, C_struct(elems)), false);
ret tup(res(cx, C_struct(elems)), false); }
case (n_ary(_)) {
cx.fcx.ccx.sess.unimpl("n-ary tag " +
"constructor in " +
"trans");
}
}
}
i += 1;
} }
} }
case (_) { case (_) {
@ -1716,17 +1724,15 @@ fn resolve_tag_types_for_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
let vec[TypeRef] variant_tys = vec(); let vec[TypeRef] variant_tys = vec();
auto info = cx.tags.get(tag_id); auto info = cx.tags.get(tag_id);
auto variant_indices = info.variant_indices; let vec[tup(ast.def_id,arity)] variant_info = vec();
auto n_ary_variant_indices = info.n_ary_variant_indices;
auto tag_ty; auto tag_ty;
if (_vec.len[ast.variant](variants) == 0u) { if (_vec.len[ast.variant](variants) == 0u) {
tag_ty = T_struct(vec(T_int())); tag_ty = T_struct(vec(T_int()));
} else { } else {
auto variant_idx = 0u; auto n_ary_idx = 0u;
auto n_ary_variant_idx = 0u;
for (ast.variant variant in variants) { for (ast.variant variant in variants) {
auto arity_info;
if (_vec.len[@ast.ty](variant.args) > 0u) { if (_vec.len[@ast.ty](variant.args) > 0u) {
let vec[TypeRef] lltys = vec(); let vec[TypeRef] lltys = vec();
@ -1741,18 +1747,20 @@ fn resolve_tag_types_for_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
variant_tys += vec(T_struct(lltys)); variant_tys += vec(T_struct(lltys));
n_ary_variant_indices.insert(variant.id, arity_info = n_ary(n_ary_idx);
n_ary_variant_idx); n_ary_idx += 1u;
n_ary_variant_idx += 1u; } else {
arity_info = nullary;
} }
variant_indices.insert(variant.id, variant_idx); variant_info += vec(tup(variant.id, arity_info));
variant_idx += 1u;
} }
tag_ty = T_struct(vec(T_int(), T_union(variant_tys))); tag_ty = T_struct(vec(T_int(), T_union(variant_tys)));
} }
info.variants = variant_info;
auto th = cx.tags.get(tag_id).th.llth; auto th = cx.tags.get(tag_id).th.llth;
llvm.LLVMRefineType(llvm.LLVMResolveTypeHandle(th), tag_ty); llvm.LLVMRefineType(llvm.LLVMResolveTypeHandle(th), tag_ty);
} }
@ -1782,9 +1790,9 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
case (ast.item_tag(_, ?variants, _, ?tag_id)) { case (ast.item_tag(_, ?variants, _, ?tag_id)) {
auto vi = new_def_hash[uint](); auto vi = new_def_hash[uint]();
auto navi = new_def_hash[uint](); auto navi = new_def_hash[uint]();
cx.tags.insert(tag_id, rec(th=mk_type_handle(), let vec[tup(ast.def_id,arity)] variant_info = vec();
variant_indices=vi, cx.tags.insert(tag_id, @rec(th=mk_type_handle(),
n_ary_variant_indices=navi)); mutable variants=variant_info));
} }
case (_) { /* fall through */ } case (_) { /* fall through */ }
@ -1973,7 +1981,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output) {
fn_names = new_str_hash[ValueRef](), fn_names = new_str_hash[ValueRef](),
fn_ids = new_def_hash[ValueRef](), fn_ids = new_def_hash[ValueRef](),
items = new_def_hash[@ast.item](), items = new_def_hash[@ast.item](),
tags = new_def_hash[tag_info](), tags = new_def_hash[@tag_info](),
glues = glues, glues = glues,
names = namegen(0), names = namegen(0),
path = "_rust"); path = "_rust");