@@ -69,24 +69,44 @@ type fn_ctxt =
69
69
// Used for ast_ty_to_ty() below.
70
70
type ty_getter = fn ( & ast:: def_id ) -> ty:: ty_param_count_and_ty ;
71
71
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
+ }
72
91
73
92
// Returns the type parameter count and the type for the given definition.
74
93
fn ty_param_count_and_ty_for_def ( & @fn_ctxt fcx , & span sp, & ast:: def defn ) ->
75
94
ty_param_count_and_ty {
76
95
alt ( defn) {
77
96
case ( ast:: def_arg ( ?id) ) {
78
97
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 ) ) ;
80
100
ret tup( 0 u, typ) ;
81
101
}
82
102
case ( ast:: def_local ( ?id) ) {
83
103
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 ) ) ;
85
105
ret tup( 0 u, typ) ;
86
106
}
87
107
case ( ast:: def_obj_field ( ?id) ) {
88
108
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 ) ) ;
90
110
ret tup( 0 u, typ) ;
91
111
}
92
112
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) ->
103
123
}
104
124
case ( ast:: def_binding ( ?id) ) {
105
125
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 ) ) ;
107
127
ret tup( 0 u, typ) ;
108
128
}
109
129
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 {
320
340
typ = ty:: mk_fn( tcx, proto, i, out_ty, cf, out_constrs) ;
321
341
}
322
342
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) ) ) {
325
345
typ =
326
346
instantiate( tcx, ast_ty. span, getter, id,
327
347
path. node. types) ;
328
348
}
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( _) ) {
332
354
tcx. sess. span_fatal( ast_ty. span,
333
355
"found type name used as a variable" ) ;
334
356
}
357
+ case ( _) {
358
+ tcx. sess. span_fatal( ast_ty. span,
359
+ "internal error in instantiate" ) ;
360
+ }
335
361
}
336
362
cname = some( path_to_str( path) ) ;
337
363
}
@@ -499,14 +525,20 @@ mod collect {
499
525
500
526
ret decoder:: get_type ( cx. tcx , id) ;
501
527
}
502
- auto it = cx. tcx . items . get ( id. _1 ) ;
528
+ auto it = cx. tcx . items . find ( id. _1 ) ;
503
529
auto tpt;
504
530
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) ) ) {
507
535
tpt = ty_of_native_item ( cx, native_item,
508
536
ast:: native_abi_cdecl) ;
509
537
}
538
+ case ( _) {
539
+ cx. tcx . sess . fatal ( "internal error " +
540
+ util:: common:: istr ( id. _1 ) ) ;
541
+ }
510
542
}
511
543
ret tpt;
512
544
}
@@ -1027,7 +1059,7 @@ mod writeback {
1027
1059
resolve_type_vars_for_node( fcx, p. span, ty:: pat_node_id( p) ) ;
1028
1060
}
1029
1061
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) ;
1031
1063
auto fix_rslt =
1032
1064
ty:: unify:: resolve_type_var( fcx. ccx. tcx, fcx. var_bindings,
1033
1065
var_id) ;
@@ -1226,15 +1258,15 @@ fn check_pat(&@fn_ctxt fcx, &@ast::pat pat, ty::t expected) {
1226
1258
write:: ty_only_fixup( fcx, id, typ) ;
1227
1259
}
1228
1260
case ( ast:: pat_bind( ?name, ?id) ) {
1229
- auto vid = fcx. locals . get ( id) ;
1261
+ auto vid = lookup_local ( fcx, pat . span , id) ;
1230
1262
auto typ = ty:: mk_var( fcx. ccx. tcx, vid) ;
1231
1263
typ = demand:: simple( fcx, pat. span, expected, typ) ;
1232
1264
write:: ty_only_fixup( fcx, id, typ) ;
1233
1265
}
1234
1266
case ( ast:: pat_tag( ?path, ?subpats, ?id) ) {
1235
1267
// Typecheck the path.
1236
1268
1237
- auto v_def = fcx. ccx . tcx . def_map . get ( id) ;
1269
+ auto v_def = lookup_def ( fcx, path . span , id) ;
1238
1270
auto v_def_ids = ast:: variant_def_ids( v_def) ;
1239
1271
auto tag_tpt = ty:: lookup_item_type( fcx. ccx. tcx, v_def_ids. _0) ;
1240
1272
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,
1329
1361
alt ( caller_purity) {
1330
1362
case ( ast:: impure_fn) { ret; }
1331
1363
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) ) ) {
1334
1366
ret;
1335
1367
}
1336
1368
case ( _) {
@@ -1458,8 +1490,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
1458
1490
case ( ast:: expr_call( ?operator, ?operands) ) {
1459
1491
alt ( operator. node) {
1460
1492
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) ) ) {
1463
1496
// do nothing
1464
1497
}
1465
1498
case ( _) {
@@ -1600,7 +1633,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
1600
1633
write:: ty_only_fixup( fcx, id, oper_t) ;
1601
1634
}
1602
1635
case ( ast:: expr_path( ?pth) ) {
1603
- auto defn = fcx. ccx . tcx . def_map . get ( id) ;
1636
+ auto defn = lookup_def ( fcx, pth . span , id) ;
1604
1637
auto tpt = ty_param_count_and_ty_for_def( fcx, expr. span, defn) ;
1605
1638
if ( ty:: def_has_ty_params( defn) ) {
1606
1639
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)
2287
2320
fn check_decl_initializer( & @fn_ctxt fcx, ast:: node_id nid,
2288
2321
& ast:: initializer init) {
2289
2322
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) ) ;
2291
2325
alt ( init. op) {
2292
2326
case ( ast:: init_assign) {
2293
2327
demand:: simple( fcx, init. expr. span, lty,
0 commit comments