Skip to content

Commit 7dfb865

Browse files
committed
Remove local_imm/local_mem since all variables are now by reference
1 parent 2616581 commit 7dfb865

File tree

6 files changed

+33
-46
lines changed

6 files changed

+33
-46
lines changed

src/librustc/middle/trans/_match.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@
140140
* the various values we copied explicitly. Note that guards and moves are
141141
* just plain incompatible.
142142
*
143+
* Some relevant helper functions that manage bindings:
144+
* - `create_bindings_map()`
145+
* - `store_non_ref_bindings()`
146+
* - `insert_lllocals()`
147+
*
143148
*/
144149

145150
use core::prelude::*;
@@ -1201,7 +1206,7 @@ fn insert_lllocals(bcx: block,
12011206
debug!("binding %? to %s",
12021207
binding_info.id,
12031208
val_str(bcx.ccx().tn, llval));
1204-
llmap.insert(binding_info.id, local_mem(llval));
1209+
llmap.insert(binding_info.id, llval);
12051210
}
12061211
return bcx;
12071212
}
@@ -1673,7 +1678,7 @@ pub fn trans_match_inner(scope_cx: block,
16731678

16741679
let mut arm_datas = ~[], matches = ~[];
16751680
for vec::each(arms) |arm| {
1676-
let body = scope_block(bcx, arm.body.info(), ~"case_body");
1681+
let body = scope_block(bcx, arm.body.info(), "case_body");
16771682
let bindings_map = create_bindings_map(bcx, arm.pats[0]);
16781683
let arm_data = @ArmData {bodycx: body,
16791684
arm: arm,
@@ -1765,22 +1770,20 @@ pub fn bind_irrefutable_pat(bcx: block,
17651770
datum.copy_to_datum(bcx, INIT, scratch);
17661771
match binding_mode {
17671772
BindLocal => {
1768-
bcx.fcx.lllocals.insert(pat.id,
1769-
local_mem(scratch.val));
1773+
bcx.fcx.lllocals.insert(pat.id, scratch.val);
17701774
}
17711775
BindArgument => {
1772-
bcx.fcx.llargs.insert(pat.id,
1773-
local_mem(scratch.val));
1776+
bcx.fcx.llargs.insert(pat.id, scratch.val);
17741777
}
17751778
}
17761779
add_clean(bcx, scratch.val, binding_ty);
17771780
} else {
17781781
match binding_mode {
17791782
BindLocal => {
1780-
bcx.fcx.lllocals.insert(pat.id, local_mem(val));
1783+
bcx.fcx.lllocals.insert(pat.id, val);
17811784
}
17821785
BindArgument => {
1783-
bcx.fcx.llargs.insert(pat.id, local_mem(val));
1786+
bcx.fcx.llargs.insert(pat.id, val);
17841787
}
17851788
}
17861789
}

src/librustc/middle/trans/base.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,8 @@ pub fn init_local(bcx: block, local: @ast::local) -> block {
11051105
}
11061106
}
11071107

1108-
let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
1109-
Some(&local_mem(v)) => v,
1108+
let llptr = match bcx.fcx.lllocals.find_copy(&local.node.id) {
1109+
Some(v) => v,
11101110
_ => {
11111111
bcx.tcx().sess.span_bug(local.span,
11121112
"init_local: Someone forgot to document why it's\
@@ -1432,7 +1432,7 @@ pub fn alloc_local(cx: block, local: @ast::local) -> block {
14321432
});
14331433
}
14341434
}
1435-
cx.fcx.lllocals.insert(local.node.id, local_mem(val));
1435+
cx.fcx.lllocals.insert(local.node.id, val);
14361436
cx
14371437
}
14381438

@@ -1768,7 +1768,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
17681768
false,
17691769
_match::BindArgument);
17701770

1771-
fcx.llargs.insert(arg_id, local_mem(llarg));
1771+
fcx.llargs.insert(arg_id, llarg);
17721772

17731773
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
17741774
debuginfo::create_arg(bcx, args[arg_n], args[arg_n].ty.span);
@@ -2004,7 +2004,7 @@ pub fn trans_enum_variant(ccx: @CrateContext,
20042004
// this function as an opaque blob due to the way that type_of()
20052005
// works. So we have to cast to the destination's view of the type.
20062006
let llarg = match fcx.llargs.find(&va.id) {
2007-
Some(&local_mem(x)) => x,
2007+
Some(&x) => x,
20082008
_ => fail!("trans_enum_variant: how do we know this works?"),
20092009
};
20102010
let arg_ty = arg_tys[i];
@@ -2074,12 +2074,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
20742074
fcx.llretptr.get(),
20752075
0,
20762076
i);
2077-
let llarg = match fcx.llargs.get_copy(&field.node.id) {
2078-
local_mem(x) => x,
2079-
_ => {
2080-
ccx.tcx.sess.bug("trans_tuple_struct: llarg wasn't local_mem")
2081-
}
2082-
};
2077+
let llarg = fcx.llargs.get_copy(&field.node.id);
20832078
let arg_ty = arg_tys[i];
20842079
memcpy_ty(bcx, lldestptr, llarg, arg_ty);
20852080
}

src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ pub struct ValSelfData {
240240
is_owned: bool
241241
}
242242

243-
pub enum local_val { local_mem(ValueRef), local_imm(ValueRef), }
244-
245243
// Here `self_ty` is the real type of the self parameter to this method. It
246244
// will only be set in the case of default methods.
247245
pub struct param_substs {
@@ -328,10 +326,10 @@ pub struct fn_ctxt_ {
328326
has_immediate_return_value: bool,
329327

330328
// Maps arguments to allocas created for them in llallocas.
331-
llargs: @mut HashMap<ast::node_id, local_val>,
329+
llargs: @mut HashMap<ast::node_id, ValueRef>,
332330
// Maps the def_ids for local variables to the allocas created for
333331
// them in llallocas.
334-
lllocals: @mut HashMap<ast::node_id, local_val>,
332+
lllocals: @mut HashMap<ast::node_id, ValueRef>,
335333
// Same as above, but for closure upvars
336334
llupvars: @mut HashMap<ast::node_id, ValueRef>,
337335

src/librustc/middle/trans/datum.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ use middle::ty;
105105
use util::common::indenter;
106106
use util::ppaux::ty_to_str;
107107

108-
use core::to_bytes;
109108
use core::uint;
110109
use syntax::ast;
111110
use syntax::codemap::span;

src/librustc/middle/trans/debuginfo.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -864,17 +864,14 @@ pub fn create_local_var(bcx: block, local: @ast::local)
864864
};
865865
update_cache(cache, AutoVariableTag, local_var_metadata(mdval));
866866

867-
let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
868-
option::Some(&local_mem(v)) => v,
869-
option::Some(_) => {
870-
bcx.tcx().sess.span_bug(local.span, "local is bound to something weird");
871-
}
872-
option::None => {
873-
match bcx.fcx.lllocals.get_copy(&local.node.pat.id) {
874-
local_imm(v) => v,
875-
_ => bcx.tcx().sess.span_bug(local.span, "local is bound to something weird")
867+
// NDM Should use `pat_util::pat_bindings` for pats like (a, b) etc
868+
let llptr = match bcx.fcx.lllocals.find_copy(&local.node.pat.id) {
869+
Some(v) => v,
870+
None => {
871+
bcx.tcx().sess.span_bug(
872+
local.span,
873+
fmt!("No entry in lllocals table for %?", local.node.id));
876874
}
877-
}
878875
};
879876
let declargs = ~[llmdnode([llptr]), mdnode];
880877
trans::build::Call(bcx, *cx.intrinsics.get(&~"llvm.dbg.declare"),
@@ -922,9 +919,7 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
922919
};
923920
update_cache(cache, tg, argument_metadata(mdval));
924921
925-
let llptr = match fcx.llargs.get_copy(&arg.id) {
926-
local_mem(v) | local_imm(v) => v,
927-
};
922+
let llptr = fcx.llargs.get_copy(&arg.id);
928923
let declargs = ~[llmdnode([llptr]), mdnode];
929924
trans::build::Call(bcx,
930925
*cx.intrinsics.get(&~"llvm.dbg.declare"),

src/librustc/middle/trans/expr.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,25 +1058,22 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
10581058
};
10591059

10601060
fn take_local(bcx: block,
1061-
table: &HashMap<ast::node_id, local_val>,
1061+
table: &HashMap<ast::node_id, ValueRef>,
10621062
nid: ast::node_id) -> Datum {
1063-
let (v, mode) = match table.find(&nid) {
1064-
Some(&local_mem(v)) => (v, ByRef(ZeroMem)),
1065-
Some(&local_imm(v)) => (v, ByValue),
1063+
let v = match table.find(&nid) {
1064+
Some(&v) => v,
10661065
None => {
10671066
bcx.sess().bug(fmt!(
10681067
"trans_local_var: no llval for local/arg %? found", nid));
10691068
}
10701069
};
10711070
let ty = node_id_type(bcx, nid);
1072-
1073-
debug!("take_local(nid=%?, v=%s, mode=%?, ty=%s)",
1074-
nid, bcx.val_str(v), mode, bcx.ty_to_str(ty));
1075-
1071+
debug!("take_local(nid=%?, v=%s, ty=%s)",
1072+
nid, bcx.val_str(v), bcx.ty_to_str(ty));
10761073
Datum {
10771074
val: v,
10781075
ty: ty,
1079-
mode: mode,
1076+
mode: ByRef(ZeroMem)
10801077
}
10811078
}
10821079
}

0 commit comments

Comments
 (0)