about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-05-29 17:44:19 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-05-30 09:54:38 -0400
commit7dfb865339c85139682d74acf0f90984aee8f2a2 (patch)
treea81ec2c0a32cd90936363abb392120ae85217ac9
parent2616581863ea71ecc23f1f126cb409e047139b6c (diff)
downloadrust-7dfb865339c85139682d74acf0f90984aee8f2a2.tar.gz
rust-7dfb865339c85139682d74acf0f90984aee8f2a2.zip
Remove local_imm/local_mem since all variables are now by reference
-rw-r--r--src/librustc/middle/trans/_match.rs19
-rw-r--r--src/librustc/middle/trans/base.rs17
-rw-r--r--src/librustc/middle/trans/common.rs6
-rw-r--r--src/librustc/middle/trans/datum.rs1
-rw-r--r--src/librustc/middle/trans/debuginfo.rs21
-rw-r--r--src/librustc/middle/trans/expr.rs15
6 files changed, 33 insertions, 46 deletions
diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs
index 153eec1bc7b..f222cd72492 100644
--- a/src/librustc/middle/trans/_match.rs
+++ b/src/librustc/middle/trans/_match.rs
@@ -140,6 +140,11 @@
  * the various values we copied explicitly.  Note that guards and moves are
  * just plain incompatible.
  *
+ * Some relevant helper functions that manage bindings:
+ * - `create_bindings_map()`
+ * - `store_non_ref_bindings()`
+ * - `insert_lllocals()`
+ *
  */
 
 use core::prelude::*;
@@ -1201,7 +1206,7 @@ fn insert_lllocals(bcx: block,
         debug!("binding %? to %s",
                binding_info.id,
                val_str(bcx.ccx().tn, llval));
-        llmap.insert(binding_info.id, local_mem(llval));
+        llmap.insert(binding_info.id, llval);
     }
     return bcx;
 }
@@ -1673,7 +1678,7 @@ pub fn trans_match_inner(scope_cx: block,
 
     let mut arm_datas = ~[], matches = ~[];
     for vec::each(arms) |arm| {
-        let body = scope_block(bcx, arm.body.info(), ~"case_body");
+        let body = scope_block(bcx, arm.body.info(), "case_body");
         let bindings_map = create_bindings_map(bcx, arm.pats[0]);
         let arm_data = @ArmData {bodycx: body,
                                  arm: arm,
@@ -1765,22 +1770,20 @@ pub fn bind_irrefutable_pat(bcx: block,
                 datum.copy_to_datum(bcx, INIT, scratch);
                 match binding_mode {
                     BindLocal => {
-                        bcx.fcx.lllocals.insert(pat.id,
-                                                local_mem(scratch.val));
+                        bcx.fcx.lllocals.insert(pat.id, scratch.val);
                     }
                     BindArgument => {
-                        bcx.fcx.llargs.insert(pat.id,
-                                              local_mem(scratch.val));
+                        bcx.fcx.llargs.insert(pat.id, scratch.val);
                     }
                 }
                 add_clean(bcx, scratch.val, binding_ty);
             } else {
                 match binding_mode {
                     BindLocal => {
-                        bcx.fcx.lllocals.insert(pat.id, local_mem(val));
+                        bcx.fcx.lllocals.insert(pat.id, val);
                     }
                     BindArgument => {
-                        bcx.fcx.llargs.insert(pat.id, local_mem(val));
+                        bcx.fcx.llargs.insert(pat.id, val);
                     }
                 }
             }
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs
index 6a49ae4cbc6..dcd638d1a62 100644
--- a/src/librustc/middle/trans/base.rs
+++ b/src/librustc/middle/trans/base.rs
@@ -1105,8 +1105,8 @@ pub fn init_local(bcx: block, local: @ast::local) -> block {
         }
     }
 
-    let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
-        Some(&local_mem(v)) => v,
+    let llptr = match bcx.fcx.lllocals.find_copy(&local.node.id) {
+        Some(v) => v,
         _ => {
             bcx.tcx().sess.span_bug(local.span,
                                     "init_local: Someone forgot to document why it's\
@@ -1432,7 +1432,7 @@ pub fn alloc_local(cx: block, local: @ast::local) -> block {
             });
         }
     }
-    cx.fcx.lllocals.insert(local.node.id, local_mem(val));
+    cx.fcx.lllocals.insert(local.node.id, val);
     cx
 }
 
@@ -1768,7 +1768,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
                                           false,
                                           _match::BindArgument);
 
-        fcx.llargs.insert(arg_id, local_mem(llarg));
+        fcx.llargs.insert(arg_id, llarg);
 
         if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
             debuginfo::create_arg(bcx, args[arg_n], args[arg_n].ty.span);
@@ -2004,7 +2004,7 @@ pub fn trans_enum_variant(ccx: @CrateContext,
         // this function as an opaque blob due to the way that type_of()
         // works. So we have to cast to the destination's view of the type.
         let llarg = match fcx.llargs.find(&va.id) {
-            Some(&local_mem(x)) => x,
+            Some(&x) => x,
             _ => fail!("trans_enum_variant: how do we know this works?"),
         };
         let arg_ty = arg_tys[i];
@@ -2074,12 +2074,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
                                              fcx.llretptr.get(),
                                              0,
                                              i);
-        let llarg = match fcx.llargs.get_copy(&field.node.id) {
-            local_mem(x) => x,
-            _ => {
-                ccx.tcx.sess.bug("trans_tuple_struct: llarg wasn't local_mem")
-            }
-        };
+        let llarg = fcx.llargs.get_copy(&field.node.id);
         let arg_ty = arg_tys[i];
         memcpy_ty(bcx, lldestptr, llarg, arg_ty);
     }
diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs
index d148dbd2183..a2fa840ad79 100644
--- a/src/librustc/middle/trans/common.rs
+++ b/src/librustc/middle/trans/common.rs
@@ -240,8 +240,6 @@ pub struct ValSelfData {
     is_owned: bool
 }
 
-pub enum local_val { local_mem(ValueRef), local_imm(ValueRef), }
-
 // Here `self_ty` is the real type of the self parameter to this method. It
 // will only be set in the case of default methods.
 pub struct param_substs {
@@ -328,10 +326,10 @@ pub struct fn_ctxt_ {
     has_immediate_return_value: bool,
 
     // Maps arguments to allocas created for them in llallocas.
-    llargs: @mut HashMap<ast::node_id, local_val>,
+    llargs: @mut HashMap<ast::node_id, ValueRef>,
     // Maps the def_ids for local variables to the allocas created for
     // them in llallocas.
-    lllocals: @mut HashMap<ast::node_id, local_val>,
+    lllocals: @mut HashMap<ast::node_id, ValueRef>,
     // Same as above, but for closure upvars
     llupvars: @mut HashMap<ast::node_id, ValueRef>,
 
diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs
index 692fbf47957..0f325c432f4 100644
--- a/src/librustc/middle/trans/datum.rs
+++ b/src/librustc/middle/trans/datum.rs
@@ -105,7 +105,6 @@ use middle::ty;
 use util::common::indenter;
 use util::ppaux::ty_to_str;
 
-use core::to_bytes;
 use core::uint;
 use syntax::ast;
 use syntax::codemap::span;
diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs
index c1661b80cf8..38740f69c3a 100644
--- a/src/librustc/middle/trans/debuginfo.rs
+++ b/src/librustc/middle/trans/debuginfo.rs
@@ -864,17 +864,14 @@ pub fn create_local_var(bcx: block, local: @ast::local)
     };
     update_cache(cache, AutoVariableTag, local_var_metadata(mdval));
 
-    let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
-      option::Some(&local_mem(v)) => v,
-      option::Some(_) => {
-        bcx.tcx().sess.span_bug(local.span, "local is bound to something weird");
-      }
-      option::None => {
-        match bcx.fcx.lllocals.get_copy(&local.node.pat.id) {
-          local_imm(v) => v,
-          _ => bcx.tcx().sess.span_bug(local.span, "local is bound to something weird")
+    // NDM Should use `pat_util::pat_bindings` for pats like (a, b) etc
+    let llptr = match bcx.fcx.lllocals.find_copy(&local.node.pat.id) {
+        Some(v) => v,
+        None => {
+            bcx.tcx().sess.span_bug(
+                local.span,
+                fmt!("No entry in lllocals table for %?", local.node.id));
         }
-      }
     };
     let declargs = ~[llmdnode([llptr]), mdnode];
     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)
             };
             update_cache(cache, tg, argument_metadata(mdval));
 
-            let llptr = match fcx.llargs.get_copy(&arg.id) {
-              local_mem(v) | local_imm(v) => v,
-            };
+            let llptr = fcx.llargs.get_copy(&arg.id);
             let declargs = ~[llmdnode([llptr]), mdnode];
             trans::build::Call(bcx,
                                *cx.intrinsics.get(&~"llvm.dbg.declare"),
diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs
index a7d064dde46..42ba06aad76 100644
--- a/src/librustc/middle/trans/expr.rs
+++ b/src/librustc/middle/trans/expr.rs
@@ -1058,25 +1058,22 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
     };
 
     fn take_local(bcx: block,
-                  table: &HashMap<ast::node_id, local_val>,
+                  table: &HashMap<ast::node_id, ValueRef>,
                   nid: ast::node_id) -> Datum {
-        let (v, mode) = match table.find(&nid) {
-            Some(&local_mem(v)) => (v, ByRef(ZeroMem)),
-            Some(&local_imm(v)) => (v, ByValue),
+        let v = match table.find(&nid) {
+            Some(&v) => v,
             None => {
                 bcx.sess().bug(fmt!(
                     "trans_local_var: no llval for local/arg %? found", nid));
             }
         };
         let ty = node_id_type(bcx, nid);
-
-        debug!("take_local(nid=%?, v=%s, mode=%?, ty=%s)",
-               nid, bcx.val_str(v), mode, bcx.ty_to_str(ty));
-
+        debug!("take_local(nid=%?, v=%s, ty=%s)",
+               nid, bcx.val_str(v), bcx.ty_to_str(ty));
         Datum {
             val: v,
             ty: ty,
-            mode: mode,
+            mode: ByRef(ZeroMem)
         }
     }
 }