Commit Graph

1852 Commits

Author SHA1 Message Date
Björn Steinbrink
15ea4a8dd8 Generate better code for intrinsics
Currently, our intrinsics are generated as functions that have the
usual setup, which means an alloca, and therefore also a jump, for
those intrinsics that return an immediate value. This is especially bad
for unoptimized builds because it means that an intrinsic like
"contains_managed" that should be just "ret 0" or "ret 1" actually ends
up allocating stack space, doing a jump and a store/load sequence
before it finally returns the value.

To fix that, we need a way to stop the generic function declaration
mechanism from allocating stack space for the return value. This
implicitly also kills the jump, because the block for static allocas
isn't required anymore.

Additionally, trans_intrinsic needs to build the return itself instead
of calling finish_fn, because the latter relies on the availability of
the return value pointer.

With these changes, we get the bare minimum code required for our
intrinsics, which makes them small enough that inlining them makes the
resulting code smaller, so we can mark them as "always inline" to get
better performing unoptimized builds.

Optimized builds also benefit slightly from this change as there's less
code for LLVM to translate and the smaller intrinsics help it to make
better inlining decisions for a few code paths.

Building stage2 librustc gets ~1% faster for the optimized version and 5% for
the unoptimized version.
2013-07-17 17:21:41 +02:00
Björn Steinbrink
3e572511af Remove duplicated code from trans_intrinsics
Most arms of the huge match contain the same code, differing only in
small details like the name of the llvm intrinsic that is to be called.
Thus the duplicated code can be factored out into a few functions that
take some parameters to handle the differences.
2013-07-17 17:18:29 +02:00
bors
93c270c63d auto merge of #7843 : alexcrichton/rust/better-lint-help, r=huonw
Closes #7818
2013-07-17 05:55:42 -07:00
bors
af54f633fd auto merge of #7828 : alexcrichton/rust/lang-opt, r=graydon
Whenever a lang_item is required, some relevant message is displayed, often with
a span of what triggered the usage of the lang item.

Now "hello word" is as small as:

```rust
#[no_std];

extern {
    fn puts(s: *u8);
}

extern "rust-intrinsic" {
    fn transmute<T, U>(t: T) -> U;
}

#[start]
fn main(_: int, _: **u8, _: *u8) -> int {
    unsafe {
        let (ptr, _): (*u8, uint) = transmute("Hello!");
        puts(ptr);
    }
    return 0;
}
```
2013-07-16 23:10:44 -07:00
Alex Crichton
88a1b71305 Make all lang_items optional
Whenever a lang_item is required, some relevant message is displayed, often with
a span of what triggered the usage of the lang item
2013-07-16 21:37:52 -07:00
Alex Crichton
0fd4d5d778 Sort lint attributes to print them in a more sane way
Closes #7818
2013-07-16 21:28:10 -07:00
bors
8a1002fbd9 auto merge of #7827 : jdm/rust/enumlength, r=graydon
Allowing them in type signatures is a significant amount of extra work, unfortunately. This also doesn't apply to static values, which takes a different code path.
2013-07-16 16:19:37 -07:00
bors
ad212ecee4 auto merge of #7822 : huonw/rust/cond-debug, r=graydon
As per @pcwalton's request, `debug!(..)` is only activated when the `debug` cfg is set; that is, for `RUST_LOG=some_module=4 ./some_program` to work, it needs to be compiled with `rustc --cfg debug some_program.rs`. (Although, there is the sneaky `__debug!(..)` macro that is always active, if you *really* need it.)

It functions by making `debug!` expand to `if false { __debug!(..) }` (expanding to an `if` like this is required to make sure `debug!` statements are typechecked and to avoid unused variable warnings), and adjusting trans to skip the pointless branches in `if true ...` and `if false ...`.

The conditional expansion change also required moving the inject-std-macros step into a new pass, and makes it actually insert them at the top of the crate; this means that the cfg stripping traverses over the macros and so filters out the unused ones.

This appears to takes an unoptimised build of `librustc` from 65s to 59s; and the full bootstrap from 18m41s to 18m26s on my computer (with general background use).

`./configure --enable-debug` will enable `debug!` statements in the bootstrap build.
2013-07-16 11:19:20 -07:00
Huon Wilson
4797dd4087 rustc: selectively trans branches for if <literal-bool>.
That is, the `b` branch in `if true { a } else { b }` will not be
trans'd, and that expression will be exactly the same as `a`. This
means that, for example, macros conditionally expanding to `if false
{ .. }` (like debug!) will not waste time in LLVM (or trans).
2013-07-17 03:13:41 +10:00
Huon Wilson
e252277fe9 rustc: handle allocas and LoadRangeAsserts in unreachable blocks correctly.
An alloca in an unreachable block would shortcircuit with Undef, but with type
`Type`, rather than type `*Type` (i.e. a plain value, not a pointer) but it is
expected to return a pointer into the stack, leading to confusion and LLVM
asserts later.

Similarly, attaching the range metadata to a Load in an unreachable block
makes LLVM unhappy, since the Load returns Undef.

Fixes #7344.
2013-07-17 03:13:23 +10:00
Josh Matthews
877bba91d5 Permit C-style enums in vector repeat length expressions (N.B. values only, not type signatures) 2013-07-16 12:05:24 -04:00
Huon Wilson
b48e37e8ee syntax: make a macros-injection pass; conditionally define debug! to a noop based on cfg(debug).
Macros can be conditionally defined because stripping occurs before macro
expansion, but, the built-in macros were only added as part of the actual
expansion process and so couldn't be stripped to have definitions conditional
on cfg flags.

debug! is defined conditionally in terms of the debug config, expanding to
nothing unless the --cfg debug flag is passed (to be precise it expands to
`if false { normal_debug!(...) }` so that they are still type checked, and
to avoid unused variable lints).
2013-07-16 15:05:50 +10:00
Daniel Micay
e118555ce6 remove headers from unique vectors 2013-07-15 23:57:27 -04:00
Alex Crichton
9fd2ac7428 Make TLS keys actually take up space
If the TLS key is 0-sized, then the linux linker is apparently smart enough to
put everything at the same pointer. OSX on the other hand, will reserve some
space for all of them. To get around this, the TLS key now actuall consumes
space to ensure that it gets a unique pointer
2013-07-14 10:15:07 -07:00
Alex Crichton
e3211fa1f1 Purge the last remnants of the old TLS api
Closes #3273
2013-07-14 09:29:12 -07:00
Alex Crichton
242606c793 Clean up various warnings throughout the codebase 2013-07-14 09:29:12 -07:00
Alex Crichton
23fbe936bf Allow non-uppercase-statics by default
I think of this as a stylistic opinion which shouldn't necessarily be enforced
by default on all users of rust, but that's just my opinion.
2013-07-14 09:29:12 -07:00
bors
66e2857253 auto merge of #7781 : dotdash/rust/glue, r=huonw
We used to have concrete types in glue functions, but the way we used
to implement that broke inlining of those functions. To fix that, we
converted all glue to just take an i8* and always casted to that type.

The problem with the old implementation was that we made a wrong
assumption about the glue functions, taking it for granted that they
always take an i8*, because that's the function type expected by the
TyDesc fields. Therefore, we always ended up with some kind of cast.

But actually, we can initially have the glue with concrete types and
only cast the functions to the generic type once we actually emit the
TyDesc data.

That means that for glue calls that can be statically resolved, we don't
need any casts, unless the glue uses a simplified type. In that case we
cast the argument. And for glue calls that are resolved at runtime, we
cast the argument to i8*, because that's what the glue function in the
TyDesc expects.

Since most of out glue calls are static, this saves a lot of bitcasts.
The size of the unoptimized librustc.ll goes down by 240k lines.
2013-07-14 05:55:22 -07:00
bors
247ad4515d auto merge of #7769 : alexcrichton/rust/issue-7732-fix-rusti-again, r=cmr
Turns out this was a more subtle bug than I originally thought. My analysis can be found in #7732, but I also tried to put descriptive info into the comments.

Closes #7732
2013-07-13 23:07:31 -07:00
Alex Crichton
21d7098427 Fix running code via '-Z jit' 2013-07-13 21:25:17 -07:00
Björn Steinbrink
e56b3691c8 Use concrete types in glue functions
We used to have concrete types in glue functions, but the way we used
to implement that broke inlining of those functions. To fix that, we
converted all glue to just take an i8* and always casted to that type.

The problem with the old implementation was that we made a wrong
assumption about the glue functions, taking it for granted that they
always take an i8*, because that's the function type expected by the
TyDesc fields. Therefore, we always ended up with some kind of cast.

But actually, we can initially have the glue with concrete types and
only cast the functions to the generic type once we actually emit the
TyDesc data.

That means that for glue calls that can be statically resolved, we don't
need any casts, unless the glue uses a simplified type. In that case we
cast the argument. And for glue calls that are resolved at runtime, we
cast the argument to i8*, because that's what the glue function in the
TyDesc expects.

Since most of out glue calls are static, this saves a lot of bitcasts.
The size of the unoptimized librustc.ll goes down by 240k lines.
2013-07-13 18:23:08 +02:00
Björn Steinbrink
1d2e1a9ae5 Avoid empty "else" blocks
If an "if" expression has no "else", we don't have to create an LLVM
basic block either.
2013-07-13 13:33:48 +02:00
Björn Steinbrink
5df2bb1bcc Avoid empty "static_allocas" blocks
When there are no allocas, we don't need a block for them.
2013-07-13 13:33:48 +02:00
Björn Steinbrink
dcd5d14e6c Avoid return blocks that have only a single predecessor
Currently, we always create a dedicated "return" basic block, but when
there's only a single predecessor for that block, it can be merged with
that predecessor. We can achieve that merge by only creating the return
block on demand, avoiding its creation when its not required.

Reduces the pre-optimization size of librustc.ll created with --passes ""
by about 90k lines which equals about 4%.
2013-07-13 13:33:48 +02:00
Alex Crichton
48aa18d26a Squirrel away the JIT contexts into TLS when done
This prevents attempting to run deallocated code (which is no longer present
always)
2013-07-12 23:16:50 -07:00
bors
d582eeb1ec auto merge of #7734 : alexcrichton/rust/issue-3395, r=sanxiyn
Also ends up fixing one case in libstd. 

Closes #3395
2013-07-12 21:40:36 -07:00
bors
1ee54a8617 auto merge of #7725 : msullivan/rust/default-methods, r=pcwalton
r?
2013-07-12 17:28:28 -07:00
bors
96453eb5c5 auto merge of #7736 : thestinger/rust/doc, r=thestinger
2b96408 r=sanxiyn

documents conversion, size hints and double-ended iterators and adds
more of the traits to the prelude
2013-07-12 13:34:29 -07:00
Alex Crichton
1ec06e0124 Remove the global 'vec::to_owned' function 2013-07-12 16:13:51 -04:00
bors
96b3163c83 auto merge of #7717 : dotdash/rust/transmute, r=pcwalton
Currently, immediate values are copied into an alloca only to have an
addressable storage so that it can be used with memcpy. Obviously we
can skip the memcpy in this case.
2013-07-12 07:43:38 -07:00
bors
ad708139fe auto merge of #7706 : sanxiyn/rust/qualification-lint, r=pcwalton
Fix #2551.

Lint is off by default because I didn't bother to fix all of std and extra.
2013-07-12 05:46:42 -07:00
bors
d56c9762a3 auto merge of #7705 : sanxiyn/rust/simd-op, r=cmr
Fix #3499.

This is the other half of #5841 that was left out when I revised it to #6214.
2013-07-12 01:49:45 -07:00
bors
07183ea6e7 auto merge of #7677 : alexcrichton/rust/tls-gc, r=pcwalton
cc #6004 and #3273

This is a rewrite of TLS to get towards not requiring `@` when using task local storage. Most of the rewrite is straightforward, although there are two caveats:

1. Changing `local_set` to not require `@` is blocked on #7673
2. The code in `local_pop` is some of the most unsafe code I've written. A second set of eyes should definitely scrutinize it...

The public-facing interface currently hasn't changed, although it will have to change because `local_data::get` cannot return `Option<T>`, nor can it return `Option<&T>` (the lifetime isn't known). This will have to be changed to be given a closure which yield `&T` (or as an Option). I didn't do this part of the api rewrite in this pull request as I figured that it could wait until when `@` is fully removed.

This also doesn't deal with the issue of using something other than functions as keys, but I'm looking into using static slices (as mentioned in the issues).
2013-07-11 19:52:37 -07:00
Alex Crichton
2cd9d7bc88 Expand ctypes warnings to warn about *int/*uint
Also ends up fixing one case in libstd
2013-07-11 19:45:25 -07:00
Michael Sullivan
3fa5203273 Take default methods out from behind the flag. 2013-07-11 15:51:10 -07:00
Michael Sullivan
19446418bc Drop a now unnecessary argument from maybe_instantiate_inline. 2013-07-11 15:51:10 -07:00
Michael Sullivan
186f6faf1e Get cross crate static default methods working. Closes #7569. 2013-07-11 15:51:10 -07:00
Michael Sullivan
1bbb434880 Get static default methods working in the non-cross-crate case. Work on #7569. 2013-07-11 15:51:09 -07:00
Michael Sullivan
2b89b437fb Normalize self types for monomorphization. 2013-07-11 15:51:09 -07:00
Michael Sullivan
82ae2fa93a Clean up Repr impls a bit so we can add generic impls for @ and ~. 2013-07-11 15:51:09 -07:00
Michael Sullivan
38dc832154 Fix another default method ICE in type_use. Closes #7675.
Also reworks a bunch of type_use to make things work for default
static methods soon.
2013-07-11 15:51:09 -07:00
Michael Sullivan
a8e4301a5d Fix the handling of type params on generic static methods. Closes #7571. 2013-07-11 15:51:09 -07:00
Michael Sullivan
052c482bbd Improve the error messages for mismatched numbers of type params. 2013-07-11 15:51:09 -07:00
Niko Matsakis
3b911816ec Silence various warnings 2013-07-11 15:21:29 -04:00
Niko Matsakis
86b6e6e2f5 Add simple control-flow-graph abstraction based on graph, currently unused 2013-07-11 14:37:45 -04:00
Niko Matsakis
a2fbe4d09a Construct the graph only when it is needed to report errors. 2013-07-11 14:37:45 -04:00
Niko Matsakis
e706590e70 Port region inference code to use new graph 2013-07-11 14:37:45 -04:00
Niko Matsakis
7429e7a114 rustc: Add new graph library, based on code from region_infernece 2013-07-11 14:37:45 -04:00
Björn Steinbrink
7e97277289 transmute: Avoid double copy for immediate values
Currently, immediate values are copied into an alloca only to have an
addressable storage so that it can be used with memcpy. Obviously we
can skip the memcpy in this case.
2013-07-11 18:46:05 +02:00
bors
278ed50e0a auto merge of #7455 : nikomatsakis/rust/issue-7336-constrain-closure-lifetimes, r=pnkfelix
Constrain maximum lifetime of stack closures that capture variables to be limited by the innermost repeating scope.

Fixes #7336.

r? whomever.
2013-07-11 09:34:40 -07:00