From a8733162772feec5f498427ea10d869272d164ab Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 22 Jan 2015 16:59:23 -0500 Subject: [PATCH] remove dead code --- src/librustc/middle/cfg/construct.rs | 2 +- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/liveness.rs | 10 +- src/librustc_back/svh.rs | 1 - src/librustc_resolve/lib.rs | 2 +- src/librustc_trans/trans/_match.rs | 25 ----- src/librustc_trans/trans/controlflow.rs | 136 ------------------------ src/librustc_trans/trans/debuginfo.rs | 42 -------- src/librustc_typeck/check/mod.rs | 87 --------------- 9 files changed, 5 insertions(+), 302 deletions(-) diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 3f6c19680e7..0a575a31ead 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -263,7 +263,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ast::ExprForLoop(ref pat, ref head, ref body, _) => { + ast::ExprForLoop(..) => { self.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop"); } diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index b09dac6b1dc..a79e6fac0cc 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -537,7 +537,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { self.tcx().sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ast::ExprForLoop(ref pat, ref head, ref blk, _) => { + ast::ExprForLoop(..) => { self.tcx().sess.span_bug(expr.span, "non-desugared ExprForLoop"); } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index d91816d1c14..982bc41f06a 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -135,8 +135,6 @@ enum LoopKind<'a> { LoopLoop, /// A `while` loop, with the given expression as condition. WhileLoop(&'a Expr), - /// A `for` loop, with the given pattern to bind. - ForLoop(&'a ast::Pat), } #[derive(Copy, PartialEq)] @@ -490,7 +488,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) { ast::ExprWhileLet(..) => { ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ast::ExprForLoop(ref pat, _, _, _) => { + ast::ExprForLoop(..) => { ir.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop"); } ast::ExprBinary(op, _, _) if ast_util::lazy_binop(op.node) => { @@ -1023,7 +1021,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ast::ExprForLoop(ref pat, ref head, ref blk, _) => { + ast::ExprForLoop(..) => { self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop"); } @@ -1361,7 +1359,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let cond_ln = match kind { LoopLoop => ln, - ForLoop(ref pat) => self.define_bindings_in_pat(*pat, ln), WhileLoop(ref cond) => self.propagate_through_expr(&**cond, ln), }; let body_ln = self.with_loop_nodes(expr.id, succ, ln, |this| { @@ -1374,9 +1371,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let new_cond_ln = match kind { LoopLoop => ln, - ForLoop(ref pat) => { - self.define_bindings_in_pat(*pat, ln) - } WhileLoop(ref cond) => { self.propagate_through_expr(&**cond, ln) } diff --git a/src/librustc_back/svh.rs b/src/librustc_back/svh.rs index aefed4b87b4..3d7adc9934f 100644 --- a/src/librustc_back/svh.rs +++ b/src/librustc_back/svh.rs @@ -252,7 +252,6 @@ mod svh_visitor { SawExprStruct, SawExprRepeat, SawExprParen, - SawExprForLoop, } fn saw_expr<'a>(node: &'a Expr_) -> SawExprComponent<'a> { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index fbccc466d57..89d36ef5801 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -68,7 +68,7 @@ use rustc::util::lev_distance::lev_distance; use syntax::ast::{Arm, BindByRef, BindByValue, BindingMode, Block, Crate, CrateNum}; use syntax::ast::{DefId, Expr, ExprAgain, ExprBreak, ExprField}; -use syntax::ast::{ExprClosure, ExprForLoop, ExprLoop, ExprWhile, ExprMethodCall}; +use syntax::ast::{ExprClosure, ExprLoop, ExprWhile, ExprMethodCall}; use syntax::ast::{ExprPath, ExprQPath, ExprStruct, FnDecl}; use syntax::ast::{ForeignItemFn, ForeignItemStatic, Generics}; use syntax::ast::{Ident, ImplItem, Item, ItemConst, ItemEnum, ItemExternCrate}; diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index 8d7eb5816c2..7074a970ba9 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -1537,31 +1537,6 @@ pub fn store_arg<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, } } -/// Generates code for the pattern binding in a `for` loop like -/// `for in { ... }`. -pub fn store_for_loop_binding<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - pat: &ast::Pat, - llvalue: ValueRef, - body_scope: cleanup::ScopeId) - -> Block<'blk, 'tcx> { - let _icx = push_ctxt("match::store_for_loop_binding"); - - if simple_identifier(&*pat).is_some() && - bcx.sess().opts.debuginfo != FullDebugInfo { - // Generate nicer LLVM for the common case of a `for` loop pattern - // like `for x in blahblah { ... }`. - let binding_type = node_id_type(bcx, pat.id); - bcx.fcx.lllocals.borrow_mut().insert(pat.id, - Datum::new(llvalue, - binding_type, - Lvalue)); - return bcx - } - - // General path. Copy out the values that are used in the pattern. - bind_irrefutable_pat(bcx, pat, llvalue, body_scope) -} - fn mk_binding_alloca<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>, p_id: ast::NodeId, ident: &ast::Ident, diff --git a/src/librustc_trans/trans/controlflow.rs b/src/librustc_trans/trans/controlflow.rs index bea8a759971..c4388603145 100644 --- a/src/librustc_trans/trans/controlflow.rs +++ b/src/librustc_trans/trans/controlflow.rs @@ -11,8 +11,6 @@ use llvm::ValueRef; use middle::def; use middle::lang_items::{PanicFnLangItem, PanicBoundsCheckFnLangItem}; -use trans::_match; -use trans::adt; use trans::base::*; use trans::build::*; use trans::callee; @@ -20,17 +18,12 @@ use trans::cleanup::CleanupMethods; use trans::cleanup; use trans::common::*; use trans::consts; -use trans::datum; use trans::debuginfo; use trans::debuginfo::{DebugLoc, ToDebugLoc}; use trans::expr; -use trans::meth; -use trans::type_::Type; use trans; use middle::ty; -use middle::ty::MethodCall; use util::ppaux::Repr; -use util::ppaux; use syntax::ast; use syntax::ast::Ident; @@ -259,135 +252,6 @@ pub fn trans_while<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, return next_bcx_in; } -/// Translates a `for` loop. -pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, - loop_info: NodeIdAndSpan, - pat: &ast::Pat, - head: &ast::Expr, - body: &ast::Block) - -> Block<'blk, 'tcx> -{ - let _icx = push_ctxt("trans_for"); - - // bcx - // | - // loopback_bcx_in <-------+ - // | | - // loopback_bcx_out | - // | | | - // | body_bcx_in | - // cleanup_blk | | - // | body_bcx_out --+ - // next_bcx_in - - // Codegen the head to create the iterator value. - let iterator_datum = - unpack_datum!(bcx, expr::trans_to_lvalue(bcx, head, "for_head")); - let iterator_type = node_id_type(bcx, head.id); - debug!("iterator type is {}, datum type is {}", - ppaux::ty_to_string(bcx.tcx(), iterator_type), - ppaux::ty_to_string(bcx.tcx(), iterator_datum.ty)); - - let lliterator = load_ty(bcx, iterator_datum.val, iterator_datum.ty); - - // Create our basic blocks and set up our loop cleanups. - let next_bcx_in = bcx.fcx.new_id_block("for_exit", loop_info.id); - let loopback_bcx_in = bcx.fcx.new_id_block("for_loopback", head.id); - let body_bcx_in = bcx.fcx.new_id_block("for_body", body.id); - bcx.fcx.push_loop_cleanup_scope(loop_info.id, - [next_bcx_in, loopback_bcx_in]); - Br(bcx, loopback_bcx_in.llbb, DebugLoc::None); - let cleanup_llbb = bcx.fcx.normal_exit_block(loop_info.id, - cleanup::EXIT_BREAK); - - // Set up the method call (to `.next()`). - let method_call = MethodCall::expr(loop_info.id); - let method_type = (*loopback_bcx_in.tcx() - .method_map - .borrow())[method_call] - .ty; - let method_type = monomorphize_type(loopback_bcx_in, method_type); - let method_result_type = - ty::assert_no_late_bound_regions( // LB regions are instantiated in invoked methods - loopback_bcx_in.tcx(), &ty::ty_fn_ret(method_type)).unwrap(); - let option_cleanup_scope = body_bcx_in.fcx.push_custom_cleanup_scope(); - let option_cleanup_scope_id = cleanup::CustomScope(option_cleanup_scope); - - // Compile the method call (to `.next()`). - let mut loopback_bcx_out = loopback_bcx_in; - let option_datum = - unpack_datum!(loopback_bcx_out, - datum::lvalue_scratch_datum(loopback_bcx_out, - method_result_type, - "loop_option", - false, - option_cleanup_scope_id, - (), - |(), bcx, lloption| { - let Result { - bcx, - val: _ - } = callee::trans_call_inner(bcx, - Some(loop_info), - method_type, - |bcx, arg_cleanup_scope| { - meth::trans_method_callee( - bcx, - method_call, - None, - arg_cleanup_scope) - }, - callee::ArgVals(&[lliterator]), - Some(expr::SaveIn(lloption))); - bcx - })); - - // Check the discriminant; if the `None` case, exit the loop. - let option_representation = adt::represent_type(loopback_bcx_out.ccx(), - method_result_type); - let lldiscriminant = adt::trans_get_discr(loopback_bcx_out, - &*option_representation, - option_datum.val, - None); - let i1_type = Type::i1(loopback_bcx_out.ccx()); - let llcondition = Trunc(loopback_bcx_out, lldiscriminant, i1_type); - CondBr(loopback_bcx_out, llcondition, body_bcx_in.llbb, cleanup_llbb, DebugLoc::None); - - // Now we're in the body. Unpack the `Option` value into the programmer- - // supplied pattern. - let llpayload = adt::trans_field_ptr(body_bcx_in, - &*option_representation, - option_datum.val, - 1, - 0); - let binding_cleanup_scope = body_bcx_in.fcx.push_custom_cleanup_scope(); - let binding_cleanup_scope_id = - cleanup::CustomScope(binding_cleanup_scope); - let mut body_bcx_out = - _match::store_for_loop_binding(body_bcx_in, - pat, - llpayload, - binding_cleanup_scope_id); - - debuginfo::create_for_loop_var_metadata(body_bcx_in, pat); - - // Codegen the body. - body_bcx_out = trans_block(body_bcx_out, body, expr::Ignore); - body_bcx_out = - body_bcx_out.fcx - .pop_and_trans_custom_cleanup_scope(body_bcx_out, - binding_cleanup_scope); - body_bcx_out = - body_bcx_out.fcx - .pop_and_trans_custom_cleanup_scope(body_bcx_out, - option_cleanup_scope); - Br(body_bcx_out, loopback_bcx_in.llbb, DebugLoc::None); - - // Codegen cleanups and leave. - next_bcx_in.fcx.pop_loop_cleanup_scope(loop_info.id); - next_bcx_in -} - pub fn trans_loop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, loop_expr: &ast::Expr, body: &ast::Block) diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 7aa0a30b455..4f9c97795e1 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -1053,48 +1053,6 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) { }) } -/// Creates debug information for the given for-loop variable. -/// -/// This function assumes that there's a datum for each pattern component of the -/// loop variable in `bcx.fcx.lllocals`. -/// Adds the created metadata nodes directly to the crate's IR. -pub fn create_for_loop_var_metadata(bcx: Block, pat: &ast::Pat) { - if bcx.unreachable.get() || - fn_should_be_ignored(bcx.fcx) || - bcx.sess().opts.debuginfo != FullDebugInfo { - return; - } - - let def_map = &bcx.tcx().def_map; - let locals = bcx.fcx.lllocals.borrow(); - - pat_util::pat_bindings(def_map, pat, |_, node_id, span, var_ident| { - let datum = match locals.get(&node_id) { - Some(datum) => datum, - None => { - bcx.sess().span_bug(span, - format!("no entry in lllocals table for {}", - node_id).as_slice()); - } - }; - - if unsafe { llvm::LLVMIsAAllocaInst(datum.val) } == ptr::null_mut() { - bcx.sess().span_bug(span, "debuginfo::create_for_loop_var_metadata() - \ - Referenced variable location is not an alloca!"); - } - - let scope_metadata = scope_metadata(bcx.fcx, node_id, span); - - declare_local(bcx, - var_ident.node, - datum.ty, - scope_metadata, - DirectVariable { alloca: datum.val }, - LocalVariable, - span); - }) -} - pub fn get_cleanup_debug_loc_for_ast_node<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, node_id: ast::NodeId, node_span: Span, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 14c976c6ae8..12bf507c057 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -87,7 +87,6 @@ use check::_match::pat_ctxt; use fmt_macros::{Parser, Piece, Position}; use middle::{const_eval, def}; use middle::infer; -use middle::lang_items::IteratorItem; use middle::mem_categorization as mc; use middle::mem_categorization::McResult; use middle::pat_util::{self, pat_id_map}; @@ -2140,92 +2139,6 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, }) } -/// Given the head of a `for` expression, looks up the `next` method in the -/// `Iterator` trait. Panics if the expression does not implement `next`. -/// -/// The return type of this function represents the concrete element type -/// `A` in the type `Iterator` that the method returns. -fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, - iterator_expr: &ast::Expr, - loop_id: ast::NodeId) - -> Ty<'tcx> { - let trait_did = match fcx.tcx().lang_items.require(IteratorItem) { - Ok(trait_did) => trait_did, - Err(ref err_string) => { - span_err!(fcx.tcx().sess, iterator_expr.span, E0233, - "{}", &err_string[]); - return fcx.tcx().types.err - } - }; - - let expr_type = fcx.expr_ty(&*iterator_expr); - let method = method::lookup_in_trait(fcx, - iterator_expr.span, - Some(&*iterator_expr), - token::intern("next"), - trait_did, - expr_type, - None); - - // Regardless of whether the lookup succeeds, check the method arguments - // so that we have *some* type for each argument. - let method_type = match method { - Some(ref method) => method.ty, - None => { - let true_expr_type = fcx.infcx().resolve_type_vars_if_possible(&expr_type); - - if !ty::type_is_error(true_expr_type) { - let ty_string = fcx.infcx().ty_to_string(true_expr_type); - span_err!(fcx.tcx().sess, iterator_expr.span, E0234, - "`for` loop expression has type `{}` which does \ - not implement the `Iterator` trait; \ - maybe try .iter()", ty_string); - } - fcx.tcx().types.err - } - }; - let return_type = check_method_argument_types(fcx, - iterator_expr.span, - method_type, - iterator_expr, - &[], - AutorefArgs::No, - DontTupleArguments, - NoExpectation); - - match method { - Some(method) => { - fcx.inh.method_map.borrow_mut().insert(MethodCall::expr(loop_id), - method); - - // We expect the return type to be `Option` or something like it. - // Grab the first parameter of its type substitution. - let return_type = match return_type { - ty::FnConverging(return_type) => - structurally_resolved_type(fcx, iterator_expr.span, return_type), - ty::FnDiverging => fcx.tcx().types.err - }; - match return_type.sty { - ty::ty_enum(_, ref substs) - if !substs.types.is_empty_in(subst::TypeSpace) => { - *substs.types.get(subst::TypeSpace, 0) - } - ty::ty_err => { - fcx.tcx().types.err - } - _ => { - span_err!(fcx.tcx().sess, iterator_expr.span, E0239, - "`next` method of the `Iterator` \ - trait has an unexpected type `{}`", - fcx.infcx().ty_to_string(return_type)); - fcx.tcx().types.err - } - } - } - None => fcx.tcx().types.err - } -} - fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, method_fn_ty: Ty<'tcx>,