Skip to content

Commit 44d0335

Browse files
committed
---
yaml --- r: 82618 b: refs/heads/auto c: 04ca6dc h: refs/heads/master v: v3
1 parent e116301 commit 44d0335

File tree

10 files changed

+269
-267
lines changed

10 files changed

+269
-267
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 339027ec157757e903bc23ad0eed11e8a75867fa
16+
refs/heads/auto: 04ca6dcd84d7c5c24ff7bb9b74233fbbae5dd53d
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/middle/region.rs

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,18 @@ pub struct RegionMaps {
6565

6666
#[deriving(Clone)]
6767
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 {
7668
sess: Session,
7769
def_map: resolve::DefMap,
7870

7971
// Generated maps:
8072
region_maps: @mut RegionMaps,
81-
}
8273

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+
}
8380

8481
impl RegionMaps {
8582
pub fn relate_free_regions(&mut self, sub: FreeRegion, sup: FreeRegion) {
@@ -321,24 +318,24 @@ impl RegionMaps {
321318
}
322319

323320
/// 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) {
326322
debug!("region::parent_to_expr(span=%?)",
327-
visitor.sess.codemap.span_to_str(sp));
323+
cx.sess.codemap.span_to_str(sp));
328324
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);
330326
}
331327
}
332328

333329
fn resolve_block(visitor: &mut RegionResolutionVisitor,
334330
blk: &ast::Block,
335331
cx: Context) {
336332
// 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);
338334

339335
// Descend.
340336
let new_cx = Context {var_parent: Some(blk.id),
341-
parent: Some(blk.id)};
337+
parent: Some(blk.id),
338+
..cx};
342339
visit::walk_block(visitor, blk, new_cx);
343340
}
344341

@@ -352,7 +349,7 @@ fn resolve_pat(visitor: &mut RegionResolutionVisitor,
352349
pat: @ast::Pat,
353350
cx: Context) {
354351
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);
356353
visit::walk_pat(visitor, pat, cx);
357354
}
358355

@@ -365,18 +362,18 @@ fn resolve_stmt(visitor: &mut RegionResolutionVisitor,
365362
}
366363
ast::StmtExpr(_, stmt_id) |
367364
ast::StmtSemi(_, stmt_id) => {
368-
parent_to_expr(visitor, cx, stmt_id, stmt.span);
365+
parent_to_expr(cx, stmt_id, stmt.span);
369366
let expr_cx = Context {parent: Some(stmt_id), ..cx};
370367
visit::walk_stmt(visitor, stmt, expr_cx);
371368
}
372-
ast::StmtMac(*) => visitor.sess.bug("unexpanded macro")
369+
ast::StmtMac(*) => cx.sess.bug("unexpanded macro")
373370
}
374371
}
375372

376373
fn resolve_expr(visitor: &mut RegionResolutionVisitor,
377374
expr: @ast::Expr,
378375
cx: Context) {
379-
parent_to_expr(visitor, cx, expr.id, expr.span);
376+
parent_to_expr(cx, expr.id, expr.span);
380377

381378
let mut new_cx = cx;
382379
new_cx.parent = Some(expr.id);
@@ -418,7 +415,7 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor,
418415
local: @ast::Local,
419416
cx: Context) {
420417
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);
422419
visit::walk_local(visitor, local, cx);
423420
}
424421

@@ -442,7 +439,7 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
442439
body.id=%?, \
443440
cx.parent=%?)",
444441
id,
445-
visitor.sess.codemap.span_to_str(sp),
442+
cx.sess.codemap.span_to_str(sp),
446443
body.id,
447444
cx.parent);
448445

@@ -452,7 +449,7 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
452449
..cx};
453450
match *fk {
454451
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);
456453
}
457454
_ => {}
458455
}
@@ -473,6 +470,8 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
473470
visitor.visit_block(body, body_cx);
474471
}
475472

473+
struct RegionResolutionVisitor;
474+
476475
impl Visitor<Context> for RegionResolutionVisitor {
477476

478477
fn visit_block(&mut self, b:&Block, cx:Context) {
@@ -512,13 +511,12 @@ pub fn resolve_crate(sess: Session,
512511
free_region_map: HashMap::new(),
513512
cleanup_scopes: HashSet::new(),
514513
};
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,
516518
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;
522520
visit::walk_crate(&mut visitor, crate, cx);
523521
return region_maps;
524522
}
@@ -735,9 +733,10 @@ impl DetermineRpCtxt {
735733
}
736734

737735
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);
741740
}
742741
}
743742

@@ -746,33 +745,32 @@ fn determine_rp_in_fn(visitor: &mut DetermineRpVisitor,
746745
decl: &ast::fn_decl,
747746
body: &ast::Block,
748747
_: Span,
749-
_: ast::NodeId) {
750-
let cx = visitor.cx;
748+
_: ast::NodeId,
749+
cx: @mut DetermineRpCtxt) {
751750
do cx.with(cx.item_id, false) {
752751
do cx.with_ambient_variance(rv_contravariant) {
753752
for a in decl.inputs.iter() {
754-
visitor.visit_ty(&a.ty, ());
753+
visitor.visit_ty(&a.ty, cx);
755754
}
756755
}
757-
visitor.visit_ty(&decl.output, ());
756+
visitor.visit_ty(&decl.output, cx);
758757
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);
761760
}
762761
}
763762

764763
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) {
767766
do cx.with(cx.item_id, false) {
768-
visit::walk_ty_method(visitor, ty_m, ());
767+
visit::walk_ty_method(visitor, ty_m, cx);
769768
}
770769
}
771770

772771
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) {
776774
// we are only interested in types that will require an item to
777775
// be region-parameterized. if cx.item_id is zero, then this type
778776
// 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,
856854
match ty.node {
857855
ast::ty_box(ref mt) | ast::ty_uniq(ref mt) | ast::ty_vec(ref mt) |
858856
ast::ty_rptr(_, ref mt) | ast::ty_ptr(ref mt) => {
859-
visit_mt(visitor, mt);
857+
visit_mt(visitor, mt, cx);
860858
}
861859

862860
ast::ty_path(ref path, _, _) => {
863861
// type parameters are---for now, anyway---always invariant
864862
do cx.with_ambient_variance(rv_invariant) {
865863
for tp in path.segments.iter().flat_map(|s| s.types.iter()) {
866-
visitor.visit_ty(tp, ());
864+
visitor.visit_ty(tp, cx);
867865
}
868866
}
869867
}
@@ -876,58 +874,57 @@ fn determine_rp_in_ty(visitor: &mut DetermineRpVisitor,
876874
// parameters are contravariant
877875
do cx.with_ambient_variance(rv_contravariant) {
878876
for a in decl.inputs.iter() {
879-
visitor.visit_ty(&a.ty, ());
877+
visitor.visit_ty(&a.ty, cx);
880878
}
881879
}
882-
visitor.visit_ty(&decl.output, ());
880+
visitor.visit_ty(&decl.output, cx);
883881
}
884882
}
885883

886884
_ => {
887-
visit::walk_ty(visitor, ty, ());
885+
visit::walk_ty(visitor, ty, cx);
888886
}
889887
}
890888

891889
fn visit_mt(visitor: &mut DetermineRpVisitor,
892-
mt: &ast::mt) {
893-
let cx = visitor.cx;
890+
mt: &ast::mt,
891+
cx: @mut DetermineRpCtxt) {
894892
// mutability is invariant
895893
if mt.mutbl == ast::MutMutable {
896894
do cx.with_ambient_variance(rv_invariant) {
897-
visitor.visit_ty(mt.ty, ());
895+
visitor.visit_ty(mt.ty, cx);
898896
}
899897
} else {
900-
visitor.visit_ty(mt.ty, ());
898+
visitor.visit_ty(mt.ty, cx);
901899
}
902900
}
903901
}
904902

905903
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);
908907
}
909908

910-
struct DetermineRpVisitor {
911-
cx: @mut DetermineRpCtxt
912-
}
909+
struct DetermineRpVisitor;
913910

914-
impl Visitor<()> for DetermineRpVisitor {
911+
impl Visitor<@mut DetermineRpCtxt> for DetermineRpVisitor {
915912

916913
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);
919916
}
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);
922919
}
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);
925922
}
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);
928925
}
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);
931928
}
932929

933930
}
@@ -950,8 +947,8 @@ pub fn determine_rp_in_crate(sess: Session,
950947
};
951948

952949
// 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);
955952

956953
// Propagate indirect dependencies
957954
//

0 commit comments

Comments
 (0)