@@ -58,13 +58,15 @@ type creader_cache = hashmap[tup(int,uint,uint),ty::t];
58
58
type ctxt = rec ( @type_store ts ,
59
59
session:: session sess,
60
60
resolve:: def_map def_map,
61
+ node_type_table node_types,
62
+ type_cache tcache,
61
63
creader_cache rcache,
62
64
hashmap[ t, str] short_names_cache ) ;
63
65
type ty_ctxt = ctxt ; // Needed for disambiguation from unify::ctxt.
64
66
65
67
// Convert from method type to function type. Pretty easy; we just drop
66
68
// 'ident'.
67
- fn method_ty_to_fn_ty ( ctxt cx, method m) -> t {
69
+ fn method_ty_to_fn_ty ( & ctxt cx, method m) -> t {
68
70
ret mk_fn ( cx, m. proto , m. inputs , m. output ) ;
69
71
}
70
72
@@ -215,9 +217,19 @@ fn mk_rcache() -> creader_cache {
215
217
}
216
218
217
219
fn mk_ctxt ( session:: session s, resolve:: def_map dm) -> ctxt {
220
+
221
+ let vec[ mutable option:: t[ ty:: ty_param_substs_opt_and_ty] ] ntt_sub =
222
+ [ mutable] ;
223
+ let node_type_table ntt = @mutable ntt_sub;
224
+
225
+ auto tcache =
226
+ common:: new_def_hash[ ty:: ty_param_count_and_ty] ( ) ;
227
+
218
228
ret rec( ts = mk_type_store ( ) ,
219
229
sess = s,
220
230
def_map = dm,
231
+ node_types = ntt,
232
+ tcache = tcache,
221
233
rcache = mk_rcache ( ) ,
222
234
short_names_cache =
223
235
map:: mk_hashmap[ ty:: t, str] ( ty:: hash_ty, ty:: eq_ty) ) ;
@@ -489,9 +501,9 @@ fn path_to_str(&ast::path pth) -> str {
489
501
ret result;
490
502
}
491
503
492
- fn ty_to_str ( ctxt cx, & t typ ) -> str {
504
+ fn ty_to_str ( & ctxt cx, & t typ ) -> str {
493
505
494
- fn fn_input_to_str ( ctxt cx, & rec( mode mode, t ty) input ) -> str {
506
+ fn fn_input_to_str ( & ctxt cx, & rec( mode mode, t ty) input ) -> str {
495
507
auto s;
496
508
alt ( input. mode ) {
497
509
case ( mo_val) { s = "" ; }
@@ -502,7 +514,7 @@ fn ty_to_str(ctxt cx, &t typ) -> str {
502
514
ret s + ty_to_str ( cx, input. ty ) ;
503
515
}
504
516
505
- fn fn_to_str ( ctxt cx,
517
+ fn fn_to_str ( & ctxt cx,
506
518
ast:: proto proto,
507
519
option:: t[ ast:: ident ] ident ,
508
520
vec[ arg] inputs , t output ) -> str {
@@ -536,16 +548,16 @@ fn ty_to_str(ctxt cx, &t typ) -> str {
536
548
ret s;
537
549
}
538
550
539
- fn method_to_str ( ctxt cx, & method m) -> str {
551
+ fn method_to_str ( & ctxt cx, & method m) -> str {
540
552
ret fn_to_str ( cx, m. proto , some[ ast:: ident] ( m. ident ) ,
541
553
m. inputs , m. output ) + ";" ;
542
554
}
543
555
544
- fn field_to_str ( ctxt cx, & field f) -> str {
556
+ fn field_to_str ( & ctxt cx, & field f) -> str {
545
557
ret mt_to_str ( cx, f. mt ) + " " + f. ident ;
546
558
}
547
559
548
- fn mt_to_str ( ctxt cx, & mt m) -> str {
560
+ fn mt_to_str ( & ctxt cx, & mt m) -> str {
549
561
auto mstr;
550
562
alt ( m. mut ) {
551
563
case ( ast:: mut) { mstr = "mutable " ; }
@@ -648,7 +660,7 @@ fn ty_to_str(ctxt cx, &t typ) -> str {
648
660
ret s;
649
661
}
650
662
651
- fn ty_to_short_str ( ctxt cx, t typ ) -> str {
663
+ fn ty_to_short_str ( & ctxt cx, t typ ) -> str {
652
664
auto f = def_to_str;
653
665
auto ecx = @rec ( ds=f, tcx=cx, abbrevs=metadata:: ac_no_abbrevs) ;
654
666
auto s = metadata:: Encode :: ty_str ( ecx, typ) ;
@@ -660,7 +672,7 @@ fn ty_to_short_str(ctxt cx, t typ) -> str {
660
672
661
673
type ty_walk = fn ( t ) ;
662
674
663
- fn walk_ty ( ctxt cx, ty_walk walker, t ty ) {
675
+ fn walk_ty ( & ctxt cx, ty_walk walker, t ty ) {
664
676
alt ( struct ( cx, ty) ) {
665
677
case ( ty_nil) { /* no-op */ }
666
678
case ( ty_bot) { /* no-op */ }
@@ -724,7 +736,7 @@ fn walk_ty(ctxt cx, ty_walk walker, t ty) {
724
736
725
737
type ty_fold = fn ( t ) -> t ;
726
738
727
- fn fold_ty ( ctxt cx, ty_fold fld, t ty_0 ) -> t {
739
+ fn fold_ty ( & ctxt cx, ty_fold fld, t ty_0 ) -> t {
728
740
auto ty = ty_0;
729
741
alt ( struct ( cx, ty) ) {
730
742
case ( ty_nil) { /* no-op */ }
@@ -819,13 +831,13 @@ fn fold_ty(ctxt cx, ty_fold fld, t ty_0) -> t {
819
831
820
832
// Type utilities
821
833
822
- fn rename( ctxt cx, t typ, str new_cname) -> t {
834
+ fn rename( & ctxt cx, t typ, str new_cname) -> t {
823
835
ret gen_ty_full( cx, struct( cx, typ) , some[ str] ( new_cname) ) ;
824
836
}
825
837
826
838
// Returns a type with the structural part taken from `struct_ty` and the
827
839
// canonical name from `cname_ty`.
828
- fn copy_cname( ctxt cx, t struct_ty, t cname_ty) -> t {
840
+ fn copy_cname( & ctxt cx, t struct_ty, t cname_ty) -> t {
829
841
ret gen_ty_full( cx, struct( cx, struct_ty) , cname( cx, cname_ty) ) ;
830
842
}
831
843
@@ -1484,8 +1496,8 @@ fn ann_has_type_params(&node_type_table ntt, &ast::ann ann) -> bool {
1484
1496
1485
1497
// Returns the type of an annotation, with type parameter substitutions
1486
1498
// performed if applicable.
1487
- fn ann_to_monotype ( ctxt cx, & node_type_table ntt , ast:: ann a) -> t {
1488
- auto tpot = ann_to_ty_param_substs_opt_and_ty ( ntt , a) ;
1499
+ fn ann_to_monotype ( & ctxt cx, ast:: ann a) -> t {
1500
+ auto tpot = ann_to_ty_param_substs_opt_and_ty ( cx . node_types , a) ;
1489
1501
alt ( tpot. _0 ) {
1490
1502
case ( none[ vec[ t] ] ) { ret tpot. _1 ; }
1491
1503
case ( some[ vec[ t] ] ( ?tps) ) {
@@ -1518,8 +1530,8 @@ fn bot_ann(uint node_id, ctxt tcx) -> ast::ann {
1518
1530
1519
1531
1520
1532
// Returns the number of distinct type parameters in the given type.
1521
- fn count_ty_params ( ctxt cx, t ty ) -> uint {
1522
- fn counter ( ctxt cx, @mutable vec[ uint] param_indices , t ty ) {
1533
+ fn count_ty_params ( & ctxt cx, t ty ) -> uint {
1534
+ fn counter ( & ctxt cx, @mutable vec[ uint] param_indices , t ty ) {
1523
1535
alt ( struct ( cx, ty) ) {
1524
1536
case ( ty_param ( ?param_idx) ) {
1525
1537
auto seen = false ;
@@ -1650,28 +1662,28 @@ fn item_ty(&node_type_table ntt, &@ast::item it) -> ty_param_count_and_ty {
1650
1662
ret tup( ty_param_count, result_ty) ;
1651
1663
}
1652
1664
1653
- fn stmt_ty ( & ctxt cx, & node_type_table ntt , & @ast:: stmt s) -> t {
1665
+ fn stmt_ty ( & ctxt cx, & @ast:: stmt s) -> t {
1654
1666
alt ( s. node ) {
1655
1667
case ( ast:: stmt_expr ( ?e, _) ) {
1656
- ret expr_ty ( cx, ntt , e) ;
1668
+ ret expr_ty ( cx, e) ;
1657
1669
}
1658
1670
case ( _) {
1659
1671
ret mk_nil ( cx) ;
1660
1672
}
1661
1673
}
1662
1674
}
1663
1675
1664
- fn block_ty ( & ctxt cx, & node_type_table ntt , & ast:: block b) -> t {
1676
+ fn block_ty ( & ctxt cx, & ast:: block b) -> t {
1665
1677
alt ( b. node . expr ) {
1666
- case ( some[ @ast:: expr] ( ?e) ) { ret expr_ty ( cx, ntt , e) ; }
1678
+ case ( some[ @ast:: expr] ( ?e) ) { ret expr_ty ( cx, e) ; }
1667
1679
case ( none[ @ast:: expr] ) { ret mk_nil ( cx) ; }
1668
1680
}
1669
1681
}
1670
1682
1671
1683
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
1672
1684
// doesn't provide type parameter substitutions.
1673
- fn pat_ty ( & ctxt cx, & node_type_table ntt , & @ast:: pat pat) -> t {
1674
- ret ann_to_monotype ( cx, ntt , pat_ann ( pat) ) ;
1685
+ fn pat_ty ( & ctxt cx, & @ast:: pat pat) -> t {
1686
+ ret ann_to_monotype ( cx, pat_ann ( pat) ) ;
1675
1687
}
1676
1688
1677
1689
fn item_ann ( & @ast:: item it) -> ast:: ann {
@@ -1743,15 +1755,16 @@ fn expr_ann(&@ast::expr e) -> ast::ann {
1743
1755
// ask for the type of "id" in "id(3)", it will return "fn(&int) -> int"
1744
1756
// instead of "fn(&T) -> T with T = int". If this isn't what you want, see
1745
1757
// expr_ty_params_and_ty() below.
1746
- fn expr_ty ( & ctxt cx, & node_type_table ntt , & @ast:: expr expr) -> t {
1747
- ret ann_to_monotype ( cx, ntt , expr_ann ( expr) ) ;
1758
+ fn expr_ty ( & ctxt cx, & @ast:: expr expr) -> t {
1759
+ ret ann_to_monotype ( cx, expr_ann ( expr) ) ;
1748
1760
}
1749
1761
1750
- fn expr_ty_params_and_ty ( & ctxt cx, & node_type_table ntt , & @ast:: expr expr)
1762
+ fn expr_ty_params_and_ty ( & ctxt cx, & @ast:: expr expr)
1751
1763
-> tup ( vec[ t ] , t ) {
1752
1764
auto a = expr_ann ( expr) ;
1753
1765
1754
- ret tup( ann_to_type_params ( ntt, a) , ann_to_type ( ntt, a) ) ;
1766
+ ret tup( ann_to_type_params ( cx. node_types , a) ,
1767
+ ann_to_type ( cx. node_types , a) ) ;
1755
1768
}
1756
1769
1757
1770
fn expr_has_ty_params ( & node_type_table ntt, & @ast:: expr expr) -> bool {
@@ -2644,7 +2657,7 @@ fn substitute_type_params(&ctxt cx, &vec[t] bindings, &t typ) -> t {
2644
2657
if ( !type_contains_bound_params ( cx, typ) ) {
2645
2658
ret typ;
2646
2659
}
2647
- fn replacer ( ctxt cx, vec[ t] bindings , t typ ) -> t {
2660
+ fn replacer ( & ctxt cx, vec[ t] bindings , t typ ) -> t {
2648
2661
alt ( struct ( cx, typ) ) {
2649
2662
case ( ty_bound_param ( ?param_index) ) {
2650
2663
ret bindings. ( param_index) ;
@@ -2662,7 +2675,7 @@ fn bind_params_in_type(&ctxt cx, &t typ) -> t {
2662
2675
if ( !type_contains_params ( cx, typ) ) {
2663
2676
ret typ;
2664
2677
}
2665
- fn binder ( ctxt cx, t typ ) -> t {
2678
+ fn binder ( & ctxt cx, t typ ) -> t {
2666
2679
alt ( struct ( cx, typ) ) {
2667
2680
case ( ty_bound_param ( ?index) ) {
2668
2681
log_err "bind_params_in_type() called on type that already " +
@@ -2701,20 +2714,18 @@ fn def_has_ty_params(&ast::def def) -> bool {
2701
2714
// If the given item is in an external crate, looks up its type and adds it to
2702
2715
// the type cache. Returns the type parameters and type.
2703
2716
fn lookup_item_type ( session:: session sess,
2704
- ctxt cx,
2705
- & type_cache cache,
2706
- ast:: def_id did) -> ty_param_count_and_ty {
2717
+ ctxt cx, ast:: def_id did) -> ty_param_count_and_ty {
2707
2718
if ( did. _0 == sess. get_targ_crate_num ( ) ) {
2708
2719
// The item is in this crate. The caller should have added it to the
2709
2720
// type cache already; we simply return it.
2710
- ret cache . get ( did) ;
2721
+ ret cx . tcache . get ( did) ;
2711
2722
}
2712
2723
2713
- alt ( cache . find ( did) ) {
2724
+ alt ( cx . tcache . find ( did) ) {
2714
2725
case ( some[ ty_param_count_and_ty] ( ?tpt) ) { ret tpt; }
2715
2726
case ( none[ ty_param_count_and_ty] ) {
2716
2727
auto tyt = creader:: get_type ( sess, cx, did) ;
2717
- cache . insert ( did, tyt) ;
2728
+ cx . tcache . insert ( did, tyt) ;
2718
2729
ret tyt;
2719
2730
}
2720
2731
}
@@ -2731,8 +2742,8 @@ fn ret_ty_of_fn_ty(ty_ctxt tcx, t a_ty) -> t {
2731
2742
}
2732
2743
}
2733
2744
2734
- fn ret_ty_of_fn ( node_type_table ntt , ty_ctxt tcx, ast:: ann ann) -> t {
2735
- ret ret_ty_of_fn_ty ( tcx, ann_to_type ( ntt , ann) ) ;
2745
+ fn ret_ty_of_fn ( ty_ctxt tcx, ast:: ann ann) -> t {
2746
+ ret ret_ty_of_fn_ty ( tcx, ann_to_type ( tcx . node_types , ann) ) ;
2736
2747
}
2737
2748
2738
2749
// Local Variables:
0 commit comments