Commit Graph

31191 Commits

Author SHA1 Message Date
nham
3f1c37e96d Small fixes for tests 2014-07-26 12:06:52 -04:00
bors
7aa407958b auto merge of #15998 : luqmana/rust/nmnnbd, r=thestinger
LLVM recently added a new attribute, dereferenceable: http://reviews.llvm.org/D4449

>This patch adds a dereferencable attribute. In some sense, this is a companion to the nonnull attribute, but specifies that the pointer is known to be dereferencable in the same sense as a pointer generated by alloca is known to be dereferencable.

With rust, everywhere that we previously marked `nonnull` we can actually mark as `dereferenceable` (which implies nonnull) since we know the size. That is, except for one case: when generating calls for TyVisitor. It seems like we haven't substituted the self type (so we have `ty_param`) and just treat it as an opaque pointer so I just left that bit as nonnull.

With this, LLVM can for example hoist a load out of a loop where it previously couldn't:

```Rust
pub fn baz(c: &uint, n: uint) -> uint {
    let mut res = 0;
    for i in range(0, n) {
        if i > 0 {
            res += *c * i;
        }
    }
    res
}
```

Before:
```llvm
define i64 @baz(i64* noalias nocapture nonnull readonly, i64) unnamed_addr #0 {
entry-block:
  br label %for_loopback.outer

for_loopback.outer:                               ; preds = %then-block-33-, %entry-block
  %.ph = phi i64 [ %.lcssa, %then-block-33- ], [ 0, %entry-block ]
  %res.0.ph = phi i64 [ %8, %then-block-33- ], [ 0, %entry-block ]
  br label %for_loopback

for_exit:                                         ; preds = %for_loopback
  %res.0.ph.lcssa = phi i64 [ %res.0.ph, %for_loopback ]
  ret i64 %res.0.ph.lcssa

for_loopback:                                     ; preds = %for_loopback.outer, %for_body
  %2 = phi i64 [ %4, %for_body ], [ %.ph, %for_loopback.outer ]
  %3 = icmp ult i64 %2, %1
  br i1 %3, label %for_body, label %for_exit

for_body:                                         ; preds = %for_loopback
  %4 = add i64 %2, 1
  %5 = icmp eq i64 %2, 0
  br i1 %5, label %for_loopback, label %then-block-33-

then-block-33-:                                   ; preds = %for_body
  %.lcssa = phi i64 [ %4, %for_body ]
  %.lcssa15 = phi i64 [ %2, %for_body ]
  %6 = load i64* %0, align 8                     ; <------- this load
  %7 = mul i64 %6, %.lcssa15
  %8 = add i64 %7, %res.0.ph
  br label %for_loopback.outer
}
```

After:
```llvm
define i64 @baz(i64* noalias nocapture readonly dereferenceable(8), i64) unnamed_addr #0 {
entry-block:
  %2 = load i64* %0, align 8                    ; <------- load once instead
  br label %for_loopback.outer

for_loopback.outer:                               ; preds = %then-block-33-, %entry-block
  %.ph = phi i64 [ %.lcssa, %then-block-33- ], [ 0, %entry-block ]
  %res.0.ph = phi i64 [ %8, %then-block-33- ], [ 0, %entry-block ]
  br label %for_loopback

for_exit:                                         ; preds = %for_loopback
  %res.0.ph.lcssa = phi i64 [ %res.0.ph, %for_loopback ]
  ret i64 %res.0.ph.lcssa

for_loopback:                                     ; preds = %for_loopback.outer, %for_body
  %3 = phi i64 [ %5, %for_body ], [ %.ph, %for_loopback.outer ]
  %4 = icmp ult i64 %3, %1
  br i1 %4, label %for_body, label %for_exit

for_body:                                         ; preds = %for_loopback
  %5 = add i64 %3, 1
  %6 = icmp eq i64 %3, 0
  br i1 %6, label %for_loopback, label %then-block-33-

then-block-33-:                                   ; preds = %for_body
  %.lcssa = phi i64 [ %5, %for_body ]
  %.lcssa15 = phi i64 [ %3, %for_body ]
  %7 = mul i64 %2, %.lcssa15
  %8 = add i64 %7, %res.0.ph
  br label %for_loopback.outer
}
```
2014-07-26 15:46:18 +00:00
bors
50c62b4667 auto merge of #15996 : nham/rust/smallintmap_not_hashmap, r=sanxiyn
SmallIntMap doesn't involve hashing?
2014-07-26 14:01:22 +00:00
Guillaume Pinot
92792248c1 Relicense shootout-k-nucleotide.rs
Everyone agreed except @thestinger. As @thestinger contribution on this file is trivial,
we can relicense it.

Related to #14248, close #15330
2014-07-26 15:06:40 +02:00
bors
ee21b009bb auto merge of #15991 : pcwalton/rust/resolve-regions-in-trait-matching, r=alexcrichton
matching.

This breaks code like:

    struct Foo<'a,'b> {
        x: &'a int,
        y: &'b int,
    }

    trait Tr {
        fn foo(x: Self) {}
    }

    impl<'a,'b> Tr for Foo<'a,'b> {
        fn foo(x: Foo<'b,'a>) {} // <-- bad
    }

Change this code to not contain a lifetime mismatch error. For example:

    struct Foo<'a,'b> {
        x: &'a int,
        y: &'b int,
    }

    trait Tr {
        fn foo(x: Self) {}
    }

    impl<'a,'b> Tr for Foo<'a,'b> {
        fn foo(x: Foo<'a,'b>) {} // OK
    }

Closes #15517.

[breaking-change]

r? @alexcrichton
2014-07-26 12:16:21 +00:00
bors
0d53597ce2 auto merge of #15988 : brson/rust/antlrprep, r=cmr
Add `check-secondary`, which runs the pretty and lexer tests so we can run them on a dedicated bot. Leaves the pretty tests running under `check` until the bots are switched over. Also fixes some issues.

r? @cmr
2014-07-26 10:31:23 +00:00
bors
cf61980db2 auto merge of #15987 : brson/rust/hidestdrt, r=alexcrichton
Rename and gensym the runtime on import, so that users
can't refer to the `native` crate.

This is unlikely to break code, but users should import the "native" crate directly.

[breaking-change]

cc @alexcrichton
2014-07-26 08:46:21 +00:00
bors
c0fa8764ef auto merge of #15982 : alexcrichton/rust/rustdoc-fixes, r=brson
Sadly there's still a lot of open issues, but this tackles some of the more pressing ones. Each commit has its own description along with the issues it closes.
2014-07-26 06:56:23 +00:00
Michael Matuzak
ca18c12243 fix small typo in guide-lifetimes 2014-07-25 21:13:39 -07:00
bors
34a6a8fc59 auto merge of #15975 : dotdash/rust/unwind_lifetimes, r=pcwalton
Currently we don't emit lifetime end markers when translating the
unwinding code. I omitted that when I added the support for lifetime
intrinsics, because I initially made the mistake of just returning true
in clean_on_unwind(). That caused almost all calls to be translated as
invokes, leading to quite awful results.

To correctly emit the lifetime end markers, we must differentiate
between cleanup that requires unwinding and such cleanup that just wants
to emit code during unwinding.
2014-07-26 03:31:22 +00:00
Luqman Aden
a78c0f1019 rustllvm: Stub out some functions for llvm < 3.5 2014-07-25 19:47:29 -07:00
nham
b2e81d1618 Fix a typo in SmallIntMap documentation 2014-07-25 21:40:47 -04:00
nham
1e997d62b7 Implement PartialEq/Eq/Clone/Hash/FromIterator/Extendable for SmallIntMap and Show/Clone for TrieMap and TrieSet 2014-07-25 21:34:01 -04:00
Luqman Aden
e10d674de0 librustc: Use dereferenceable attribute instead of nonnull where we can. 2014-07-25 18:33:10 -07:00
bors
cf1381c1d0 auto merge of #15789 : steveklabnik/rust/guide_pointers, r=cmr
This is super, super WIP, but I'm going to go get lunch for a while, and figured I'd toss my work up here in case anyone wants to see my work as I do it.

This contains a new introductory section explaining the basics of pointers, and some pitfalls that Rust attempts to solve. I'd be interested in hearing how my explanation is, as well as if this belongs here. Pointers are such a crucial concept, I don't mind having a beginners' section on them in the main docs, even though our main audience is supposed to understand them already. Reasonable people may disagree, however.
2014-07-26 00:46:16 +00:00
Brian Anderson
6e03944dde Add tests that the injected runtime is inaccessible 2014-07-25 16:54:09 -07:00
Luqman Aden
17256197a9 librustc: Use builder for llvm attributes. 2014-07-25 16:06:44 -07:00
bors
92c97059ff auto merge of #15787 : treeman/rust/hashmap-doc, r=alexcrichton
Add an example showing how to use the map with a custom type. Fill in
examples for methods  without ones.

Also move `pop_equiv` next to related public methods, to not create a
duplicate trait in the docs.
2014-07-25 23:01:16 +00:00
Patrick Walton
5de8ed541a librustc: Resolve regions and report errors in trait/impl method
matching.

This breaks code like:

    struct Foo<'a,'b> {
        x: &'a int,
        y: &'b int,
    }

    trait Tr {
        fn foo(x: Self) {}
    }

    impl<'a,'b> Tr for Foo<'a,'b> {
        fn foo(x: Foo<'b,'a>) {} // <-- bad
    }

Change this code to not contain a lifetime mismatch error. For example:

    struct Foo<'a,'b> {
        x: &'a int,
        y: &'b int,
    }

    trait Tr {
        fn foo(x: Self) {}
    }

    impl<'a,'b> Tr for Foo<'a,'b> {
        fn foo(x: Foo<'a,'b>) {} // OK
    }

Closes #15517.

[breaking-change]
2014-07-25 15:58:01 -07:00
Brian Anderson
53f0eae386 Revert "Use fewer instructions for fail!"
This reverts commit c61f9763e2.

Conflicts:
	src/librustrt/unwind.rs
	src/libstd/macros.rs
2014-07-25 15:57:15 -07:00
Brian Anderson
cf7a89f0c0 std: Use correct conventions for statics in macros 2014-07-25 15:54:56 -07:00
Brian Anderson
a43e7d5cb9 core: Remove unneeded cfgs 2014-07-25 15:54:10 -07:00
Patrick Walton
b2eb88843d librustc: Disallow mutation and assignment in pattern guards, and modify
the CFG for match statements.

There were two bugs in issue #14684. One was simply that the borrow
check didn't know about the correct CFG for match statements: the
pattern must be a predecessor of the guard. This disallows the bad
behavior if there are bindings in the pattern. But it isn't enough to
prevent the memory safety problem, because of wildcards; thus, this
patch introduces a more restrictive rule, which disallows assignments
and mutable borrows inside guards outright.

I discussed this with Niko and we decided this was the best plan of
action.

This breaks code that performs mutable borrows in pattern guards. Most
commonly, the code looks like this:

    impl Foo {
        fn f(&mut self, ...) {}
        fn g(&mut self, ...) {
            match bar {
                Baz if self.f(...) => { ... }
                _ => { ... }
            }
        }
    }

Change this code to not use a guard. For example:

    impl Foo {
        fn f(&mut self, ...) {}
        fn g(&mut self, ...) {
            match bar {
                Baz => {
                    if self.f(...) {
                        ...
                    } else {
                        ...
                    }
                }
                _ => { ... }
            }
        }
    }

Sometimes this can result in code duplication, but often it illustrates
a hidden memory safety problem.

Closes #14684.

[breaking-change]
2014-07-25 15:26:21 -07:00
Brian Anderson
3382ffef32 mk: Print grammar info message like others 2014-07-25 14:32:34 -07:00
Brian Anderson
ae97e6f8d3 mk: Remove check-syntax target
This appears to be redundantly named with a shortcut target for
testing the syntax crate.
2014-07-25 14:28:55 -07:00
Brian Anderson
8f692e6ab0 rustc: Future proof runtime injection
Rename and gensym the runtime on import, so that users
can't refer to the `native` crate.

This is unlikely to break code, but users should import the "native" crate directly.

[breaking-change]
2014-07-25 14:17:28 -07:00
bors
66a0b528a6 auto merge of #15979 : Randati/rust/patch-2, r=kballard 2014-07-25 20:36:10 +00:00
bors
74db69995a auto merge of #15968 : nham/rust/keys_values_other_maps, r=alexcrichton
Adds methods for obtaining iterators over the keys or values of a SmallIntMap/TreeMap/TrieMap.

Closes #14376
2014-07-25 18:51:09 +00:00
Alex Crichton
98f48630fc rustdoc: Inline items from foreign mods
These were all just previously skipped.

Closes #15648
2014-07-25 10:37:23 -07:00
Alex Crichton
8d7eb0598a rustdoc: Correctly handle local renamings
Previously a `pub use` would not rename the destination in rustdoc, it would
always use the destination ident instead of the renamed ident.
2014-07-25 10:24:29 -07:00
Alex Crichton
431622e1e2 rustdoc: Fix links to Box/Gc
These are lang items now, so the internal representations need to be
re-translated back to the original structures manually.

Closes #15185
Closes #15800
2014-07-25 10:24:26 -07:00
Alex Crichton
15a727bba1 rustdoc: Fix inlining type parameters
I'm not entirely sure if the correct space can be inferred when cleaning
Generics, so the impl has been switched to take the space explicitly.

Closes #15099
2014-07-25 09:07:20 -07:00
Alex Crichton
80efb220e0 rustdoc: Bind keydown instead of keypress for nav
Apparently keypress doesn't quite work in all browsers due to some not invoking
the handler and jquery not setting the right `which` field in all circumstances.
According to http://stackoverflow.com/questions/2166771 switching over to
`keydown` works and it appears to do the trick. Tested in Safari, Firefox, and
Chrome.

Closes #15011
2014-07-25 08:56:00 -07:00
bors
d30776ec24 auto merge of #15958 : hirschenberger/rust/borrock-stats-div-by-zero, r=alexcrichton
`rustc -Z borrowck-stats` displays ugly `-NaN%` in the stats

```
paths requiring guarantees: 0
paths requiring loans     : 0 (-NaN%)
paths requiring imm loans : 0 (-NaN%)
stable paths              : 0 (-NaN%)
```
2014-07-25 15:41:08 +00:00
Alex Crichton
724bcec089 rustdoc: Hide impls for #[doc(hidden)] traits
Closes #14585
2014-07-25 08:26:17 -07:00
Randati
c7700077a1 Fix assert message 2014-07-25 18:12:21 +03:00
Alex Crichton
51355478f4 rustdoc: Add a --target flag
Closes #13893
2014-07-25 07:55:25 -07:00
bors
7ff5bbd494 auto merge of #15971 : alexcrichton/rust/hurray-for-windows, r=pcwalton
The right hand side of the comparison in these checks are values of type
Option<&Path> which are normalized versions of the left-hand side, so they're
not guaranteed to be byte-for-byte equivalent even though they're the same path.

For this reasons, the command line arguments are promoted to paths for
comparison of equality.

This fixes a bug on windows where if a library was specified with --extern it
would then be picked up twice because it was not considered to have been
previously registered.
2014-07-25 13:56:08 +00:00
Björn Steinbrink
b13cad3a9c Emit lifetime end markers in unwinding codepaths
Currently we don't emit lifetime end markers when translating the
unwinding code. I omitted that when I added the support for lifetime
intrinsics, because I initially made the mistake of just returning true
in clean_on_unwind(). That caused almost all calls to be translated as
invokes, leading to quite awful results.

To correctly emit the lifetime end markers, we must differentiate
between cleanup that requires unwinding and such cleanup that just wants
to emit code during unwinding.
2014-07-25 14:31:05 +02:00
bors
44019c79e0 auto merge of #15970 : Zoxc/rust/noalias-ref, r=cmr
This add the LLVM noalias attribute to parameters of a
shared reference type (&) which have a safe interior.
2014-07-25 12:11:08 +00:00
bors
470dbef29a auto merge of #15957 : pcwalton/rust/builtin-bound-impl-checking, r=huonw,pnkfelix
method calls are involved.

This breaks code like:

    impl<T:Copy> Foo for T { ... }

    fn take_param<T:Foo>(foo: &T) { ... }

    fn main() {
        let x = box 3i; // note no `Copy` bound
        take_param(&x);
    }

Change this code to not contain a type error. For example:

    impl<T:Copy> Foo for T { ... }

    fn take_param<T:Foo>(foo: &T) { ... }

    fn main() {
        let x = 3i; // satisfies `Copy` bound
        take_param(&x);
    }

Closes #15860.

[breaking-change]

r? @alexcrichton
2014-07-25 09:31:10 +00:00
Patrick Walton
f1520ea0cf librustc: Check built-in trait bounds on implementations when direct
method calls are involved.

This breaks code like:

    impl<T:Copy> Foo for T { ... }

    fn take_param<T:Foo>(foo: &T) { ... }

    fn main() {
        let x = box 3i; // note no `Copy` bound
        take_param(&x);
    }

Change this code to not contain a type error. For example:

    impl<T:Copy> Foo for T { ... }

    fn take_param<T:Foo>(foo: &T) { ... }

    fn main() {
        let x = 3i; // satisfies `Copy` bound
        take_param(&x);
    }

Closes #15860.

[breaking-change]
2014-07-25 00:50:35 -07:00
bors
e5984640e6 auto merge of #15961 : pcwalton/rust/fn-pointer-in-iterator, r=huonw
This breaks code like:

    struct A<'a> {
        func: &'a fn() -> Option<int>
    }

    fn foo() -> Option<int> { ... }

    fn create() -> A<'static> {
        A {
            func: &foo
        }
    }

Change this code to not take functions by reference. For example:

    struct A {
        func: extern "Rust" fn() -> Option<int>
    }

    fn foo() -> Option<int> { ... }

    fn create() -> A {
        A {
            func: foo
        }
    }

Closes #13595.

[breaking-change]

r? @huonw
2014-07-25 07:46:12 +00:00
Brian Anderson
f7ab07c780 Put the struct passed to unwinding functions into a static
Produces very clean asm, but makes bigger binaries.
2014-07-25 00:40:58 -07:00
Brian Anderson
4636b32a42 Make most of the failure functions take &(&'static str, uint)
Passing one pointer takes less code than one pointer and an integer.
2014-07-25 00:02:29 -07:00
bors
4e388859a2 auto merge of #15959 : omasanori/rust/cleanup-ja, r=alexcrichton
The translation is based on an early version of tutorial.md, thus most
of entries have been marked as fuzzy and actually they are incorrect.
Now tutorial.md is planed to be replaced with guide.md, so I'd suggest
removing translation files for a while.

/cc @gifnksm
2014-07-25 06:01:13 +00:00
Alex Crichton
bd838a3b7e rustc: Compare paths with --extern, not bytes
The right hand side of the comparison in these checks are values of type
Option<&Path> which are normalized versions of the left-hand side, so they're
not guaranteed to be byte-for-byte equivalent even though they're the same path.

For this reasons, the command line arguments are promoted to paths for
comparison of equality.

This fixes a bug on windows where if a library was specified with --extern it
would then be picked up twice because it was not considered to have been
previously registered.
2014-07-24 22:41:52 -07:00
John Kåre Alsaker
4c2d4cd3de Add noalias to safe shared reference parameters
This add the LLVM noalias attribute to parameters of a
shared reference type (&) which have a safe interior.
2014-07-25 07:29:12 +02:00
nham
74b1aed0ec Add methods for obtaining iterators over the keys and values of a TrieMap 2014-07-25 01:14:49 -04:00
nham
0b339e09ab Add methods for obtaining iterators over the keys and values of a SmallIntMap 2014-07-25 00:48:05 -04:00