Skip to content

Commit fd3ed2e

Browse files
committed
---
yaml --- r: 3557 b: refs/heads/master c: 48a69d2 h: refs/heads/master i: 3555: aa9e3f1 v: v3
1 parent b71e559 commit fd3ed2e

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
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: c425a422ed8aec799532ba96e6f274ef83a0b759
2+
refs/heads/master: 48a69d2100622df88e3f1014eff00227401bf079

trunk/src/comp/middle/typeck.rs

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,44 @@ type fn_ctxt =
6969
// Used for ast_ty_to_ty() below.
7070
type ty_getter = fn(&ast::def_id) -> ty::ty_param_count_and_ty ;
7171

72+
fn lookup_local(&@fn_ctxt fcx, &span sp, ast::node_id id) -> int {
73+
alt (fcx.locals.find(id)) {
74+
case (some(?x)) { x }
75+
case (_) {
76+
fcx.ccx.tcx.sess.span_fatal(sp, "internal error looking up a \
77+
local var")
78+
}
79+
}
80+
}
81+
82+
fn lookup_def(&@fn_ctxt fcx, &span sp, ast::node_id id) -> ast::def {
83+
alt (fcx.ccx.tcx.def_map.find(id)) {
84+
case (some(?x)) { x }
85+
case (_) {
86+
fcx.ccx.tcx.sess.span_fatal(sp, "internal error looking up \
87+
a definition")
88+
}
89+
}
90+
}
7291

7392
// Returns the type parameter count and the type for the given definition.
7493
fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &span sp, &ast::def defn) ->
7594
ty_param_count_and_ty {
7695
alt (defn) {
7796
case (ast::def_arg(?id)) {
7897
assert (fcx.locals.contains_key(id._1));
79-
auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id._1));
98+
auto typ = ty::mk_var(fcx.ccx.tcx,
99+
lookup_local(fcx, sp, id._1));
80100
ret tup(0u, typ);
81101
}
82102
case (ast::def_local(?id)) {
83103
assert (fcx.locals.contains_key(id._1));
84-
auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id._1));
104+
auto typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id._1));
85105
ret tup(0u, typ);
86106
}
87107
case (ast::def_obj_field(?id)) {
88108
assert (fcx.locals.contains_key(id._1));
89-
auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id._1));
109+
auto typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id._1));
90110
ret tup(0u, typ);
91111
}
92112
case (ast::def_fn(?id, _)) {
@@ -103,7 +123,7 @@ fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &span sp, &ast::def defn) ->
103123
}
104124
case (ast::def_binding(?id)) {
105125
assert (fcx.locals.contains_key(id._1));
106-
auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id._1));
126+
auto typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id._1));
107127
ret tup(0u, typ);
108128
}
109129
case (ast::def_mod(_)) {
@@ -320,18 +340,24 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
320340
typ = ty::mk_fn(tcx, proto, i, out_ty, cf, out_constrs);
321341
}
322342
case (ast::ty_path(?path, ?id)) {
323-
alt (tcx.def_map.get(id)) {
324-
case (ast::def_ty(?id)) {
343+
alt (tcx.def_map.find(id)) {
344+
case (some(ast::def_ty(?id))) {
325345
typ =
326346
instantiate(tcx, ast_ty.span, getter, id,
327347
path.node.types);
328348
}
329-
case (ast::def_native_ty(?id)) { typ = getter(id)._1; }
330-
case (ast::def_ty_arg(?id)) { typ = ty::mk_param(tcx, id); }
331-
case (_) {
349+
case (some(ast::def_native_ty(?id))) { typ = getter(id)._1; }
350+
case (some(ast::def_ty_arg(?id))) {
351+
typ = ty::mk_param(tcx, id);
352+
}
353+
case (some(_)) {
332354
tcx.sess.span_fatal(ast_ty.span,
333355
"found type name used as a variable");
334356
}
357+
case (_) {
358+
tcx.sess.span_fatal(ast_ty.span,
359+
"internal error in instantiate");
360+
}
335361
}
336362
cname = some(path_to_str(path));
337363
}
@@ -499,14 +525,20 @@ mod collect {
499525

500526
ret decoder::get_type(cx.tcx, id);
501527
}
502-
auto it = cx.tcx.items.get(id._1);
528+
auto it = cx.tcx.items.find(id._1);
503529
auto tpt;
504530
alt (it) {
505-
case (ast_map::node_item(?item)) { tpt = ty_of_item(cx, item); }
506-
case (ast_map::node_native_item(?native_item)) {
531+
case (some(ast_map::node_item(?item))) {
532+
tpt = ty_of_item(cx, item);
533+
}
534+
case (some(ast_map::node_native_item(?native_item))) {
507535
tpt = ty_of_native_item(cx, native_item,
508536
ast::native_abi_cdecl);
509537
}
538+
case (_) {
539+
cx.tcx.sess.fatal("internal error " +
540+
util::common::istr(id._1));
541+
}
510542
}
511543
ret tpt;
512544
}
@@ -1027,7 +1059,7 @@ mod writeback {
10271059
resolve_type_vars_for_node(fcx, p.span, ty::pat_node_id(p));
10281060
}
10291061
fn visit_local_pre(@fn_ctxt fcx, &@ast::local l) {
1030-
auto var_id = fcx.locals.get(l.node.id);
1062+
auto var_id = lookup_local(fcx, l.span, l.node.id);
10311063
auto fix_rslt =
10321064
ty::unify::resolve_type_var(fcx.ccx.tcx, fcx.var_bindings,
10331065
var_id);
@@ -1226,15 +1258,15 @@ fn check_pat(&@fn_ctxt fcx, &@ast::pat pat, ty::t expected) {
12261258
write::ty_only_fixup(fcx, id, typ);
12271259
}
12281260
case (ast::pat_bind(?name, ?id)) {
1229-
auto vid = fcx.locals.get(id);
1261+
auto vid = lookup_local(fcx, pat.span, id);
12301262
auto typ = ty::mk_var(fcx.ccx.tcx, vid);
12311263
typ = demand::simple(fcx, pat.span, expected, typ);
12321264
write::ty_only_fixup(fcx, id, typ);
12331265
}
12341266
case (ast::pat_tag(?path, ?subpats, ?id)) {
12351267
// Typecheck the path.
12361268

1237-
auto v_def = fcx.ccx.tcx.def_map.get(id);
1269+
auto v_def = lookup_def(fcx, path.span, id);
12381270
auto v_def_ids = ast::variant_def_ids(v_def);
12391271
auto tag_tpt = ty::lookup_item_type(fcx.ccx.tcx, v_def_ids._0);
12401272
auto path_tpot = instantiate_path(fcx, path, tag_tpt, pat.span);
@@ -1329,8 +1361,8 @@ fn require_pure_call(@crate_ctxt ccx, &ast::purity caller_purity,
13291361
alt (caller_purity) {
13301362
case (ast::impure_fn) { ret; }
13311363
case (ast::pure_fn) {
1332-
alt (ccx.tcx.def_map.get(callee.id)) {
1333-
case (ast::def_fn(_, ast::pure_fn)) {
1364+
alt (ccx.tcx.def_map.find(callee.id)) {
1365+
case (some(ast::def_fn(_, ast::pure_fn))) {
13341366
ret;
13351367
}
13361368
case (_) {
@@ -1458,8 +1490,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
14581490
case (ast::expr_call(?operator, ?operands)) {
14591491
alt (operator.node) {
14601492
case (ast::expr_path(?oper_name)) {
1461-
alt (fcx.ccx.tcx.def_map.get(operator.id)) {
1462-
case (ast::def_fn(?_d_id, ast::pure_fn)) {
1493+
alt (fcx.ccx.tcx.def_map.find(operator.id)) {
1494+
case (some(ast::def_fn(?_d_id,
1495+
ast::pure_fn))) {
14631496
// do nothing
14641497
}
14651498
case (_) {
@@ -1600,7 +1633,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
16001633
write::ty_only_fixup(fcx, id, oper_t);
16011634
}
16021635
case (ast::expr_path(?pth)) {
1603-
auto defn = fcx.ccx.tcx.def_map.get(id);
1636+
auto defn = lookup_def(fcx, pth.span, id);
16041637
auto tpt = ty_param_count_and_ty_for_def(fcx, expr.span, defn);
16051638
if (ty::def_has_ty_params(defn)) {
16061639
auto path_tpot = instantiate_path(fcx, pth, tpt, expr.span);
@@ -2287,7 +2320,8 @@ fn ast_constr_to_constr(ty::ctxt tcx, &@ast::constr c)
22872320
fn check_decl_initializer(&@fn_ctxt fcx, ast::node_id nid,
22882321
&ast::initializer init) {
22892322
check_expr(fcx, init.expr);
2290-
auto lty = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(nid));
2323+
auto lty = ty::mk_var(fcx.ccx.tcx,
2324+
lookup_local(fcx, init.expr.span, nid));
22912325
alt (init.op) {
22922326
case (ast::init_assign) {
22932327
demand::simple(fcx, init.expr.span, lty,

0 commit comments

Comments
 (0)