Skip to content

Commit e8a1dd0

Browse files
committed
---
yaml --- r: 3923 b: refs/heads/master c: 53c4cb6 h: refs/heads/master i: 3921: 635a656 3919: 52ebcbc v: v3
1 parent 984bbde commit e8a1dd0

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 759317ca8bf3d2997b5a0973679d9c7bae063e15
2+
refs/heads/master: 53c4cb6a2fa99df20a2cd720890e888402773fe7

trunk/src/comp/middle/trans.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,6 +4556,29 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc,
45564556
ret result;
45574557
}
45584558

4559+
// Finds the ValueRef associated with a variable in a function
4560+
// context. It checks locals, upvars, and args.
4561+
fn find_variable(&@fn_ctxt fcx, ast::node_id nid) -> ValueRef {
4562+
ret
4563+
alt (fcx.lllocals.find(nid)) {
4564+
case (none) {
4565+
alt (fcx.llupvars.find(nid)) {
4566+
case (none) {
4567+
alt (fcx.llargs.find(nid)) {
4568+
case (some(?llval)) { llval }
4569+
case (_) {
4570+
fcx.lcx.ccx.sess.bug("unbound var \
4571+
in build_environment " + int::str(nid))
4572+
}
4573+
}
4574+
}
4575+
case (some(?llval)) { llval }
4576+
}
4577+
}
4578+
case (some(?llval)) { llval }
4579+
}
4580+
}
4581+
45594582
// Given a block context and a list of upvars, construct a closure that
45604583
// contains pointers to all of the upvars and all of the tydescs in
45614584
// scope. Return the ValueRef and TypeRef corresponding to the closure.
@@ -4575,24 +4598,7 @@ fn build_environment(&@block_ctxt cx, &ast::node_id[] upvars) ->
45754598
llbindingtys += ~[val_ty(llbindings.(0))];
45764599
}
45774600
for (ast::node_id nid in upvars) {
4578-
auto llbinding;
4579-
alt (cx.fcx.lllocals.find(nid)) {
4580-
case (none) {
4581-
alt (cx.fcx.llupvars.find(nid)) {
4582-
case (none) {
4583-
alt (cx.fcx.llargs.find(nid)) {
4584-
case (some(?x)) { llbinding = x; }
4585-
case (_) {
4586-
cx.fcx.lcx.ccx.sess.bug("unbound var \
4587-
in build_environment " + int::str(nid));
4588-
}
4589-
}
4590-
}
4591-
case (some(?llval)) { llbinding = llval; }
4592-
}
4593-
}
4594-
case (some(?llval)) { llbinding = llval; }
4595-
}
4601+
auto llbinding = find_variable(cx.fcx, nid);
45964602
llbindings += ~[llbinding];
45974603
llbindingtys += ~[val_ty(llbinding)];
45984604
}

0 commit comments

Comments
 (0)