Commit Graph

22996 Commits

Author SHA1 Message Date
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
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
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
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
Erick Tryzelaar
6dfc5d5de1 std: fix an infinite loop in num::ToPrimitive and add tests 2013-10-07 19:56:30 -07:00
Benjamin Herr
d7dfe0ae34 pp: add test for raw strs in non-expression positions 2013-10-08 03:47:21 +02: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
Tim Chevalier
77d9ac37fc syntax: Remove unnecessary @ 2013-10-07 18:37:36 -07:00
Tim Chevalier
bed669cba6 syntax: Display spans for open delimiters when a file ends prematurely
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-07 18:06:30 -07:00
bors
b17dc4a946 auto merge of #9751 : thestinger/rust/immediate, r=alexcrichton
This is incorrect, as take glue isn't used for moves.
2013-10-07 16:56:36 -07:00
Benjamin Herr
9787872553 add token::LIT_STR_RAW(ident, num of # symbols)
Treat it as a synonym for LIT_STR for now.
2013-10-08 01:44:05 +02:00
Benjamin Herr
18099fe085 add vim syntax highlighting support for raw string literals 2013-10-08 01:44:05 +02:00
Benjamin Herr
6885c7337f document raw string literals in tutorial.md and rust.md 2013-10-08 01:44:05 +02:00
Benjamin Herr
904c6c43c4 lex raw string literals, like r#"blah"#
Raw string literals are lexed into regular string literals. This is okay
for them to "work" and be usable/testable, but the pretty-printer does
not know about them yet and will just emit regular string literals.
2013-10-08 01:44:05 +02:00
Benjamin Herr
e007f94747 pp: print spaces around '=' in 'extern mod blah = "blah"' 2013-10-08 01:44:05 +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
2c76cdae3e Document visibility in the manual/tutorial
This removes the warning "Note" about visibility not being fully defined, as it
should now be considered fully defined with further bugs being considered just
bugs in the implementation.
2013-10-07 13:00:52 -07: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