Commit Graph

2009 Commits

Author SHA1 Message Date
Patrick Walton
b4e674f6e6 librustc: Add a lint mode for unnecessary copy and remove a bunch of them. 2013-07-17 14:56:42 -07:00
bors
060de1016b auto merge of #7844 : huonw/rust/no-implicit-prelude, r=alexcrichton
It disables the insertion of `use std::prelude::*;` into the top of
all the modules below the item on which it is placed (including that
item itself).

(Similar to GHC's `-XNoImplicitPrelude`.)
2013-07-17 11:28:46 -07:00
Daniel Micay
8d561587b2 stop initializing ref_count for stack closures
the only part of the header ~fn and &fn should be touching right now is
the tydesc
2013-07-17 13:30:32 -04:00
bors
9c1e530bde auto merge of #7826 : michaelwoerister/rust/end_of_spanned, r=cmr
This is the first of a series of refactorings to get rid of the `codemap::spanned<T>` struct (see this thread for more information: https://mail.mozilla.org/pipermail/rust-dev/2013-July/004798.html).

The changes in this PR should not change any semantics, just rename `ast::blk_` to `ast::blk` and add a span field to it. 95% of the changes were of the form `block.node.id` -> `block.id`. Only some transformations in `libsyntax::fold` where not entirely trivial.
2013-07-17 09:49:43 -07:00
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
Niko Matsakis
81c576cd5b Issue #7444 - Borrowck permits moved values to be captured 2013-07-17 07:19:43 -04:00
Michael Woerister
0cc70743d2 Made ast::blk not use spanned<T> anymore. 2013-07-17 08:21:46 +02: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
Huon Wilson
040e470f47 rustc: implement a #[no_implicit_prelude] attribute.
It disables the insertion of `use std::prelude::*;` into the top of
all the modules below the item on which it is placed (including that
item itself).
2013-07-17 15:01:02 +10: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
Alex Crichton
f9bf69d253 Remove all external requirements of @ from TLS
Closes #6004
2013-07-11 00:37:13 -07:00
Brendan Cully
990dc435aa unused variable 2013-07-10 22:23:09 -07:00
Brendan Cully
202fcb29bd unnecessarily mutable variables 2013-07-10 22:12:30 -07:00
Brendan Cully
e6e4f52bcf remove unused imports 2013-07-10 22:08:50 -07:00
bors
e7040e8a24 auto merge of #7698 : nikomatsakis/rust/issue-2951-type-parameter-names, r=cmr
Fixes #2951
2013-07-10 14:37:39 -07:00
Niko Matsakis
4412df20ae Add an identifier to TypeParameterDefs and use it to pretty print type parameters 2013-07-10 14:42:53 -04:00
Seo Sanghyeon
2bc06b40ba Implement SIMD arithmetics 2013-07-10 23:35:59 +09:00
Seo Sanghyeon
f81986031c Add a lint to detect unnecessarily qualified names 2013-07-10 19:09:03 +09:00
Alex Crichton
cb5b9a477c Rename local_data methods/types for less keystrokes 2013-07-09 17:39:49 -07:00
bors
137d1fb210 auto merge of #7657 : thestinger/rust/rollup, r=thestinger
d3be8ab r=brson
05eb3cf r=thestinger
c80f4e1 r=huonw
8c27af1 r=huonw
0eee0b6 r=cmr
ea2756a r=thestinger
2013-07-09 15:13:40 -07:00
Alex Crichton
31114acdd7 Require extern "Rust" fn main() exactly 2013-07-09 16:56:16 -04:00
Daniel Micay
a4af0960bd remove the unused exchange_malloc align parameter
`malloc` already returns memory correctly aligned for every possible
type in standard C, and that's enough for all types in Rust too
2013-07-09 16:35:56 -04:00
bors
e388a80c23 auto merge of #7117 : jensnockert/rust/freestanding, r=cmr
The free-standing functions in f32, f64, i8, i16, i32, i64, u8, u16,
u32, u64, float, int, and uint are replaced with generic functions in
num instead.

This means that instead of having to know everywhere what the type is, like

~~~
f64::sin(x)
~~~

You can simply write code that uses the type-generic versions in num instead, this works for all types that implement the corresponding trait in num.

~~~
num::sin(x)
~~~

Note 1: If you were previously using any of those functions, just replace them
with the corresponding function with the same name in num.

Note 2: If you were using a function that corresponds to an operator, use the
operator instead.

Note 3: This is just https://github.com/mozilla/rust/pull/7090 reopened against master.
2013-07-09 13:34:50 -07:00
Niko Matsakis
3b8c5a1a37 Constrain maximum lifetime of stack closures that capture variables to
be limited by the innermost repeating scope.

Fixes #7336.
2013-07-09 10:38:26 -04:00
bors
a48ca3290d auto merge of #7262 : nikomatsakis/rust/ref-bindings-in-irrefut-patterns, r=catamorphism
Correct treatment of irrefutable patterns. The old code was wrong in many, many ways. `ref` bindings didn't work, it sometimes copied when it should have moved, the borrow checker didn't even look at such patterns at all, we weren't consistent about preventing values with destructors from being pulled apart, etc.

Fixes #3224.
Fixes #3225.
Fixes #3255.
Fixes #6225.
Fixes #6386.

r? @catamorphism
2013-07-08 18:49:46 -07:00
Niko Matsakis
0c6d02f391 Correct merge errors 2013-07-08 13:55:11 -04:00
Niko Matsakis
979d3a54f9 Correct merge failures 2013-07-08 13:55:11 -04:00
Niko Matsakis
ce602c66b8 Add llvm instrumentation 2013-07-08 13:55:11 -04:00
Niko Matsakis
0e81072ded Move stats into an @mut stats 2013-07-08 13:55:11 -04:00
Niko Matsakis
541c45b0b7 Miscellaneous fixes and cleanup 2013-07-08 13:55:10 -04:00
Niko Matsakis
729b07f83c Modify borrow checker to visit irrefutable patterns that appear in
let and function arguments; modify type checker to store type
information for all patterns and handles some missing cases.
2013-07-08 13:55:10 -04:00
Niko Matsakis
2d3262ca7b Update trans to use type to decide when to move, not the moves table (simpler
for cases where it's hard to decide what id to use for the lookup); modify
irrefutable bindings code to move or copy depending on the type, rather than
threading through a flag. Also updates how local variables and arguments are
registered. These changes were hard to isolate.
2013-07-08 13:55:10 -04:00
Niko Matsakis
41efcdf299 Make all allocas named so we can see where they originate
in the generated LLVM code.
2013-07-08 13:55:10 -04:00
Brian Anderson
b0a9d8193f Bump version numbers to 0.8-pre 2013-07-08 10:25:45 -07:00
Jens Nockert
1aae28a57d Replaces the free-standing functions in f32, &c.
The free-standing functions in f32, f64, i8, i16, i32, i64, u8, u16,
u32, u64, float, int, and uint are replaced with generic functions in
num instead.

If you were previously using any of those functions, just replace them
with the corresponding function with the same name in num.

Note: If you were using a function that corresponds to an operator, use
the operator instead.
2013-07-08 18:05:17 +02:00
Björn Steinbrink
00ba8b3ac0 Improve handling of immediate return values
We currently still handle immediate return values a lot like
non-immediate ones. We provide a slot for them and store them into
memory, often just to immediately load them again. To improve this
situation, trans_call_inner has to return a Result which contains the
immediate return value.

Also, it also needs to accept "No destination" in addition to just
SaveIn and Ignore. Since "No destination" isn't something that fits
well into the Dest type, I've chosen to simply use Option<Dest>
instead, paired with an assertion that checks that "None" is only
allowed for immediate return values.
2013-07-08 13:34:13 +02:00
Björn Steinbrink
4a485f8cec Avoid unused allocas for immediate return values
There's no need to allocate a return slot for anykind of immediate
return value, not just not for nils. Also, when the return value is
ignored, we only have to copy it to a temporary alloca if it's actually
required to call drop_ty on it.
2013-07-08 13:17:46 +02:00
bors
48ad726f2a auto merge of #7605 : thestinger/rust/vec, r=Aatch
This is work continued from the now landed #7495 and #7521 pulls.

Removing the headers from unique vectors is another project, so I've separated the allocator.
2013-07-08 02:52:56 -07:00
Daniel Micay
90f1db10fa remove headers from exchange allocations 2013-07-08 04:54:41 -04:00
Daniel Micay
44770ae3a8 Merge pull request #7595 from thestinger/iterator
remove some method resolve workarounds
2013-07-08 01:42:07 -07:00
Daniel Micay
0aedecf96b add a temporary vector_exchange_malloc lang item 2013-07-08 03:41:21 -04:00
Alex Crichton
a02e37c397 Fix a warning when generating tests 2013-07-07 19:03:57 -07:00
Daniel Micay
641aec7407 remove some method resolve workarounds 2013-07-07 19:51:13 -04:00
bors
28643d4135 auto merge of #7456 : graydon/rust/better-trans-stats, r=cmr
This way when you compile with -Z trans-stats you'll get a per-function cost breakdown, sorted with the most expensive functions first. Should help highlight pathological code.
2013-07-07 12:53:06 -07:00
bors
52abd1cc32 auto merge of #7636 : dotdash/rust/scope_cleanup, r=graydon
Currently, scopes are tied to LLVM basic blocks. For each scope, there
are two new basic blocks, which means two extra jumps in the unoptimized
IR. These blocks aren't actually required, but only used to act as the
boundary for cleanups.

By keeping track of the current scope within a single basic block, we
can avoid those extra blocks and jumps, shrinking the pre-optimization
IR quite considerably. For example, the IR for trans_intrinsic goes
from ~22k lines to ~16k lines, almost 30% less.

The impact on the build times of optimized builds is rather small (about
1%), but unoptimized builds are about 11% faster. The testsuite for
unoptimized builds runs between 15% (CPU time) and 7.5% (wallclock time on
my i7) faster.

Also, in some situations this helps LLVM to generate better code by
inlining functions that it previously considered to be too large.
Likely because of the pointless blocks/jumps that were still present at
the time the inlining pass runs.

Refs #7462
2013-07-07 11:16:59 -07:00
Björn Steinbrink
e41e435851 Implement scopes independent of LLVM basic blocks
Currently, scopes are tied to LLVM basic blocks. For each scope, there
are two new basic blocks, which means two extra jumps in the unoptimized
IR. These blocks aren't actually required, but only used to act as the
boundary for cleanups.

By keeping track of the current scope within a single basic block, we
can avoid those extra blocks and jumps, shrinking the pre-optimization
IR quite considerably. For example, the IR for trans_intrinsic goes
from ~22k lines to ~16k lines, almost 30% less.

The impact on the build times of optimized builds is rather small (about
1%), but unoptimized builds are about 11% faster. The testsuite for
unoptimized builds runs between 15% (CPU time) and 7.5% (wallclock time on
my i7) faster.

Also, in some situations this helps LLVM to generate better code by
inlining functions that it previously considered to be too large.
Likely because of the pointless blocks/jumps that were still present at
the time the inlining pass runs.

Refs #7462
2013-07-07 14:53:57 +02:00
James Miller
280e4245c0 Fix merge-fallout-typo 2013-07-07 23:05:03 +12:00
James Miller
7ce68dc9e1 Clean up warnings 2013-07-07 22:51:10 +12:00
James Miller
47eca2113c De-share ast::Ty 2013-07-07 22:51:10 +12:00
James Miller
46a1f54666 De-manage OptVec<TyParamBounds> 2013-07-07 22:51:10 +12:00
James Miller
97c5a44d3e De-share trait_ref
Also, makes the pretty-printer use & instead of @ as much as possible,
which will help with later changes, though in the interim has produced
some... interesting constructs.
2013-07-07 22:51:09 +12:00
James Miller
62c83bb17b De-manage Lifetime 2013-07-07 22:51:09 +12:00
James Miller
cd1b6c8979 De-managed ast::Path 2013-07-07 22:51:09 +12:00
James Miller
a69eb95233 Stop allocating view_items with @ 2013-07-07 22:51:09 +12:00
bors
88487d8274 auto merge of #7557 : michaelwoerister/rust/enum_structs, r=pcwalton
After getting an ICE trying to use the `Repr` enum from middle::trans::adt (see issue #7527), I tried to implement the missing case for struct-like enum variants in `middle::ty::enum_variants()`. It seems to work now (and passes make check) but there are still some uncertainties that bother me:
+ I'm not sure I did everything, right. Especially getting the variant constructor function from the variant node id is just copied from the tuple-variant case. Someone with more experience in the code base should be able to see rather quickly whether this OK so.
+ It is kind of strange that I could not reproduce the ICE with a smaller test case. The unimplemented code path never seems to be hit in most cases, even when using the exact same `Repr` enum, just with `ty::t` replaced by an opaque pointer. Also, within the `adt` module, `Repr` and matching on it is used multiple times, again without running into problems. Can anyone explain why this is the case? That would be much appreciated. 

Apart from that, I hope this PR is useful.
2013-07-06 23:59:05 -07:00
bors
d243e0047d auto merge of #7572 : Dretch/rust/missing-trait-message-followup, r=pcwalton
This a followup to #7510. @catamorphism requested a test - so I have created one, but in doing so I noticed some inconsistency in the error messages resulting from referencing nonexistent traits, so I changed the messages to be more consistent.
2013-07-06 20:32:09 -07:00
bors
a9f178c148 auto merge of #7570 : kballard/rust/iterator-size-hint, r=thestinger
Change the signature of Iterator.size_hint() to always have a lower bound.

Implement .size_hint() on all remaining iterators (if it differs from the default).
2013-07-06 14:59:09 -07:00
bors
e9897cd08a auto merge of #7598 : sanxiyn/rust/rollup-1, r=sanxiyn
c9b9462 r=z0w0
2e65782 r=cmr
2045889 r=thestinger
30fca57 r=huonw
2013-07-06 06:50:16 -07:00
bors
58eb70a5e2 auto merge of #7554 : jld/rust/rm-ssoe, r=catamorphism 2013-07-05 04:28:56 -07:00
Kevin Ballard
dc9b3ff1b3 Change signature of Iterator.size_hint
Remove the Option wrapper around the lower bound. None is semantically
the same as Size(0), so there's no point in having a distinction.
2013-07-05 01:56:48 -07:00
Seo Sanghyeon
2e65782c17 Do not rely on newtype enum dereference 2013-07-05 13:03:04 +09:00
Seo Sanghyeon
c9b9462e8f Remove visit_struct_method 2013-07-05 13:02:43 +09:00
bors
b055a10662 auto merge of #7545 : msullivan/rust/default-methods, r=catamorphism
r?
2013-07-04 13:49:53 -07:00
bors
e07e9bbf36 auto merge of #7543 : sanxiyn/rust/newtype-immediates, r=catamorphism
Fix #6612. Rebase of #6725. Fixed an additional bug and added a test.
2013-07-03 23:31:56 -07:00
Graydon Hoare
f80d6dc4c1 rustc: improve -Z trans-stats to report per-fn LLVM instruction counts and translation timing 2013-07-03 18:06:36 -07:00
Gareth Smith
908a22b626 Address @catamorphism's error message grammar nit. 2013-07-03 23:43:03 +01:00
bors
648c5e9c92 auto merge of #7534 : bblum/rust/soundness-messages, r=catamorphism 2013-07-03 15:25:55 -07:00
Gareth Smith
656c8f9143 Make the error messages that result from referencing
nonexistent traits consistent, and add a test.
2013-07-03 22:16:08 +01:00
Michael Sullivan
7238d5a141 Make privacy checking on default methods for cross crate structs not fail. Closes #7481.
It is unclear to me that the way method call privacy checking is done
makes any sense, though. It is only performed if the type is a
struct...
2013-07-03 09:59:45 -07:00
Michael Sullivan
419a14772a Fix make_mono_id to take into account self types. Closes #7536. 2013-07-03 09:59:45 -07:00
bors
0c6fc46c03 auto merge of #7566 : huonw/rust/vec-kill, r=cmr
The last remaining internal iterator in `vec` is `each_permutation`.
2013-07-03 08:16:54 -07:00
Huon Wilson
cdea73cf5b Convert vec::{as_imm_buf, as_mut_buf} to methods. 2013-07-04 00:46:50 +10:00
Huon Wilson
f19fb2459f Remove standalone comparison functions in vec, make the trait impls better. 2013-07-04 00:46:50 +10:00
Huon Wilson
9207802589 Remove vec::reversed, replaced by iterators. 2013-07-04 00:46:50 +10:00
Huon Wilson
de0d696561 Remove vec::{filter, filtered, filter_map, filter_mapped}, replaced by iterators. 2013-07-04 00:46:49 +10:00
Huon Wilson
eee6775642 Implement consuming iterators for ~[], remove vec::{consume, consume_reverse, map_consume}. 2013-07-04 00:46:49 +10:00
bors
1cee9d4c38 auto merge of #7531 : sankha93/rust/master, r=bblum
This pull request fixes #7118.
2013-07-03 06:34:56 -07:00
bors
55f155521d auto merge of #7523 : huonw/rust/uppercase-statics-lint, r=cmr
Adds a lint for `static some_lowercase_name: uint = 1;`. Warning by default since it causes confusion, e.g. `static a: uint = 1; ... let a = 2;` => `error: only refutable patterns allowed here`.
2013-07-03 04:31:50 -07:00
bors
ea31b9cca1 auto merge of #7474 : Seldaek/rust/clean-iter, r=thestinger
I think it's WIP - but I wanted to ask for feedback (/cc @thestinger)

I had to move the impl of FromIter for vec into extra::iter because I don't think std can depend on extra, but that's a bit messed up. Similarly some FromIter uses are gone now, not sure if this is fixable or if I made a complete mess here..
2013-07-03 01:07:55 -07:00
bors
025dc6e64e auto merge of #7510 : Dretch/rust/missing-trait-message, r=catamorphism 2013-07-02 22:40:56 -07:00
Michael Woerister
866a5b1c78 Added support for struct-like enum variants in middle::ty::enum_variants(). 2013-07-02 23:35:36 +02:00
Jed Davis
2f27d43166 GC static_size_of_enum, which was unused 2013-07-02 09:27:11 -07:00
Niko Matsakis
ef5c439fb0 Correct merge errors, broken tests 2013-07-01 20:43:55 -04:00
Niko Matsakis
4a0469e3d7 Add copyright notice and kill broken test 2013-07-01 20:43:55 -04:00
Niko Matsakis
e416c9fa17 Adjust documentation to describe how closures and closure bounds
affect things.
2013-07-01 20:43:54 -04:00
Niko Matsakis
d7522fec15 Move existing docs into doc.rs 2013-07-01 20:43:54 -04:00
Niko Matsakis
9d48a7d550 convert region_inference into a module, so I can attach docs 2013-07-01 20:43:54 -04:00
Niko Matsakis
79ea26630d move docs into doc.rs 2013-07-01 20:43:54 -04:00
Niko Matsakis
42344af713 Correct handling of if/match, and make explicit computation of
common supertypes.

This was breaking with the change to regions because of the
(now incorrect) assumpton that our inference code makes,
which is that if a <: b succeeds, there is no need to compute
the LUB/GLB.
2013-07-01 20:43:54 -04:00
Niko Matsakis
9e6d5e152e Defer reasoning about region relationships until after regionck.
This patch makes error handling for region inference failures more
uniform by not reporting *any* region errors until the reigon inference
step. This requires threading through more information about what
caused a region constraint, so that we can still give informative
error messages.

I have only taken partial advantage of this information: when region
inference fails, we still report the same error we always did, despite
the fact that we now know precisely what caused the various constriants
and what the region variable represents, which we did not know before.

This change is required not only to improve error messages but
because the region hierarchy is not in fact fully known until regionck,
because it is not clear where closure bodies fit in (our current
treatment is unsound). Moreover, the relationships between free variables
cannot be fully determined until type inference is otherwise complete.

cc #3238.
2013-07-01 20:43:54 -04:00
Ben Blum
313dd37acb Better error messages in report_use_of_moved_value; close #7286 2013-07-01 15:48:49 -04:00
Sankha Narayan Guria
af30fe25a5 Improve the attempted dynamic environment-capture error message 2013-07-02 01:05:57 +05:30
bors
e482856d76 auto merge of #7409 : alexcrichton/rust/threadsafe, r=cmr
@catamorphism, this re-enables threadsafe rustpkg tests, @brson this will fail unless the bots have LLVM rebuilt, so this is a good indicator of whether that happened or not.
2013-07-01 11:29:24 -07:00
Seo Sanghyeon
8aa26ad454 Fix dereference of temporary immediate newtype structs 2013-07-02 01:08:51 +09:00
Alex Crichton
5183a6cc6c Turn on using LLVM threadsafely 2013-07-01 08:30:05 -07:00
bors
b44953b8a3 auto merge of #7488 : yichoi/rust/sanitize_utf8, r=huonw
back:🔗:sanitize support escape_utf8
fix #7486
2013-07-01 08:03:15 -07:00
bors
0bd67f6891 auto merge of #7443 : yjh0502/rust/fix_field_dup, r=huonw
Check if there is duplicated field names in struct.
2013-07-01 04:37:59 -07:00
bors
d324014c6c auto merge of #7521 : thestinger/rust/vec, r=Aatch
continued from #7495
2013-07-01 02:26:46 -07:00
Huon Wilson
c437a16c5d rustc: add a lint to enforce uppercase statics. 2013-07-01 17:52:57 +10:00
Huon Wilson
da4384583b lint: make the non_camel_case_types lint work with scripts without a upper/lowercase distinction. 2013-07-01 17:46:57 +10:00
Young-il Choi
567cf30450 librustc: apply changes of char::escape_unicode 2013-07-01 16:11:32 +09:00
Young-il Choi
d387e78712 librustc: back:🔗:sanitize support esacpe_utf8 2013-07-01 16:10:10 +09:00
bors
07feeb95c5 auto merge of #7487 : huonw/rust/vec-kill, r=cmr
Continuation of #7430.

I haven't removed the `map` method, since the replacement `v.iter().transform(f).collect::<~[SomeType]>()` is a little ridiculous at the moment.
2013-06-30 21:14:13 -07:00
Seo Sanghyeon
fd19289108 Classify newtype structs S(T) as immediates if T is an immediate 2013-07-01 13:02:14 +09:00
Daniel Micay
5b40f2ae5b pass exchange_malloc an alignment, not a tydesc 2013-06-30 23:30:40 -04:00
bors
1c48aac9aa auto merge of #7517 : brson/rust/0.7, r=brson 2013-06-30 17:34:58 -07:00
Jordi Boggiano
3fe05a987c Move most iter functionality to extra, fixes #7343 2013-07-01 01:50:40 +02:00
Jordi Boggiano
0fc99f1997 Add an EnumSetIterator and EnumSet::iter 2013-07-01 01:50:27 +02:00
Brian Anderson
a766a955a9 Bump version from 0.7-pre to 0.7 2013-06-30 16:36:48 -07:00
bors
040ac2a932 auto merge of #7495 : thestinger/rust/exchange, r=cmr
With these changes, exchange allocator headers are never initialized, read or written to. Removing the header will now just involve updating the code in trans using an offset to only do it if the type contained is managed.

The only thing blocking removing the initialization of the last field in the header was ~fn since it uses it to store the dynamic size/types due to captures. I temporarily switched it to a `closure_exchange_alloc` lang item (it uses the same `exchange_free`) and #7496 is filed about removing that.

Since the `exchange_free` call is now inlined all over the codebase, I don't think we should have an assert for null. It doesn't currently ever happen, but it would be fine if we started generating code that did do it. The `exchange_free` function also had a comment declaring that it must not fail, but a regular assert would cause a failure. I also removed the atomic counter because valgrind can already find these leaks, and we have valgrind bots now.

Note that exchange free does not currently print an error an out-of-memory when it aborts, because our `io` code may allocate. We could probably get away with a `#[rust_stack]` call to a `stdio` function but it would be better to make a write system call.
2013-06-30 15:02:05 -07:00
gareth
31004835e2 When an impl references an unknown trait, mention what
the trait is called in the error message.
2013-06-30 21:43:53 +01:00
Daniel Micay
4a29d6eb3f add a closure_exchange_malloc lang item
this makes the exchange allocation header completely unused, and leaves
it uninitialized
2013-06-30 16:24:47 -04:00
Daniel Micay
45e2582e09 stop copying the tydesc in unique box take glue
the only user of the tydesc is ~fn, and it doesn't use this glue code
2013-06-30 16:22:58 -04:00
Huon Wilson
c0a20d2929 Remove vec::{map, mapi, zip_map} and the methods, except for .map, since this
is very common, and the replacement (.iter().transform().collect()) is very
ugly.
2013-06-30 21:59:44 +10:00
Huon Wilson
2eea642c30 Convert vec::dedup to a method. 2013-06-30 21:17:09 +10:00
Huon Wilson
a890c2cbf1 Convert vec::{rposition, rposition_elem, position_elem, contains} to methods. 2013-06-30 21:15:24 +10:00
Huon Wilson
5d46bcc0e4 Remove vec::{rfind, rfind_between, find_between}, replaced by slices and iterator adapators. 2013-06-30 21:06:47 +10:00
bors
6fcd8bf567 auto merge of #7468 : cmr/rust/great_renaming, r=pcwalton 2013-06-30 01:19:38 -07:00
Daniel Micay
b91416214e add a contains_managed intrinsic 2013-06-30 03:45:39 -04:00
bors
3017343232 auto merge of #7457 : Blei/rust/fix-ffi-floats, r=cmr
Also contains a fix to help ctag pick up macro definitions.
2013-06-29 18:40:33 -07:00
jihyun
7bcde87d1b Fixes #7377 2013-06-30 09:41:21 +09:00
bors
df39932090 auto merge of #7452 : dotdash/rust/self_indirection, r=cmr
Currently we pass all "self" arguments by reference, for the pointer
variants this means that we end up with double indirection which causes
a unnecessary performance hit.

The fix itself is pretty straight-forward and just means that "self"
needs to be handled like any other argument, except for by-value "self"
which still needs to be passed by reference. This is because
non-pointer types can't just be stuffed into the environment slot which
is used to pass "self".

What made things tricky is that there was also a bug in the typechecker
where the method map entries are created. For type impls, that stored
the base type instead of the actual self-type in the method map, e.g.
Foo instead of &Foo for &self. That worked with pass-by-reference, but
fails with pass-by-value which needs the real type.

Code that makes use of methods seems to be about 10% faster with this
change. Also, build times are reduced by about 4%.

Fixes #4355, #4402, #5280, #4406 and #7285
2013-06-29 16:46:32 -07:00
Björn Steinbrink
765a2901d5 Avoid double indirection for the "self" arg in methods
Currently we pass all "self" arguments by reference, for the pointer
variants this means that we end up with double indirection which causes
a unnecessary performance hit.

The fix itself is pretty straight-forward and just means that "self"
needs to be handled like any other argument, except for by-value "self"
which still needs to be passed by reference. This is because
non-pointer types can't just be stuffed into the environment slot which
is used to pass "self".

What made things tricky is that there was also a bug in the typechecker
where the method map entries are created. For type impls, that stored
the base type instead of the actual self-type in the method map, e.g.
Foo instead of &Foo for &self. That worked with pass-by-reference, but
fails with pass-by-value which needs the real type.

Code that makes use of methods seems to be about 10% faster with this
change. Also, build times are reduced by about 4%.

Fixes #4355, #4402, #5280, #4406 and #7285
2013-06-29 19:27:40 +02:00
Björn Steinbrink
ba922a4027 Fix handling of temp cleanups for the "self" argument
The code that tried to revoke the cleanup for the self argument tried
to use "llself" to do so, but the cleanup might actually be registered
with a different ValueRef due to e.g. casting. Currently, this is
worked around by early revocation of the cleanup for self in
trans_self_arg.

To handle this correctly, we have to put the ValueRef for the cleanup
into the MethodData, so trans_call_inner can use it to revoke the
cleanup when it's actually supposed to.
2013-06-29 18:02:21 +02:00
Alex Crichton
3bad7129eb Remove mutability from unique boxes in the AST 2013-06-29 08:36:25 -07:00
Alex Crichton
b29c368674 Removing a lot of usage of '&const' 2013-06-29 08:35:48 -07:00
Corey Richardson
71b1c6ab60 Warning cleanup 2013-06-29 11:20:04 -04:00
Corey Richardson
95d22a3c81 Fix merge fallout 2013-06-29 11:20:04 -04:00
Corey Richardson
1662bd371c Great renaming: propagate throughout the rest of the codebase 2013-06-29 11:20:02 -04:00
Björn Steinbrink
2a40c5db46 Avoid extra casts for "self" arguments
"self" is always passed as an opaque box, so there's no point in using
the concrete self type when translating the argument. All it does it
causing the value to be casted back to an opaque box right away.
2013-06-29 17:08:20 +02:00
Björn Steinbrink
08a5278bb5 Add missing argument to a debug! call in trans_arg_expr 2013-06-29 15:59:33 +02:00
bors
132cfcdd88 auto merge of #7363 : bblum/rust/soundness, r=nikomatsakis
The commit f9a5453 is meant to be a temporary hold-over. Whether or not there is added a way for the compiler to "implicitly borrow" stack closures in this way, there should be a codegen optimization that prevents having to traverse possibly-very-many function pointers to find the function you ultimately wanted to call. I tried to separate out the changes so this particular commit could be straight-up reverted if auto-borrowing happens in the future.

r? @nikomatsakis
2013-06-29 04:22:53 -07:00
bors
c80e3bac3e auto merge of #7244 : bblum/rust/once, r=nikomatsakis
@graydon suggested that once closures not be part of the language for 1.0, but that they might be hidden behind a -Z compile flag as an "experimental feature" in case people decide they need them.

Regardless of whether ```-Z once-fns``` is set, this PR will parse the ```once``` keyword and will prevent closures labelled with it from being called more than once. It will also permit moving out of captured vars in heap closures, just to let the runtime writers stop using ```Cell``` sooner. Setting ```-Z once-fns``` only toggles whether the move-out-from-capture privilege is also given for stack closures.

r? @nikomatsakis
2013-06-29 02:34:43 -07:00
Ben Blum
d4722e5333 Trade stack closure copyability for type soundness. 2013-06-29 04:39:37 -04:00
Ben Blum
ff4ab9e147 'Borrow' stack closures rather than copying them (e.g., "|x|f(x)"), in prep for making them noncopyable. 2013-06-29 04:39:34 -04:00
Ben Blum
89110fdf55 Use more deriving(IterBytes) in librustc. 2013-06-29 03:58:50 -04:00
bors
4e78c1e2a8 auto merge of #7479 : mozilla/rust/rollup, r=thestinger
22b7eb3 r=thestinger 
28a3613 r=cmr
a0c31ec r=bstrie
ee7307e r=thestinger
b9cf6a3 r=thestinger
2013-06-28 22:25:48 -07:00
Young-il Choi
21cc0ccea1 librustc: fix #7467 for android 2013-06-29 01:22:35 -04:00
Brian Anderson
22b7eb3802 Rename #[mutable] to #[no_freeze] 2013-06-29 00:56:36 -04:00
Brian Anderson
4af7ebcd8f Rename #[non_sendable] to #[no_send] 2013-06-29 00:56:36 -04:00
bors
d681bccb6a auto merge of #7471 : msullivan/rust/default-methods, r=graydon
This fixes a bunch of default method bugs and restructures how vtable resolutions are represented.

(It also adds a depth counter to llvm::type_to_str as a hacky work around for our circular llvm types. This is related in the sense that I needed to do it to make debug tracing not cause rustc to crash after running out of stack space.)
2013-06-28 20:16:56 -07:00
Michael Sullivan
c05165bf93 Drop the impl_id field from fn_ctxt. 2013-06-28 18:09:02 -07:00
Michael Sullivan
5943118728 Drop an unused field from param_substs. 2013-06-28 18:09:02 -07:00
Michael Sullivan
0252693db2 Improve handling of trait bounds on a trait in default methods.
This is work on #7460.
It does not properly handle certain cross crate situations,
because we don't properly export vtable resolution information.
2013-06-28 18:09:02 -07:00
bors
e23934645a auto merge of #7466 : thestinger/rust/passes, r=cmr 2013-06-28 16:49:49 -07:00
Michael Sullivan
649b26f7c6 Rework vtable_res to not be flattened. It is now a list of the resolutions for each param. 2013-06-28 16:12:08 -07:00
Michael Sullivan
57ee34c2bf Actually resolve trait bounds on impls. Closes #7266. 2013-06-28 16:12:08 -07:00
Michael Sullivan
817f98085f Make calling methods parameterized on the trait work from default methods.
This is done by adding a new notion of "vtable_self".
We do not yet properly handle super traits.

Closes #7183.
2013-06-28 16:12:08 -07:00
Michael Sullivan
a9e51f5f70 Make default method handling not choke on self region params. Closes #7341. 2013-06-28 16:12:08 -07:00
Michael Sullivan
050d0e6b29 Add a depth counter to llvm::type_to_str to work around infinite llvm types. 2013-06-28 16:12:04 -07:00
Michael Sullivan
47afb33981 Add Float to llvm::type_to_str. 2013-06-28 16:12:04 -07:00
Daniel Micay
2bdc88b652 copy the optimization passes from clang 2013-06-28 18:18:09 -04:00
Philipp Brüschweiler
a2227f9e0c librustc: don't skip ahead when computing register types of SSEFloatVectors
Also fixes an unrelated typo (found by comparing to the original code
of the clay project) and some cleanup.

Fixes #7415.
2013-06-28 21:28:58 +02:00