auto merge of #16059 : epdtry/rust/mono-item-dedup, r=alexcrichton

Currently, each time a function is monomorphized, all items within that function are translated.  This is unnecessary work because the inner items already get translated when the function declaration is visited by `trans_item`.  This patch adds a flag to the `FunctionContext` to prevent translation of items during monomorphization.
This commit is contained in:
bors 2014-07-30 20:51:22 +00:00
commit 7c28dd080c
13 changed files with 81 additions and 21 deletions

View file

@ -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 function several times, but the magic constant
# `8675309` used in the inner function should appear only once in the generated
# IR.
all:
$(RUSTC) foo.rs --emit=ir
[ "$$(grep -c 8675309 "$(TMPDIR)/foo.ll")" -eq "1" ]

View file

@ -0,0 +1,21 @@
// 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
}
}
fn main() {
outer::<int>();
outer::<uint>();
}