Get rid of block indices
This commit is contained in:
parent
7d086df095
commit
5405f45274
6 changed files with 62 additions and 116 deletions
|
@ -94,15 +94,8 @@ type meta_item = spanned[meta_item_];
|
||||||
type meta_item_ = rec(ident name, str value);
|
type meta_item_ = rec(ident name, str value);
|
||||||
|
|
||||||
type block = spanned[block_];
|
type block = spanned[block_];
|
||||||
type block_index = hashmap[ident, block_index_entry];
|
|
||||||
tag block_index_entry {
|
|
||||||
bie_item(@item);
|
|
||||||
bie_local(@local);
|
|
||||||
bie_tag_variant(@item /* tag item */, uint /* variant index */);
|
|
||||||
}
|
|
||||||
type block_ = rec(vec[@stmt] stmts,
|
type block_ = rec(vec[@stmt] stmts,
|
||||||
Option.t[@expr] expr,
|
Option.t[@expr] expr,
|
||||||
hashmap[ident,block_index_entry] index,
|
|
||||||
ann a); /* ann is only meaningful for the ts_ann field */
|
ann a); /* ann is only meaningful for the ts_ann field */
|
||||||
|
|
||||||
type variant_def = tup(def_id /* tag */, def_id /* variant */);
|
type variant_def = tup(def_id /* tag */, def_id /* variant */);
|
||||||
|
@ -421,6 +414,18 @@ tag item_ {
|
||||||
item_obj(ident, _obj, vec[ty_param], obj_def_ids, ann);
|
item_obj(ident, _obj, vec[ty_param], obj_def_ids, ann);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn item_ident(@item it) -> ident {
|
||||||
|
ret alt (it.node) {
|
||||||
|
case (item_const(?ident, _, _, _, _)) { ident }
|
||||||
|
case (item_fn(?ident, _, _, _, _)) { ident }
|
||||||
|
case (item_mod(?ident, _, _)) { ident }
|
||||||
|
case (item_native_mod(?ident, _, _)) { ident }
|
||||||
|
case (item_ty(?ident, _, _, _, _)) { ident }
|
||||||
|
case (item_tag(?ident, _, _, _, _)) { ident }
|
||||||
|
case (item_obj(?ident, _, _, _, _)) { ident }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type native_item = spanned[native_item_];
|
type native_item = spanned[native_item_];
|
||||||
tag native_item_ {
|
tag native_item_ {
|
||||||
native_item_ty(ident, def_id);
|
native_item_ty(ident, def_id);
|
||||||
|
@ -500,44 +505,6 @@ fn index_native_view_item(native_mod_index index, @view_item it) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index_stmt(block_index index, @stmt s) {
|
|
||||||
alt (s.node) {
|
|
||||||
case (ast.stmt_decl(?d,_)) {
|
|
||||||
alt (d.node) {
|
|
||||||
case (ast.decl_local(?loc)) {
|
|
||||||
index.insert(loc.ident, ast.bie_local(loc));
|
|
||||||
}
|
|
||||||
case (ast.decl_item(?it)) {
|
|
||||||
alt (it.node) {
|
|
||||||
case (ast.item_fn(?i, _, _, _, _)) {
|
|
||||||
index.insert(i, ast.bie_item(it));
|
|
||||||
}
|
|
||||||
case (ast.item_mod(?i, _, _)) {
|
|
||||||
index.insert(i, ast.bie_item(it));
|
|
||||||
}
|
|
||||||
case (ast.item_ty(?i, _, _, _, _)) {
|
|
||||||
index.insert(i, ast.bie_item(it));
|
|
||||||
}
|
|
||||||
case (ast.item_tag(?i, ?variants, _, _, _)) {
|
|
||||||
index.insert(i, ast.bie_item(it));
|
|
||||||
let uint vid = 0u;
|
|
||||||
for (ast.variant v in variants) {
|
|
||||||
auto t = ast.bie_tag_variant(it, vid);
|
|
||||||
index.insert(v.node.name, t);
|
|
||||||
vid += 1u;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case (ast.item_obj(?i, _, _, _, _)) {
|
|
||||||
index.insert(i, ast.bie_item(it));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case (_) { /* fall through */ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_exported(ident i, _mod m) -> bool {
|
fn is_exported(ident i, _mod m) -> bool {
|
||||||
auto count = 0;
|
auto count = 0;
|
||||||
for (@ast.view_item vi in m.view_items) {
|
for (@ast.view_item vi in m.view_items) {
|
||||||
|
|
|
@ -1626,15 +1626,6 @@ fn parse_source_stmt(parser p) -> @ast.stmt {
|
||||||
fail;
|
fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index_block(parser p, vec[@ast.stmt] stmts, Option.t[@ast.expr] expr)
|
|
||||||
-> ast.block_ {
|
|
||||||
auto index = new_str_hash[ast.block_index_entry]();
|
|
||||||
for (@ast.stmt s in stmts) {
|
|
||||||
ast.index_stmt(index, s);
|
|
||||||
}
|
|
||||||
ret rec(stmts=stmts, expr=expr, index=index, a=p.get_ann());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn index_arm(@ast.pat pat) -> hashmap[ast.ident,ast.def_id] {
|
fn index_arm(@ast.pat pat) -> hashmap[ast.ident,ast.def_id] {
|
||||||
fn do_index_arm(&hashmap[ast.ident,ast.def_id] index, @ast.pat pat) {
|
fn do_index_arm(&hashmap[ast.ident,ast.def_id] index, @ast.pat pat) {
|
||||||
alt (pat.node) {
|
alt (pat.node) {
|
||||||
|
@ -1770,7 +1761,7 @@ fn parse_block(parser p) -> ast.block {
|
||||||
auto hi = p.get_hi_pos();
|
auto hi = p.get_hi_pos();
|
||||||
p.bump();
|
p.bump();
|
||||||
|
|
||||||
auto bloc = index_block(p, stmts, expr);
|
auto bloc = rec(stmts=stmts, expr=expr, a=p.get_ann());
|
||||||
ret spanned[ast.block_](lo, hi, bloc);
|
ret spanned[ast.block_](lo, hi, bloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -862,7 +862,6 @@ fn fold_stmt[ENV](&ENV env, &ast_fold[ENV] fld, &@stmt s) -> @stmt {
|
||||||
|
|
||||||
fn fold_block[ENV](&ENV env, &ast_fold[ENV] fld, &block blk) -> block {
|
fn fold_block[ENV](&ENV env, &ast_fold[ENV] fld, &block blk) -> block {
|
||||||
|
|
||||||
auto index = new_str_hash[ast.block_index_entry]();
|
|
||||||
let ENV env_ = fld.update_env_for_block(env, blk);
|
let ENV env_ = fld.update_env_for_block(env, blk);
|
||||||
|
|
||||||
if (!fld.keep_going(env_)) {
|
if (!fld.keep_going(env_)) {
|
||||||
|
@ -873,7 +872,6 @@ fn fold_block[ENV](&ENV env, &ast_fold[ENV] fld, &block blk) -> block {
|
||||||
for (@ast.stmt s in blk.node.stmts) {
|
for (@ast.stmt s in blk.node.stmts) {
|
||||||
auto new_stmt = fold_stmt[ENV](env_, fld, s);
|
auto new_stmt = fold_stmt[ENV](env_, fld, s);
|
||||||
Vec.push[@ast.stmt](stmts, new_stmt);
|
Vec.push[@ast.stmt](stmts, new_stmt);
|
||||||
ast.index_stmt(index, new_stmt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto expr = none[@ast.expr];
|
auto expr = none[@ast.expr];
|
||||||
|
@ -887,7 +885,7 @@ fn fold_block[ENV](&ENV env, &ast_fold[ENV] fld, &block blk) -> block {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto aa = fld.fold_ann(env, blk.node.a);
|
auto aa = fld.fold_ann(env, blk.node.a);
|
||||||
ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index, a=aa));
|
ret respan(blk.span, rec(stmts=stmts, expr=expr, a=aa));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_arm[ENV](&ENV env, &ast_fold[ENV] fld, &arm a) -> arm {
|
fn fold_arm[ENV](&ENV env, &ast_fold[ENV] fld, &arm a) -> arm {
|
||||||
|
|
|
@ -500,82 +500,77 @@ fn lookup_in_obj(ident id, &ast._obj ob, &vec[ast.ty_param] ty_params,
|
||||||
|
|
||||||
fn lookup_in_block(ident id, &ast.block_ b, namespace ns)
|
fn lookup_in_block(ident id, &ast.block_ b, namespace ns)
|
||||||
-> Option.t[def] {
|
-> Option.t[def] {
|
||||||
alt (b.index.find(id)) {
|
for (@ast.stmt st in b.stmts) {
|
||||||
case (some[ast.block_index_entry](?ix)) {
|
alt (st.node) {
|
||||||
alt (ix) {
|
case (ast.stmt_decl(?d,_)) {
|
||||||
case (ast.bie_item(?it)) {
|
alt (d.node) {
|
||||||
ret found_def_item(it, ns);
|
case (ast.decl_local(?loc)) {
|
||||||
}
|
if (ns == ns_value && Str.eq(id, loc.ident)) {
|
||||||
case (ast.bie_local(?l)) {
|
ret some(ast.def_local(loc.id));
|
||||||
if (ns == ns_value) {
|
}
|
||||||
ret some(ast.def_local(l.id));
|
|
||||||
}
|
}
|
||||||
}
|
case (ast.decl_item(?it)) {
|
||||||
case (ast.bie_tag_variant(?item, ?variant_idx)) {
|
alt (it.node) {
|
||||||
if (ns == ns_value) {
|
case (ast.item_tag(?name, ?variants, _,
|
||||||
ret some(found_def_tag(item, variant_idx));
|
?defid, _)) {
|
||||||
|
if (ns == ns_type) {
|
||||||
|
if (Str.eq(name, id)) {
|
||||||
|
ret some(ast.def_ty(defid));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (ast.variant v in variants) {
|
||||||
|
if (Str.eq(v.node.name, id)) {
|
||||||
|
ret some(ast.def_variant(
|
||||||
|
defid, v.node.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case (_) {
|
||||||
|
if (Str.eq(ast.item_ident(it), id)) {
|
||||||
|
auto found = found_def_item(it, ns);
|
||||||
|
if (found != none[def]) { ret found; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case (_) {}
|
||||||
}
|
}
|
||||||
case (_) { }
|
|
||||||
}
|
}
|
||||||
ret none[def];
|
ret none[def];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn found_def_item(@ast.item i, namespace ns) -> Option.t[def] {
|
fn found_def_item(@ast.item i, namespace ns) -> Option.t[def] {
|
||||||
alt (i.node) {
|
alt (i.node) {
|
||||||
case (ast.item_const(_, _, _, ?id, _)) {
|
case (ast.item_const(_, _, _, ?defid, _)) {
|
||||||
if (ns == ns_value) {
|
if (ns == ns_value) { ret some(ast.def_const(defid)); }
|
||||||
ret some(ast.def_const(id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case (ast.item_fn(_, _, _, ?id, _)) {
|
case (ast.item_fn(_, _, _, ?defid, _)) {
|
||||||
if (ns == ns_value) {
|
if (ns == ns_value) { ret some(ast.def_fn(defid)); }
|
||||||
ret some(ast.def_fn(id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case (ast.item_mod(_, _, ?id)) {
|
case (ast.item_mod(_, _, ?defid)) {
|
||||||
ret some(ast.def_mod(id));
|
ret some(ast.def_mod(defid));
|
||||||
}
|
}
|
||||||
case (ast.item_native_mod(_, _, ?id)) {
|
case (ast.item_native_mod(_, _, ?defid)) {
|
||||||
ret some(ast.def_native_mod(id));
|
ret some(ast.def_native_mod(defid));
|
||||||
}
|
}
|
||||||
case (ast.item_ty(_, _, _, ?id, _)) {
|
case (ast.item_ty(_, _, _, ?defid, _)) {
|
||||||
if (ns == ns_type) {
|
if (ns == ns_type) { ret some(ast.def_ty(defid)); }
|
||||||
ret some(ast.def_ty(id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case (ast.item_tag(_, _, _, ?id, _)) {
|
case (ast.item_tag(_, _, _, ?defid, _)) {
|
||||||
if (ns == ns_type) {
|
if (ns == ns_type) { ret some(ast.def_ty(defid)); }
|
||||||
ret some(ast.def_ty(id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case (ast.item_obj(_, _, _, ?odid, _)) {
|
case (ast.item_obj(_, _, _, ?odid, _)) {
|
||||||
if (ns == ns_value) {
|
if (ns == ns_value) { ret some(ast.def_obj(odid.ctor)); }
|
||||||
ret some(ast.def_obj(odid.ctor));
|
else { ret some(ast.def_obj(odid.ty)); }
|
||||||
} else {
|
|
||||||
ret some(ast.def_obj(odid.ty));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case (_) { }
|
case (_) { }
|
||||||
}
|
}
|
||||||
ret none[def];
|
ret none[def];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn found_def_tag(@ast.item item, uint variant_idx) -> def {
|
|
||||||
alt (item.node) {
|
|
||||||
case (ast.item_tag(_, ?variants, _, ?tid, _)) {
|
|
||||||
auto vid = variants.(variant_idx).node.id;
|
|
||||||
ret ast.def_variant(tid, vid);
|
|
||||||
}
|
|
||||||
case (_) {
|
|
||||||
log_err "tag item not actually a tag";
|
|
||||||
fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lookup_in_mod_strict(&env e, def m, &span sp, ident id,
|
fn lookup_in_mod_strict(&env e, def m, &span sp, ident id,
|
||||||
namespace ns, dir dr) -> def {
|
namespace ns, dir dr) -> def {
|
||||||
alt (lookup_in_mod(e, m, id, ns, dr)) {
|
alt (lookup_in_mod(e, m, id, ns, dr)) {
|
||||||
|
|
|
@ -1507,7 +1507,6 @@ mod Pushdown {
|
||||||
auto e_1 = pushdown_expr(fcx, expected, e_0);
|
auto e_1 = pushdown_expr(fcx, expected, e_0);
|
||||||
auto block_ = rec(stmts=bloc.node.stmts,
|
auto block_ = rec(stmts=bloc.node.stmts,
|
||||||
expr=some[@ast.expr](e_1),
|
expr=some[@ast.expr](e_1),
|
||||||
index=bloc.node.index,
|
|
||||||
a=plain_ann(fcx.ccx.tcx));
|
a=plain_ann(fcx.ccx.tcx));
|
||||||
ret fold.respan[ast.block_](bloc.span, block_);
|
ret fold.respan[ast.block_](bloc.span, block_);
|
||||||
}
|
}
|
||||||
|
@ -2806,7 +2805,6 @@ fn check_block(&@fn_ctxt fcx, &ast.block block) -> ast.block {
|
||||||
|
|
||||||
ret fold.respan[ast.block_](block.span,
|
ret fold.respan[ast.block_](block.span,
|
||||||
rec(stmts=stmts, expr=expr,
|
rec(stmts=stmts, expr=expr,
|
||||||
index=block.node.index,
|
|
||||||
a=plain_ann(fcx.ccx.tcx)));
|
a=plain_ann(fcx.ccx.tcx)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import front.ast.mutability;
|
||||||
import front.ast.item;
|
import front.ast.item;
|
||||||
import front.ast.block;
|
import front.ast.block;
|
||||||
import front.ast.block_;
|
import front.ast.block_;
|
||||||
import front.ast.block_index_entry;
|
|
||||||
import front.ast.mod_index_entry;
|
import front.ast.mod_index_entry;
|
||||||
import front.ast.obj_field;
|
import front.ast.obj_field;
|
||||||
import front.ast.decl;
|
import front.ast.decl;
|
||||||
|
@ -2337,12 +2336,10 @@ fn annotate_stmt(&fn_info_map fm, &@stmt s) -> @stmt {
|
||||||
}
|
}
|
||||||
fn annotate_block(&fn_info_map fm, &block b) -> block {
|
fn annotate_block(&fn_info_map fm, &block b) -> block {
|
||||||
let vec[@stmt] new_stmts = vec();
|
let vec[@stmt] new_stmts = vec();
|
||||||
auto new_index = new_str_hash[block_index_entry]();
|
|
||||||
|
|
||||||
for (@stmt s in b.node.stmts) {
|
for (@stmt s in b.node.stmts) {
|
||||||
auto new_s = annotate_stmt(fm, s);
|
auto new_s = annotate_stmt(fm, s);
|
||||||
Vec.push[@stmt](new_stmts, new_s);
|
Vec.push[@stmt](new_stmts, new_s);
|
||||||
ast.index_stmt(new_index, new_s);
|
|
||||||
}
|
}
|
||||||
fn ann_e(fn_info_map fm, &@expr e) -> @expr {
|
fn ann_e(fn_info_map fm, &@expr e) -> @expr {
|
||||||
ret annotate_expr(fm, e);
|
ret annotate_expr(fm, e);
|
||||||
|
@ -2352,7 +2349,7 @@ fn annotate_block(&fn_info_map fm, &block b) -> block {
|
||||||
auto new_e = Option.map[@expr, @expr](f, b.node.expr);
|
auto new_e = Option.map[@expr, @expr](f, b.node.expr);
|
||||||
|
|
||||||
ret respan(b.span,
|
ret respan(b.span,
|
||||||
rec(stmts=new_stmts, expr=new_e, index=new_index with b.node));
|
rec(stmts=new_stmts, expr=new_e with b.node));
|
||||||
}
|
}
|
||||||
fn annotate_fn(&fn_info_map fm, &ast._fn f) -> ast._fn {
|
fn annotate_fn(&fn_info_map fm, &ast._fn f) -> ast._fn {
|
||||||
// subexps have *already* been annotated based on
|
// subexps have *already* been annotated based on
|
||||||
|
|
Loading…
Reference in a new issue