Skip to content

Commit 51a3da8

Browse files
committed
---
yaml --- r: 112255 b: refs/heads/try c: 186ac71 h: refs/heads/master i: 112253: 0b51b57 112251: 5c8c4eb 112247: 45c2c0e 112239: c89def0 112223: 9ea64c1 112191: 724178f 112127: 367f153 v: v3
1 parent 806342d commit 51a3da8

File tree

6 files changed

+66
-63
lines changed

6 files changed

+66
-63
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: a692e9b1234ff6573b0cfbc39394d9222eb38f81
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b5dd3f05fe95168b5569d0f519636149479eb6ac
5-
refs/heads/try: 1350fbdb24a06bd389cf1617ad5b78289a0c2354
5+
refs/heads/try: 186ac7116c555ba90031eab71fa27dd71326bf6a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/middle/astencode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl tr for ty::TraitStore {
526526
// ______________________________________________________________________
527527
// Encoding and decoding of freevar information
528528

529-
fn encode_freevar_entry(ebml_w: &mut Encoder, fv: @freevar_entry) {
529+
fn encode_freevar_entry(ebml_w: &mut Encoder, fv: &freevar_entry) {
530530
(*fv).encode(ebml_w).unwrap();
531531
}
532532

@@ -1018,7 +1018,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10181018
ebml_w.id(id);
10191019
ebml_w.tag(c::tag_table_val, |ebml_w| {
10201020
ebml_w.emit_from_vec(fv.as_slice(), |ebml_w, fv_entry| {
1021-
Ok(encode_freevar_entry(ebml_w, *fv_entry))
1021+
Ok(encode_freevar_entry(ebml_w, fv_entry))
10221022
});
10231023
})
10241024
})
@@ -1370,8 +1370,8 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext,
13701370
dcx.tcx.node_type_substs.borrow_mut().insert(id, tys);
13711371
}
13721372
c::tag_table_freevars => {
1373-
let fv_info = @val_dsr.read_to_vec(|val_dsr| {
1374-
Ok(@val_dsr.read_freevar_entry(xcx))
1373+
let fv_info = val_dsr.read_to_vec(|val_dsr| {
1374+
Ok(val_dsr.read_freevar_entry(xcx))
13751375
}).unwrap().move_iter().collect();
13761376
dcx.tcx.freevars.borrow_mut().insert(id, fv_info);
13771377
}

branches/try/src/librustc/middle/freevars.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ pub struct freevar_entry {
2929
pub def: ast::Def, //< The variable being accessed free.
3030
pub span: Span //< First span where it is accessed (there can be multiple)
3131
}
32-
pub type freevar_info = @Vec<@freevar_entry> ;
33-
pub type freevar_map = NodeMap<freevar_info>;
32+
pub type freevar_map = NodeMap<Vec<freevar_entry>>;
3433

3534
struct CollectFreevarsVisitor<'a> {
3635
seen: NodeSet,
37-
refs: Vec<@freevar_entry>,
36+
refs: Vec<freevar_entry>,
3837
def_map: &'a resolve::DefMap,
3938
}
4039

@@ -65,7 +64,7 @@ impl<'a> Visitor<int> for CollectFreevarsVisitor<'a> {
6564
if i == depth { // Made it to end of loop
6665
let dnum = ast_util::def_id_of_def(def).node;
6766
if !self.seen.contains(&dnum) {
68-
self.refs.push(@freevar_entry {
67+
self.refs.push(freevar_entry {
6968
def: def,
7069
span: expr.span,
7170
});
@@ -87,15 +86,15 @@ impl<'a> Visitor<int> for CollectFreevarsVisitor<'a> {
8786
// Since we want to be able to collect upvars in some arbitrary piece
8887
// of the AST, we take a walker function that we invoke with a visitor
8988
// in order to start the search.
90-
fn collect_freevars(def_map: &resolve::DefMap, blk: &ast::Block) -> freevar_info {
89+
fn collect_freevars(def_map: &resolve::DefMap, blk: &ast::Block) -> Vec<freevar_entry> {
9190
let mut v = CollectFreevarsVisitor {
9291
seen: NodeSet::new(),
9392
refs: Vec::new(),
9493
def_map: def_map,
9594
};
9695

9796
v.visit_block(blk, 1);
98-
@v.refs
97+
v.refs
9998
}
10099

101100
struct AnnotateFreevarsVisitor<'a> {
@@ -128,9 +127,9 @@ pub fn annotate_freevars(def_map: &resolve::DefMap, krate: &ast::Crate) ->
128127
visitor.freevars
129128
}
130129

131-
pub fn get_freevars(tcx: &ty::ctxt, fid: ast::NodeId) -> freevar_info {
130+
pub fn with_freevars<T>(tcx: &ty::ctxt, fid: ast::NodeId, f: |&[freevar_entry]| -> T) -> T {
132131
match tcx.freevars.borrow().find(&fid) {
133-
None => fail!("get_freevars: {} has no freevars", fid),
134-
Some(&d) => return d
132+
None => fail!("with_freevars: {} has no freevars", fid),
133+
Some(d) => f(d.as_slice())
135134
}
136135
}

branches/try/src/librustc/middle/kind.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn check_item(cx: &mut Context, item: &Item) {
163163
// closure.
164164
fn with_appropriate_checker(cx: &Context,
165165
id: NodeId,
166-
b: |checker: |&Context, @freevar_entry||) {
166+
b: |checker: |&Context, &freevar_entry||) {
167167
fn check_for_uniq(cx: &Context, fv: &freevar_entry, bounds: ty::BuiltinBounds) {
168168
// all captured data must be owned, regardless of whether it is
169169
// moved in or copied in.
@@ -184,7 +184,7 @@ fn with_appropriate_checker(cx: &Context,
184184
bounds, Some(var_t));
185185
}
186186

187-
fn check_for_bare(cx: &Context, fv: @freevar_entry) {
187+
fn check_for_bare(cx: &Context, fv: &freevar_entry) {
188188
cx.tcx.sess.span_err(
189189
fv.span,
190190
"can't capture dynamic environment in a fn item; \
@@ -223,10 +223,11 @@ fn check_fn(
223223

224224
// Check kinds on free variables:
225225
with_appropriate_checker(cx, fn_id, |chk| {
226-
let r = freevars::get_freevars(cx.tcx, fn_id);
227-
for fv in r.iter() {
228-
chk(cx, *fv);
229-
}
226+
freevars::with_freevars(cx.tcx, fn_id, |r| {
227+
for fv in r.iter() {
228+
chk(cx, fv);
229+
}
230+
})
230231
});
231232

232233
visit::walk_fn(cx, fk, decl, body, sp, fn_id, ());

branches/try/src/librustc/middle/moves.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl<'a> VisitContext<'a> {
544544
self.use_pat(a.pat);
545545
}
546546
let cap_vars = self.compute_captures(expr.id);
547-
self.move_maps.capture_map.insert(expr.id, cap_vars);
547+
self.move_maps.capture_map.insert(expr.id, Rc::new(cap_vars));
548548
self.consume_block(body);
549549
}
550550

@@ -639,34 +639,35 @@ impl<'a> VisitContext<'a> {
639639
self.consume_expr(arg_expr)
640640
}
641641

642-
pub fn compute_captures(&mut self, fn_expr_id: NodeId) -> Rc<Vec<CaptureVar> > {
642+
fn compute_captures(&mut self, fn_expr_id: NodeId) -> Vec<CaptureVar> {
643643
debug!("compute_capture_vars(fn_expr_id={:?})", fn_expr_id);
644644
let _indenter = indenter();
645645

646646
let fn_ty = ty::node_id_to_type(self.tcx, fn_expr_id);
647-
let freevars = freevars::get_freevars(self.tcx, fn_expr_id);
648-
Rc::new(match ty::ty_closure_store(fn_ty) {
649-
ty::RegionTraitStore(..) => {
650-
// || captures everything by ref
651-
freevars.iter()
652-
.map(|fvar| CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef})
653-
.collect()
654-
}
655-
ty::UniqTraitStore => {
656-
// proc captures by copy or by move depending on type
657-
freevars.iter()
658-
.map(|fvar| {
659-
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
660-
let fvar_ty = ty::node_id_to_type(self.tcx, fvar_def_id);
661-
debug!("fvar_def_id={:?} fvar_ty={}",
662-
fvar_def_id, ppaux::ty_to_str(self.tcx, fvar_ty));
663-
let mode = if ty::type_moves_by_default(self.tcx, fvar_ty) {
664-
CapMove
665-
} else {
666-
CapCopy
667-
};
668-
CaptureVar {def: fvar.def, span: fvar.span, mode:mode}
669-
}).collect()
647+
freevars::with_freevars(self.tcx, fn_expr_id, |freevars| {
648+
match ty::ty_closure_store(fn_ty) {
649+
ty::RegionTraitStore(..) => {
650+
// || captures everything by ref
651+
freevars.iter()
652+
.map(|fvar| CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef})
653+
.collect()
654+
}
655+
ty::UniqTraitStore => {
656+
// proc captures by copy or by move depending on type
657+
freevars.iter()
658+
.map(|fvar| {
659+
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
660+
let fvar_ty = ty::node_id_to_type(self.tcx, fvar_def_id);
661+
debug!("fvar_def_id={:?} fvar_ty={}",
662+
fvar_def_id, ppaux::ty_to_str(self.tcx, fvar_ty));
663+
let mode = if ty::type_moves_by_default(self.tcx, fvar_ty) {
664+
CapMove
665+
} else {
666+
CapCopy
667+
};
668+
CaptureVar {def: fvar.def, span: fvar.span, mode:mode}
669+
}).collect()
670+
}
670671
}
671672
})
672673
}

branches/try/src/librustc/middle/typeck/check/regionck.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -611,20 +611,21 @@ fn check_expr_fn_block(rcx: &mut Rcx,
611611
match ty::get(function_type).sty {
612612
ty::ty_closure(~ty::ClosureTy {
613613
store: ty::RegionTraitStore(region, _), ..}) => {
614-
let freevars = freevars::get_freevars(tcx, expr.id);
615-
if freevars.is_empty() {
616-
// No free variables means that the environment
617-
// will be NULL at runtime and hence the closure
618-
// has static lifetime.
619-
} else {
620-
// Closure must not outlive the variables it closes over.
621-
constrain_free_variables(rcx, region, expr, freevars);
622-
623-
// Closure cannot outlive the appropriate temporary scope.
624-
let s = rcx.repeating_scope;
625-
rcx.fcx.mk_subr(true, infer::InfStackClosure(expr.span),
626-
region, ty::ReScope(s));
627-
}
614+
freevars::with_freevars(tcx, expr.id, |freevars| {
615+
if freevars.is_empty() {
616+
// No free variables means that the environment
617+
// will be NULL at runtime and hence the closure
618+
// has static lifetime.
619+
} else {
620+
// Closure must not outlive the variables it closes over.
621+
constrain_free_variables(rcx, region, expr, freevars);
622+
623+
// Closure cannot outlive the appropriate temporary scope.
624+
let s = rcx.repeating_scope;
625+
rcx.fcx.mk_subr(true, infer::InfStackClosure(expr.span),
626+
region, ty::ReScope(s));
627+
}
628+
});
628629
}
629630
_ => ()
630631
}
@@ -635,16 +636,17 @@ fn check_expr_fn_block(rcx: &mut Rcx,
635636

636637
match ty::get(function_type).sty {
637638
ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(..), ..}) => {
638-
let freevars = freevars::get_freevars(tcx, expr.id);
639-
propagate_upupvar_borrow_kind(rcx, expr, freevars);
639+
freevars::with_freevars(tcx, expr.id, |freevars| {
640+
propagate_upupvar_borrow_kind(rcx, expr, freevars);
641+
});
640642
}
641643
_ => ()
642644
}
643645

644646
fn constrain_free_variables(rcx: &mut Rcx,
645647
region: ty::Region,
646648
expr: &ast::Expr,
647-
freevars: freevars::freevar_info) {
649+
freevars: &[freevars::freevar_entry]) {
648650
/*!
649651
* Make sure that all free variables referenced inside the closure
650652
* outlive the closure itself. Also, create an entry in the
@@ -690,7 +692,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
690692

691693
fn propagate_upupvar_borrow_kind(rcx: &mut Rcx,
692694
expr: &ast::Expr,
693-
freevars: freevars::freevar_info) {
695+
freevars: &[freevars::freevar_entry]) {
694696
let tcx = rcx.fcx.ccx.tcx;
695697
debug!("propagate_upupvar_borrow_kind({})", expr.repr(tcx));
696698
for freevar in freevars.iter() {

0 commit comments

Comments
 (0)