Skip to content

Commit 6f23304

Browse files
committed
---
yaml --- r: 2587 b: refs/heads/master c: 5047ab0 h: refs/heads/master i: 2585: 5b660ad 2583: 14fc313 v: v3
1 parent 2c074c3 commit 6f23304

File tree

12 files changed

+308
-590
lines changed

12 files changed

+308
-590
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a90df393f9acb9633e0581711a3bc43f97bfe946
2+
refs/heads/master: 5047ab0b0cc84af577d1a0816d2496986397e967

trunk/src/comp/front/ast.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,10 @@ type def_id = tup(crate_num, def_num);
2121
type ty_param = ident;
2222

2323
// Annotations added during successive passes.
24-
tag ann {
25-
ann_none(uint);
26-
ann_type(uint,
27-
middle::ty::t,
28-
option::t[vec[middle::ty::t]], /* ty param substs */
29-
option::t[@ts_ann]); /* pre- and postcondition for typestate */
30-
}
31-
32-
fn ann_tag(&ann a) -> uint {
33-
ret alt (a) {
34-
case (ann_none(?t)) { t }
35-
case (ann_type(?t, _, _, _)) { t }
36-
};
37-
}
24+
type ann = rec(uint id,
25+
middle::ty::t ty,
26+
option::t[vec[middle::ty::t]] tps,
27+
option::t[@ts_ann] ts);
3828

3929
tag def {
4030
def_fn(def_id);

trunk/src/comp/front/parser.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ fn new_parser(session::session sess,
147147
fn get_chpos() -> uint {ret rdr.get_chpos();}
148148

149149
fn get_ann() -> ast::ann {
150-
auto rv = ast::ann_none(next_ann_var);
150+
// TODO: Remove ty, tps, and ts. ty and tps should be unused
151+
// by now.
152+
auto rv = rec(id=next_ann_var, ty=0u,
153+
tps=none[vec[middle::ty::t]],
154+
ts=none[@middle::tstate::ann::ts_ann]);
151155
next_ann_var += 1u;
152156
ret rv;
153157
}

trunk/src/comp/middle/resolve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn resolve_names(&@env e, &ast::crate c) {
193193
case (ast::expr_path(?p, ?a)) {
194194
auto df = lookup_path_strict(*e, *sc, exp.span, p.node.idents,
195195
ns_value);
196-
e.def_map.insert(ast::ann_tag(a), df);
196+
e.def_map.insert(a.id, df);
197197
}
198198
case (_) {}
199199
}
@@ -203,7 +203,7 @@ fn resolve_names(&@env e, &ast::crate c) {
203203
case (ast::ty_path(?p, ?a)) {
204204
auto new_def = lookup_path_strict(*e, *sc, t.span,
205205
p.node.idents, ns_type);
206-
e.def_map.insert(ast::ann_tag(a), new_def);
206+
e.def_map.insert(a.id, new_def);
207207
}
208208
case (_) {}
209209
}
@@ -219,7 +219,7 @@ fn resolve_names(&@env e, &ast::crate c) {
219219
ns_value);
220220
alt (fnd) {
221221
case (ast::def_variant(?did, ?vid)) {
222-
e.def_map.insert(ast::ann_tag(a), fnd);
222+
e.def_map.insert(a.id, fnd);
223223
}
224224
case (_) {
225225
e.sess.span_err(p.span, "not a tag variant: " +

trunk/src/comp/middle/trans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,7 +3804,7 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc,
38043804
fn walk_expr(env e, &@ast::expr expr) {
38053805
alt (expr.node) {
38063806
case (ast::expr_path(?path, ?ann)) {
3807-
alt (e.def_map.get(ast::ann_tag(ann))) {
3807+
alt (e.def_map.get(ann.id)) {
38083808
case (ast::def_arg(?did)) {
38093809
vec::push[ast::def_id](e.refs, did);
38103810
}
@@ -4126,7 +4126,7 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
41264126
auto lldiscrim = cx.build.Load(lldiscrimptr);
41274127

41284128
auto vdef = ast::variant_def_ids
4129-
(cx.fcx.lcx.ccx.tcx.def_map.get(ast::ann_tag(ann)));
4129+
(cx.fcx.lcx.ccx.tcx.def_map.get(ann.id));
41304130
auto variant_tag = 0;
41314131

41324132
auto variants = tag_variants(cx.fcx.lcx.ccx, vdef._0);
@@ -4205,7 +4205,7 @@ fn trans_pat_binding(&@block_ctxt cx, &@ast::pat pat,
42054205

42064206
// Get the appropriate variant for this tag.
42074207
auto vdef = ast::variant_def_ids
4208-
(cx.fcx.lcx.ccx.tcx.def_map.get(ast::ann_tag(ann)));
4208+
(cx.fcx.lcx.ccx.tcx.def_map.get(ann.id));
42094209

42104210
auto lltagptr = cx.build.PointerCast(llval,
42114211
T_opaque_tag_ptr(cx.fcx.lcx.ccx.tn));
@@ -4368,7 +4368,7 @@ fn lookup_discriminant(&@local_ctxt lcx, &ast::def_id tid, &ast::def_id vid)
43684368
}
43694369

43704370
fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result {
4371-
alt (cx.fcx.lcx.ccx.tcx.def_map.get(ast::ann_tag(ann))) {
4371+
alt (cx.fcx.lcx.ccx.tcx.def_map.get(ann.id)) {
43724372
case (ast::def_arg(?did)) {
43734373
alt (cx.fcx.llargs.find(did)) {
43744374
case (none[ValueRef]) {

trunk/src/comp/middle/tstate/auxiliary.rs

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import std::option::some;
77
import std::option::maybe;
88

99
import front::ast;
10-
import front::ast::ann_tag;
1110
import front::ast::def;
1211
import front::ast::def_fn;
1312
import front::ast::_fn;
@@ -17,8 +16,6 @@ import front::ast::expr_path;
1716
import front::ast::ident;
1817
import front::ast::controlflow;
1918
import front::ast::ann;
20-
import front::ast::ann_none;
21-
import front::ast::ann_type;
2219
import front::ast::ts_ann;
2320
import front::ast::stmt;
2421
import front::ast::expr;
@@ -188,27 +185,15 @@ fn ann_to_ts_ann(ann a, uint nv) -> @ts_ann {
188185
}
189186

190187

191-
fn ann_to_ts_ann_fail(ann a) -> option::t[@ts_ann] {
192-
alt (a) {
193-
case (ann_none(_)) {
194-
log("ann_to_ts_ann_fail: didn't expect ann_none here");
195-
fail;
196-
}
197-
case (ann_type(_,_,_,?ty)) {
198-
ret ty;
199-
}
200-
}
201-
}
188+
fn ann_to_ts_ann_fail(ann a) -> option::t[@ts_ann] { ret a.ts; }
202189

203190
fn ann_to_ts_ann_strict(ann a) -> @ts_ann {
204191
alt (ann_to_ts_ann_fail(a)) {
205-
case (none[@ts_ann]) {
206-
log("ann_to_ts_ann_fail: didn't expect ann_none here");
192+
case (none[@ts_ann]) {
193+
log("ann_to_ts_ann_strict: didn't expect none here");
207194
fail;
208195
}
209-
case (some[@ts_ann](?t)) {
210-
ret t;
211-
}
196+
case (some[@ts_ann](?t)) { ret t; }
212197
}
213198
}
214199

@@ -320,18 +305,9 @@ fn block_poststate(&block b) -> poststate {
320305

321306
/* returns a new annotation where the pre_and_post is p */
322307
fn with_pp(ann a, pre_and_post p) -> ann {
323-
alt (a) {
324-
case (ann_none(_)) {
325-
log("with_pp: the impossible happened");
326-
fail; /* shouldn't happen b/c code is typechecked */
327-
}
328-
case (ann_type(?i, ?t, ?ps, _)) {
329-
ret (ann_type(i, t, ps,
330-
some[@ts_ann]
331-
(@rec(conditions=p,
332-
states=empty_states(pps_len(p))))));
333-
}
334-
}
308+
ret rec(id=a.id, ty=a.ty, tps=a.tps,
309+
ts=some[@ts_ann](@rec(conditions=p,
310+
states=empty_states(pps_len(p)))));
335311
}
336312

337313
fn set_prestate_ann(&ann a, &prestate pre) -> bool {
@@ -379,50 +355,22 @@ fn fixed_point_states(&fn_ctxt fcx,
379355
}
380356

381357
fn init_ann(&fn_info fi, &ann a) -> ann {
382-
alt (a) {
383-
case (ann_none(_)) {
384-
// log("init_ann: shouldn't see ann_none");
385-
// fail;
386-
log("warning: init_ann: saw ann_none");
387-
ret a; // Would be better to fail so we can catch bugs that
388-
// result in an uninitialized ann -- but don't want to have to
389-
// write code to handle native_mods properly
390-
}
391-
case (ann_type(?i, ?t, ?ps, _)) {
392-
ret ann_type(i, t, ps, some[@ts_ann](@empty_ann(num_locals(fi))));
393-
}
394-
}
358+
ret rec(id=a.id, ty=a.ty, tps=a.tps,
359+
ts=some[@ts_ann](@empty_ann(num_locals(fi))));
395360
}
396361

397362
fn init_blank_ann(&() ignore, &ann a) -> ann {
398-
alt (a) {
399-
case (ann_none(_)) {
400-
// log("init_blank_ann: shouldn't see ann_none");
401-
//fail;
402-
log("warning: init_blank_ann: saw ann_none");
403-
ret a;
404-
}
405-
case (ann_type(?i, ?t, ?ps,_)) {
406-
ret ann_type(i, t, ps, some[@ts_ann](@empty_ann(0u)));
407-
}
408-
}
363+
ret rec(id=a.id, ty=a.ty, tps=a.tps, ts=some[@ts_ann](@empty_ann(0u)));
409364
}
410365

411366
fn init_block(&fn_info fi, &span sp, &block_ b) -> block {
412367
log("init_block:");
413368
log_block(respan(sp, b));
414-
alt(b.a) {
415-
case (ann_none(_)) {
416-
log("init_block: shouldn't see ann_none");
417-
fail;
418-
}
419-
case (ann_type(_, _, _, _)) {
420-
auto fld0 = new_identity_fold[fn_info]();
421369

422-
fld0 = @rec(fold_ann = bind init_ann(_,_) with *fld0);
423-
ret fold_block[fn_info](fi, fld0, respan(sp, b));
424-
}
425-
}
370+
auto fld0 = new_identity_fold[fn_info]();
371+
372+
fld0 = @rec(fold_ann = bind init_ann(_,_) with *fld0);
373+
ret fold_block[fn_info](fi, fld0, respan(sp, b));
426374
}
427375

428376
fn num_locals(fn_info m) -> uint {
@@ -445,7 +393,7 @@ fn controlflow_def_id(&crate_ctxt ccx, &def_id d) -> controlflow {
445393
There's no case for fail b/c we assume e is the callee and it
446394
seems unlikely that one would apply "fail" to arguments. */
447395
fn controlflow_expr(&crate_ctxt ccx, @expr e) -> controlflow {
448-
auto f = ann_tag(expr_ann(e));
396+
auto f = expr_ann(e).id;
449397
alt (ccx.tcx.def_map.find(f)) {
450398
case (some[def](def_fn(?d))) { ret controlflow_def_id(ccx, d); }
451399
case (some[def](def_obj_field(?d))) { ret controlflow_def_id(ccx, d); }
@@ -454,19 +402,17 @@ fn controlflow_expr(&crate_ctxt ccx, @expr e) -> controlflow {
454402
}
455403

456404
fn ann_to_def_strict(&crate_ctxt ccx, &ann a) -> def {
457-
alt (ccx.tcx.def_map.find(ann_tag(a))) {
405+
alt (ccx.tcx.def_map.find(a.id)) {
458406
case (none[def]) {
459-
log_err("ann_to_def: node_id " +
460-
uistr(ann_tag(a)) +
461-
" has no def");
407+
log_err("ann_to_def: node_id " + uistr(a.id) + " has no def");
462408
fail;
463409
}
464410
case (some[def](?d)) { ret d; }
465411
}
466412
}
467413

468414
fn ann_to_def(&crate_ctxt ccx, &ann a) -> option::t[def] {
469-
ret ccx.tcx.def_map.find(ann_tag(a));
415+
ret ccx.tcx.def_map.find(a.id);
470416
}
471417

472418
//

trunk/src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ import front::ast::controlflow;
8080
import front::ast::return;
8181
import front::ast::noreturn;
8282
import front::ast::_fn;
83-
import front::ast::ann_none;
84-
import front::ast::ann_type;
8583
import front::ast::_obj;
8684
import front::ast::_mod;
8785
import front::ast::crate;

trunk/src/comp/middle/tstate/states.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ import front::ast::init_op;
9292
import front::ast::controlflow;
9393
import front::ast::return;
9494
import front::ast::noreturn;
95-
import front::ast::ann_none;
96-
import front::ast::ann_type;
9795
import front::ast::_obj;
9896
import front::ast::_mod;
9997
import front::ast::crate;
@@ -243,7 +241,7 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
243241
/*
244242
log_err("states:");
245243
log_expr_err(*e);
246-
log_err(ast.ann_tag(middle.ty.expr_ann(e)));
244+
log_err(middle::ty::expr_ann(e).id);
247245
*/
248246

249247
/* FIXME could get rid of some of the copy/paste */

trunk/src/comp/middle/ty.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ fn eq_ty(&t a, &t b) -> bool { ret a == b; }
14521452

14531453
fn ann_to_ty_param_substs_opt_and_ty(&node_type_table ntt, &ast::ann ann)
14541454
-> ty_param_substs_opt_and_ty {
1455-
alt (ntt.(ast::ann_tag(ann))) {
1455+
alt (ntt.(ann.id)) {
14561456
case (none[ty::ty_param_substs_opt_and_ty]) {
14571457
log_err "ann_to_ty_param_substs_opt_and_ty() called on an " +
14581458
"untyped node";
@@ -1495,19 +1495,25 @@ fn ann_to_monotype(ctxt cx, &node_type_table ntt, ast::ann a) -> t {
14951495
}
14961496

14971497

1498-
// Turns a type into an ann_type, using defaults for other fields.
1498+
// Turns a type and optional type parameters into an annotation, using
1499+
// defaults for other fields.
1500+
fn mk_ann_type(uint node_id, t typ, option::t[vec[t]] tps) -> ast::ann {
1501+
ret rec(id=node_id, ty=typ, tps=tps, ts=none[@ts_ann]);
1502+
}
1503+
1504+
// Turns a type into an annotation, using defaults for other fields.
14991505
fn triv_ann(uint node_id, t typ) -> ast::ann {
1500-
ret ast::ann_type(node_id, typ, none[vec[t]], none[@ts_ann]);
1506+
ret mk_ann_type(node_id, typ, none[vec[t]]);
15011507
}
15021508

15031509
// Creates a nil type annotation.
15041510
fn plain_ann(uint node_id, ctxt tcx) -> ast::ann {
1505-
ret ast::ann_type(node_id, mk_nil(tcx), none[vec[t]], none[@ts_ann]);
1511+
ret triv_ann(node_id, mk_nil(tcx));
15061512
}
15071513

15081514
// Creates a _|_ type annotation.
15091515
fn bot_ann(uint node_id, ctxt tcx) -> ast::ann {
1510-
ret ast::ann_type(node_id, mk_bot(tcx), none[vec[t]], none[@ts_ann]);
1516+
ret triv_ann(node_id, mk_bot(tcx));
15111517
}
15121518

15131519

0 commit comments

Comments
 (0)