Commit Graph

26463 Commits

Author SHA1 Message Date
Huon Wilson
a39056e614 std: convert first_non_utf8_byte to use the iterator.
This makes it very slightly faster, especially when the string is valid
UTF-8, and completely removes the use of `unsafe` from the first half.

Before:

    from_utf8_lossy_100_ascii              ... bench:       151 ns/iter (+/- 17)
    from_utf8_lossy_100_invalid            ... bench:       447 ns/iter (+/- 33)
    from_utf8_lossy_100_multibyte          ... bench:       135 ns/iter (+/- 4)
    from_utf8_lossy_invalid                ... bench:       124 ns/iter (+/- 10

After:

    from_utf8_lossy_100_ascii              ... bench:       119 ns/iter (+/- 8)
    from_utf8_lossy_100_invalid            ... bench:       454 ns/iter (+/- 16)
    from_utf8_lossy_100_multibyte          ... bench:       116 ns/iter (+/- 9)
    from_utf8_lossy_invalid                ... bench:       119 ns/iter (+/- 9)
2014-02-18 21:55:53 +11:00
Huon Wilson
a68d10e6ad std::str: safen and optimize is_utf8.
This uses a vector iterator to avoid the necessity for unsafe indexing,
and makes this function slightly faster. Unfortunately #11751 means that
the iterator comes with repeated `null` checks which means the
pure-ASCII case still has room for significant improvement (and the
other cases too, but it's most significant for just ASCII).

Before:

    is_utf8_100_ascii             ... bench:       143 ns/iter (+/- 6)
    is_utf8_100_multibyte         ... bench:       134 ns/iter (+/- 4)

After:

    is_utf8_100_ascii             ... bench:       123 ns/iter (+/- 4)
    is_utf8_100_multibyte         ... bench:       115 ns/iter (+/- 5)
2014-02-18 21:55:53 +11:00
bors
c8489069b4 auto merge of #12085 : alexcrichton/rust/issue-12082, r=brson
This just copies the libuv implementation for libnative which seems reasonable
enough (uid/gid fail on windows).

Closes #12082
2014-02-16 16:46:39 -08:00
Alex Crichton
74b42c646e Upgrade libuv
This notably includes joyent/libuv@6f62d62c in order to fix when processes fail
to spawn on windows
2014-02-16 16:01:03 -08:00
Alex Crichton
553b7e67d7 Allow configuration of uid/gid/detach on processes
This just copies the libuv implementation for libnative which seems reasonable
enough (uid/gid fail on windows).

Closes #12082
2014-02-16 16:01:03 -08:00
bors
425f57477f auto merge of #12319 : SimonSapin/rust/build-symlink, r=alexcrichton 2014-02-16 12:51:40 -08:00
bors
13dc521861 auto merge of #12312 : brson/rust/doc, r=alexcrichton
Only single out std. Put everything else in a consistent list.
2014-02-16 11:36:40 -08:00
bors
0ba6d4885f auto merge of #12313 : bjz/rust/tuple, r=huonw
This renames the `n*` and `n*_ref` tuple getters to `val*` and `ref*` respectively, and adds `mut*` getters. It also removes the `CloneableTuple` and `ImmutableTuple` traits.
2014-02-16 07:11:34 -08:00
Brendan Zabarauskas
f450b2b379 Remove CloneableTuple and ImmutableTuple traits
These are adequately covered by the Tuple2 trait.
2014-02-17 00:57:56 +11:00
Brendan Zabarauskas
cf0654c47c Improve naming of tuple getters, and add mutable tuple getter
Renames the `n*` and `n*_ref` tuple getters to `val*` and `ref*` respectively, and adds `mut*` getters.
2014-02-17 00:57:56 +11:00
Simon Sapin
3a66548979 Ignore /build even if it’s a symlink. 2014-02-16 12:41:41 +00:00
Brendan Zabarauskas
2cd7a29013 Merge ImmutableTuple* traits into their respective Tuple* trait 2014-02-16 20:25:28 +11:00
bors
6fe775e2b5 auto merge of #12310 : brson/rust/mkfilecleanup, r=sfackler
Two small fixes
2014-02-16 00:51:33 -08:00
Brian Anderson
58a2b7da07 doc: Reorganize the library index
Only single out std. Put everything else in a consistent list.
2014-02-16 00:21:08 -08:00
Brendan Zabarauskas
6f39eb1a56 Delegate ToStr implementation to Show for tuples 2014-02-16 19:12:28 +11:00
Brendan Zabarauskas
bf6abf8cb3 Implement Show for 1-12 element tuples 2014-02-16 19:12:28 +11:00
bors
b36340b626 auto merge of #12302 : alexcrichton/rust/issue-12295, r=brson
The previous code erroneously assumed that 'steals > cnt' was always true, but
that was a false assumption. The code was altered to decrement steals to a
minimum of 0 instead of taking all of cnt into account.

I didn't include the exact test from #12295 because it could run for quite
awhile, and instead set the threshold for MAX_STEALS to much lower during
testing. I found that this triggered the old bug quite frequently when running
without this fix.

Closes #12295
2014-02-15 23:36:26 -08:00
Brian Anderson
58678dc229 mk: Fix typo, NO_MAKEFILE_DEPS -> NO_MKFILE_DEPS 2014-02-15 23:12:56 -08:00
Brian Anderson
109673f368 mk: Remove check-notidy, check-full, check-test
Mostly useless
2014-02-15 23:11:56 -08:00
bors
5d4fd50af3 auto merge of #12301 : FlaPer87/rust/issue-8893, r=alexcrichton 2014-02-15 22:06:27 -08:00
bors
f3d4fe7500 auto merge of #12305 : luqmana/rust/ub, r=sfackler
These are no longer valid options as of the recent llvm upgrade.
2014-02-15 20:46:26 -08:00
bors
49ba513c78 auto merge of #12299 : sfackler/rust/limit-return, r=alexcrichton
This is useful in contexts like this:

```rust
let size = rdr.read_be_i32() as uint;
let mut limit = LimitReader::new(rdr.by_ref(), size);
let thing = read_a_thing(&mut limit);
assert!(limit.limit() == 0);
```
2014-02-15 18:56:29 -08:00
Luqman Aden
615536a265 mk: Remove old flags to llc for arm. 2014-02-15 20:08:33 -05:00
bors
0c62d9d83d auto merge of #12298 : alexcrichton/rust/rustdoc-testing, r=sfackler
It's too easy to forget the `rust` tag to test something.

Closes #11698
2014-02-15 16:36:27 -08:00
Alex Crichton
bea7862d94 Correctly reset steals when hitting MAX_STEALS
The previous code erroneously assumed that 'steals > cnt' was always true, but
that was a false assumption. The code was altered to decrement steals to a
minimum of 0 instead of taking all of cnt into account.

I didn't include the exact test from #12295 because it could run for quite
awhile, and instead set the threshold for MAX_STEALS to much lower during
testing. I found that this triggered the old bug quite frequently when running
without this fix.

Closes #12295
2014-02-15 15:54:29 -08:00
Alex Crichton
836ffb5288 Silence some unused import warnings 2014-02-15 15:53:52 -08:00
bors
d98668a559 auto merge of #12235 : huonw/rust/raii-lock, r=alexcrichton
- adds a `LockGuard` type returned by `.lock` and `.trylock` that unlocks the mutex in the destructor
- renames `mutex::Mutex` to `StaticNativeMutex` 
- adds a `NativeMutex` type with a destructor
- removes `LittleLock`
- adds `#[must_use]` to `sync::mutex::Guard` to remind people to use it
2014-02-15 15:21:28 -08:00
Huon Wilson
4668cdf3c4 Convert some unnecessary StaticNativeMutexes to NativeMutexes. 2014-02-16 10:13:56 +11:00
Huon Wilson
5d86e24ab2 std::unstable::mutex: streamline & clarify documentation. 2014-02-16 10:13:56 +11:00
Huon Wilson
0f4294b4e2 sync: Add #[must_use] to the Mutex guard.
This helps people remember to save the return value to keep the mutex
locked as appropriate.
2014-02-16 10:13:56 +11:00
Huon Wilson
0937f65999 std: add a NativeMutex type as a wrapper to destroy StaticNativeMutex.
This obsoletes LittleLock, and so it is removed.
2014-02-16 10:13:56 +11:00
Huon Wilson
b87ed605c0 std: Rename unstable::mutex::Mutex to StaticNativeMutex.
This better reflects its purpose and design.
2014-02-16 10:13:56 +11:00
Huon Wilson
75d92dbabe std: add tests for the _noguard lock/signal/wait methods on Mutex. 2014-02-16 10:13:56 +11:00
Huon Wilson
76a59fd6e2 std: add an RAII unlocker to Mutex.
This automatically unlocks its lock when it goes out of scope, and
provides a safe(ish) method to call .wait.
2014-02-16 10:13:56 +11:00
Flavio Percoco
fd57717b16 Add test and close #8893 2014-02-16 00:00:38 +01:00
Steven Fackler
23fdbcf7dd Add a method to LimitReader to return the limit
This is useful in contexts like this:

let size = rdr.read_be_i32() as uint;
let mut limit = LimitReader::new(rdr.by_ref(), size);
let thing = read_a_thing(&mut limit);
assert!(limit.limit() == 0);
2014-02-15 14:22:56 -08:00
bors
6b025c803c auto merge of #12272 : alexcrichton/rust/snapshot, r=kballard
This notably contains the `extern mod` => `extern crate` change.

Closes #9880
2014-02-15 14:06:26 -08:00
bors
4af28c98fa auto merge of #12296 : dotdash/rust/byval_noalias, r=cmr
Function parameters that are to be passed by value but don't fit into a
single register are currently passed by creating a copy on the stack and
passing a pointer to that copy to the callee. Since the copy is made
just for the function call, there are no aliases.

For example, this sometimes allows LLVM to eliminate unnecessary calls
to drop glue. Given

````rust
struct Foo {
    a: int,
    b: Option<~str>,
}

extern {
    fn eat(eat: Option<~str>);
}

pub fn foo(v: Foo) {
    match v {
        Foo { a: _, b } => unsafe { eat(b) }
    }
}
````

LLVM currently can't eliminate the drop call for the string, because it
only sees a _pointer_ to Foo, for which it has to expect an alias. So we
get:

````llvm
; Function Attrs: uwtable
define void @_ZN3foo20h9f32c90ae7201edbxaa4v0.0E(%struct.Foo* nocapture) unnamed_addr #0 {
"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit":
  %1 = getelementptr inbounds %struct.Foo* %0, i64 0, i32 1, i32 0
  %2 = load { i64, i64, [0 x i8] }** %1, align 8
  store { i64, i64, [0 x i8] }* null, { i64, i64, [0 x i8] }** %1, align 8
  %3 = ptrtoint { i64, i64, [0 x i8] }* %2 to i64
  %.fca.0.insert = insertvalue { i64 } undef, i64 %3, 0
  tail call void @eat({ i64 } %.fca.0.insert)
  %4 = load { i64, i64, [0 x i8] }** %1, align 8
  %5 = icmp eq { i64, i64, [0 x i8] }* %4, null
  br i1 %5, label %_ZN3Foo9glue_drop17hf611996539d3036fE.exit, label %"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i"

"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i": ; preds = %"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit"
  %6 = bitcast { i64, i64, [0 x i8] }* %4 to i8*
  tail call void @free(i8* %6) #1
  br label %_ZN3Foo9glue_drop17hf611996539d3036fE.exit

_ZN3Foo9glue_drop17hf611996539d3036fE.exit:       ; preds = %"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit", %"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i"
  ret void
}
````

But with the `noalias` attribute, it can safely optimize that to:

````llvm
define void @_ZN3foo20hd28431f929f0d6c4xaa4v0.0E(%struct.Foo* noalias nocapture) unnamed_addr #0 {
_ZN3Foo9glue_drop17he9afbc09d4e9c851E.exit:
  %1 = getelementptr inbounds %struct.Foo* %0, i64 0, i32 1, i32 0
  %2 = load { i64, i64, [0 x i8] }** %1, align 8
  store { i64, i64, [0 x i8] }* null, { i64, i64, [0 x i8] }** %1, align 8
  %3 = ptrtoint { i64, i64, [0 x i8] }* %2 to i64
  %.fca.0.insert = insertvalue { i64 } undef, i64 %3, 0
  tail call void @eat({ i64 } %.fca.0.insert)
  ret void
}
````
2014-02-15 12:46:23 -08:00
Björn Steinbrink
500d29b589 Declare by-value on-stack parameters to be noalias
Function parameters that are to be passed by value but don't fit into a
single register are currently passed by creating a copy on the stack and
passing a pointer to that copy to the callee. Since the copy is made
just for the function call, there are no aliases.

For example, this sometimes allows LLVM to eliminate unnecessary calls
to drop glue. Given

````rust
struct Foo {
    a: int,
    b: Option<~str>,
}

extern {
    fn eat(eat: Option<~str>);
}

pub fn foo(v: Foo) {
    match v {
        Foo { a: _, b } => unsafe { eat(b) }
    }
}
````

LLVM currently can't eliminate the drop call for the string, because it
only sees a _pointer_ to Foo, for which it has to expect an alias. So we
get:

````llvm
; Function Attrs: uwtable
define void @_ZN3foo20h9f32c90ae7201edbxaa4v0.0E(%struct.Foo* nocapture) unnamed_addr #0 {
"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit":
  %1 = getelementptr inbounds %struct.Foo* %0, i64 0, i32 1, i32 0
  %2 = load { i64, i64, [0 x i8] }** %1, align 8
  store { i64, i64, [0 x i8] }* null, { i64, i64, [0 x i8] }** %1, align 8
  %3 = ptrtoint { i64, i64, [0 x i8] }* %2 to i64
  %.fca.0.insert = insertvalue { i64 } undef, i64 %3, 0
  tail call void @eat({ i64 } %.fca.0.insert)
  %4 = load { i64, i64, [0 x i8] }** %1, align 8
  %5 = icmp eq { i64, i64, [0 x i8] }* %4, null
  br i1 %5, label %_ZN3Foo9glue_drop17hf611996539d3036fE.exit, label %"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i"

"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i": ; preds = %"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit"
  %6 = bitcast { i64, i64, [0 x i8] }* %4 to i8*
  tail call void @free(i8* %6) #1
  br label %_ZN3Foo9glue_drop17hf611996539d3036fE.exit

_ZN3Foo9glue_drop17hf611996539d3036fE.exit:       ; preds = %"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit", %"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i"
  ret void
}
````

But with the `noalias` attribute, it can safely optimize that to:

````llvm
define void @_ZN3foo20hd28431f929f0d6c4xaa4v0.0E(%struct.Foo* noalias nocapture) unnamed_addr #0 {
_ZN3Foo9glue_drop17he9afbc09d4e9c851E.exit:
  %1 = getelementptr inbounds %struct.Foo* %0, i64 0, i32 1, i32 0
  %2 = load { i64, i64, [0 x i8] }** %1, align 8
  store { i64, i64, [0 x i8] }* null, { i64, i64, [0 x i8] }** %1, align 8
  %3 = ptrtoint { i64, i64, [0 x i8] }* %2 to i64
  %.fca.0.insert = insertvalue { i64 } undef, i64 %3, 0
  tail call void @eat({ i64 } %.fca.0.insert)
  ret void
}
````
2014-02-15 21:34:11 +01:00
bors
adea48abb7 auto merge of #12270 : bstrie/rust/pnoise, r=huonw
Mostly just style fixes, but also remove a heap allocation and switch to using a buffered writer rather than doing 60,000 `println!`s.
2014-02-15 10:51:26 -08:00
Ben Striegel
bfa3e6062f Clean up the Perlin noise benchmark 2014-02-15 13:12:32 -05:00
bors
7762baa89b auto merge of #12282 : cmr/rust/cleanup-ptr, r=huonw 2014-02-15 09:36:26 -08:00
Corey Richardson
254c155fca impl fmt::Pointer for &T and &mut T 2014-02-15 12:11:50 -05:00
Corey Richardson
49e11630fa std: clean up ptr a bit 2014-02-15 12:11:41 -05:00
bors
a7aa4c477e auto merge of #12286 : sfackler/rust/no-conditions, r=alexcrichton 2014-02-15 03:56:27 -08:00
bors
fba32ea79f auto merge of #12283 : kballard/rust/env-args-bytes, r=erickt
Change `os::args()` and `os::env()` to use `str::from_utf8_lossy()`.
Add new functions `os::args_as_bytes()` and `os::env_as_bytes()` to retrieve the args/env as byte vectors instead.

The existing methods were left returning strings because I expect that the common use-case is to want string handling.

Fixes #7188.
2014-02-15 02:36:27 -08:00
Alex Crichton
e72ddbdc25 Fix all code examples 2014-02-14 23:49:22 -08:00
bors
c9f13b47fe auto merge of #12230 : DaGenix/rust/io-decorator-changes, r=sfackler
I created RefReader and RefWriter structs that wrap a mutable reference to a Reader or Writer value. This works exactly like the ByRef struct in the iter module and allows passing a reference to a Reader or Writer to function expecting a Reader or Writer by value with the caller retaining ownership to the original value.

I also modified LimitReader to take the wrapped Reader by value instead of by reference.

@sfackler
2014-02-14 23:46:29 -08:00
Steven Fackler
e7147ce84f Remove broken link to old conditions tutorial 2014-02-14 23:45:57 -08:00
Alex Crichton
6667f90292 Update rustdoc testing to test all code blocks
It's too easy to forget the `rust` tag to have a code example tested, and it's
far more common to have testable code than untestable code.

This alters rustdoc to have only two directives, `ignore` and `should_fail`. The
`ignore` directive ignores the code block entirely, and the `should_fail`
directive has been fixed to only fail the test if the code execution fails, not
also compilation.
2014-02-14 23:30:10 -08:00