Skip to content

Commit

Permalink
more consistent handling of inner items
Browse files Browse the repository at this point in the history
  • Loading branch information
spernsteiner committed Aug 12, 2014
1 parent 428d5ac commit 0f847ba
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/librustc/middle/trans/base.rs
Expand Up @@ -2070,12 +2070,12 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
item.id,
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);
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/controlflow.rs
Expand Up @@ -69,7 +69,8 @@ pub fn trans_stmt<'a>(cx: &'a Block<'a>,
debuginfo::create_local_var_metadata(bcx, &**local);
}
}
ast::DeclItem(ref i) => trans_item(cx.fcx.ccx, &**i)
// Inner items are visited by `trans_item`/`trans_meth`.
ast::DeclItem(_) => {},
}
}
ast::StmtMac(..) => cx.tcx().sess.bug("unexpanded macro")
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/trans/meth.rs
Expand Up @@ -76,10 +76,9 @@ pub fn trans_impl(ccx: &CrateContext,
&param_substs::empty(),
method.id,
[]);
} 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, ());
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/run-make/issue-7349/Makefile
@@ -0,0 +1,11 @@
-include ../tools.mk

# Test to make sure that inner functions within a polymorphic outer function
# don't get re-translated when the outer function is monomorphized. The test
# code monomorphizes the outer functions several times, but the magic constants
# used in the inner functions should each appear only once in the generated IR.

all:
$(RUSTC) foo.rs --emit=ir
[ "$$(grep -c 8675309 "$(TMPDIR)/foo.ll")" -eq "1" ]
[ "$$(grep -c 11235813 "$(TMPDIR)/foo.ll")" -eq "1" ]
30 changes: 30 additions & 0 deletions src/test/run-make/issue-7349/foo.rs
@@ -0,0 +1,30 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn outer<T>() {
#[allow(dead_code)]
fn inner() -> uint {
8675309
}
}

extern "C" fn outer_foreign<T>() {
#[allow(dead_code)]
fn inner() -> uint {
11235813
}
}

fn main() {
outer::<int>();
outer::<uint>();
outer_foreign::<int>();
outer_foreign::<uint>();
}

5 comments on commit 0f847ba

@bors
Copy link
Contributor

@bors bors commented on 0f847ba Aug 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 0f847ba Aug 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging epdtry/rust/unreachable-item-ice = 0f847ba into auto

@bors
Copy link
Contributor

@bors bors commented on 0f847ba Aug 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

epdtry/rust/unreachable-item-ice = 0f847ba merged ok, testing candidate = e189122

@bors
Copy link
Contributor

@bors bors commented on 0f847ba Aug 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e189122

Please sign in to comment.