Commit Graph

23118 Commits

Author SHA1 Message Date
Geoffroy Couprie
0b4f052422 Correct code examples for base64 documentation 2013-10-09 18:36:51 +02:00
bors
4fd7f852e1 auto merge of #9748 : klutzy/rust/print-git-revision, r=alexcrichton
Fixes a bug that `rustc.exe -v` didn't show git revision hash.
The bug is caused by that `$(wildcard $(CFG_GIT))` requires
space-escaped inputs while `$(CFG_GIT)` is usually
`C:\Program Files (x86)\Gitin\git.exe`.
2013-10-09 09:31:36 -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
bors
a3b04c1535 auto merge of #9359 : thestinger/rust/option, r=huonw
See #9355 for discussion.
2013-10-09 06:21:36 -07:00
Daniel Micay
6a90e80b62 option: rewrite the API to use composition 2013-10-09 09:17:29 -04:00
bors
f647ccc79c auto merge of #9695 : huonw/rust/rand2, r=alexcrichton
A pile of changes to `std::rand`:

- Add the 64-bit variant of the ISAAC Rng. This also splits the `Rng.next() -> u32` method into `Rng.next_u32() -> u32` and `Rng.next_u64() -> u64` to be able to actually take advantage of the wider numbers. They have default implementations in terms of each other. (This is ~2× faster than the 32 bit one for generating anything larger than a `u32` on 64-bit computers.)
- Add `ReaderRng` which just wraps a reader as an RNG, useful for `/dev/urandom`, `/dev/random`, `/dev/hwrng`, etc. This also adds the overrideable `fill_bytes` method to `Rng`, since readers can "generate" randomness more than just 8 bytes at a time.
- Add an interface to `/dev/urandom` (and the windows API) that implements `Rng` (`os::OSRng`) so that it is a first-class randomness source. This means that experimenting with things like seeding hashmaps from it will be much easier. It deletes most of the C++ supporting the old form, except for thin wrappers around the Windows API; I don't have access to a windows with Rust other than the try branch. ( **Note:** on unices, this means that `OSRng` requires the runtime, so it's not possible to use it to seed the scheduler RNG; I've replaced it with direct libc calls for reading from `/dev/urandom`.)
- Add the "blessed" `StdRng` which means users who just want a random number generator don't need to worry about the implementation details (which will make changing the underlying implementation from Isaac to something else will be easier, if this every happen). This actually changes between the 32 and 64-bit variants of Isaac depending on the platform at the moment.
- Add a `SeedableRng` trait for random number generators that can be explicitly seeded, 
- Add the `ReseedingRng` wrapper for reseeding a RNG after a certain amount of randomness is emitted. (The method for reseeding is controlled via the `Reseeder` trait from the same module)
- changes to the task rng: 
 - uses `StdRng`
 - it will reseed itself every 32KB, that is, after outputting 32KB of random data it will read new data from the OS (via `OSRng`)
- Implements `Rand` for `char`, and makes the `f32` and `f64` instances more reasonable (and more similar to most other languages I've looked at).
- Documentation, examples and tests
2013-10-09 05:11:33 -07:00
Huon Wilson
e678435cab std::rand: Minor clean-up of comments & add a missing default method. 2013-10-09 22:22:44 +11:00
Huon Wilson
5442a47362 std::rand: remove seed_task_rng and RUST_SEED. 2013-10-09 22:22:44 +11:00
Huon Wilson
62fededd8e std::rand: Make Rng.next_u32 non-default, waiting for #7771. 2013-10-09 22:22:44 +11:00
Huon Wilson
618c6afe32 std::rand::os: use the externfn! macro for the Windows RNG. 2013-10-09 22:22:44 +11:00
Huon Wilson
d86de18b61 std::rand::reseeding: seed the reseeder in the SeedableRng impl.
This stops us relying on Default here.
2013-10-09 22:22:43 +11:00
Huon Wilson
649c1759e8 std::rand::reader: describe cfg!(endianness). 2013-10-09 22:22:43 +11:00
Huon Wilson
38732c4b5c std::rand: Correct the implementation of Rand for f32 & f64. 2013-10-09 22:22:43 +11:00
Huon Wilson
a836f13dc0 Documentation & address minor point. 2013-10-09 22:22:43 +11:00
Huon Wilson
71addded64 std::rand: remove seed.
This much better handled by directly calling out to `OSRng` where
appropriate.
2013-10-09 22:22:43 +11:00
Huon Wilson
5bb5f76785 Convert rt::sched::new_sched_rng to use open/read/close rather than f*. 2013-10-09 22:22:43 +11:00
Huon Wilson
9db32a2f1d std::rand: adjust the f32 & f64 Rand instances.
The f32 generator now just uses a single u32, and the f64 uses a
single u64. This will make both significantly faster, especially
on 64-bit platforms.
2013-10-09 22:22:43 +11:00
Huon Wilson
98869799eb std::rand: documentation additions & fixes. 2013-10-09 22:22:43 +11:00
Huon Wilson
0b1a0d01a8 std::rand: move the Rand impls into a separate file for neatness. 2013-10-09 22:22:43 +11:00
Huon Wilson
6f4ec72362 std::rand: add & split some tests. 2013-10-09 22:22:43 +11:00
Huon Wilson
29e3b33a09 std::rand: make the windows OSRng more correct, remove some C++.
This lets the C++ code in the rt handle the (slightly) tricky parts of
random number generation: e.g. error detection/handling, and using the
values of the `#define`d options to the various functions.
2013-10-09 22:22:42 +11:00
Huon Wilson
fb9706338d std::rand: improve the task_rng code.
It now:
- can be explicitly seeded from user code (`seed_task_rng`) or from the
  environment (`RUST_SEED`, a positive integer)
- automatically reseeds itself from the OS *unless* it was seeded by
  either method above
- has more documentation
2013-10-09 22:22:42 +11:00
Huon Wilson
92725ae765 std::rand: Add a trait for seeding RNGs: SeedableRng.
This provides 2 methods: .reseed() and ::from_seed that modify and
create respecitively.

Implement this trait for the RNGs in the stdlib for which this makes
sense.
2013-10-09 22:22:42 +11:00
Huon Wilson
0223cf65e4 std::rand: Add ReseedingRng, which will reseed an RNG after it generates a certain number of bytes.
It is an "RNG adaptor" and so any RNG can be wrapped to have this behaviour.
2013-10-09 22:22:42 +11:00
Huon Wilson
f39a215f27 std::rand: add the StdRng wrapper for a blessed RNG.
This is implemented as a wrapper around another RNG. It is designed
to allow the actual implementation to be changed without changing
the external API (e.g. it currently uses a 64-bit generator on 64-
bit platforms, and a 32-bit one on 32-bit platforms; but one could
imagine that the IsaacRng may be deprecated later, and having this
ability to switch algorithms without having to update the points of
use is convenient.)

This is the recommended general use RNG.
2013-10-09 22:22:42 +11:00
Huon Wilson
39a69d323d std::rand: Add OSRng, ReaderRng wrappers around the OS RNG & generic Readers respectively.
The former reads from e.g. /dev/urandom, the latter just wraps any
std::rt::io::Reader into an interface that implements Rng.

This also adds Rng.fill_bytes for efficient implementations of the above
(reading 8 bytes at a time is inefficient when you can read 1000), and
removes the dependence on src/rt (i.e. rand_gen_seed) although this last
one requires implementing hand-seeding of the XorShiftRng used in the
scheduler on Linux/unixes, since OSRng relies on a scheduler existing to
be able to read from /dev/urandom.
2013-10-09 22:22:42 +11:00
Huon Wilson
a2b509656a std::rand: Add an implementation of ISAAC64.
This is 2x faster on 64-bit computers at generating anything larger
than 32-bits.

It has been verified against the canonical C implementation from the
website of the creator of ISAAC64.

Also, move `Rng.next` to `Rng.next_u32` and add `Rng.next_u64` to
take full advantage of the wider word width; otherwise Isaac64 will
always be squeezed down into a u32 wasting half the entropy and
offering no advantage over the 32-bit variant.
2013-10-09 22:22:42 +11:00
Huon Wilson
72bf201d61 std::rand: move the Isaac implementation to its own file. 2013-10-09 22:22:42 +11:00
bors
e505d4c353 auto merge of #9782 : geoffhill/rust/lint-format2, r=alexcrichton
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.

Supersedes the patch suggested in #9778
Closes #6580
2013-10-09 03:11:37 -07:00
klutzy
6434d0b58f Makefile: Get git revision correctly on Windows
Fixes a bug that `rustc.exe -v` didn't show git revision hash.
The bug is caused by that `$(wildcard $(CFG_GIT))` requires
space-escaped inputs while `$(CFG_GIT)` is usually
`C:\Program Files (x86)\Git\bin\git.exe`.
2013-10-09 16:38:41 +09: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
Steven Fackler
3c62ed6578 Make std::rt::io::extensions public
This works around #9779, but is probably the right thing to do anyways
since that's the module where all of the documentation for those traits
lives.
2013-10-08 23:36:26 -07:00
bors
3a70df1d3c auto merge of #9753 : alexcrichton/rust/macro-attrs, r=brson
It's unclear to me why these currently aren't allowed, and my best guess is that
a long time ago we didn't strip the ast of cfg nodes before syntax expansion.
Now that this is done, I'm not certain that we should continue to prohibit this
functionality.

This is a step in the right direction towards #5605, because now we can add an
empty `std::macros` module to the documentation with a bunch of empty macros
explaining how they're supposed to be used.
2013-10-08 19:26:35 -07:00
Alex Crichton
252d17a07c Allow attributes on macros
It's unclear to me why these currently aren't allowed, and my best guess is that
a long time ago we didn't strip the ast of cfg nodes before syntax expansion.
Now that this is done, I'm not certain that we should continue to prohibit this
functionality.

This is a step in the right direction towards #5605, because now we can add an
empty `std::macros` module to the documentation with a bunch of empty macros
explaining how they're supposed to be used.
2013-10-08 19:12:30 -07:00
bors
6c2cdb3436 auto merge of #9772 : alexcrichton/rust/buildsystem, r=thestinger
Reorganize the makefiles to stop building these once per stage because there's
no need to do this at all.

Closes #7002
2013-10-08 14:31:41 -07:00
Alex Crichton
d858360483 Build libuv/jemalloc only once (not per stage)
Reorganize the makefiles to stop building these once per stage because there's
no need to do this at all.

Closes #7002
2013-10-08 14:26:56 -07:00
bors
6db889996b auto merge of #9771 : alexcrichton/rust/snapshots, r=thestinger
Still building locally, we'll see if anything dies...
2013-10-08 13:01:49 -07:00
Sébastien Crozet
8ac0d0a59e Fix float to float ToPrimitive implementation.
The mimimum (negative) value of a float is -Bounded::max_value(), not Bounded::min_value().
2013-10-08 21:49:35 +02:00
bors
e42e32291e auto merge of #9757 : erickt/rust/master, r=alexcrichton
I accidentally left an infinite loop in a default method in `num::ToPrimitive::to_u64()`. This fixes it.
2013-10-08 11:06:41 -07:00
Alex Crichton
0cca359da6 Register new snapshots 2013-10-08 09:30:03 -07:00
bors
8db52a5c0e auto merge of #9756 : catamorphism/rust/issue-2354, r=alexcrichton
r? anybody It's more helpful to list the span of each open delimiter seen so far
than to print out an error with the span of the last position in the file.

Closes #2354
2013-10-08 09:11:35 -07:00
bors
e293026e9c auto merge of #9768 : pnkfelix/rust/fsk-fix-issue-9762, r=bstrie
r? anyone

Add bindings for start and ends of keyword ranges; use bindings in match arms.

Also, fixed latent bug that inspired this change: the pattern in `is_any_keyword` had not been updated to match the new range of reserved keyword identifiers.

(I briefly tried to expose the latent bug, but `is_any_keyword` is currently only called in contexts where a failure of this kind merely causes a bit more fruitless compilation before `check_reserved_keywords` is called by the parser, which correctly tags `sizeof` as reserved.)
2013-10-08 07:21:46 -07:00
bors
7ba8033113 auto merge of #9766 : thestinger/rust/fast_ffi, r=huonw
this is no longer used by the compiler
2013-10-08 06:11:35 -07:00
Daniel Micay
313052aeb2 rm useless fast_ffi attributes
this is no longer used by the compiler
2013-10-08 09:03:43 -04:00
Felix S. Klock II
580adc9ad3 Add bindings for start and ends of keyword ranges; use bindings in match arms. 2013-10-08 14:45:02 +02: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
bors
e87205c578 auto merge of #9658 : michaelwoerister/rust/namespace_fixes, r=jdm
This should fix some outstanding namespace issues. It also fixes an issue with LLVM metadata uniquing that caused an LLVM assertion when compiling libstd.

One thing to keep in mind is that the `-O` flag and the debug info flags are essentially incompatible. It may work but I would not consider this in any way supported at the moment. On the other hand, there is also good news: With the changes in this PR I am able to compile all of rust with extra-debug-info:
```
make RUSTFLAGS_STAGE2='-Zextra-debug-info' check
```
compiles the whole thing without warning and passes the whole test suite (given that `configure` is run with `--disable-optimize`). That's kind of nice `:)` Still, I'm reluctant to automatically close the related issues (#9167, #9190, #9268) without confirmation from the openers. I'll post to the individual threads once this gets merged.
2013-10-08 03:01:36 -07: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