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