@@ -65,19 +65,22 @@ pub struct RegionMaps {
65
65
66
66
#[ deriving( Clone ) ]
67
67
pub struct Context {
68
- sess : Session ,
69
- def_map : resolve:: DefMap ,
70
-
71
- // Generated maps:
72
- region_maps : @mut RegionMaps ,
73
-
74
68
// Scope where variables should be parented to
75
69
var_parent : Option < ast:: NodeId > ,
76
70
77
71
// Innermost enclosing expression
78
72
parent : Option < ast:: NodeId > ,
79
73
}
80
74
75
+ struct RegionResolutionVisitor {
76
+ sess : Session ,
77
+ def_map : resolve:: DefMap ,
78
+
79
+ // Generated maps:
80
+ region_maps : @mut RegionMaps ,
81
+ }
82
+
83
+
81
84
impl RegionMaps {
82
85
pub fn relate_free_regions ( & mut self , sub : FreeRegion , sup : FreeRegion ) {
83
86
match self . free_region_map . find_mut ( & sub) {
@@ -318,24 +321,24 @@ impl RegionMaps {
318
321
}
319
322
320
323
/// Records the current parent (if any) as the parent of `child_id`.
321
- fn parent_to_expr ( cx : Context , child_id : ast:: NodeId , sp : Span ) {
324
+ fn parent_to_expr ( visitor : & mut RegionResolutionVisitor ,
325
+ cx : Context , child_id : ast:: NodeId , sp : Span ) {
322
326
debug ! ( "region::parent_to_expr(span=%?)" ,
323
- cx . sess. codemap. span_to_str( sp) ) ;
327
+ visitor . sess. codemap. span_to_str( sp) ) ;
324
328
for parent_id in cx. parent . iter ( ) {
325
- cx . region_maps . record_parent ( child_id, * parent_id) ;
329
+ visitor . region_maps . record_parent ( child_id, * parent_id) ;
326
330
}
327
331
}
328
332
329
333
fn resolve_block ( visitor : & mut RegionResolutionVisitor ,
330
334
blk : & ast:: Block ,
331
335
cx : Context ) {
332
336
// Record the parent of this block.
333
- parent_to_expr ( cx, blk. id , blk. span ) ;
337
+ parent_to_expr ( visitor , cx, blk. id , blk. span ) ;
334
338
335
339
// Descend.
336
340
let new_cx = Context { var_parent : Some ( blk. id ) ,
337
- parent : Some ( blk. id ) ,
338
- ..cx} ;
341
+ parent : Some ( blk. id ) } ;
339
342
visit:: walk_block ( visitor, blk, new_cx) ;
340
343
}
341
344
@@ -349,7 +352,7 @@ fn resolve_pat(visitor: &mut RegionResolutionVisitor,
349
352
pat : @ast:: Pat ,
350
353
cx : Context ) {
351
354
assert_eq ! ( cx. var_parent, cx. parent) ;
352
- parent_to_expr ( cx, pat. id , pat. span ) ;
355
+ parent_to_expr ( visitor , cx, pat. id , pat. span ) ;
353
356
visit:: walk_pat ( visitor, pat, cx) ;
354
357
}
355
358
@@ -362,18 +365,18 @@ fn resolve_stmt(visitor: &mut RegionResolutionVisitor,
362
365
}
363
366
ast:: StmtExpr ( _, stmt_id) |
364
367
ast:: StmtSemi ( _, stmt_id) => {
365
- parent_to_expr ( cx, stmt_id, stmt. span ) ;
368
+ parent_to_expr ( visitor , cx, stmt_id, stmt. span ) ;
366
369
let expr_cx = Context { parent : Some ( stmt_id) , ..cx} ;
367
370
visit:: walk_stmt ( visitor, stmt, expr_cx) ;
368
371
}
369
- ast:: StmtMac ( * ) => cx . sess . bug ( "unexpanded macro" )
372
+ ast:: StmtMac ( * ) => visitor . sess . bug ( "unexpanded macro" )
370
373
}
371
374
}
372
375
373
376
fn resolve_expr ( visitor : & mut RegionResolutionVisitor ,
374
377
expr : @ast:: Expr ,
375
378
cx : Context ) {
376
- parent_to_expr ( cx, expr. id , expr. span ) ;
379
+ parent_to_expr ( visitor , cx, expr. id , expr. span ) ;
377
380
378
381
let mut new_cx = cx;
379
382
new_cx. parent = Some ( expr. id ) ;
@@ -415,7 +418,7 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor,
415
418
local : @ast:: Local ,
416
419
cx : Context ) {
417
420
assert_eq ! ( cx. var_parent, cx. parent) ;
418
- parent_to_expr ( cx, local. id , local. span ) ;
421
+ parent_to_expr ( visitor , cx, local. id , local. span ) ;
419
422
visit:: walk_local ( visitor, local, cx) ;
420
423
}
421
424
@@ -439,7 +442,7 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
439
442
body.id=%?, \
440
443
cx.parent=%?)",
441
444
id,
442
- cx . sess. codemap. span_to_str( sp) ,
445
+ visitor . sess. codemap. span_to_str( sp) ,
443
446
body. id,
444
447
cx. parent) ;
445
448
@@ -449,7 +452,7 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
449
452
..cx} ;
450
453
match * fk {
451
454
visit:: fk_method( _, _, method) => {
452
- cx . region_maps . record_parent ( method. self_id , body. id ) ;
455
+ visitor . region_maps . record_parent ( method. self_id , body. id ) ;
453
456
}
454
457
_ => { }
455
458
}
@@ -470,8 +473,6 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
470
473
visitor. visit_block ( body, body_cx) ;
471
474
}
472
475
473
- struct RegionResolutionVisitor ;
474
-
475
476
impl Visitor < Context > for RegionResolutionVisitor {
476
477
477
478
fn visit_block ( & mut self , b : & Block , cx : Context ) {
@@ -511,12 +512,13 @@ pub fn resolve_crate(sess: Session,
511
512
free_region_map : HashMap :: new ( ) ,
512
513
cleanup_scopes : HashSet :: new ( ) ,
513
514
} ;
514
- let cx = Context { sess : sess,
515
- def_map : def_map,
516
- region_maps : region_maps,
517
- parent : None ,
515
+ let cx = Context { parent : None ,
518
516
var_parent : None } ;
519
- let mut visitor = RegionResolutionVisitor ;
517
+ let mut visitor = RegionResolutionVisitor {
518
+ sess : sess,
519
+ def_map : def_map,
520
+ region_maps : region_maps,
521
+ } ;
520
522
visit:: walk_crate ( & mut visitor, crate , cx) ;
521
523
return region_maps;
522
524
}
@@ -733,10 +735,9 @@ impl DetermineRpCtxt {
733
735
}
734
736
735
737
fn determine_rp_in_item ( visitor : & mut DetermineRpVisitor ,
736
- item : @ast:: item ,
737
- cx : @mut DetermineRpCtxt ) {
738
- do cx. with ( item. id , true ) {
739
- visit:: walk_item ( visitor, item, cx) ;
738
+ item : @ast:: item ) {
739
+ do visitor. cx . with ( item. id , true ) {
740
+ visit:: walk_item ( visitor, item, ( ) ) ;
740
741
}
741
742
}
742
743
@@ -745,32 +746,33 @@ fn determine_rp_in_fn(visitor: &mut DetermineRpVisitor,
745
746
decl : & ast:: fn_decl ,
746
747
body : & ast:: Block ,
747
748
_: Span ,
748
- _: ast:: NodeId ,
749
- cx : @ mut DetermineRpCtxt ) {
749
+ _: ast:: NodeId ) {
750
+ let cx = visitor . cx ;
750
751
do cx. with ( cx. item_id , false ) {
751
752
do cx. with_ambient_variance ( rv_contravariant) {
752
753
for a in decl. inputs . iter ( ) {
753
- visitor. visit_ty ( & a. ty , cx ) ;
754
+ visitor. visit_ty ( & a. ty , ( ) ) ;
754
755
}
755
756
}
756
- visitor. visit_ty ( & decl. output , cx ) ;
757
+ visitor. visit_ty ( & decl. output , ( ) ) ;
757
758
let generics = visit:: generics_of_fn ( fk) ;
758
- visitor. visit_generics ( & generics, cx ) ;
759
- visitor. visit_block ( body, cx ) ;
759
+ visitor. visit_generics ( & generics, ( ) ) ;
760
+ visitor. visit_block ( body, ( ) ) ;
760
761
}
761
762
}
762
763
763
764
fn determine_rp_in_ty_method ( visitor : & mut DetermineRpVisitor ,
764
- ty_m : & ast:: TypeMethod ,
765
- cx : @ mut DetermineRpCtxt ) {
765
+ ty_m : & ast:: TypeMethod ) {
766
+ let cx = visitor . cx ;
766
767
do cx. with ( cx. item_id , false ) {
767
- visit:: walk_ty_method ( visitor, ty_m, cx ) ;
768
+ visit:: walk_ty_method ( visitor, ty_m, ( ) ) ;
768
769
}
769
770
}
770
771
771
772
fn determine_rp_in_ty ( visitor : & mut DetermineRpVisitor ,
772
- ty : & ast:: Ty ,
773
- cx : @mut DetermineRpCtxt ) {
773
+ ty : & ast:: Ty ) {
774
+ let cx = visitor. cx ;
775
+
774
776
// we are only interested in types that will require an item to
775
777
// be region-parameterized. if cx.item_id is zero, then this type
776
778
// is not a member of a type defn nor is it a constitutent of an
@@ -854,14 +856,14 @@ fn determine_rp_in_ty(visitor: &mut DetermineRpVisitor,
854
856
match ty. node {
855
857
ast:: ty_box( ref mt) | ast:: ty_uniq( ref mt) | ast:: ty_vec( ref mt) |
856
858
ast:: ty_rptr( _, ref mt) | ast:: ty_ptr( ref mt) => {
857
- visit_mt ( visitor, mt, cx ) ;
859
+ visit_mt ( visitor, mt) ;
858
860
}
859
861
860
862
ast:: ty_path( ref path, _, _) => {
861
863
// type parameters are---for now, anyway---always invariant
862
864
do cx. with_ambient_variance ( rv_invariant) {
863
865
for tp in path. segments . iter ( ) . flat_map ( |s| s. types . iter ( ) ) {
864
- visitor. visit_ty ( tp, cx ) ;
866
+ visitor. visit_ty ( tp, ( ) ) ;
865
867
}
866
868
}
867
869
}
@@ -874,57 +876,58 @@ fn determine_rp_in_ty(visitor: &mut DetermineRpVisitor,
874
876
// parameters are contravariant
875
877
do cx. with_ambient_variance ( rv_contravariant) {
876
878
for a in decl. inputs . iter ( ) {
877
- visitor. visit_ty ( & a. ty , cx ) ;
879
+ visitor. visit_ty ( & a. ty , ( ) ) ;
878
880
}
879
881
}
880
- visitor. visit_ty ( & decl. output , cx ) ;
882
+ visitor. visit_ty ( & decl. output , ( ) ) ;
881
883
}
882
884
}
883
885
884
886
_ => {
885
- visit:: walk_ty ( visitor, ty, cx ) ;
887
+ visit:: walk_ty ( visitor, ty, ( ) ) ;
886
888
}
887
889
}
888
890
889
891
fn visit_mt ( visitor : & mut DetermineRpVisitor ,
890
- mt : & ast:: mt ,
891
- cx : @ mut DetermineRpCtxt ) {
892
+ mt : & ast:: mt ) {
893
+ let cx = visitor . cx ;
892
894
// mutability is invariant
893
895
if mt. mutbl == ast:: MutMutable {
894
896
do cx. with_ambient_variance ( rv_invariant) {
895
- visitor. visit_ty ( mt. ty , cx ) ;
897
+ visitor. visit_ty ( mt. ty , ( ) ) ;
896
898
}
897
899
} else {
898
- visitor. visit_ty ( mt. ty , cx ) ;
900
+ visitor. visit_ty ( mt. ty , ( ) ) ;
899
901
}
900
902
}
901
903
}
902
904
903
905
fn determine_rp_in_struct_field ( visitor : & mut DetermineRpVisitor ,
904
- cm : @ast:: struct_field ,
905
- cx : @mut DetermineRpCtxt ) {
906
- visit:: walk_struct_field ( visitor, cm, cx) ;
906
+ cm : @ast:: struct_field ) {
907
+ visit:: walk_struct_field ( visitor, cm, ( ) ) ;
907
908
}
908
909
909
- struct DetermineRpVisitor ;
910
+ struct DetermineRpVisitor {
911
+ cx : @mut DetermineRpCtxt
912
+ }
910
913
911
- impl Visitor < @ mut DetermineRpCtxt > for DetermineRpVisitor {
914
+ impl Visitor < ( ) > for DetermineRpVisitor {
912
915
913
916
fn visit_fn ( & mut self , fk : & fn_kind , fd : & fn_decl ,
914
- b : & Block , s : Span , n : NodeId , e : @ mut DetermineRpCtxt ) {
915
- determine_rp_in_fn ( self , fk, fd, b, s, n, e ) ;
917
+ b : & Block , s : Span , n : NodeId , _ : ( ) ) {
918
+ determine_rp_in_fn ( self , fk, fd, b, s, n) ;
916
919
}
917
- fn visit_item ( & mut self , i: @item, e : @ mut DetermineRpCtxt ) {
918
- determine_rp_in_item ( self , i, e ) ;
920
+ fn visit_item ( & mut self , i: @item, _ : ( ) ) {
921
+ determine_rp_in_item ( self , i) ;
919
922
}
920
- fn visit_ty ( & mut self , t : & Ty , e : @ mut DetermineRpCtxt ) {
921
- determine_rp_in_ty ( self , t, e ) ;
923
+ fn visit_ty ( & mut self , t : & Ty , _ : ( ) ) {
924
+ determine_rp_in_ty ( self , t) ;
922
925
}
923
- fn visit_ty_method ( & mut self , t : & TypeMethod , e : @ mut DetermineRpCtxt ) {
924
- determine_rp_in_ty_method ( self , t, e ) ;
926
+ fn visit_ty_method ( & mut self , t : & TypeMethod , _ : ( ) ) {
927
+ determine_rp_in_ty_method ( self , t) ;
925
928
}
926
- fn visit_struct_field ( & mut self , s : @struct_field , e : @ mut DetermineRpCtxt ) {
927
- determine_rp_in_struct_field ( self , s, e ) ;
929
+ fn visit_struct_field ( & mut self , s : @struct_field , _ : ( ) ) {
930
+ determine_rp_in_struct_field ( self , s) ;
928
931
}
929
932
930
933
}
@@ -947,8 +950,8 @@ pub fn determine_rp_in_crate(sess: Session,
947
950
} ;
948
951
949
952
// Gather up the base set, worklist and dep_map
950
- let mut visitor = DetermineRpVisitor ;
951
- visit:: walk_crate ( & mut visitor, crate , cx ) ;
953
+ let mut visitor = DetermineRpVisitor { cx : cx } ;
954
+ visit:: walk_crate ( & mut visitor, crate , ( ) ) ;
952
955
953
956
// Propagate indirect dependencies
954
957
//
0 commit comments