mozilla/rust — pull request #6616 by huonw (2013-05-19 11:44:54+00:00)
Title: rustc: Add inline(maybe) which only writes the AST to crate metadata.

This gives LLVM the data required to inline (i.e. writes the AST to the crate), but doesn't force it to like `#[inline]` (very aggressive for a "hint") or `#[inline(always)]`.

I'm not sure how to test, but given:

```rust
// inline_maybe.rs
#[inline(maybe)]
pub fn foo() -> int { 1 }

// inline_maybe2.rs
extern mod inline_maybe;
use inline_maybe::foo;
fn main() {
if foo() == 2 {
print("hi");
}
}
```

With a pre-`inline(maybe)` rustc the asm for `inline_maybe2.rs` contains:

```asm
callq	_ZN3foo15_8faebfb4af26143_00E@PLT
cmpq	$1, %rax
jne	.LBB0_4
```

With this patch, the `foo` call is inlined and constant-folded away.

With a huge `foo` (that wouldn't be normally inlined even within the same crate), the actual call remains in `inline_maybe2`, i.e. it isn't inlined.