Skip to content

Commit b39f66b

Browse files
committed
---
yaml --- r: 2495 b: refs/heads/master c: 0b7dd0d h: refs/heads/master i: 2493: 0d334ac 2491: 51c393c 2487: 167e1b6 2479: 8c30ced 2463: 03dc3a5 2431: fb5433a v: v3
1 parent f98863f commit b39f66b

File tree

5 files changed

+219
-155
lines changed

5 files changed

+219
-155
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: 5ceaf345ed8d70b444907b09e61c1b347dad436c
2+
refs/heads/master: 0b7dd0d918d9c23ad4ac4933d5c53d0a0024b92e

trunk/src/comp/driver/rustc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,18 @@ fn compile_input(session::session sess,
103103
auto typeck_result =
104104
time[typeck::typecheck_result](time_passes, "typechecking",
105105
bind typeck::check_crate(ty_cx, crate));
106-
crate = typeck_result._0;
106+
auto node_type_table = typeck_result._0;
107107
auto type_cache = typeck_result._1;
108+
crate = typeck_result._2;
108109

109110
if (sess.get_opts().run_typestate) {
110111
crate = time(time_passes, "typestate checking",
111112
bind typestate_check::check_crate(crate, def_map));
112113
}
113114

114115
auto llmod = time[llvm::ModuleRef](time_passes, "translation",
115-
bind trans::trans_crate(sess, crate, ty_cx, type_cache, output));
116+
bind trans::trans_crate(sess, crate, ty_cx, node_type_table,
117+
type_cache, output));
116118

117119
time[()](time_passes, "LLVM passes",
118120
bind Link::Write::run_passes(sess, llmod, output));

trunk/src/comp/middle/trans.rs

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import back::x86;
1919
import back::abi;
2020
import back::upcall;
2121

22+
import middle::ty::node_type_table;
2223
import middle::ty::pat_ty;
2324

2425
import util::common;
@@ -128,7 +129,8 @@ state type crate_ctxt = rec(session::session sess,
128129
hashmap[ty::t, str] type_short_names,
129130
ty::ctxt tcx,
130131
stats stats,
131-
@upcall::upcalls upcalls);
132+
@upcall::upcalls upcalls,
133+
node_type_table node_types);
132134

133135
type local_ctxt = rec(vec[str] path,
134136
vec[str] module_path,
@@ -3270,7 +3272,7 @@ fn target_type(&@crate_ctxt cx, &ty::t t) -> ty::t {
32703272

32713273
// Converts an annotation to a type
32723274
fn node_ann_type(&@crate_ctxt cx, &ast::ann a) -> ty::t {
3273-
ret target_type(cx, ty::ann_to_monotype(cx.tcx, a));
3275+
ret target_type(cx, ty::ann_to_monotype(cx.tcx, cx.node_types, a));
32743276
}
32753277

32763278
fn node_ann_ty_params(&ast::ann a) -> vec[ty::t] {
@@ -3299,22 +3301,25 @@ fn trans_unary(&@block_ctxt cx, ast::unop op,
32993301
&@ast::expr e, &ast::ann a) -> result {
33003302

33013303
auto sub = trans_expr(cx, e);
3302-
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
3304+
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e);
33033305

33043306
alt (op) {
33053307
case (ast::bitnot) {
33063308
sub = autoderef(sub.bcx, sub.val,
3307-
ty::expr_ty(cx.fcx.lcx.ccx.tcx, e));
3309+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3310+
cx.fcx.lcx.ccx.node_types, e));
33083311
ret res(sub.bcx, sub.bcx.build.Not(sub.val));
33093312
}
33103313
case (ast::not) {
33113314
sub = autoderef(sub.bcx, sub.val,
3312-
ty::expr_ty(cx.fcx.lcx.ccx.tcx, e));
3315+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3316+
cx.fcx.lcx.ccx.node_types, e));
33133317
ret res(sub.bcx, sub.bcx.build.Not(sub.val));
33143318
}
33153319
case (ast::neg) {
33163320
sub = autoderef(sub.bcx, sub.val,
3317-
ty::expr_ty(cx.fcx.lcx.ccx.tcx, e));
3321+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3322+
cx.fcx.lcx.ccx.node_types, e));
33183323
if(ty::struct(cx.fcx.lcx.ccx.tcx, e_ty) == ty::ty_float) {
33193324
ret res(sub.bcx, sub.bcx.build.FNeg(sub.val));
33203325
}
@@ -3323,7 +3328,8 @@ fn trans_unary(&@block_ctxt cx, ast::unop op,
33233328
}
33243329
}
33253330
case (ast::box(_)) {
3326-
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
3331+
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3332+
cx.fcx.lcx.ccx.node_types, e);
33273333
auto e_val = sub.val;
33283334
auto box_ty = node_ann_type(sub.bcx.fcx.lcx.ccx, a);
33293335
sub = trans_malloc_boxed(sub.bcx, e_ty);
@@ -3579,12 +3585,14 @@ fn trans_binary(&@block_ctxt cx, ast::binop op,
35793585
// Lazy-eval and
35803586
auto lhs_res = trans_expr(cx, a);
35813587
lhs_res = autoderef(lhs_res.bcx, lhs_res.val,
3582-
ty::expr_ty(cx.fcx.lcx.ccx.tcx, a));
3588+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3589+
cx.fcx.lcx.ccx.node_types, a));
35833590

35843591
auto rhs_cx = new_scope_block_ctxt(cx, "rhs");
35853592
auto rhs_res = trans_expr(rhs_cx, b);
35863593
rhs_res = autoderef(rhs_res.bcx, rhs_res.val,
3587-
ty::expr_ty(cx.fcx.lcx.ccx.tcx, b));
3594+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3595+
cx.fcx.lcx.ccx.node_types, b));
35883596

35893597
auto lhs_false_cx = new_scope_block_ctxt(cx, "lhs false");
35903598
auto lhs_false_res = res(lhs_false_cx, C_bool(false));
@@ -3601,12 +3609,14 @@ fn trans_binary(&@block_ctxt cx, ast::binop op,
36013609
// Lazy-eval or
36023610
auto lhs_res = trans_expr(cx, a);
36033611
lhs_res = autoderef(lhs_res.bcx, lhs_res.val,
3604-
ty::expr_ty(cx.fcx.lcx.ccx.tcx, a));
3612+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3613+
cx.fcx.lcx.ccx.node_types, a));
36053614

36063615
auto rhs_cx = new_scope_block_ctxt(cx, "rhs");
36073616
auto rhs_res = trans_expr(rhs_cx, b);
36083617
rhs_res = autoderef(rhs_res.bcx, rhs_res.val,
3609-
ty::expr_ty(cx.fcx.lcx.ccx.tcx, b));
3618+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3619+
cx.fcx.lcx.ccx.node_types, b));
36103620

36113621
auto lhs_true_cx = new_scope_block_ctxt(cx, "lhs true");
36123622
auto lhs_true_res = res(lhs_true_cx, C_bool(true));
@@ -3622,10 +3632,12 @@ fn trans_binary(&@block_ctxt cx, ast::binop op,
36223632
case (_) {
36233633
// Remaining cases are eager:
36243634
auto lhs = trans_expr(cx, a);
3625-
auto lhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, a);
3635+
auto lhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3636+
cx.fcx.lcx.ccx.node_types, a);
36263637
lhs = autoderef(lhs.bcx, lhs.val, lhty);
36273638
auto rhs = trans_expr(lhs.bcx, b);
3628-
auto rhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, b);
3639+
auto rhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3640+
cx.fcx.lcx.ccx.node_types, b);
36293641
rhs = autoderef(rhs.bcx, rhs.val, rhty);
36303642
ret trans_eager_binop(rhs.bcx, op,
36313643
autoderefed_ty(cx.fcx.lcx.ccx, lhty), lhs.val, rhs.val);
@@ -3702,7 +3714,8 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond,
37023714
// If we have an else expression, then the entire
37033715
// if expression can have a non-nil type.
37043716
// FIXME: This isn't quite right, particularly re: dynamic types
3705-
auto expr_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, elexpr);
3717+
auto expr_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx,
3718+
cx.fcx.lcx.ccx.node_types, elexpr);
37063719
if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) {
37073720
expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn);
37083721
} else {
@@ -3759,7 +3772,8 @@ fn trans_for(&@block_ctxt cx,
37593772
}
37603773

37613774
auto next_cx = new_sub_block_ctxt(cx, "next");
3762-
auto seq_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, seq);
3775+
auto seq_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types,
3776+
seq);
37633777
auto seq_res = trans_expr(cx, seq);
37643778
auto it = iter_sequence(seq_res.bcx, seq_res.val, seq_ty,
37653779
bind inner(_, local, _, _, body, next_cx));
@@ -4091,7 +4105,7 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
40914105

40924106
case (ast::pat_lit(?lt, ?ann)) {
40934107
auto lllit = trans_lit(cx.fcx.lcx.ccx, *lt, ann);
4094-
auto lltype = ty::ann_to_type(ann);
4108+
auto lltype = ty::ann_to_type(cx.fcx.lcx.ccx.node_types, ann);
40954109
auto lleq = trans_compare(cx, ast::eq, lltype, llval, lllit);
40964110

40974111
auto matched_cx = new_sub_block_ctxt(lleq.bcx, "matched_cx");
@@ -4141,7 +4155,9 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
41414155
matched_cx = rslt.bcx;
41424156

41434157
auto llsubval = load_if_immediate(matched_cx,
4144-
llsubvalptr, pat_ty(cx.fcx.lcx.ccx.tcx, subpat));
4158+
llsubvalptr, pat_ty(cx.fcx.lcx.ccx.tcx,
4159+
cx.fcx.lcx.ccx.node_types,
4160+
subpat));
41454161
auto subpat_res = trans_pat_match(matched_cx, subpat,
41464162
llsubval, next_cx);
41474163
matched_cx = subpat_res.bcx;
@@ -4237,7 +4253,7 @@ fn trans_alt(&@block_ctxt cx, &@ast::expr expr,
42374253
"non-exhaustive match failure");
42384254

42394255
// FIXME: This isn't quite right, particularly re: dynamic types
4240-
auto expr_ty = ty::ann_to_type(ann);
4256+
auto expr_ty = ty::ann_to_type(cx.fcx.lcx.ccx.node_types, ann);
42414257
auto expr_llty;
42424258
if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) {
42434259
expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn);
@@ -4499,7 +4515,9 @@ fn trans_index(&@block_ctxt cx, &ast::span sp, &@ast::expr base,
44994515
&@ast::expr idx, &ast::ann ann) -> lval_result {
45004516

45014517
auto lv = trans_expr(cx, base);
4502-
lv = autoderef(lv.bcx, lv.val, ty::expr_ty(cx.fcx.lcx.ccx.tcx, base));
4518+
lv = autoderef(lv.bcx, lv.val, ty::expr_ty(cx.fcx.lcx.ccx.tcx,
4519+
cx.fcx.lcx.ccx.node_types,
4520+
base));
45034521
auto ix = trans_expr(lv.bcx, idx);
45044522
auto v = lv.val;
45054523
auto bcx = ix.bcx;
@@ -4565,7 +4583,8 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
45654583
}
45664584
case (ast::expr_field(?base, ?ident, ?ann)) {
45674585
auto r = trans_expr(cx, base);
4568-
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, base);
4586+
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx,
4587+
cx.fcx.lcx.ccx.node_types, base);
45694588
ret trans_field(r.bcx, e.span, r.val, t, ident, ann);
45704589
}
45714590
case (ast::expr_index(?base, ?idx, ?ann)) {
@@ -4626,7 +4645,8 @@ fn trans_cast(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result {
46264645
if (!ty::type_is_fp(cx.fcx.lcx.ccx.tcx, t)) {
46274646
// TODO: native-to-native casts
46284647
if (ty::type_is_native(cx.fcx.lcx.ccx.tcx,
4629-
ty::expr_ty(cx.fcx.lcx.ccx.tcx, e))) {
4648+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
4649+
cx.fcx.lcx.ccx.node_types, e))) {
46304650
e_res.val = e_res.bcx.build.PtrToInt(e_res.val, lldsttype);
46314651
} else if (ty::type_is_native(cx.fcx.lcx.ccx.tcx, t)) {
46324652
e_res.val = e_res.bcx.build.IntToPtr(e_res.val, lldsttype);
@@ -4716,7 +4736,7 @@ fn trans_bind_thunk(&@local_ctxt cx,
47164736

47174737
// Arg provided at binding time; thunk copies it from closure.
47184738
case (some[@ast::expr](?e)) {
4719-
auto e_ty = ty::expr_ty(cx.ccx.tcx, e);
4739+
auto e_ty = ty::expr_ty(cx.ccx.tcx, cx.ccx.node_types, e);
47204740
auto bound_arg =
47214741
GEP_tup_like(bcx, closure_ty, llclosure,
47224742
vec(0,
@@ -4812,7 +4832,8 @@ fn trans_bind(&@block_ctxt cx, &@ast::expr f,
48124832
let vec[ValueRef] lltydescs;
48134833
alt (f_res.generic) {
48144834
case (none[generic_info]) {
4815-
outgoing_fty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, f);
4835+
outgoing_fty = ty::expr_ty(cx.fcx.lcx.ccx.tcx,
4836+
cx.fcx.lcx.ccx.node_types, f);
48164837
lltydescs = vec();
48174838
}
48184839
case (some[generic_info](?ginfo)) {
@@ -4841,7 +4862,8 @@ fn trans_bind(&@block_ctxt cx, &@ast::expr f,
48414862

48424863
_vec::push[ValueRef](bound_vals, arg.val);
48434864
_vec::push[ty::t](bound_tys,
4844-
ty::expr_ty(cx.fcx.lcx.ccx.tcx, e));
4865+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
4866+
cx.fcx.lcx.ccx.node_types, e));
48454867

48464868
i += 1u;
48474869
}
@@ -4988,7 +5010,7 @@ fn trans_arg_expr(&@block_ctxt cx,
49885010

49895011
auto val;
49905012
auto bcx = cx;
4991-
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
5013+
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e);
49925014

49935015
if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
49945016
auto re = trans_expr(bcx, e);
@@ -5188,13 +5210,13 @@ fn trans_call(&@block_ctxt cx, &@ast::expr f,
51885210
}
51895211

51905212
case (_) {
5191-
fn_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, f);
5192-
5213+
fn_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types,
5214+
f);
51935215
}
51945216

51955217
}
51965218

5197-
auto ret_ty = ty::ann_to_type(ann);
5219+
auto ret_ty = ty::ann_to_type(cx.fcx.lcx.ccx.node_types, ann);
51985220
auto args_res = trans_args(f_res.res.bcx,
51995221
llenv, f_res.llobj,
52005222
f_res.generic,
@@ -5249,7 +5271,8 @@ fn trans_tup(&@block_ctxt cx, &vec[ast::elt] elts,
52495271
let int i = 0;
52505272

52515273
for (ast::elt e in elts) {
5252-
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e.expr);
5274+
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types,
5275+
e.expr);
52535276
auto src_res = trans_expr(bcx, e.expr);
52545277
bcx = src_res.bcx;
52555278
auto dst_res = GEP_tup_like(bcx, t, tup_val, vec(0, i));
@@ -5565,7 +5588,7 @@ fn trans_expr(&@block_ctxt cx, &@ast::expr e) -> result {
55655588
// lval cases fall through to trans_lval and then
55665589
// possibly load the result (if it's non-structural).
55675590

5568-
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
5591+
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e);
55695592
auto sub = trans_lval(cx, e);
55705593
ret res(sub.res.bcx, load_if_immediate(sub.res.bcx, sub.res.val, t));
55715594
}
@@ -5626,7 +5649,7 @@ fn trans_log(int lvl, &@block_ctxt cx, &@ast::expr e) -> result {
56265649
cx.build.CondBr(test, log_cx.llbb, after_cx.llbb);
56275650

56285651
auto sub = trans_expr(log_cx, e);
5629-
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
5652+
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e);
56305653

56315654
auto log_bcx = sub.bcx;
56325655
if (ty::type_is_fp(cx.fcx.lcx.ccx.tcx, e_ty)) {
@@ -5744,7 +5767,8 @@ fn trans_put(&@block_ctxt cx, &option::t[@ast::expr] e) -> result {
57445767
alt (e) {
57455768
case (none[@ast::expr]) { }
57465769
case (some[@ast::expr](?x)) {
5747-
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, x);
5770+
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx,
5771+
cx.fcx.lcx.ccx.node_types, x);
57485772
auto arg = rec(mode=ty::mo_alias, ty=e_ty);
57495773
auto arg_tys = type_of_explicit_args(cx.fcx.lcx.ccx, vec(arg));
57505774
auto r = trans_arg_expr(bcx, arg, arg_tys.(0), x);
@@ -5804,7 +5828,8 @@ fn trans_ret(&@block_ctxt cx, &option::t[@ast::expr] e) -> result {
58045828

58055829
alt (e) {
58065830
case (some[@ast::expr](?x)) {
5807-
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, x);
5831+
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx,
5832+
cx.fcx.lcx.ccx.node_types, x);
58085833
auto r = trans_expr(cx, x);
58095834
bcx = r.bcx;
58105835
val = r.val;
@@ -6192,7 +6217,8 @@ fn trans_block(&@block_ctxt cx, &ast::block b) -> result {
61926217
if (is_terminated(bcx)) {
61936218
ret r;
61946219
} else {
6195-
auto r_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
6220+
auto r_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx,
6221+
cx.fcx.lcx.ccx.node_types, e);
61966222
if (!ty::type_is_nil(cx.fcx.lcx.ccx.tcx, r_ty)) {
61976223
// The value resulting from the block gets copied into an
61986224
// alloca created in an outer scope and its refcount
@@ -6416,7 +6442,7 @@ fn is_terminated(&@block_ctxt cx) -> bool {
64166442
}
64176443

64186444
fn arg_tys_of_fn(&@crate_ctxt ccx, ast::ann ann) -> vec[ty::arg] {
6419-
alt (ty::struct(ccx.tcx, ty::ann_to_type(ann))) {
6445+
alt (ty::struct(ccx.tcx, ty::ann_to_type(ccx.node_types, ann))) {
64206446
case (ty::ty_fn(_, ?arg_tys, _)) {
64216447
ret arg_tys;
64226448
}
@@ -6435,7 +6461,7 @@ fn ret_ty_of_fn_ty(&@crate_ctxt ccx, ty::t t) -> ty::t {
64356461

64366462

64376463
fn ret_ty_of_fn(&@crate_ctxt ccx, ast::ann ann) -> ty::t {
6438-
ret ret_ty_of_fn_ty(ccx, ty::ann_to_type(ann));
6464+
ret ret_ty_of_fn_ty(ccx, ty::ann_to_type(ccx.node_types, ann));
64396465
}
64406466

64416467
fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, self_vt llself) {
@@ -7920,7 +7946,8 @@ fn create_crate_map(&@crate_ctxt ccx) -> ValueRef {
79207946
}
79217947

79227948
fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
7923-
&ty::type_cache type_cache, &str output)
7949+
&ty::node_type_table node_types, &ty::type_cache type_cache,
7950+
&str output)
79247951
-> ModuleRef {
79257952
auto llmod =
79267953
llvm::LLVMModuleCreateWithNameInContext(_str::buf("rust_out"),
@@ -7978,7 +8005,8 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
79788005
mutable n_glues_created = 0u,
79798006
mutable n_null_glues = 0u,
79808007
mutable n_real_glues = 0u),
7981-
upcalls = upcall::declare_upcalls(tn, llmod));
8008+
upcalls = upcall::declare_upcalls(tn, llmod),
8009+
node_types = node_types);
79828010
auto cx = new_local_ctxt(ccx);
79838011

79848012
create_typedefs(ccx);

0 commit comments

Comments
 (0)