Commit Graph

2386 Commits

Author SHA1 Message Date
bors
9d6c251881 auto merge of #9885 : thestinger/rust/vector, r=brson
The goal here is to avoid requiring a division or multiplication to compare against the length. The bounds check previously used an incorrect micro-optimization to replace the division by a multiplication, but now neither is necessary *for slices*. Unique/managed vectors will have to do a division to get the length until they are reworked/replaced.
2013-10-16 15:21:35 -07:00
Daniel Micay
bd7610f3e3 introduce base_and_len fns for element length 2013-10-16 12:28:25 -04:00
Daniel Micay
ef3ec1fe97 rename base_and_len -> base_and_byte_len 2013-10-16 12:00:31 -04:00
Alex Crichton
a84c2999c9 Require module documentation with missing_doc
Closes #9824
2013-10-15 22:27:10 -07:00
Kevin Ballard
73d3d00ec4 path2: Replace the path module outright
Remove the old path.
Rename path2 to path.
Update all clients for the new path.

Also make some miscellaneous changes to the Path APIs to help the
adoption process.
2013-10-15 21:56:54 -07:00
Daniel Micay
e1a26ad271 use element count in slices, not size in bytes
This allows the indexing bounds check or other comparisons against an
element length to avoid a multiplication by the size.
2013-10-15 16:23:28 -04:00
Daniel Micay
aa93381e14 fix overflow on bounds checks
Closes #9020
2013-10-15 16:23:28 -04:00
Daniel Micay
45e2cf39a2 add an abort intrinsic
This should be preferred to the libc `abort` function.
2013-10-14 22:45:43 -04:00
Alex Crichton
082cc96090 Refine privacy error messages to be more accurate
This stops labeling everything as "is private" when in fact the destination may
be public. Instead, the clause "is inaccessible" is used and the private part of
the flag is called out with a "is private" message.

Closes #9793
2013-10-14 15:12:40 -07:00
Luqman Aden
e88064d18f librustc: Combine C_struct and C_packed_struct. 2013-10-12 23:19:22 -04:00
Luqman Aden
4b4b2136e0 librustc: Don't ICE on packed structs in statics. 2013-10-12 21:42:24 -04:00
bors
e5fc0ca6dc auto merge of #9804 : alexcrichton/rust/always-anon-extern, r=brson
There's currently a fair amount of code which is being ignored on unnamed blocks
(which are the default now), and I opted to leave it commented out for now. I
intend on very soon revisiting on how we perform linking with extern crates in
an effort to support static linking.
2013-10-10 21:31:21 -07:00
Alex Crichton
b70306158f Remove named extern blocks from the AST
There's currently a fair amount of code which is being ignored on unnamed blocks
(which are the default now), and I opted to leave it commented out for now. I
intend on very soon revisiting on how we perform linking with extern crates in
an effort to support static linking.
2013-10-10 18:04:58 -07:00
Jyun-Yan You
95fc31ae9b improve C ABI
I borrow some ideas from clang's ABIInfo.h and TargetInfo.cpp.
LLVMType is replaced with ArgType, which is similar to clang's ABIArgInfo,
and I also merge attrs of FnType into it.

Now ABI implementation doesn't need to insert hidden return pointer
to arg_tys of FnType. Instead it is handled in foreign.rs.

This change also fixes LLVM assertion failure when compiling MIPS target.
2013-10-11 08:03:34 +08:00
bors
8015f9c27e auto merge of #9791 : alexcrichton/rust/reachable, r=catamorphism
This fixes a bug in which the visibility rules were approximated by
reachability, but forgot to cover the case where a 'pub use' reexports a private
item. This fixes the commit by instead using the results of the privacy pass of
the compiler to create the initial working set of the reachability pass.

This may have the side effect of increasing the size of metadata, but it's
difficult to avoid for correctness purposes sadly.

Closes #9790
2013-10-10 06:06:24 -07:00
Alex Crichton
b0f6c29b4f Use the result of privacy for reachability
This fixes a bug in which the visibility rules were approximated by
reachability, but forgot to cover the case where a 'pub use' reexports a private
item. This fixes the commit by instead using the results of the privacy pass of
the compiler to create the initial working set of the reachability pass.

This may have the side effect of increasing the size of metadata, but it's
difficult to avoid for correctness purposes sadly.

Closes #9790
2013-10-10 03:31:59 -07:00
Geoff Hill
e538c95e4d Typeck: Disallow scalar casts to bare_fn.
Bare functions are another example of a scalar but non-numeric
type (like char) that should be handled separately in casts.
This disallows expressions like `0 as extern "Rust" fn() -> int;`.

It might be advantageous to allow casts between bare functions
and raw pointers in unsafe code in the future, to pass function
pointers between Rust and C.

Closes #8728
2013-10-10 01:11:09 +00:00
bors
2076959336 auto merge of #9750 : alexcrichton/rust/safer-strings, r=brson
This behavior was decided to get out-right forbidden by the compiler


Closes #8891
2013-10-09 15:31:26 -07:00
Alex Crichton
a69e4a55eb Forbid modifications of strings in the compiler
This disallows `str[0] = foo` along with `foo = &mut str[i]` to prevent strings
from being modified at runtime (except possibly through the `str` module)

Closes #8891
2013-10-09 10:34:35 -07:00
bors
2e64a718ea auto merge of #9664 : alexcrichton/rust/logging, r=huonw
This makes some headway on #3309, see commits for details.
2013-10-09 07:31:36 -07:00
Daniel Micay
6a90e80b62 option: rewrite the API to use composition 2013-10-09 09:17:29 -04:00
Geoff Hill
9c84982531 Change default lint output format.
Since lint check attributes are the preferred way of selectively
enabling/disabling lint checks, the output format of a failed
default check has been changed to reflect that.

When lint checks are being explicitly set by a command-line flag
or an attribute, the behavior is unchanged, so that the user can
quickly pinpoint the source.

Closes #6580
2013-10-09 00:14:35 -07:00
bors
5c8c8bc966 auto merge of #9759 : thestinger/rust/immediate, r=alexcrichton
Closes #9651
2013-10-08 04:16:33 -07:00
Daniel Micay
ac1faba4df make small ty_struct immediate
Closes #9651
2013-10-08 07:11:08 -04:00
Michael Woerister
85deeeab59 debuginfo: Unified namespace generation approach for crate-local and external items. Fixed bug related to LLVM metadata uniquing. 2013-10-08 10:35:24 +02:00
bors
c9196290af auto merge of #9674 : ben0x539/rust/raw-str, r=alexcrichton
This branch parses raw string literals as in #9411.
2013-10-07 23:01:39 -07:00
bors
6ddd011ce8 auto merge of #9735 : alexcrichton/rust/privacy, r=cmr
This is the culmination and attempted resolution of #8215. The commits have many more details about implementation details and the consequences of this refinement.

I'll point out specific locations which may be possible causes for alarm. In general, I have been very happy with how things have turned out. I'm a little sad that I couldn't remove privacy from resolve as much as I did, but I blame glob imports (although in theory even some of this can be mitigated as well).
2013-10-07 21:46:39 -07:00
Alex Crichton
7cd6692425 Fix merge fallout of privacy changes 2013-10-07 21:44:02 -07:00
bors
132099950f auto merge of #9747 : dim-an/rust/fix-match, r=alexcrichton
When `specialize`ing struct-like enum patterns, compare struct fields to
pattern fields, not pattern fields to pattern fields.

Closes #8351.
2013-10-07 18:46:37 -07:00
Benjamin Herr
9d7b130041 add new enum ast::StrStyle as field to ast::lit_str
For the benefit of the pretty printer we want to keep track of how
string literals in the ast were originally represented in the source
code.

This commit changes parser functions so they don't extract strings from
the token stream without at least also returning what style of string
literal it was. This is stored in the resulting ast node for string
literals, obviously, for the package id in `extern mod = r"package id"`
view items, for the inline asm in `asm!()` invocations.

For `asm!()`'s other arguments or for `extern "Rust" fn()` items, I just
the style of string, because it seemed disproportionally cumbersome to
thread that information through the string processing that happens with
those string literals, given the limited advantage raw string literals
would provide in these positions.

The other syntax extensions don't seem to store passed string literals
in the ast, so they also discard the style of strings they parse.
2013-10-08 03:43:28 +02:00
Daniel Micay
f56cf16b80 stop zeroing the drop flag in drop glue
this is only going to cover up real bugs, as it's not part of the model
used to prevent multiple destructor calls
2013-10-07 18:41:20 -04:00
Daniel Micay
a9fb88d4f8 rm special case for ty_struct from take glue
This is incorrect, as take glue isn't used for moves.
2013-10-07 17:18:10 -04:00
Alex Crichton
de7d143176 Fix existing privacy/visibility violations
This commit fixes all of the fallout of the previous commit which is an attempt
to refine privacy. There were a few unfortunate leaks which now must be plugged,
and the most horrible one is the current `shouldnt_be_public` module now inside
`std::rt`. I think that this either needs a slight reorganization of the
runtime, or otherwise it needs to just wait for the external users of these
modules to get replaced with their `rt` implementations.

Other fixes involve making things pub which should be pub, and otherwise
updating error messages that now reference privacy instead of referencing an
"unresolved name" (yay!).
2013-10-07 13:00:52 -07:00
Alex Crichton
439e2770be Extract privacy checking from name resolution
This commit is the culmination of my recent effort to refine Rust's notion of
privacy and visibility among crates. The major goals of this commit were to
remove privacy checking from resolve for the sake of sane error messages, and to
attempt a much more rigid and well-tested implementation of visibility
throughout rust. The implemented rules for name visibility are:

1. Everything pub from the root namespace is visible to anyone
2. You may access any private item of your ancestors.

"Accessing a private item" depends on what the item is, so for a function this
means that you can call it, but for a module it means that you can look inside
of it. Once you look inside a private module, any accessed item must be "pub
from the root" where the new root is the private module that you looked into.
These rules required some more analysis results to get propagated from trans to
privacy in the form of a few hash tables.

I added a new test in which my goal was to showcase all of the privacy nuances
of the language, and I hope to place any new bugs into this file to prevent
regressions.

Overall, I was unable to completely remove the notion of privacy from resolve.
One use of privacy is for dealing with glob imports. Essentially a glob import
can only import *public* items from the destination, and because this must be
done at namespace resolution time, resolve must maintain the notion of "what
items are public in a module". There are some sad approximations of privacy, but
I unfortunately can't see clear methods to extract them outside.

The other use case of privacy in resolve now is one that must stick around
regardless of glob imports. When dealing with privacy, checking a private path
needs to know "what the last private thing was" when looking at a path. Resolve
is the only compiler pass which knows the answer to this question, so it
maintains the answer on a per-path resolution basis (works similarly to the
def_map generated).

Closes #8215
2013-10-07 13:00:52 -07:00
Dmitry Ermolov
da7f41104d Fix bug in match checking
When `specialize`ing struct-like enum patterns, compare struct fields to
pattern fields, not pattern fields to pattern fields.

Closes #8351.
2013-10-07 22:28:18 +04:00
Dmitry Ermolov
fdb49aa917 Hide internal stuff in check_match.rs 2013-10-07 13:33:50 +04:00
bors
c05fbc5a2c auto merge of #9593 : fhahn/rust/logging-unsafe-removal, r=alexcrichton
This pull request changes to memory layout of the `CrateMap` struct to use static slices instead of raw pointers. Most of the discussion took place [here](63b5975efa (L1R92)) .

The memory layout of CrateMap changed, without bumping the version number in the struct. Another, more backward compatible, solution would be to keep the old code and increase the version number in the new struct. On the other hand, the `annihilate_fn` pointer was removed without bumping the version number recently.

At the moment, the stage0 compiler does not use the new memory layout, which would lead the segfaults during stage0 compilation, so I've added a dummy `iter_crate_map` function for stage0, which does nothing. Again, this could be avoided if we'd bump the version number in the struct and keep the old code.

I'd like to use a normal `for` loop [here](https://github.com/fhahn/rust/compare/logging-unsafe-removal?expand=1#L1R109), 

        for child in children.iter() {
            do_iter_crate_map(child, |x| f(x), visited);
        }


but for some reason this only yields `error: unresolved enum variant, struct or const 'Some'` and I have no idea why.
2013-10-06 03:21:32 -07:00
Florian Gilcher
8154d23e44 Clearer error message for external trait and type
The old error message implied that external traits could never
be implemented locally.
2013-10-06 09:56:46 +02:00
bors
0114ab631d auto merge of #9729 : dwrensha/rust/regionmanip-cleanup, r=catamorphism 2013-10-05 19:56:32 -07:00
Tim Chevalier
310c0e3d4b testsuite: Two tests for fixed bugs
Closes #7246
Closes #7573
2013-10-05 20:36:14 -04:00
David Renshaw
3b26bb9022 remove duplicate statement 2013-10-05 20:28:09 -04:00
bors
2733b189ac auto merge of #9250 : erickt/rust/num, r=erickt
This PR solves one of the pain points with c-style enums. Simplifies writing a fn to convert from an int/uint to an enum. It does this through a `#[deriving(FromPrimitive)]` syntax extension.

Before this is committed though, we need to discuss if `ToPrimitive`/`FromPrimitive` has the right design (cc #4819). I've changed all the `.to_int()` and `from_int()` style functions to return `Option<int>` so we can handle partial functions. For this PR though only enums and `extra::num::bigint::*` take advantage of returning None for unrepresentable values. In the long run it'd be better if `i64.to_i8()` returned `None` if the value was too large, but I'll save this for a future PR.

Closes #3868.
2013-10-05 14:26:44 -07:00
Florian Hahn
b7b4f7a5e2 Add code for older crate map versions, bumped crate map version number 2013-10-05 12:09:30 +02:00
Florian Hahn
5dd1145c9b Use &'self str instead of raw char pointer in ModEntry 2013-10-05 12:09:30 +02:00
Florian Hahn
9ef4463b2a Use slice representation for module entries in CrateMap
Relaxe lifetime of CrateMap as well.
2013-10-05 12:09:30 +02:00
Florian Hahn
787f20a255 Use slice representation for child crate maps 2013-10-05 12:09:30 +02:00
Alex Crichton
1996a11bb2 Cache more results of const_eval
According to http://huonw.github.io/isrustfastyet/mem/#012f909, the "const
marking" pass generates about 400MB of extra memory during compilation. It
appears that this is due to two different factors:

    1. There is a `ccache` map in the ty::ctxt which is only ever used in this
       pass, so this commit moves the map out of the ty::ctxt struct and into
       just this pass's visitor. This turned out to not benefit that much in
       memory (as indicated by http://i.imgur.com/Eo4iOzK.png), but it's helpful
       to do nonetheless.

    2. During const_eval, there are a lot of lookups into decoding inlined items
       from external crates. There is no caching involved here, so the same
       static or variant could be re-translated many times. After adding
       separate caches for variants and statics, the memory peak of compiling
       rustc decreased by 200MB (as evident by http://i.imgur.com/ULAUMtq.png)

The culmination of this is basically a slight reorganization of a caching map
for the const_eval pass along with a 200MB decrease in peak memory usage when
compiling librustc.
2013-10-04 17:41:15 -07:00
bors
8cb3426f16 auto merge of #9723 : blake2-ppc/rust/trans-no-push-ctxt-clone, r=alexcrichton
Avoid cloning the stack on every `push_ctxt` call in trans

Rewrite the use of TLS variable for `push_ctxt` so that it uses a ~[]
instead of a @~[]. Before it cloned the whole vector on each push and
pop, which is unnecessary.
2013-10-04 16:21:36 -07:00
blake2-ppc
87294c23ba Avoid cloning the stack on every push_ctxt call in trans
Rewrite the use of TLS variable for `push_ctxt` so that it uses a ~[]
instead of a @~[]. Before it cloned the whole vector on each push and
pop, which is unnecessary.
2013-10-05 01:10:27 +02:00
bors
c5295f9c47 auto merge of #9717 : blake2-ppc/rust/rustc-static-str, r=alexcrichton
rustc: Use static strings in a few literals

Avoid allocating extra copies of strings by using "" instead of ~"" for
the debug options list and for the `time` function. This is a small
change, but it is in a path that's always executed.
2013-10-04 12:36:36 -07:00
blake2-ppc
9ac175c503 rustc: Use static strings in a few literals
Avoid allocating extra copies of strings by using "" instead of ~"" for
the debug options list and for the `time` function. This is a small
change, but it is in a path that's always executed.
2013-10-04 19:46:53 +02:00
bors
3f32898a7b auto merge of #9711 : sanxiyn/rust/ambiguous-default-method, r=alexcrichton
Fix #8808.
2013-10-03 20:21:31 -07:00
bors
9344e2a866 auto merge of #9686 : alexcrichton/rust/lint, r=thestinger
This purges about 500 lines of visitor cruft from lint passes. All lints are
handled in a much more sane way at this point. The other huge bonus of this
commit is that there are no more @-boxes in the lint passes, fixing the 500MB
memory regression seen when the lint passes were refactored.

Closes #8589
2013-10-03 10:31:33 -07:00
Alex Crichton
c0388cd691 Rewrite lint passes with less visitor cruft
This purges about 500 lines of visitor cruft from lint passes. All lints are
handled in a much more sane way at this point. The other huge bonus of this
commit is that there are no more @-boxes in the lint passes, fixing the 500MB
memory regression seen when the lint passes were refactored.

Closes #8589
2013-10-03 10:25:14 -07:00
Alex Crichton
a1ffb06ac8 Use the correct logging crate while monomorphing
This makes sure that the top-level crate name is correct when emitting log
statements for a monomorphized function in another crate. This happens by
tracing the monomorphized ID back to the external source and then using that
crate index to get the name of the crate.

Closes #3046
2013-10-03 09:16:31 -07:00
Seo Sanghyeon
fbd56396bc Correctly report errors for ambiguous default methods 2013-10-04 01:10:28 +09:00
Daniel Micay
f504461a40 make C-like enums immediate
This fixes two existing bugs along the way:

* The `transmute` intrinsic did not correctly handle casts of immediate
  aggregates like newtype structs and tuples.
* The code for calling foreign functions used the wrong type to create
  an `alloca` temporary

    enum Foo { A, B }
    fn foo() -> Foo { A }

Before:

    ; Function Attrs: nounwind uwtable
    define void @_ZN3foo18hbedc642d5d9cf5aag4v0.0E(%enum.Foo* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      %2 = getelementptr inbounds %enum.Foo* %0, i64 0, i32 0
      store i64 0, i64* %2, align 8
      ret void
    }

After:

    ; Function Attrs: nounwind readnone uwtable
    define %enum.Foo @_ZN3foo18hbedc642d5d9cf5aag4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      ret %enum.Foo zeroinitializer
    }
2013-10-03 06:27:00 -04:00
Daniel Micay
249b356fb3 make unit structs immediate
struct Foo;
    fn foo() -> Foo { Foo }

Before:

    ; Function Attrs: nounwind readnone uwtable
    define void @_ZN3foo18he8ca29755dedebbaf4v0.0E(%struct.Foo* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture) #0 {
    "function top level":
      ret void
    }

After:

    ; Function Attrs: nounwind readnone uwtable
    define %struct.Foo @_ZN3foo18he8ca29755dedebbaf4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      ret %struct.Foo undef
    }
2013-10-03 03:59:58 -04:00
bors
371a7ec569 auto merge of #9675 : sfackler/rust/lint, r=alexcrichton
Closes #9671
2013-10-02 13:26:36 -07:00
bors
353578a7b3 auto merge of #9680 : thestinger/rust/overflow, r=huonw
This is pointless, since it's just used to load an `undef` value and
never touched again.
2013-10-02 12:11:39 -07:00
Steven Fackler
b7fe83d573 Check enums in missing_doc lint
Closes #9671
2013-10-02 08:57:03 -07:00
bors
c44826fdcd auto merge of #9677 : thestinger/rust/immediate, r=huonw
C-like enums are excluded from this for now, because the code paths
specific to them need to be changed.

    fn foo() -> Option<~int> { Some(~5) }

Before:

    ; Function Attrs: uwtable
    define void @_ZN3foo18hdec6e36682b87eeaf4v0.0E(%"enum.std::option::Option<~int>[#1]"* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      %2 = tail call %"enum.std::libc::types::common::c95::c_void[#1]"* @"_ZN2rt11global_heap10malloc_raw17h56c543b77f9b78aY11v0.9$x2dpreE"({ i64, %tydesc*, i8*, i8*, i8 }* undef, i64 8)
      %3 = bitcast %"enum.std::libc::types::common::c95::c_void[#1]"* %2 to i64*
      store i64 5, i64* %3, align 8
      %4 = getelementptr inbounds %"enum.std::option::Option<~int>[#1]"* %0, i64 0, i32 0
      store i64* %3, i64** %4, align 8
      ret void
    }

After:

    ; Function Attrs: uwtable
    define %"enum.std::option::Option<~int>[#1]" @_ZN3foo18h2cbf6557a3143edah4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      %1 = tail call %"enum.std::libc::types::common::c95::c_void[#1]"* @"_ZN2rt11global_heap10malloc_raw18hb1e9dd1beab35edau11v0.9$x2dpreE"({ i64, %tydesc*, i8*, i8*, i8 }* undef, i64 8)
      %2 = bitcast %"enum.std::libc::types::common::c95::c_void[#1]"* %1 to i64*
      store i64 5, i64* %2, align 8
      %oldret = insertvalue %"enum.std::option::Option<~int>[#1]" undef, i64* %2, 0
      ret %"enum.std::option::Option<~int>[#1]" %oldret
    }
2013-10-02 07:56:36 -07:00
Erick Tryzelaar
d9d1dfc195 std: Replace num::IntConvertible with {To,From}Primitive 2013-10-02 07:55:41 -07:00
Daniel Micay
f2932e4661 make small (<= size_of::<int>()) enums immediate
C-like enums are excluded from this for now, because the code paths
specific to them need to be changed.

    fn foo() -> Option<~int> { Some(~5) }

Before:

    ; Function Attrs: uwtable
    define void @_ZN3foo18hdec6e36682b87eeaf4v0.0E(%"enum.std::option::Option<~int>[#1]"* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      %2 = tail call %"enum.std::libc::types::common::c95::c_void[#1]"* @"_ZN2rt11global_heap10malloc_raw17h56c543b77f9b78aY11v0.9$x2dpreE"({ i64, %tydesc*, i8*, i8*, i8 }* undef, i64 8)
      %3 = bitcast %"enum.std::libc::types::common::c95::c_void[#1]"* %2 to i64*
      store i64 5, i64* %3, align 8
      %4 = getelementptr inbounds %"enum.std::option::Option<~int>[#1]"* %0, i64 0, i32 0
      store i64* %3, i64** %4, align 8
      ret void
    }

After:

    ; Function Attrs: uwtable
    define %"enum.std::option::Option<~int>[#1]" @_ZN3foo18h2cbf6557a3143edah4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      %1 = tail call %"enum.std::libc::types::common::c95::c_void[#1]"* @"_ZN2rt11global_heap10malloc_raw18hb1e9dd1beab35edau11v0.9$x2dpreE"({ i64, %tydesc*, i8*, i8*, i8 }* undef, i64 8)
      %2 = bitcast %"enum.std::libc::types::common::c95::c_void[#1]"* %1 to i64*
      store i64 5, i64* %2, align 8
      %oldret = insertvalue %"enum.std::option::Option<~int>[#1]" undef, i64* %2, 0
      ret %"enum.std::option::Option<~int>[#1]" %oldret
    }
2013-10-02 10:02:52 -04:00
Daniel Micay
abe648d608 treat uninhabited enums as voidish 2013-10-02 10:02:52 -04:00
bors
17548378a7 auto merge of #9679 : pnkfelix/rust/de-pub-resolve-code, r=huonw
r? anyone

For context (and the archaeological dig that @huonw did to see how this arose), see:
  https://botbot.me/mozilla/rust-internals/msg/6547222/
2013-10-02 06:36:30 -07:00
Daniel Micay
ee114b6cb1 avoid alloca in with_overflow intrinsics
This is pointless, since it's just used to load an `undef` value and
never touched again.
2013-10-02 08:53:47 -04:00
Felix S. Klock II
55da145ab1 De-pub resolve.rs 2013-10-02 14:33:01 +02:00
bors
d00c9269dc auto merge of #9665 : alexcrichton/rust/snapshot, r=brson
Uses the new snapshots to kill the old `loop` and introduce the new `continue`.
2013-10-02 02:31:29 -07:00
bors
97cd495aca auto merge of #9638 : pnkfelix/rust/fsk-issue7526-attempt-to-catch-nonuc-statics-in-match-patterns, r=alexcrichton
r? anyone

Address scariest part of #7526 by adding a new more specific lint (that is set to warn by default, rather than allow).
2013-10-02 01:16:31 -07:00
bors
33a5928b46 auto merge of #9656 : thestinger/rust/immediate, r=alexcrichton
fn foo() -> (u32, u8, u8, u8, u8) {
        (4, 5, 6, 7, 8)
    }

Before:

    ; Function Attrs: nounwind uwtable
    define void @_ZN3foo18hbb616262f874f8daf4v0.0E({ i32, i8, i8, i8, i8 }* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      %2 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 0
      store i32 4, i32* %2, align 4
      %3 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 1
      store i8 5, i8* %3, align 4
      %4 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 2
      store i8 6, i8* %4, align 1
      %5 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 3
      store i8 7, i8* %5, align 2
      %6 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 4
      store i8 8, i8* %6, align 1
      ret void
    }

After:

    ; Function Attrs: nounwind readnone uwtable
    define { i32, i8, i8, i8, i8 } @_ZN3foo18hbb616262f874f8daf4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      ret { i32, i8, i8, i8, i8 } { i32 4, i8 5, i8 6, i8 7, i8 8 }
    }
2013-10-01 21:56:27 -07:00
Alex Crichton
4f67dcb24a Migrate users of 'loop' to 'continue'
Closes #9467
2013-10-01 15:53:13 -07:00
bors
fe4e7478c5 auto merge of #9560 : pcwalton/rust/xc-tuple-structs, r=pcwalton
r? @thestinger
2013-10-01 15:06:25 -07:00
Patrick Walton
76d92c5472 librustc: Inline cross-crate tuple struct constructors 2013-10-01 14:24:34 -07:00
Daniel Micay
c9d4ad07c4 remove the float type
It is simply defined as `f64` across every platform right now.

A use case hasn't been presented for a `float` type defined as the
highest precision floating point type implemented in hardware on the
platform. Performance-wise, using the smallest precision correct for the
use case greatly saves on cache space and allows for fitting more
numbers into SSE/AVX registers.

If there was a use case, this could be implemented as simply a type
alias or a struct thanks to `#[cfg(...)]`.

Closes #6592

The mailing list thread, for reference:

https://mail.mozilla.org/pipermail/rust-dev/2013-July/004632.html
2013-10-01 14:54:10 -04:00
Felix S. Klock II
2461b31026 incoporate suggestion from huonw to move code into lint.rs 2013-10-01 18:03:26 +02:00
Daniel Micay
5e4ae4f45f make small (<= size_of::<int>()) tuples immediate
fn foo() -> (u32, u8, u8, u8, u8) {
        (4, 5, 6, 7, 8)
    }

Before:

    ; Function Attrs: nounwind uwtable
    define void @_ZN3foo18hbb616262f874f8daf4v0.0E({ i32, i8, i8, i8, i8 }* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      %2 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 0
      store i32 4, i32* %2, align 4
      %3 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 1
      store i8 5, i8* %3, align 4
      %4 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 2
      store i8 6, i8* %4, align 1
      %5 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 3
      store i8 7, i8* %5, align 2
      %6 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 4
      store i8 8, i8* %6, align 1
      ret void
    }

After:

    ; Function Attrs: nounwind readnone uwtable
    define { i32, i8, i8, i8, i8 } @_ZN3foo18hbb616262f874f8daf4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
    "function top level":
      ret { i32, i8, i8, i8, i8 } { i32 4, i8 5, i8 6, i8 7, i8 8 }
    }
2013-10-01 02:57:59 -04:00
Alex Crichton
1b80558be3 rustc: Remove usage of fmt! 2013-09-30 23:21:19 -07:00
Daniel Micay
ab0a884a73 fix dropping non-primitive immediates
Closes #9446
2013-10-01 00:38:37 -04:00
Felix S. Klock II
155857f548 Revise error message to use phrase "all caps" instead of "uppercase".
This is to clarify that the lint is checking for THIS_THING and not This.
2013-10-01 03:10:19 +02:00
Felix S. Klock II
a076fef2b6 Add new lint: non_uppercase_pattern_statics, for #7526.
This tries to warn about code like:
    ```rust
    match (0,0) {
        (0, aha) => { ... },
        ...
    }
    ```
where `aha` is actually a static constant, not a binding.
2013-10-01 01:44:25 +02:00
Daniel Micay
11b7109b7b rm only use of type_is_immediate outside of trans 2013-09-30 18:16:35 -04:00
bors
5011bbfbb6 auto merge of #9630 : blake2-ppc/rust/de-at-smaller, r=huonw
This is mostly an incremental change, picking off some uses of
@- or @mut-pointers that can be replaced by references.

Almost all of the builder functions in trans::build are updated,
mostly using `&Block` arguments instead of `@mut Block`.
2013-09-30 10:41:20 -07:00
blake2-ppc
f4d8d8c122 trans::build: Change @mut Block to &Block or &mut Block
Use &mut Block and &Block references where possible in the builder
functions in trans::build.

@mut Block remains in a few functions where I could not (not yet at
least) track down the runtime borrowck failures.
2013-09-30 19:37:22 +02:00
blake2-ppc
b88517ec93 trans: Change @ast::Pat and @mut CrateContext in a few places
Use borrowed references in a few locations that were encountered when
working on other changes.
2013-09-30 19:37:17 +02:00
blake2-ppc
948b5ab87a trans: Change @ast::Expr -> &ast::Expr where possible 2013-09-30 19:37:17 +02:00
bors
ca2d5965d1 auto merge of #9614 : blake2-ppc/rust/lang-item-iter, r=alexcrichton
Cleanup in middle::lang_items

Use static string keys in the lang item hashmap, and convert
the traversal function to be an iterator.
2013-09-30 01:56:23 -07:00
blake2-ppc
abcca1c7d1 rustc: Convert lang_item to use an iterator 2013-09-30 05:13:04 +02:00
blake2-ppc
8e69c05b7c rustc: Convert lang_items hashmap to use &'static str keys 2013-09-30 05:13:04 +02:00
Alex Crichton
7b18976f08 Remove all usage of @ast::Crate 2013-09-29 16:21:25 -07:00
Alex Crichton
22ef7e72f4 Require &Crate instead of @Crate
This help enable some later refactorings.
2013-09-29 16:21:25 -07:00
bors
c635fba748 auto merge of #9583 : blake2-ppc/rust/connect-vec, r=huonw
std::vec: Sane implementations for connect_vec and concat_vec

Avoid unnecessary copying of subvectors, and calculate the needed space
beforehand. These implementations are simple but better than the
previous.

Also only implement it once, for all `Vector<T>` using:

    impl<'self, T: Clone, V: Vector<T>> VectorVector<T> for &'self [V]

Closes #9581
2013-09-28 07:31:02 -07:00
blake2-ppc
3709aa78d8 std::vec: Remove functions concat, connect
std::vec::{concat, connect, concat_slices, connect_slices} are replaced
by the already existing trait methods .concat_vec() and .connect_vec().
2013-09-28 05:56:49 +02:00
bors
6828d2e018 auto merge of #9556 : alexcrichton/rust/less-at-mut, r=luqmana
Instead use &mut everywhere as much as possible and then reorganize lots of code
to get past the borrow checker.
2013-09-27 17:56:06 -07:00
bors
10e7f12daf auto merge of #9550 : alexcrichton/rust/remove-printf, r=thestinger
The 0.8 release was cut, down with printf!
2013-09-27 08:21:23 -07:00
bors
01313a131b auto merge of #9548 : thestinger/rust/internal, r=alexcrichton
Closes #9494
2013-09-27 06:21:22 -07:00
bors
ae8a2ff379 auto merge of #9538 : thestinger/rust/type_use, r=pcwalton
This is broken, and results in poor performance due to the undefined
behaviour in the LLVM IR. LLVM's `mergefunc` is a *much* better way of
doing this since it merges based on the equality of the bytecode.

For example, consider `std::repr`. It generates different code per
type, but is not included in the type bounds of generics.

The `mergefunc` pass works for most of our code but currently hits an
assert on libstd. It is receiving attention upstream so it will be
ready soon, but I don't think removing this broken code should wait any
longer. I've opened #9536 about enabling it by default.

Closes #8651
Closes #3547
Closes #2537
Closes #6971
Closes #9222
2013-09-27 03:31:13 -07:00
bors
afbc242a20 auto merge of #9527 : bmaxa/rust/master, r=alexcrichton
that is, if super trait had more methods, tnen subtrait, compiling would fail. I simply forgot to update
variable name. Updated test case , too.
2013-09-27 01:36:15 -07:00
Erick Tryzelaar
4834661c66 std and rustc: Convert users of c_str to use .with_c_str 2013-09-26 22:20:39 -07:00
Alex Crichton
5fe09563ac Remove @mut Resolver
Instead use &mut everywhere as much as possible and then reorganize lots of code
to get past the borrow checker.
2013-09-26 20:12:55 -07:00
Alex Crichton
409182de6d Update the compiler to not use printf/printfln 2013-09-26 17:05:59 -07:00
Daniel Micay
2aadd3652d mark globals as internal when not building a library
Closes #9494
2013-09-26 19:21:22 -04:00
Daniel Micay
c3e4e06841 remove type_use
This is broken, and results in poor performance due to the undefined
behaviour in the LLVM IR. LLVM's `mergefunc` is a *much* better way of
doing this since it merges based on the equality of the bytecode.

For example, consider `std::repr`. It generates different code per
type, but is not included in the type bounds of generics.

The `mergefunc` pass works for most of our code but currently hits an
assert on libstd. It is receiving attention upstream so it will be
ready soon, but I don't think removing this broken code should wait any
longer. I've opened #9536 about enabling it by default.

Closes #8651
Closes #3547
Closes #2537
Closes #6971
Closes #9222
2013-09-26 17:27:23 -04:00
Alex Crichton
daee1b4d5c Ensure that skipped items aren't encoded
If an item is skipped due to it being unreachable or for some optimization, then
it shouldn't be encoded into the metadata (because it wasn't present in the
first place).
2013-09-26 13:54:50 -07:00
Branimir
a4b7474461 Fix ICE caused by my previous patch, that is, if super trait had more
methods tnan subtrait, compiling would fail. I simply forgot to update
variable name. Updated test case , too.
2013-09-26 16:59:54 +02:00
bors
a8a69ec15d auto merge of #9464 : bmaxa/rust/master, r=cmr
I have tried this fix and it seems to work either with single or multiple trait inheritance.

trait Base:Base2 + Base3{
fn foo(&self);
}

trait Base2 {
fn baz(&self);
}

trait Base3{
fn root(&self);
}

trait Super: Base{
fn bar(&self);
}

struct X;

impl Base for X {
fn foo(&self) {
println("base foo");
}

}
impl Base2 for X {
fn baz(&self) {
println("base2 baz");
}

}
impl Base3 for X {
fn root(&self) {
println("base3 root");
}

}
impl Super for X {
fn bar(&self) {
println("super bar");
}
}

fn main() {
let n = X;
let s = &n as &Super;
s.bar();
s.foo(); // super bar
s.baz();
s.root();
}

bmaxa@maxa:~/examples/rust$ rustc error.rs
bmaxa@maxa:~/examples/rust$ ./error 
super bar
base foo
base2 baz
base3 root
2013-09-26 02:56:03 -07:00
Branimir
56d415aa60 fix for issue #9394
This solves problem of incorrect indexing into vtable
    when method from super trait was called through pointer
    to derived trait.
    Problem was that offset of super trait vtables
    was not calculated at all.
    Now it works, correct offset is calculated by
    traversing all super traits up to super trait
    where method belongs. That is how it is
    intended to work.
2013-09-26 11:14:18 +02:00
Alex Crichton
5c6f8a976f rustdoc: Linkify all reexports.
This way each component of a reexport path is click-able to the destination that
it's referencing.
2013-09-25 14:27:42 -07:00
Alex Crichton
3585c64d09 rustdoc: Change all code-blocks with a script
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g'
    find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g'
    find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-09-25 14:27:42 -07:00
bors
5375cf8718 auto merge of #9491 : thestinger/rust/noreturn, r=huonw
Closes #9317
2013-09-25 07:25:56 -07:00
bors
797a373cd1 auto merge of #9492 : pnkfelix/rust/fsk-syntax-visit-refactor-remainder, r=huonw
r? anyone

Part of #7081.

Removed many unnecessary context arguments, turning them into visitors.  Removed some @allocation.

If this lands, then I think the only thing left that is unaddressed are:
 * the various lint visitors, and
 * middle/privacy.rs, which has `impl<'self> Visitor<&'self method_map> for PrivacyVisitor`
2013-09-25 06:10:57 -07:00
Felix S. Klock II
37481641b1 Fold env into CheckItemRecursionVisitor. 2013-09-25 11:01:43 +02:00
Felix S. Klock II
1ce1aae282 Fold ErrorCheckVisitor into Liveness. Removed some @allocation. 2013-09-25 11:01:09 +02:00
Felix S. Klock II
ffc9209471 Fold KindAnalysisVisitor into the Context. Removed unused current_item state. 2013-09-25 11:00:36 +02:00
Felix S. Klock II
339027ec15 Move unchanging portions of Context over to the Visitor. 2013-09-25 10:59:56 +02:00
Felix S. Klock II
bc13365007 Move unchanging portions of context over to the Visitor. 2013-09-25 10:59:31 +02:00
Felix S. Klock II
9d0727736b Fold context into CalleeTranslationVisitor. 2013-09-25 10:59:06 +02:00
Felix S. Klock II
2ceebf1070 Fold context into TransItemVisitor. 2013-09-25 10:58:40 +02:00
Felix S. Klock II
411dce85ea Fold type_use.rs Context into its Visitor. 2013-09-25 10:55:50 +02:00
Daniel Micay
e76bfae7eb add noreturn attribute to functions returning !
Closes #9317
2013-09-25 04:45:29 -04:00
bors
4531184614 auto merge of #9432 : alexcrichton/rust/correct-item-visibility, r=pcwalton
This fixes private statics and functions from being usable cross-crates, along
with some bad privacy error messages. This is a reopening of #8365 with all the
privacy checks in privacy.rs instead of resolve.rs (where they should be
anyway).

These maps of exported items will hopefully get used for generating
documentation by rustdoc

Closes #8592
2013-09-25 00:55:53 -07:00
bors
d7bb40c50c auto merge of #9470 : luqmana/rust/bba, r=brson
#8431

~~@brson: do we need to bump up the cratemap version for this change?~~ Tis a no.
2013-09-24 20:25:58 -07:00
Luqman Aden
90e009f9b6 Remove the annihilate function from the crate map. Fixes #8431 2013-09-24 20:34:11 -04:00
Daniel Micay
5867bbd794 mark functions internal if not building a library
the entry point is wrapped with what should be the only public function
2013-09-24 18:50:28 -04:00
Alex Crichton
10a583ce1a Correctly encode item visibility in metadata
This fixes private statics and functions from being usable cross-crates, along
with some bad privacy error messages. This is a reopening of #8365 with all the
privacy checks in privacy.rs instead of resolve.rs (where they should be
anyway).

These maps of exported items will hopefully get used for generating
documentation by rustdoc

Closes #8592
2013-09-24 09:57:25 -07:00
bors
7535479633 auto merge of #9463 : pnkfelix/rust/fsk-syntax-visit-refactor-rest-of-typeck, r=huonw
r? anyone

Also got rid of a bit of `@mut` allocation.  (Though not the monster that is `@mut FnCtxt`; that case is documented already on #7081; if we attack it, it will probably be its own ticket, not part of #7081.)
2013-09-24 08:26:04 -07:00
Felix S. Klock II
0e95c3434b Part of #7081: Fold remainder of typeck's visit env into their visitor structs. 2013-09-24 14:34:51 +02:00
bors
c7e672602e auto merge of #9453 : pnkfelix/rust/fsk-further-syntax-visit-refactors, r=alexcrichton
r? anyone.

Part of #7081.

More refactorings of the syntax::visit::Visitor implementations, folding so-called "environments" into the visitor impl when the latter was previously a trivial unit struct.

As usual, this refactoring only applies when the environments are not actually carrying state that is meant to be pushed and popped as we traverse the expression.  (For an example where the environment *isn't* just passed through, see the `visit_fn` in `liveness.rs`.)

Got rid of a bit of @-allocation in borrowck.

Both cases should be pure-refactorings.
2013-09-24 02:26:06 -07:00
Felix S. Klock II
4f691cd5bc visit::Visitor refactor: fold moves.rs VisitContext into ComputeModesVisitor. 2013-09-24 03:25:41 +02:00
Patrick Walton
3b1d3e5bf8 librustc: Fix merge fallout. 2013-09-23 18:23:23 -07:00
Patrick Walton
68ea9aed96 librustc: Remove @fn managed closures from the language. 2013-09-23 18:23:21 -07:00
Patrick Walton
6ecbd75843 librustc: Change the ID visitor to use traits instead of garbage-collected functions. 2013-09-23 18:23:20 -07:00
Patrick Walton
7796d519f9 librustc: Don't use garbage-collected closures to store cleanups. 2013-09-23 18:23:19 -07:00
Patrick Walton
16e87cb527 librustc: Make the fall-through case in match not use garbage collected functions 2013-09-23 18:23:18 -07:00
Patrick Walton
15ce791ff5 librustc: Port the pretty printer annotation infrastructure to use traits instead of garbage collected functions. 2013-09-23 18:23:18 -07:00
Patrick Walton
3e5de06135 librustc: Change fold to use traits instead of @fn. 2013-09-23 18:23:17 -07:00
Felix S. Klock II
7eed184dbb visit::Visitor refactor: replace (&mut BorrowckVisitor, @BorrowckCtxt) with &mut BorrowckCtxt. 2013-09-24 01:56:25 +02:00
bors
9705399504 auto merge of #9301 : luqmana/rust/ncm, r=brson
Get rid of the crate_map arg!

r? @brson
2013-09-23 15:46:05 -07:00
Luqman Aden
20a10ff9c9 Find the cratemap at runtime on windows. 2013-09-23 18:26:16 -04:00
bors
e268c7fcc5 auto merge of #9350 : pnkfelix/rust/fsk-issue-4691-catch-bad-fsu-during-compute-moves, r=nikomatsakis
Resolves third bullet of #4691: if the functional-struct-update (FSU) expression `{ a: b, ..s }` causes `s` to move and `s` has a destructor, then the expression is illegal.

r? @nikomatsakis
2013-09-20 20:26:02 -07:00
bors
89cc8529cc auto merge of #9332 : eugals/rust/master, r=alexcrichton
It is intended to optimize/beautify the code generated in a few trivial trait operations.
Let's take the following code as an example:
```
trait Stuff {
    fn bar(&self);
}

fn callBar(s: &Stuff) {
    s.bar();
}

struct Foo;

impl Stuff for Foo {
    fn bar(&self) {
    }
}

pub fn main() {
    let o = Foo;
    callBar(&o as &Stuff);
}
```

At present it is translated into something like:
```
define void @_ZN7callBar_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }*, { %tydesc*, i8* }*) #4 {
"function top level":
  %__trait_callee = alloca { %tydesc*, i8* }
  %__auto_borrow_obj = alloca { %tydesc*, i8* }
  %2 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %3 = load %tydesc** %2
  %4 = getelementptr inbounds { %tydesc*, i8* }* %__auto_borrow_obj, i32 0, i32 0
  store %tydesc* %3, %tydesc** %4
  %5 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %6 = load i8** %5
  %7 = getelementptr inbounds { %tydesc*, i8* }* %__auto_borrow_obj, i32 0, i32 1
  store i8* %6, i8** %7
  %8 = bitcast { %tydesc*, i8* }* %__auto_borrow_obj to i8*
  %9 = bitcast { %tydesc*, i8* }* %__trait_callee to i8*
  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %9, i8* %8, i32 8, i32 4, i1 false)
  %10 = getelementptr inbounds { %tydesc*, i8* }* %__trait_callee, i32 0, i32 1
  %11 = load i8** %10
  %12 = bitcast i8* %11 to { i32, %tydesc*, i8*, i8*, i8 }*
  %13 = getelementptr inbounds { %tydesc*, i8* }* %__trait_callee, i32 0, i32 0
  %14 = bitcast %tydesc** %13 to [1 x i8*]**
  %15 = load [1 x i8*]** %14
  %16 = getelementptr inbounds [1 x i8*]* %15, i32 0, i32 1
  %17 = load i8** %16
  %18 = bitcast i8* %17 to void ({ i32, %tydesc*, i8*, i8*, i8 }*)*
  call void %18({ i32, %tydesc*, i8*, i8*, i8 }* %12)
  ret void
}

...

define void @_ZN4main_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }*) #4 {
"function top level":
  %o = alloca %struct.Foo
  %1 = alloca { %tydesc*, i8* }
  %__auto_borrow_obj = alloca { %tydesc*, i8* }
  %2 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %3 = bitcast i8** %2 to %struct.Foo**
  store %struct.Foo* %o, %struct.Foo** %3
  %4 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %5 = bitcast %tydesc** %4 to { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }**
  store { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }* @vtable1081, { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }** %5
  %6 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %7 = load %tydesc** %6
  %8 = getelementptr inbounds { %tydesc*, i8* }* %__auto_borrow_obj, i32 0, i32 0
  store %tydesc* %7, %tydesc** %8
  %9 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %10 = load i8** %9
  %11 = getelementptr inbounds { %tydesc*, i8* }* %__auto_borrow_obj, i32 0, i32 1
  store i8* %10, i8** %11
  call void @_ZN7callBar_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }* undef, { %tydesc*, i8* }* %__auto_borrow_obj)
  ret void
}
```

If you apply my patch, it would become way shorter and cleaner:
```
define void @_ZN7callBar_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }*, { %tydesc*, i8* }*) #4 {
"function top level":
  %2 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %3 = load i8** %2
  %4 = bitcast i8* %3 to { i32, %tydesc*, i8*, i8*, i8 }*
  %5 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %6 = bitcast %tydesc** %5 to [1 x i8*]**
  %7 = load [1 x i8*]** %6
  %8 = getelementptr inbounds [1 x i8*]* %7, i32 0, i32 1
  %9 = load i8** %8
  %10 = bitcast i8* %9 to void ({ i32, %tydesc*, i8*, i8*, i8 }*)*
  call void %10({ i32, %tydesc*, i8*, i8*, i8 }* %4)
  ret void
}

...

define void @_ZN4main_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }*) #4 {
"function top level":
  %o = alloca %struct.Foo
  %1 = alloca { %tydesc*, i8* }
  %2 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 1
  %3 = bitcast i8** %2 to %struct.Foo**
  store %struct.Foo* %o, %struct.Foo** %3
  %4 = getelementptr inbounds { %tydesc*, i8* }* %1, i32 0, i32 0
  %5 = bitcast %tydesc** %4 to { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }**
  store { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }* @vtable1081, { %tydesc*, void ({ i32, %tydesc*, i8*, i8*, i8 }*)* }** %5
  call void @_ZN7callBar_UUID.0E({ i32, %tydesc*, i8*, i8*, i8 }* undef, { %tydesc*, i8* }* %1)
  ret void
}
```

Although this change doesn't increase the compilation speed much (I mentioned only about 1-2% boost on "rustc -O -Z time-passes syntax.rs"), but I still think it's a good thing to do as it greatly simplifies/clarifies LL generated in some cases which would definitely help in the future code generation investigations.

I don't provide any new test cases in this patch as it is merely an optimization.

Sorry guys, I somehow messed my previous PR and I don't see any better way to fix as to recreate it here.
2013-09-20 07:06:13 -07:00
bors
ccb80ab4f7 auto merge of #9321 : chris-morgan/rust/lowercase-nan-methods, r=brson
This is for consistency in naming conventions.

- ``std::num::Float::NaN()`` is changed to ``nan()``;
- ``std::num::Float.is_NaN()`` is changed to ``is_nan()``; and
- ``std::num::strconv::NumStrConv::NaN()`` is changed to ``nan()``.

Fixes #9319.
2013-09-20 02:01:13 -07:00
bors
e5fdc7dee5 auto merge of #9320 : chris-morgan/rust/unreachable-macro-part-two-of-two-containing-the-destruction-of-the-unreachable-function, r=alexcrichton
This is the second of two parts of #8991, now possible as a new snapshot
has been made. (The first part implemented the unreachable!() macro; it
was #8992, 6b7b8f2682.)

``std::util::unreachable()`` is removed summarily; any code which used
it should now use the ``unreachable!()`` macro.

Closes #9312.

Closes #8991.
2013-09-20 00:36:11 -07:00
Felix S. Klock II
89b363de0c Resolves third bullet of #4691, and adds tests for it. Fix #4691. 2013-09-20 02:59:06 +02:00
bors
85c0fb7b8a auto merge of #9295 : alexcrichton/rust/fix-lang-items, r=thestinger
Also add a test to help prevent this from getting out of sync again.
2013-09-19 11:11:01 -07:00
U-NOV2010\eugals
0c3b6ad6b8 will not copy trait_callee on stack if it's source expr is a plain borrowed ref 2013-09-19 18:34:30 +04:00
U-NOV2010\eugals
dfa3f5fa8d minor Type::opaque_trait code cleanup 2013-09-19 18:34:26 +04:00
U-NOV2010\eugals
2927ab13df optimized trans_to_datum::auto_borrow_obj code generation in case some trivial cases where simple copying can be applied 2013-09-19 18:34:23 +04:00
Chris Morgan
d9874c0885 Rename the NaN and is_NaN methods to lowercase.
This is for consistency in naming conventions.

- ``std::num::Float::NaN()`` is changed to ``nan()``;
- ``std::num::Float.is_NaN()`` is changed to ``is_nan()``; and
- ``std::num::strconv::NumStrConv::NaN()`` is changed to ``nan()``.

Fixes #9319.
2013-09-19 23:59:51 +10:00
Chris Morgan
e2807a4565 Replace unreachable() calls with unreachable!().
This is the second of two parts of #8991, now possible as a new snapshot
has been made. (The first part implemented the unreachable!() macro; it
was #8992, 6b7b8f2682.)

``std::util::unreachable()`` is removed summarily; any code which used
it should now use the ``unreachable!()`` macro.

Closes #9312.

Closes #8991.
2013-09-19 15:04:03 +10:00
bors
8f65529627 auto merge of #9284 : thestinger/rust/main, r=luqmana
the real entry point will now pass the user's main function directly to
the scheduler
2013-09-18 15:05:56 -07:00
Luqman Aden
133200a6e2 libstd/librustc: Make the crate_map a weak symbol that libstd links against. 2013-09-18 17:44:04 -04:00
Luqman Aden
9621156fc3 librustc/libstd: No longer pass crate_map to start. 2013-09-18 16:51:27 -04:00
Alex Crichton
817576ee70 Register new snapshots 2013-09-18 11:07:22 -07:00
Alex Crichton
2f845a5e0a Renumber the lang items correctly
Also add a test to help prevent this from getting out of sync again.
2013-09-18 09:09:54 -07:00
bors
e02313a172 auto merge of #9275 : blake2-ppc/rust/float-from-str, r=thestinger
std: Remove {float,f64,f32}::from_str in favor of from_str in the prelude

Like issue #9209, remove float::{from_str, from_str_radix} in favor of
the two corresponding traits. The same for modules f64 and f32.

New usage is:

    from_str::<float>("1.2e34")
2013-09-18 08:01:00 -07:00
bors
9e636f106d auto merge of #9272 : luqmana/rust/esln, r=catamorphism
Fixes #9270
2013-09-18 06:45:53 -07:00
Daniel Micay
c0cc37b963 remove useless rust_main wrapper
the real entry point will now pass the user's main function directly to
the scheduler
2013-09-18 00:57:48 -04:00
blake2-ppc
b5d560a9e0 std: Remove {float,f64,f32}::from_str in favor of from_str
Like issue #9209, remove float::{from_str, from_str_radix} in favor of
the two corresponding traits. The same for modules f64 and f32.

New usage is

	from_str::<float>("1.2e34")
2013-09-18 04:02:42 +02:00
Luqman Aden
1ce657aa1f librustc: Respect #[link_name] on extern statics. Fixes #9270 2013-09-17 21:03:56 -04:00
Alex Crichton
9adcbac30d Prevent a rare linkage issue with an xcrate static
If a static is flagged as address_insignificant, then for LLVM to actually
perform the relevant optimization it must have an internal linkage type. What
this means, though, is that the static will not be available to other crates.
Hence, if you have a generic function with an inner static, it will fail to link
when built as a library because other crates will attempt to use the inner
static externally.

This gets around the issue by inlining the static into the metadata. The same
relevant optimization is then applied separately in the external crate. What
this ends up meaning is that all statics tagged with #[address_insignificant]
will appear at most once per crate (by value), but they could appear in multiple
crates.

This should be the last blocker for using format! ...
2013-09-17 11:24:05 -07:00
bors
29cdf58861 auto merge of #9244 : thestinger/rust/drop, r=catamorphism
This doesn't close any bugs as the goal is to convert the parameter to by-value, but this is a step towards being able to make guarantees about `&T` pointers (where T is Freeze) to LLVM.
2013-09-17 07:15:42 -07:00
bors
d1c05504ba auto merge of #9130 : alexcrichton/rust/inline-globals, r=thestinger
In #8185 cross-crate condition handlers were fixed by ensuring that globals
didn't start appearing in different crates with different addressed. An
unfortunate side effect of that pull request is that constants weren't inlined
across crates (uint::bits is unknown to everything but libstd).

This commit fixes this inlining by using the `available_eternally` linkage
provided by LLVM. It partially reverts #8185, and then adds support for this
linkage type. The main caveat is that not all statics could be inlined into
other crates. Before this patch, all statics were considered "inlineable items",
but an unfortunate side effect of how we deal with `&static` and `&[static]`
means that these two cases cannot be inlined across crates. The translation of
constants was modified to propogate this condition of whether a constant
should be considered inlineable into other crates.

Closes #9036
2013-09-16 23:45:49 -07:00
Daniel Micay
4e161a4d40 switch Drop to &mut self 2013-09-16 22:19:23 -04:00
Daniel Micay
1afaf0b308 set attributes on invoke instructions too
also removes the unused `FastInvoke` wrapper, as it's never actually
going to be used (we can't *partially* switch to `fastcc`, and this is
only used for Rust functions)
2013-09-16 18:30:59 -04:00
Daniel Micay
22b6f7481f document why attributes are set on CallInst 2013-09-16 13:44:04 -04:00
Daniel Micay
b2eb1c01a4 add sret + noalias to the out pointer parameter
This brings Rust in line with how `clang` handles return pointers.

Example:

    pub fn bar() -> [uint, .. 8] {
        let a = [0, .. 8];
        a
    }

Before:

    ; Function Attrs: nounwind uwtable
    define void @_ZN3bar17ha4635c6f704bfa334v0.0E([8 x i64]* nocapture, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #1 {
    "function top level":
      %a = alloca [8 x i64], align 8
      %2 = bitcast [8 x i64]* %a to i8*
      call void @llvm.memset.p0i8.i64(i8* %2, i8 0, i64 64, i32 8, i1 false)
      %3 = bitcast [8 x i64]* %0 to i8*
      call void @llvm.memcpy.p0i8.p0i8.i64(i8* %3, i8* %2, i64 64, i32 8, i1 false)
      ret void
    }

After:

    ; Function Attrs: nounwind uwtable
    define void @_ZN3bar17ha4635c6f704bfa334v0.0E([8 x i64]* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #1 {
    "function top level":
      %2 = bitcast [8 x i64]* %0 to i8*
      call void @llvm.memset.p0i8.i64(i8* %2, i8 0, i64 64, i32 8, i1 false)
      ret void
    }

Closes #9072
Closes #7298
Closes #9154
2013-09-16 13:44:04 -04:00
Daniel Micay
3c31cf25b1 fix handling of function attributes
The `noalias` attributes were being set only on function definitions,
not on all declarations. This is harmless for `noalias`, but prevented
some optimization opportunities and is *not* harmless for other
attributes like `sret` with ABI implications.

Closes #9104
2013-09-16 13:44:01 -04:00
Alex Crichton
0107028991 Resume inlining globals across crates
In #8185 cross-crate condition handlers were fixed by ensuring that globals
didn't start appearing in different crates with different addressed. An
unfortunate side effect of that pull request is that constants weren't inlined
across crates (uint::bits is unknown to everything but libstd).

This commit fixes this inlining by using the `available_eternally` linkage
provided by LLVM. It partially reverts #8185, and then adds support for this
linkage type. The main caveat is that not all statics could be inlined into
other crates. Before this patch, all statics were considered "inlineable items",
but an unfortunate side effect of how we deal with `&static` and `&[static]`
means that these two cases cannot be inlined across crates. The translation of
constants was modified to propogate this condition of whether a constant
should be considered inlineable into other crates.

Closes #9036
2013-09-16 07:29:49 -07:00
bors
d87078be72 auto merge of #9206 : alexcrichton/rust/issue-9188, r=catamorphism
While they may have the same name within various scopes, this changes static
names to use path_pretty_name to append some hash information at the end of the
symbol. We're then guaranteed that each static has a unique NodeId, so this
NodeId is as the "hash" of the pretty name.

Closes #9188
2013-09-16 02:45:49 -07:00
bors
610c0cdf11 auto merge of #9196 : alexcrichton/rust/attempting-9055, r=cmr
Beforehand it was assumed that the standard cdecl abi was used for all extern
fns of extern crates, but this reads the abi of the extern fn type and declares
the function in the local crate with the appropriate type.

I was trying to think of how to write a test for this, but I was just drawing up blanks :(. Are there standard functions in libc which are not of the cdecl abi? If so we could try linking to them and make sure that the cal completes successfully.

Otherwise, I manually verified that the function was declared correctly by looking at the llvm assembly.

cc #9055 (I'm not sure if this will fix that issue)
2013-09-16 01:30:52 -07:00
Alex Crichton
297ac739d8 When declaring extern fns from external crates, use the correct abi
Beforehand it was assumed that the standard cdecl abi was used for all extern
fns of extern crates, but this reads the abi of the extern fn type and declares
the function in the local crate with the appropriate type.
2013-09-15 20:42:06 -07:00
Daniel Micay
6d0a847c3a teach Call/CallWithConv to set attributes 2013-09-15 23:34:11 -04:00
Daniel Micay
137eb346f6 remove unused FastCall wrapper
this can just be done using CallWithConv
2013-09-15 23:26:25 -04:00
Michael Woerister
a2d5d093e0 debuginfo: Some namespace-related cleanup. 2013-09-15 12:28:25 +02:00
Michael Woerister
c3ffbc3151 debuginfo: Fix style nits for pull request. 2013-09-15 12:28:25 +02:00
Michael Woerister
ccb721a58d debuginfo: Added description of algorithm for handling recursive types.
Also fixed nasty bug caused by calling LLVMDIBuilderCreateStructType() with a null pointer where an empty array was expected (which would trigger an unintelligable assertion somewhere down the line).
2013-09-15 12:28:25 +02:00
Michael Woerister
f85da506a8 debuginfo: Support for recursive types. 2013-09-15 12:28:25 +02:00
Michael Woerister
206cc59f46 debuginfo: Implement DI for ty_opaque_box. 2013-09-15 12:28:25 +02:00
Michael Woerister
bf37de9fc6 debuginfo: Basic support for trait objects. 2013-09-15 12:28:25 +02:00
Alex Crichton
1da4488d87 Guarantee that statics have unique names
While they may have the same name within various scopes, this changes static
names to use path_pretty_name to append some hash information at the end of the
symbol. We're then guaranteed that each static has a unique NodeId, so this
NodeId is as the "hash" of the pretty name.

Closes #9188
2013-09-14 23:19:11 -07:00
bors
9792ec6da7 auto merge of #9174 : thestinger/rust/bot, r=catamorphism
An expression such as `bottom == not_bottom` or `not_bottom == bottom`
already compiled, but this fixes the case where both sides are `bottom`.
2013-09-14 06:15:52 -07:00
bors
3d469c25e5 auto merge of #9162 : alexcrichton/rust/issue-9123, r=catamorphism
Closes #9123
2013-09-14 03:45:56 -07:00
bors
2aa578efd9 auto merge of #9115 : erickt/rust/master, r=erickt
This is a series of patches to modernize option and result. The highlights are:

* rename `.unwrap_or_default(value)` and etc to `.unwrap_or(value)`
* add `.unwrap_or_default()` that uses the `Default` trait
* add `Default` implementations for vecs, HashMap, Option
* add  `Option.and(T) -> Option<T>`, `Option.and_then(&fn() -> Option<T>) -> Option<T>`, `Option.or(T) -> Option<T>`, and `Option.or_else(&fn() -> Option<T>) -> Option<T>`
* add `option::ToOption`, `option::IntoOption`, `option::AsOption`, `result::ToResult`, `result::IntoResult`, `result::AsResult`, `either::ToEither`, and `either::IntoEither`, `either::AsEither`
* renamed `Option::chain*` and `Result::chain*` to `and_then` and `or_else` to avoid the eventual collision with `Iterator.chain`.
* Added a bunch of impls of `Default`
* Added a `#[deriving(Default)]` syntax extension
* Removed impls of `Zero` for `Option<T>` and vecs.
2013-09-14 00:01:04 -07:00
bors
a241deb979 auto merge of #9173 : thestinger/rust/offset, r=alexcrichton
This was intended to always use inbounds pointer arithmetic now.
2013-09-13 18:00:58 -07:00
Daniel Micay
298f06f267 make ! support the equality/ordering operators
An expression such as `bottom == not_bottom` or `not_bottom == bottom`
already compiled, but this fixes the case where both sides are `bottom`.
2013-09-13 17:31:59 -04:00
Daniel Micay
2dec95e417 ptr: fix offset intrinsic
This was intended to always use inbounds pointer arithmetic now.
2013-09-13 17:14:24 -04:00
Daniel Micay
1ac37d50c0 set sret attribute as needed on call instructions
Since function pointers do not carry along the function attributes with
them in the type, this needs to be set on the call instruction itself.

Closes #9152
2013-09-13 12:34:25 -04:00
Alex Crichton
62ba835573 Translate nested items in default methods
Closes #9123
2013-09-13 01:42:44 -07:00
Erick Tryzelaar
7f9c5aae9e std: Restore Option::chain{,_mut}_ref as and_then{,_mut}_ref 2013-09-12 18:54:28 -07:00
Erick Tryzelaar
38f97ea103 std: Rename {Option,Result}::chain{,_err}* to {and_then,or_else} 2013-09-12 18:54:13 -07:00
Erick Tryzelaar
e6c11313c8 std: Add Option.{result_or_default,or_default} that uses Default 2013-09-12 18:54:12 -07:00
Erick Tryzelaar
45c62c08f9 std: rename Option::unwrap_or_default() to unwrap_or() 2013-09-12 18:54:11 -07:00
Brian Anderson
0c89183e80 rustc: Fix cstack lint for default methods. Closes #8753 2013-09-12 15:21:01 -07:00
bors
cabba6b4d3 auto merge of #9136 : thestinger/rust/ptr, r=alexcrichton
This is mostly for consistency, as you can now compare raw pointers in
constant expressions or without the standard library.

It also reduces the number of `ptrtoint` instructions in the IR, making
tracking down culprits of what's usually an anti-pattern easier.
2013-09-12 13:10:55 -07:00
Daniel Micay
b7435cf447 implement raw pointer comparisons in librustc
This is mostly for consistency, as you can now compare raw pointers in
constant expressions or without the standard library.

It also reduces the number of `ptrtoint` instructions in the IR, making
tracking down culprits of what's usually an anti-pattern easier.
2013-09-12 01:58:39 -04:00
John Clements
e9832d44df ident->name cleanup 2013-09-11 22:18:45 -07:00
John Clements
f576ed0c76 fix for bug #9110 2013-09-11 22:18:45 -07:00
SiegeLord
8c5402fd36 Properly encode/decode structural variants. 2013-09-11 14:49:09 -04:00
bors
67ed30cd5e auto merge of #9097 : michaelwoerister/rust/namespaces, r=jdm
Who would have thought that namespaces are such a can of worms `:P` This is mostly because of some GDB idiosyncrasies (does not use namespace information but linkage-name attributes for displaying items contained in namespaces, also cannot handle functions lexically nested within functions), monomorphization, and information about external items only available from metadata.

This pull request tries to tackle the problem anyway:
* The `DW_AT_linkage_name` for functions is generated just to make GDB display a proper namespace-enabled function name. To this end, a pseudo-mangled name is generated, not corresponding to the real linkage name. This approach shows some success and could be extended to make GDB also show proper parameter types.
* As GDB won't accept subprogram DIEs nested within other subprogram DIEs, the `debuginfo` module now generates a *companion namespace* for each functions (iff needed). A function `fn abc()` will get a companion namespace with name `abc()`, which contains all items (modules, types, functions) declared within the functions scope. The real, proper solution, in my opinion, would be to faithfully reflect the program's lexical structure within DWARF (which allows arbitrary nesting of DIEs, afaik), but I am not sure LLVM's source level debugging implementation would like that and I am pretty sure GDB won't support this in the foreseeable future.
* Monomorphization leads to functions and companion namespaces like `somelib::some_func<int, float>()::some_other_function<bool, bool, bool>()`, which I think is the desired behaviour. There is some design space here, however. Maybe you people prefer `somelib::some_func()::some_other_function<bool, bool, bool>()` or `somelib::some_func()::some_other_function::<int, float, bool, bool, bool>()`.

The solution will work for now but there are a few things on my 'far future wish list':
* A real specification somewhere, what language constructs are mapped to what DWARF structures.
* Proper tests that directly compare the generated DWARF information to the expected results (possibly using something like [pyelftools](https://github.com/eliben/pyelftools) or llvm-dwarfdump)
* A unified implementation for crate-local and crate-external items (which would possibly involve beefing up `ast_map::path` and metadata a bit)

Any comments are welcome!

Closes #1541
Closes #1542 (there might be other issues with function name prettiness, but this specific issue should be fixed)
Closes #7715 (source locations for structs and enums are now read correctly from the AST)
2013-09-11 06:26:05 -07:00