about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-08-13 00:41:22 +0000
committerbors <bors@rust-lang.org>2014-08-13 00:41:22 +0000
commite189122e9a922438f02b639948f75df765cd370e (patch)
tree6909df7e52b3d51c57ed095e1944fc51e732b8c7
parent51c7e20d539eaed6e765612a02fbf2865e08a1bc (diff)
parent0f847ba74da083124f3d5d38d36fc1135737c12c (diff)
downloadrust-e189122e9a922438f02b639948f75df765cd370e.tar.gz
rust-e189122e9a922438f02b639948f75df765cd370e.zip
auto merge of #16452 : epdtry/rust/unreachable-item-ice, r=pcwalton
This code produces an ICE:

```rust
#![crate_type = "rlib"]
fn main() {
    if true { return }
    // remaining code is unreachable
    match () {
        () => { static MAGIC: uint = 0; }
    }
}
```
([playpen](http://is.gd/iwOISB))

The error is "encode_symbol: id not found 18", where 18 is the `NodeId` of the declaration of `MAGIC`.  The problem is that `rustc` tries to emit metadata for `MAGIC`, but some of the information is missing because `MAGIC` never gets translated by `trans_item` - the entire body of the `match` gets skipped because the `match` itself is unreachable.

This branch simplifies the handling of inner items by always processing them using the `trans_item` visitor, instead of sometimes using the visitor and sometimes waiting until `trans_stmt` encounters the item.  This fixes the ICE by making the translation of the item no longer depend on the declaration being reachable code.  This branch also reverts #16059 and #16359, since the new change to item translation fixes the same problems as those but is simpler.
-rw-r--r--src/librustc/middle/trans/base.rs36
-rw-r--r--src/librustc/middle/trans/callee.rs3
-rw-r--r--src/librustc/middle/trans/closure.rs8
-rw-r--r--src/librustc/middle/trans/common.rs9
-rw-r--r--src/librustc/middle/trans/controlflow.rs8
-rw-r--r--src/librustc/middle/trans/foreign.rs11
-rw-r--r--src/librustc/middle/trans/glue.rs2
-rw-r--r--src/librustc/middle/trans/inline.rs2
-rw-r--r--src/librustc/middle/trans/meth.rs8
-rw-r--r--src/librustc/middle/trans/monomorphize.rs10
-rw-r--r--src/librustc/middle/trans/reflect.rs2
11 files changed, 34 insertions, 65 deletions
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs
index 0860f84dbef..35d32d99525 100644
--- a/src/librustc/middle/trans/base.rs
+++ b/src/librustc/middle/trans/base.rs
@@ -1343,8 +1343,7 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
                        output_type: ty::t,
                        param_substs: &'a param_substs,
                        sp: Option<Span>,
-                       block_arena: &'a TypedArena<Block<'a>>,
-                       handle_items: HandleItemsFlag)
+                       block_arena: &'a TypedArena<Block<'a>>)
                        -> FunctionContext<'a> {
     param_substs.validate();
 
@@ -1379,8 +1378,7 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
           block_arena: block_arena,
           ccx: ccx,
           debug_context: debug_context,
-          scopes: RefCell::new(Vec::new()),
-          handle_items: handle_items,
+          scopes: RefCell::new(Vec::new())
     };
 
     if has_env {
@@ -1708,8 +1706,7 @@ pub fn trans_closure(ccx: &CrateContext,
                      abi: Abi,
                      has_env: bool,
                      is_unboxed_closure: IsUnboxedClosureFlag,
-                     maybe_load_env: <'a> |&'a Block<'a>| -> &'a Block<'a>,
-                     handle_items: HandleItemsFlag) {
+                     maybe_load_env: <'a> |&'a Block<'a>| -> &'a Block<'a>) {
     ccx.stats.n_closures.set(ccx.stats.n_closures.get() + 1);
 
     let _icx = push_ctxt("trans_closure");
@@ -1726,8 +1723,7 @@ pub fn trans_closure(ccx: &CrateContext,
                           output_type,
                           param_substs,
                           Some(body.span),
-                          &arena,
-                          handle_items);
+                          &arena);
     let mut bcx = init_function(&fcx, false, output_type);
 
     // cleanup scope for the incoming arguments
@@ -1836,8 +1832,7 @@ pub fn trans_fn(ccx: &CrateContext,
                 llfndecl: ValueRef,
                 param_substs: &param_substs,
                 id: ast::NodeId,
-                attrs: &[ast::Attribute],
-                handle_items: HandleItemsFlag) {
+                attrs: &[ast::Attribute]) {
     let _s = StatRecorder::new(ccx, ccx.tcx.map.path_to_string(id).to_string());
     debug!("trans_fn(param_substs={})", param_substs.repr(ccx.tcx()));
     let _icx = push_ctxt("trans_fn");
@@ -1857,8 +1852,7 @@ pub fn trans_fn(ccx: &CrateContext,
                   abi,
                   false,
                   NotUnboxedClosure,
-                  |bcx| bcx,
-                  handle_items);
+                  |bcx| bcx);
 }
 
 pub fn trans_enum_variant(ccx: &CrateContext,
@@ -1964,7 +1958,7 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
 
     let arena = TypedArena::new();
     let fcx = new_fn_ctxt(ccx, llfndecl, ctor_id, false, result_ty,
-                          param_substs, None, &arena, TranslateItems);
+                          param_substs, None, &arena);
     let bcx = init_function(&fcx, false, result_ty);
 
     assert!(!fcx.needs_ret_allocas);
@@ -2066,8 +2060,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
                                                         llfn,
                                                         &param_substs::empty(),
                                                         item.id,
-                                                        None,
-                                                        TranslateItems);
+                                                        None);
             } else {
                 trans_fn(ccx,
                          &**decl,
@@ -2075,15 +2068,14 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
                          llfn,
                          &param_substs::empty(),
                          item.id,
-                         item.attrs.as_slice(),
-                         TranslateItems);
+                         item.attrs.as_slice());
             }
-        } else {
-            // Be sure to travel more than just one layer deep to catch nested
-            // items in blocks and such.
-            let mut v = TransItemVisitor{ ccx: ccx };
-            v.visit_block(&**body, ());
         }
+
+        // Be sure to travel more than just one layer deep to catch nested
+        // items in blocks and such.
+        let mut v = TransItemVisitor{ ccx: ccx };
+        v.visit_block(&**body, ());
       }
       ast::ItemImpl(ref generics, _, _, ref ms) => {
         meth::trans_impl(ccx, item.ident, ms.as_slice(), generics, item.id);
diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs
index 8e6ff0cdb3e..379b53eebbb 100644
--- a/src/librustc/middle/trans/callee.rs
+++ b/src/librustc/middle/trans/callee.rs
@@ -339,8 +339,7 @@ pub fn trans_unboxing_shim(bcx: &Block,
                           return_type,
                           &empty_param_substs,
                           None,
-                          &block_arena,
-                          TranslateItems);
+                          &block_arena);
     let mut bcx = init_function(&fcx, false, return_type);
 
     // Create the substituted versions of the self type.
diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs
index eeff0609a56..44c52a6739a 100644
--- a/src/librustc/middle/trans/closure.rs
+++ b/src/librustc/middle/trans/closure.rs
@@ -394,8 +394,7 @@ pub fn trans_expr_fn<'a>(
                   ty::ty_fn_abi(fty),
                   true,
                   NotUnboxedClosure,
-                  |bcx| load_environment(bcx, cdata_ty, &freevars, store),
-                  bcx.fcx.handle_items);
+                  |bcx| load_environment(bcx, cdata_ty, &freevars, store));
     fill_fn_pair(bcx, dest_addr, llfn, llbox);
     bcx
 }
@@ -487,8 +486,7 @@ pub fn trans_unboxed_closure<'a>(
                   ty::ty_fn_abi(function_type),
                   true,
                   IsUnboxedClosure,
-                  |bcx| load_unboxed_closure_environment(bcx, freevars_ptr),
-                  bcx.fcx.handle_items);
+                  |bcx| load_unboxed_closure_environment(bcx, freevars_ptr));
 
     // Don't hoist this to the top of the function. It's perfectly legitimate
     // to have a zero-size unboxed closure (in which case dest will be
@@ -575,7 +573,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
     let arena = TypedArena::new();
     let empty_param_substs = param_substs::empty();
     let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, true, f.sig.output,
-                          &empty_param_substs, None, &arena, TranslateItems);
+                          &empty_param_substs, None, &arena);
     let bcx = init_function(&fcx, true, f.sig.output);
 
     let args = create_datums_for_fn_args(&fcx,
diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs
index 5e46550eccb..3b89c73b31d 100644
--- a/src/librustc/middle/trans/common.rs
+++ b/src/librustc/middle/trans/common.rs
@@ -224,12 +224,6 @@ impl<T:Subst+Clone> SubstP for T {
 pub type RvalueDatum = datum::Datum<datum::Rvalue>;
 pub type LvalueDatum = datum::Datum<datum::Lvalue>;
 
-#[deriving(Clone, Eq, PartialEq)]
-pub enum HandleItemsFlag {
-    IgnoreItems,
-    TranslateItems,
-}
-
 // Function context.  Every LLVM function we create will have one of
 // these.
 pub struct FunctionContext<'a> {
@@ -303,9 +297,6 @@ pub struct FunctionContext<'a> {
 
     // Cleanup scopes.
     pub scopes: RefCell<Vec<cleanup::CleanupScope<'a>> >,
-
-    // How to handle items encountered during translation of this function.
-    pub handle_items: HandleItemsFlag,
 }
 
 impl<'a> FunctionContext<'a> {
diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs
index 02a5f715ecb..a481f92db33 100644
--- a/src/librustc/middle/trans/controlflow.rs
+++ b/src/librustc/middle/trans/controlflow.rs
@@ -69,12 +69,8 @@ pub fn trans_stmt<'a>(cx: &'a Block<'a>,
                         debuginfo::create_local_var_metadata(bcx, &**local);
                     }
                 }
-                ast::DeclItem(ref i) => {
-                    match fcx.handle_items {
-                        TranslateItems => trans_item(cx.fcx.ccx, &**i),
-                        IgnoreItems => {}
-                    }
-                }
+                // Inner items are visited by `trans_item`/`trans_meth`.
+                ast::DeclItem(_) => {},
             }
         }
         ast::StmtMac(..) => cx.tcx().sess.bug("unexpanded macro")
diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs
index 4ca2060ca86..88bb88da3f0 100644
--- a/src/librustc/middle/trans/foreign.rs
+++ b/src/librustc/middle/trans/foreign.rs
@@ -577,8 +577,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
                                       llwrapfn: ValueRef,
                                       param_substs: &param_substs,
                                       id: ast::NodeId,
-                                      hash: Option<&str>,
-                                      handle_items: HandleItemsFlag) {
+                                      hash: Option<&str>) {
     let _icx = push_ctxt("foreign::build_foreign_fn");
 
     let fnty = ty::node_id_to_type(ccx.tcx(), id);
@@ -587,8 +586,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
 
     unsafe { // unsafe because we call LLVM operations
         // Build up the Rust function (`foo0` above).
-        let llrustfn = build_rust_fn(ccx, decl, body, param_substs, attrs, id,
-                                     hash, handle_items);
+        let llrustfn = build_rust_fn(ccx, decl, body, param_substs, attrs, id, hash);
 
         // Build up the foreign wrapper (`foo` above).
         return build_wrap_fn(ccx, llrustfn, llwrapfn, &tys, mty);
@@ -600,8 +598,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
                      param_substs: &param_substs,
                      attrs: &[ast::Attribute],
                      id: ast::NodeId,
-                     hash: Option<&str>,
-                     handle_items: HandleItemsFlag)
+                     hash: Option<&str>)
                      -> ValueRef {
         let _icx = push_ctxt("foreign::foreign::build_rust_fn");
         let tcx = ccx.tcx();
@@ -633,7 +630,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
 
         let llfn = base::decl_internal_rust_fn(ccx, t, ps.as_slice());
         base::set_llvm_fn_attrs(attrs, llfn);
-        base::trans_fn(ccx, decl, body, llfn, param_substs, id, [], handle_items);
+        base::trans_fn(ccx, decl, body, llfn, param_substs, id, []);
         llfn
     }
 
diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs
index 1d016f6db26..cc7cb163341 100644
--- a/src/librustc/middle/trans/glue.rs
+++ b/src/librustc/middle/trans/glue.rs
@@ -468,7 +468,7 @@ fn make_generic_glue(ccx: &CrateContext,
     let arena = TypedArena::new();
     let empty_param_substs = param_substs::empty();
     let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, false, ty::mk_nil(),
-                          &empty_param_substs, None, &arena, TranslateItems);
+                          &empty_param_substs, None, &arena);
 
     let bcx = init_function(&fcx, false, ty::mk_nil());
 
diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs
index 877dd647c3b..bf39f3a6aa3 100644
--- a/src/librustc/middle/trans/inline.rs
+++ b/src/librustc/middle/trans/inline.rs
@@ -133,7 +133,7 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
           if unparameterized {
               let llfn = get_item_val(ccx, mth.id);
                 trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), llfn,
-                       &param_substs::empty(), mth.id, [], TranslateItems);
+                       &param_substs::empty(), mth.id, []);
           }
           local_def(mth.id)
         }
diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs
index 7f7b70e075d..3578b25c839 100644
--- a/src/librustc/middle/trans/meth.rs
+++ b/src/librustc/middle/trans/meth.rs
@@ -75,12 +75,10 @@ pub fn trans_impl(ccx: &CrateContext,
                      llfn,
                      &param_substs::empty(),
                      method.id,
-                     [],
-                     TranslateItems);
-        } else {
-            let mut v = TransItemVisitor{ ccx: ccx };
-            visit::walk_method_helper(&mut v, &**method, ());
+                     []);
         }
+        let mut v = TransItemVisitor{ ccx: ccx };
+        visit::walk_method_helper(&mut v, &**method, ());
     }
 }
 
diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs
index 070bd89d289..6d705c7d914 100644
--- a/src/librustc/middle/trans/monomorphize.rs
+++ b/src/librustc/middle/trans/monomorphize.rs
@@ -164,10 +164,9 @@ pub fn monomorphic_fn(ccx: &CrateContext,
                   if abi != abi::Rust {
                       foreign::trans_rust_fn_with_foreign_abi(
                           ccx, &**decl, &**body, [], d, &psubsts, fn_id.node,
-                          Some(hash.as_slice()), IgnoreItems);
+                          Some(hash.as_slice()));
                   } else {
-                      trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, [],
-                               IgnoreItems);
+                      trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, []);
                   }
 
                   d
@@ -201,8 +200,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
         ast_map::NodeMethod(mth) => {
             let d = mk_lldecl(abi::Rust);
             set_llvm_fn_attrs(mth.attrs.as_slice(), d);
-            trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d, &psubsts, mth.id, [],
-                     IgnoreItems);
+            trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d, &psubsts, mth.id, []);
             d
         }
         ast_map::NodeTraitMethod(method) => {
@@ -211,7 +209,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
                     let d = mk_lldecl(abi::Rust);
                     set_llvm_fn_attrs(mth.attrs.as_slice(), d);
                     trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d,
-                             &psubsts, mth.id, [], IgnoreItems);
+                             &psubsts, mth.id, []);
                     d
                 }
                 _ => {
diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs
index e49d483e8d9..9caa9f681aa 100644
--- a/src/librustc/middle/trans/reflect.rs
+++ b/src/librustc/middle/trans/reflect.rs
@@ -312,7 +312,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
                 let empty_param_substs = param_substs::empty();
                 let fcx = new_fn_ctxt(ccx, llfdecl, ast::DUMMY_NODE_ID, false,
                                       ty::mk_u64(), &empty_param_substs,
-                                      None, &arena, TranslateItems);
+                                      None, &arena);
                 let bcx = init_function(&fcx, false, ty::mk_u64());
 
                 // we know the return type of llfdecl is an int here, so