rustc: remove DefArg and DefBinding in favor of DefLocal.

This commit is contained in:
Eduard Burtescu 2014-09-17 17:28:19 +03:00
parent 49dd8e8c36
commit 1813b8cf55
21 changed files with 84 additions and 204 deletions

View File

@ -954,8 +954,7 @@ impl LintPass for NonSnakeCase {
match &p.node {
&ast::PatIdent(_, ref path1, _) => {
match cx.tcx.def_map.borrow().find(&p.id) {
Some(&def::DefLocal(_, _)) | Some(&def::DefBinding(_, _)) |
Some(&def::DefArg(_, _)) => {
Some(&def::DefLocal(_, _)) => {
self.check_snake_case(cx, "variable", path1.node, p.span);
}
_ => {}

View File

@ -462,7 +462,6 @@ impl tr for def::Def {
def::DefMod(did) => { def::DefMod(did.tr(dcx)) }
def::DefForeignMod(did) => { def::DefForeignMod(did.tr(dcx)) }
def::DefStatic(did, m) => { def::DefStatic(did.tr(dcx), m) }
def::DefArg(nid, b) => { def::DefArg(dcx.tr_id(nid), b) }
def::DefLocal(nid, b) => { def::DefLocal(dcx.tr_id(nid), b) }
def::DefVariant(e_did, v_did, is_s) => {
def::DefVariant(e_did.tr(dcx), v_did.tr(dcx), is_s)
@ -472,7 +471,6 @@ impl tr for def::Def {
def::DefAssociatedTy(did) => def::DefAssociatedTy(did.tr(dcx)),
def::DefPrimTy(p) => def::DefPrimTy(p),
def::DefTyParam(s, did, v) => def::DefTyParam(s, did.tr(dcx), v),
def::DefBinding(nid, bm) => def::DefBinding(dcx.tr_id(nid), bm),
def::DefUse(did) => def::DefUse(did.tr(dcx)),
def::DefUpvar(nid1, def, nid2, nid3) => {
def::DefUpvar(dcx.tr_id(nid1),

View File

@ -514,9 +514,9 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
true
}
pub fn is_local_variable_or_arg(&self, cmt: mc::cmt) -> bool {
fn is_local_variable_or_arg(&self, cmt: mc::cmt) -> bool {
match cmt.cat {
mc::cat_local(_) | mc::cat_arg(_) => true,
mc::cat_local(_) => true,
_ => false
}
}
@ -775,7 +775,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
debug!("mark_variable_as_used_mut(cmt={})", cmt.repr(this.tcx()));
match cmt.cat.clone() {
mc::cat_copied_upvar(mc::CopiedUpvar { upvar_id: id, .. }) |
mc::cat_local(id) | mc::cat_arg(id) => {
mc::cat_local(id) => {
this.tcx().used_mut_nodes.borrow_mut().insert(id);
return;
}

View File

@ -147,8 +147,7 @@ fn check_and_get_illegal_move_origin(bccx: &BorrowckCtxt,
}
mc::cat_rvalue(..) |
mc::cat_local(..) |
mc::cat_arg(..) => {
mc::cat_local(..) => {
None
}

View File

@ -69,7 +69,6 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
mc::cat_rvalue(..) |
mc::cat_copied_upvar(..) | // L-Local
mc::cat_local(..) | // L-Local
mc::cat_arg(..) | // L-Local
mc::cat_upvar(..) |
mc::cat_deref(_, _, mc::BorrowedPtr(..)) | // L-Deref-Borrowed
mc::cat_deref(_, _, mc::Implicit(..)) |
@ -174,8 +173,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
mc::cat_static_item => {
ty::ReStatic
}
mc::cat_local(local_id) |
mc::cat_arg(local_id) => {
mc::cat_local(local_id) => {
ty::ReScope(self.bccx.tcx.region_maps.var_scope(local_id))
}
mc::cat_deref(_, _, mc::UnsafePtr(..)) => {

View File

@ -66,8 +66,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
Safe
}
mc::cat_local(local_id) |
mc::cat_arg(local_id) => {
mc::cat_local(local_id) => {
// R-Variable, locally declared
let lp = Rc::new(LpVar(local_id));
SafeIf(lp.clone(), vec![lp])

View File

@ -321,8 +321,7 @@ pub fn opt_loan_path(cmt: &mc::cmt) -> Option<Rc<LoanPath>> {
None
}
mc::cat_local(id) |
mc::cat_arg(id) => {
mc::cat_local(id) => {
Some(Rc::new(LpVar(id)))
}

View File

@ -22,7 +22,6 @@ pub enum Def {
DefMod(ast::DefId),
DefForeignMod(ast::DefId),
DefStatic(ast::DefId, bool /* is_mutbl */),
DefArg(ast::NodeId, ast::BindingMode),
DefLocal(ast::NodeId, ast::BindingMode),
DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */),
DefTy(ast::DefId, bool /* is_enum */),
@ -30,7 +29,6 @@ pub enum Def {
DefTrait(ast::DefId),
DefPrimTy(ast::PrimTy),
DefTyParam(ParamSpace, ast::DefId, uint),
DefBinding(ast::NodeId, ast::BindingMode),
DefUse(ast::DefId),
DefUpvar(ast::NodeId, // id of closed over var
Gc<Def>, // closed over def
@ -68,11 +66,9 @@ impl Def {
DefMethod(id, _) => {
id
}
DefArg(id, _) |
DefLocal(id, _) |
DefSelfTy(id) |
DefUpvar(id, _, _, _) |
DefBinding(id, _) |
DefRegion(id) |
DefTyParamBinder(id) |
DefLabel(id) => {

View File

@ -437,24 +437,15 @@ fn visit_arm(ir: &mut IrMaps, arm: &Arm) {
visit::walk_arm(ir, arm);
}
fn moved_variable_node_id_from_def(def: Def) -> Option<NodeId> {
match def {
DefBinding(nid, _) |
DefArg(nid, _) |
DefLocal(nid, _) => Some(nid),
_ => None
}
}
fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
match expr.node {
// live nodes required for uses or definitions of variables:
ExprPath(_) => {
let def = ir.tcx.def_map.borrow().get_copy(&expr.id);
debug!("expr {}: path that leads to {:?}", expr.id, def);
if moved_variable_node_id_from_def(def).is_some() {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
match def {
DefLocal(..) => ir.add_live_node_for_node(expr.id, ExprNode(expr.span)),
_ => {}
}
visit::walk_expr(ir, expr);
}
@ -470,13 +461,13 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
let mut call_caps = Vec::new();
freevars::with_freevars(ir.tcx, expr.id, |freevars| {
for fv in freevars.iter() {
match moved_variable_node_id_from_def(fv.def) {
Some(rv) => {
match fv.def {
DefLocal(rv, _) => {
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
call_caps.push(CaptureInfo {ln: fv_ln,
var_nid: rv});
}
None => {}
_ => {}
}
}
});
@ -1296,9 +1287,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
-> LiveNode {
let def = self.ir.tcx.def_map.borrow().get_copy(&expr.id);
match moved_variable_node_id_from_def(def) {
Some(nid) => {
match self.ir.tcx.def_map.borrow().get_copy(&expr.id) {
DefLocal(nid, _) => {
let ln = self.live_node(expr.id, expr.span);
if acc != 0u {
self.init_from_succ(ln, succ);
@ -1307,7 +1297,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
ln
}
None => succ
_ => succ
}
}
@ -1546,16 +1536,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
let var = self.variable(nid, expr.span);
self.warn_about_dead_assign(expr.span, expr.id, ln, var);
}
def => {
match moved_variable_node_id_from_def(def) {
Some(nid) => {
let ln = self.live_node(expr.id, expr.span);
let var = self.variable(nid, expr.span);
self.warn_about_dead_assign(expr.span, expr.id, ln, var);
}
None => {}
}
}
_ => {}
}
}

View File

@ -71,6 +71,7 @@ use util::ppaux::{ty_to_string, Repr};
use syntax::ast::{MutImmutable, MutMutable};
use syntax::ast;
use syntax::ast_map;
use syntax::codemap::Span;
use syntax::print::pprust;
use syntax::parse::token;
@ -85,7 +86,6 @@ pub enum categorization {
cat_copied_upvar(CopiedUpvar), // upvar copied into proc env
cat_upvar(ty::UpvarId, ty::UpvarBorrow), // by ref upvar from stack closure
cat_local(ast::NodeId), // local variable
cat_arg(ast::NodeId), // formal argument
cat_deref(cmt, uint, PointerKind), // deref of a ptr
cat_interior(cmt, InteriorKind), // something interior: field, tuple, etc
cat_downcast(cmt), // selects a particular enum variant (*1)
@ -326,8 +326,6 @@ impl MutabilityCategory {
def::DefStatic(_, false) => McImmutable,
def::DefStatic(_, true) => McDeclared,
def::DefArg(_, binding_mode) |
def::DefBinding(_, binding_mode) |
def::DefLocal(_, binding_mode) => match binding_mode {
ast::BindByValue(ast::MutMutable) => McDeclared,
_ => McImmutable
@ -556,19 +554,6 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
}))
}
def::DefArg(vid, _) => {
// Idea: make this could be rewritten to model by-ref
// stuff as `&const` and `&mut`?
Ok(Rc::new(cmt_ {
id: id,
span: span,
cat: cat_arg(vid),
mutbl: MutabilityCategory::from_def(&def),
ty:expr_ty
}))
}
def::DefUpvar(var_id, _, fn_node_id, _) => {
let ty = if_ok!(self.node_ty(fn_node_id));
match ty::get(ty).sty {
@ -634,9 +619,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
}
}
def::DefLocal(vid, _) |
def::DefBinding(vid, _) => {
// by-value/by-ref bindings are local variables
def::DefLocal(vid, _) => {
Ok(Rc::new(cmt_ {
id: id,
span: span,
@ -1196,11 +1179,13 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
cat_rvalue(..) => {
"non-lvalue".to_string()
}
cat_local(_) => {
"local variable".to_string()
}
cat_arg(..) => {
"argument".to_string()
cat_local(vid) => {
match self.tcx().map.find(vid) {
Some(ast_map::NodeArg(_)) => {
"argument".to_string()
}
_ => "local variable".to_string()
}
}
cat_deref(ref base, _, pk) => {
match base.cat {
@ -1267,7 +1252,6 @@ impl cmt_ {
cat_static_item |
cat_copied_upvar(..) |
cat_local(..) |
cat_arg(..) |
cat_deref(_, _, UnsafePtr(..)) |
cat_deref(_, _, GcPtr(..)) |
cat_deref(_, _, BorrowedPtr(..)) |
@ -1311,7 +1295,6 @@ impl cmt_ {
cat_rvalue(..) |
cat_local(..) |
cat_upvar(..) |
cat_arg(_) |
cat_deref(_, _, UnsafePtr(..)) => { // yes, it's aliasable, but...
None
}
@ -1363,8 +1346,7 @@ impl Repr for categorization {
cat_rvalue(..) |
cat_copied_upvar(..) |
cat_local(..) |
cat_upvar(..) |
cat_arg(..) => {
cat_upvar(..) => {
format!("{:?}", *self)
}
cat_deref(ref cmt, derefs, ptr) => {

View File

@ -270,8 +270,8 @@ enum TypeParameters<'a> {
RibKind)
}
// The rib kind controls the translation of argument or local definitions
// (`def_arg` or `def_local`) to upvars (`def_upvar`).
// The rib kind controls the translation of local
// definitions (`DefLocal`) to upvars (`DefUpvar`).
enum RibKind {
// No translation needs to be applied.
@ -1895,8 +1895,7 @@ impl<'a> Resolver<'a> {
ignoring {:?}", def);
// Ignored; handled elsewhere.
}
DefArg(..) | DefLocal(..) | DefPrimTy(..) |
DefTyParam(..) | DefBinding(..) |
DefLocal(..) | DefPrimTy(..) | DefTyParam(..) |
DefUse(..) | DefUpvar(..) | DefRegion(..) |
DefTyParamBinder(..) | DefLabel(..) | DefSelfTy(..) => {
fail!("didn't expect `{:?}`", def);
@ -3840,8 +3839,7 @@ impl<'a> Resolver<'a> {
let is_ty_param;
match def_like {
DlDef(d @ DefLocal(..)) | DlDef(d @ DefUpvar(..)) |
DlDef(d @ DefArg(..)) | DlDef(d @ DefBinding(..)) => {
DlDef(d @ DefLocal(..)) | DlDef(d @ DefUpvar(..)) => {
def = d;
is_ty_param = false;
}
@ -4942,22 +4940,7 @@ impl<'a> Resolver<'a> {
debug!("(resolving pattern) binding `{}`",
token::get_name(renamed));
let def = match mode {
RefutableMode => {
// For pattern arms, we must use
// `def_binding` definitions.
DefBinding(pattern.id, binding_mode)
}
LocalIrrefutableMode => {
// But for locals, we use `def_local`.
DefLocal(pattern.id, binding_mode)
}
ArgumentIrrefutableMode => {
// And for function arguments, `def_arg`.
DefArg(pattern.id, binding_mode)
}
};
let def = DefLocal(pattern.id, binding_mode);
// Record the definition so that later passes
// will be able to distinguish variants from

View File

@ -230,8 +230,6 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
def::DefAssociatedTy(..) |
def::DefTrait(_) => Some(recorder::TypeRef),
def::DefStatic(_, _) |
def::DefBinding(_, _) |
def::DefArg(_, _) |
def::DefLocal(_, _) |
def::DefVariant(_, _, _) |
def::DefUpvar(_, _, _, _) => Some(recorder::VarRef),
@ -739,14 +737,12 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
let def = def_map.get(&ex.id);
let sub_span = self.span.span_for_last_ident(ex.span);
match *def {
def::DefLocal(id, _) |
def::DefArg(id, _) |
def::DefUpvar(id, _, _, _) |
def::DefBinding(id, _) => self.fmt.ref_str(recorder::VarRef,
ex.span,
sub_span,
ast_util::local_def(id),
self.cur_scope),
def::DefLocal(id, _) => self.fmt.ref_str(recorder::VarRef,
ex.span,
sub_span,
ast_util::local_def(id),
self.cur_scope),
def::DefStatic(def_id,_) |
def::DefVariant(_, def_id, _) => self.fmt.ref_str(recorder::VarRef,
ex.span,
@ -814,7 +810,6 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
self.write_sub_path_trait_truncated(path);
},
def::DefLocal(_, _) |
def::DefArg(_, _) |
def::DefStatic(_,_) |
def::DefStruct(_) |
def::DefFn(_, _) => self.write_sub_paths_truncated(path),
@ -1382,12 +1377,12 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
}
let def = def_map.get(&id);
match *def {
def::DefBinding(id, _) => self.fmt.variable_str(p.span,
sub_span,
id,
path_to_string(p).as_slice(),
value.as_slice(),
""),
def::DefLocal(id, _) => self.fmt.variable_str(p.span,
sub_span,
id,
path_to_string(p).as_slice(),
value.as_slice(),
""),
def::DefVariant(_,id,_) => self.fmt.ref_str(ref_kind,
p.span,
sub_span,

View File

@ -1226,7 +1226,6 @@ pub fn trans_match<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
fn is_discr_reassigned(bcx: Block, discr: &ast::Expr, body: &ast::Expr) -> bool {
match discr.node {
ast::ExprPath(..) => match bcx.def(discr.id) {
def::DefArg(vid, _) | def::DefBinding(vid, _) |
def::DefLocal(vid, _) | def::DefUpvar(vid, _, _, _) => {
let mut rc = ReassignmentChecker {
node: vid,
@ -1259,7 +1258,7 @@ impl euv::Delegate for ReassignmentChecker {
fn mutate(&mut self, _: ast::NodeId, _: Span, cmt: mc::cmt, _: euv::MutateMode) {
match cmt.cat {
mc::cat_copied_upvar(mc::CopiedUpvar { upvar_id: vid, .. }) |
mc::cat_arg(vid) | mc::cat_local(vid) => self.reassigned = self.node == vid,
mc::cat_local(vid) => self.reassigned = self.node == vid,
_ => {}
}
}
@ -1391,13 +1390,6 @@ fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>,
return bcx;
}
enum IrrefutablePatternBindingMode {
// Stores the association between node ID and LLVM value in `lllocals`.
BindLocal,
// Stores the association between node ID and LLVM value in `llargs`.
BindArgument
}
pub fn store_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
local: &ast::Local)
-> Block<'blk, 'tcx> {
@ -1419,7 +1411,7 @@ pub fn store_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
pat_bindings(&tcx.def_map, pat, |_, p_id, _, path1| {
let scope = cleanup::var_scope(tcx, p_id);
bcx = mk_binding_alloca(
bcx, p_id, &path1.node, BindLocal, scope, (),
bcx, p_id, &path1.node, scope, (),
|(), bcx, llval, ty| { zero_mem(bcx, llval, ty); bcx });
});
bcx
@ -1441,7 +1433,7 @@ pub fn store_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
Some(ident) => {
let var_scope = cleanup::var_scope(tcx, local.id);
return mk_binding_alloca(
bcx, pat.id, ident, BindLocal, var_scope, (),
bcx, pat.id, ident, var_scope, (),
|(), bcx, v, _| expr::trans_into(bcx, &**init_expr,
expr::SaveIn(v)));
}
@ -1459,7 +1451,7 @@ pub fn store_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
add_comment(bcx, "creating zeroable ref llval");
}
let var_scope = cleanup::var_scope(tcx, local.id);
bind_irrefutable_pat(bcx, pat, init_datum.val, BindLocal, var_scope)
bind_irrefutable_pat(bcx, pat, init_datum.val, var_scope)
}
}
None => {
@ -1475,7 +1467,7 @@ pub fn store_arg<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
-> Block<'blk, 'tcx> {
/*!
* Generates code for argument patterns like `fn foo(<pat>: T)`.
* Creates entries in the `llargs` map for each of the bindings
* Creates entries in the `lllocals` map for each of the bindings
* in `pat`.
*
* # Arguments
@ -1499,12 +1491,12 @@ pub fn store_arg<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
// already put it in a temporary alloca and gave it up, unless
// we emit extra-debug-info, which requires local allocas :(.
let arg_val = arg.add_clean(bcx.fcx, arg_scope);
bcx.fcx.llargs.borrow_mut()
bcx.fcx.lllocals.borrow_mut()
.insert(pat.id, Datum::new(arg_val, arg_ty, Lvalue));
bcx
} else {
mk_binding_alloca(
bcx, pat.id, ident, BindArgument, arg_scope, arg,
bcx, pat.id, ident, arg_scope, arg,
|arg, bcx, llval, _| arg.store_to(bcx, llval))
}
}
@ -1514,8 +1506,7 @@ pub fn store_arg<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
// pattern.
let arg = unpack_datum!(
bcx, arg.to_lvalue_datum_in_scope(bcx, "__arg", arg_scope));
bind_irrefutable_pat(bcx, pat, arg.val,
BindArgument, arg_scope)
bind_irrefutable_pat(bcx, pat, arg.val, arg_scope)
}
}
}
@ -1541,13 +1532,12 @@ pub fn store_for_loop_binding<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
}
// General path. Copy out the values that are used in the pattern.
bind_irrefutable_pat(bcx, pat, llvalue, BindLocal, body_scope)
bind_irrefutable_pat(bcx, pat, llvalue, body_scope)
}
fn mk_binding_alloca<'blk, 'tcx, A>(bcx: Block<'blk, 'tcx>,
p_id: ast::NodeId,
ident: &ast::Ident,
binding_mode: IrrefutablePatternBindingMode,
cleanup_scope: cleanup::ScopeId,
arg: A,
populate: |A, Block<'blk, 'tcx>, ValueRef, ty::t|
@ -1567,18 +1557,13 @@ fn mk_binding_alloca<'blk, 'tcx, A>(bcx: Block<'blk, 'tcx>,
// Now that memory is initialized and has cleanup scheduled,
// create the datum and insert into the local variable map.
let datum = Datum::new(llval, var_ty, Lvalue);
let mut llmap = match binding_mode {
BindLocal => bcx.fcx.lllocals.borrow_mut(),
BindArgument => bcx.fcx.llargs.borrow_mut()
};
llmap.insert(p_id, datum);
bcx.fcx.lllocals.borrow_mut().insert(p_id, datum);
bcx
}
fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
pat: &ast::Pat,
val: ValueRef,
binding_mode: IrrefutablePatternBindingMode,
cleanup_scope: cleanup::ScopeId)
-> Block<'blk, 'tcx> {
/*!
@ -1594,13 +1579,11 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
* - bcx: starting basic block context
* - pat: the irrefutable pattern being matched.
* - val: the value being matched -- must be an lvalue (by ref, with cleanup)
* - binding_mode: is this for an argument or a local variable?
*/
debug!("bind_irrefutable_pat(bcx={}, pat={}, binding_mode={:?})",
debug!("bind_irrefutable_pat(bcx={}, pat={})",
bcx.to_str(),
pat.repr(bcx.tcx()),
binding_mode);
pat.repr(bcx.tcx()));
if bcx.sess().asm_comments() {
add_comment(bcx, format!("bind_irrefutable_pat(pat={})",
@ -1620,7 +1603,7 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// binding will live and place it into the appropriate
// map.
bcx = mk_binding_alloca(
bcx, pat.id, &path1.node, binding_mode, cleanup_scope, (),
bcx, pat.id, &path1.node, cleanup_scope, (),
|(), bcx, llval, ty| {
match pat_binding_mode {
ast::BindByValue(_) => {
@ -1641,8 +1624,7 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
}
for inner_pat in inner.iter() {
bcx = bind_irrefutable_pat(bcx, &**inner_pat, val,
binding_mode, cleanup_scope);
bcx = bind_irrefutable_pat(bcx, &**inner_pat, val, cleanup_scope);
}
}
ast::PatEnum(_, ref sub_pats) => {
@ -1660,8 +1642,7 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
for sub_pat in sub_pats.iter() {
for (i, &argval) in args.vals.iter().enumerate() {
bcx = bind_irrefutable_pat(bcx, &**sub_pat.get(i),
argval, binding_mode,
cleanup_scope);
argval, cleanup_scope);
}
}
}
@ -1678,8 +1659,7 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let fldptr = adt::trans_field_ptr(bcx, &*repr,
val, 0, i);
bcx = bind_irrefutable_pat(bcx, &**elem,
fldptr, binding_mode,
cleanup_scope);
fldptr, cleanup_scope);
}
}
}
@ -1698,8 +1678,7 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let ix = ty::field_idx_strict(tcx, f.ident.name, field_tys);
let fldptr = adt::trans_field_ptr(bcx, &*pat_repr, val,
discr, ix);
bcx = bind_irrefutable_pat(bcx, &*f.pat, fldptr,
binding_mode, cleanup_scope);
bcx = bind_irrefutable_pat(bcx, &*f.pat, fldptr, cleanup_scope);
}
})
}
@ -1707,17 +1686,16 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let repr = adt::represent_node(bcx, pat.id);
for (i, elem) in elems.iter().enumerate() {
let fldptr = adt::trans_field_ptr(bcx, &*repr, val, 0, i);
bcx = bind_irrefutable_pat(bcx, &**elem, fldptr,
binding_mode, cleanup_scope);
bcx = bind_irrefutable_pat(bcx, &**elem, fldptr, cleanup_scope);
}
}
ast::PatBox(ref inner) => {
let llbox = Load(bcx, val);
bcx = bind_irrefutable_pat(bcx, &**inner, llbox, binding_mode, cleanup_scope);
bcx = bind_irrefutable_pat(bcx, &**inner, llbox, cleanup_scope);
}
ast::PatRegion(ref inner) => {
let loaded_val = Load(bcx, val);
bcx = bind_irrefutable_pat(bcx, &**inner, loaded_val, binding_mode, cleanup_scope);
bcx = bind_irrefutable_pat(bcx, &**inner, loaded_val, cleanup_scope);
}
ast::PatVec(ref before, ref slice, ref after) => {
let pat_ty = node_id_type(bcx, pat.id);
@ -1737,7 +1715,7 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
.chain(after.iter())
.zip(extracted.vals.into_iter())
.fold(bcx, |bcx, (inner, elem)|
bind_irrefutable_pat(bcx, &**inner, elem, binding_mode, cleanup_scope)
bind_irrefutable_pat(bcx, &**inner, elem, cleanup_scope)
);
}
ast::PatMac(..) => {

View File

@ -1468,7 +1468,6 @@ pub fn new_fn_ctxt<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
needs_ret_allocas: nested_returns,
personality: Cell::new(None),
caller_expects_out_pointer: uses_outptr,
llargs: RefCell::new(NodeMap::new()),
lllocals: RefCell::new(NodeMap::new()),
llupvars: RefCell::new(NodeMap::new()),
id: id,

View File

@ -196,9 +196,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
}
}
def::DefStatic(..) |
def::DefArg(..) |
def::DefLocal(..) |
def::DefBinding(..) |
def::DefUpvar(..) => {
datum_callee(bcx, ref_expr)
}

View File

@ -267,10 +267,7 @@ pub struct FunctionContext<'a, 'tcx: 'a> {
// points to, but if this value is false, that slot will be a local alloca.
pub caller_expects_out_pointer: bool,
// Maps arguments to allocas created for them in llallocas.
pub llargs: RefCell<NodeMap<LvalueDatum>>,
// Maps the def_ids for local variables to the allocas created for
// Maps the DefId's for local variables to the allocas created for
// them in llallocas.
pub lllocals: RefCell<NodeMap<LvalueDatum>>,

View File

@ -1005,11 +1005,11 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
let scope_metadata = bcx.fcx.debug_context.get_ref(cx, arg.pat.span).fn_metadata;
pat_util::pat_bindings(def_map, &*arg.pat, |_, node_id, span, path1| {
let llarg = match bcx.fcx.llargs.borrow().find_copy(&node_id) {
let llarg = match bcx.fcx.lllocals.borrow().find_copy(&node_id) {
Some(v) => v,
None => {
bcx.sess().span_bug(span,
format!("no entry in llargs table for {:?}",
format!("no entry in lllocals table for {:?}",
node_id).as_slice());
}
};

View File

@ -71,7 +71,6 @@ use middle::typeck;
use middle::typeck::MethodCall;
use util::common::indenter;
use util::ppaux::Repr;
use util::nodemap::NodeMap;
use middle::trans::machine::{llsize_of, llsize_of_alloc};
use middle::trans::type_::Type;
@ -1176,7 +1175,7 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let _icx = push_ctxt("trans_local_var");
return match def {
match def {
def::DefUpvar(nid, _, _, _) => {
// Can't move upvars, so this is never a ZeroMemLastUse.
let local_ty = node_id_type(bcx, nid);
@ -1189,34 +1188,24 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
}
}
}
def::DefArg(nid, _) => {
take_local(bcx, &*bcx.fcx.llargs.borrow(), nid)
}
def::DefLocal(nid, _) | def::DefBinding(nid, _) => {
take_local(bcx, &*bcx.fcx.lllocals.borrow(), nid)
def::DefLocal(nid, _) => {
let datum = match bcx.fcx.lllocals.borrow().find(&nid) {
Some(&v) => v,
None => {
bcx.sess().bug(format!(
"trans_local_var: no datum for local/arg {:?} found",
nid).as_slice());
}
};
debug!("take_local(nid={:?}, v={}, ty={})",
nid, bcx.val_to_string(datum.val), bcx.ty_to_string(datum.ty));
datum
}
_ => {
bcx.sess().unimpl(format!(
"unsupported def type in trans_local_var: {:?}",
def).as_slice());
}
};
fn take_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
table: &NodeMap<Datum<Lvalue>>,
nid: ast::NodeId)
-> Datum<Lvalue> {
let datum = match table.find(&nid) {
Some(&v) => v,
None => {
bcx.sess().bug(format!(
"trans_local_var: no datum for local/arg {:?} found",
nid).as_slice());
}
};
debug!("take_local(nid={:?}, v={}, ty={})",
nid, bcx.val_to_string(datum.val), bcx.ty_to_string(datum.ty));
datum
}
}

View File

@ -3684,9 +3684,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
// DefArg's, particularly those of immediate type, ought to
// considered rvalues.
def::DefStatic(..) |
def::DefBinding(..) |
def::DefUpvar(..) |
def::DefArg(..) |
def::DefLocal(..) => LvalueExpr,
def => {

View File

@ -5027,8 +5027,7 @@ pub fn polytype_for_def(fcx: &FnCtxt,
defn: def::Def)
-> Polytype {
match defn {
def::DefArg(nid, _) | def::DefLocal(nid, _) |
def::DefBinding(nid, _) => {
def::DefLocal(nid, _) => {
let typ = fcx.local_ty(sp, nid);
return no_params(typ);
}
@ -5183,10 +5182,8 @@ pub fn instantiate_path(fcx: &FnCtxt,
// elsewhere. (I hope)
def::DefMod(..) |
def::DefForeignMod(..) |
def::DefArg(..) |
def::DefLocal(..) |
def::DefMethod(..) |
def::DefBinding(..) |
def::DefUse(..) |
def::DefRegion(..) |
def::DefLabel(..) |

View File

@ -119,7 +119,6 @@ and report an error, and it just seems like more mess in the end.)
*/
use middle::def;
use middle::def::{DefArg, DefBinding, DefLocal, DefUpvar};
use middle::freevars;
use middle::mem_categorization as mc;
use middle::ty::{ReScope};
@ -243,11 +242,10 @@ fn region_of_def(fcx: &FnCtxt, def: def::Def) -> ty::Region {
let tcx = fcx.tcx();
match def {
DefLocal(node_id, _) | DefArg(node_id, _) |
DefBinding(node_id, _) => {
def::DefLocal(node_id, _) => {
tcx.region_maps.var_region(node_id)
}
DefUpvar(_, subdef, closure_id, body_id) => {
def::DefUpvar(_, subdef, closure_id, body_id) => {
match ty::ty_closure_store(fcx.node_ty(closure_id)) {
ty::RegionTraitStore(..) => region_of_def(fcx, *subdef),
ty::UniqTraitStore => ReScope(body_id)
@ -1475,7 +1473,6 @@ fn link_region(rcx: &Rcx,
mc::cat_static_item |
mc::cat_copied_upvar(..) |
mc::cat_local(..) |
mc::cat_arg(..) |
mc::cat_upvar(..) |
mc::cat_rvalue(..) => {
// These are all "base cases" with independent lifetimes
@ -1701,7 +1698,6 @@ fn adjust_upvar_borrow_kind_for_mut(rcx: &Rcx,
mc::cat_rvalue(_) |
mc::cat_copied_upvar(_) |
mc::cat_local(_) |
mc::cat_arg(_) |
mc::cat_upvar(..) => {
return;
}
@ -1753,7 +1749,6 @@ fn adjust_upvar_borrow_kind_for_unique(rcx: &Rcx, cmt: mc::cmt) {
mc::cat_rvalue(_) |
mc::cat_copied_upvar(_) |
mc::cat_local(_) |
mc::cat_arg(_) |
mc::cat_upvar(..) => {
return;
}