@@ -207,9 +207,6 @@ type mt = {ty: t, mut: ast::mutability};
207
207
// the types of AST nodes.
208
208
type creader_cache = hashmap < { cnum: int , pos : uint , len : uint } , ty:: t > ;
209
209
210
- type tag_var_cache =
211
- @smallintmap:: smallintmap < @mutable [ variant_info ] > ;
212
-
213
210
type ctxt =
214
211
@{ ts : @type_store ,
215
212
sess : session:: session ,
@@ -223,7 +220,7 @@ type ctxt =
223
220
needs_drop_cache : hashmap < t , bool > ,
224
221
kind_cache : hashmap < t , ast:: kind > ,
225
222
ast_ty_to_ty_cache : hashmap < @ast:: ty , option:: t < t > > ,
226
- tag_var_cache : tag_var_cache } ;
223
+ tag_var_cache : hashmap < ast :: def_id , @ [ variant_info ] > } ;
227
224
228
225
type ty_ctxt = ctxt ;
229
226
@@ -404,7 +401,6 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
404
401
freevars : freevars:: freevar_map ) -> ctxt {
405
402
let ntt: node_type_table =
406
403
@smallintmap:: mk :: < ty:: ty_param_substs_opt_and_ty > ( ) ;
407
- let tcache = new_def_hash :: < ty:: ty_param_kinds_and_ty > ( ) ;
408
404
fn eq_raw_ty ( & & a: @raw_t , & & b: @raw_t ) -> bool {
409
405
ret a. hash == b. hash && a. struct == b. struct ;
410
406
}
@@ -416,14 +412,14 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
416
412
node_types: ntt,
417
413
items: amap,
418
414
freevars: freevars,
419
- tcache: tcache ,
415
+ tcache: new_def_hash ( ) ,
420
416
rcache: mk_rcache ( ) ,
421
417
short_names_cache: new_ty_hash ( ) ,
422
418
needs_drop_cache: new_ty_hash ( ) ,
423
419
kind_cache: new_ty_hash ( ) ,
424
420
ast_ty_to_ty_cache:
425
421
map:: mk_hashmap ( ast_util:: hash_ty, ast_util:: eq_ty) ,
426
- tag_var_cache: @smallintmap :: mk ( ) } ;
422
+ tag_var_cache: new_def_hash ( ) } ;
427
423
populate_type_store ( cx) ;
428
424
ret cx;
429
425
}
@@ -2627,45 +2623,34 @@ fn def_has_ty_params(def: ast::def) -> bool {
2627
2623
// Tag information
2628
2624
type variant_info = @{ args : [ ty:: t ] , ctor_ty : ty:: t , id : ast:: def_id } ;
2629
2625
2630
- fn tag_variants ( cx : ctxt , id : ast:: def_id ) -> @mutable [ variant_info ] {
2631
- if ast:: local_crate != id. crate {
2632
- ret @mutable csearch:: get_tag_variants ( cx, id) ;
2633
- }
2634
- assert ( id. node >= 0 ) ;
2635
- alt smallintmap:: find ( * cx. tag_var_cache , id. node as uint ) {
2636
- option:: some ( variants) { ret variants; }
2626
+ fn tag_variants ( cx : ctxt , id : ast:: def_id ) -> @[ variant_info ] {
2627
+ alt cx. tag_var_cache . find ( id) {
2628
+ some ( variants) { ret variants; }
2637
2629
_ { /* fallthrough */ }
2638
2630
}
2639
- let item =
2640
- alt cx. items . find ( id. node ) {
2641
- some ( i) { i }
2642
- none. { cx . sess . bug ( "expected to find cached node_item" ) }
2643
- } ;
2644
- alt item {
2645
- ast_map : : node_item ( item) {
2646
- alt item. node {
2647
- ast:: item_tag ( variants, _) {
2648
- let result: @mutable [ variant_info ] = @mutable [ ] ;
2649
- for variant: ast:: variant in variants {
2650
- let ctor_ty = node_id_to_monotype ( cx, variant. node . id ) ;
2651
- let arg_tys: [ t ] = [ ] ;
2652
- if vec:: len ( variant. node . args ) > 0 u {
2653
- for a: arg in ty_fn_args ( cx, ctor_ty) {
2654
- arg_tys += [ a. ty ] ;
2655
- }
2656
- }
2657
- let did = variant. node . id ;
2658
- * result +=
2659
- [ @{ args: arg_tys,
2660
- ctor_ty: ctor_ty,
2661
- id: ast_util:: local_def ( did) } ] ;
2631
+ let result = if ast:: local_crate != id. crate {
2632
+ @csearch:: get_tag_variants ( cx, id)
2633
+ } else {
2634
+ alt cx. items . get ( id. node ) {
2635
+ ast_map:: node_item ( item) {
2636
+ alt item. node {
2637
+ ast:: item_tag ( variants, _) {
2638
+ @vec:: map ( variants, { |variant|
2639
+ let ctor_ty = node_id_to_monotype ( cx, variant. node . id ) ;
2640
+ let arg_tys = if vec:: len ( variant. node . args ) > 0 u {
2641
+ vec:: map ( ty_fn_args ( cx, ctor_ty) , { |a| a. ty } )
2642
+ } else { [ ] } ;
2643
+ @{ args: arg_tys,
2644
+ ctor_ty: ctor_ty,
2645
+ id: ast_util:: local_def ( variant. node . id ) }
2646
+ } )
2647
+ }
2662
2648
}
2663
- smallintmap:: insert ( * cx. tag_var_cache , id. node as uint , result) ;
2664
- ret result;
2665
2649
}
2666
2650
}
2667
- }
2668
- }
2651
+ } ;
2652
+ cx. tag_var_cache . insert ( id, result) ;
2653
+ result
2669
2654
}
2670
2655
2671
2656
0 commit comments