Skip to content

libcore: rand refactor & remove @'s from {rand,run}.rs - #6036

Merged
bors merged 4 commits into
rust-lang:incomingfrom
huonw:core-less-at
Apr 24, 2013
Merged

libcore: rand refactor & remove @'s from {rand,run}.rs#6036
bors merged 4 commits into
rust-lang:incomingfrom
huonw:core-less-at

Conversation

@huonw

@huonw huonw commented Apr 23, 2013

Copy link
Copy Markdown
Contributor

From a cursory git grep this removes the last part of core that requires on @ (other than io and the task local data section).

It renames RandRes to StdRng IsaacRng and XorShiftState to XorShiftRng as well as moving their constructors to static methods. To go with this, it adds rng() which is designed to be used when the programmer just wants a random number generator, without caring about which exact algorithm is being used.

It also removes all the gen_int, gen_uint, gen_char (etc) methods on RngUtil (by moving the defintions to the actual Rand instances). The replacement is using RngUtil::gen, either type-inferred or with an annotation (rng.gen::<uint>()).

I tried to have the Rng and RngUtil traits exported by core::prelude (since core::rand (except for random()) is useless without them), but this caused an explosion of (seemingly unrelated) error: unresolved import's.

@z0w0

z0w0 commented Apr 24, 2013

Copy link
Copy Markdown
Contributor

I feel like rand::IsaacRng would be a better name than StdRng.

@huonw

huonw commented Apr 24, 2013

Copy link
Copy Markdown
Contributor Author

That seems reasonable. (edit: done!)

huonw added 4 commits April 24, 2013 22:34
Also, rename RandRes -> IsaacRng, and make the constructors static
methods.
Removes the dynamic @ indirection, and also converts the functions acting
on `ProgRepr`s to methods.
…ic `gen`.

This moves all the basic random value generation into the Rand instances for
each type and then removes the `gen_int`, `gen_char` (etc) methods on RngUtil,
leaving only the generic `gen` and the more specialised methods.

Also, removes some imports that are redundant due to a `use core::prelude::*`
statement.
@nikomatsakis

Copy link
Copy Markdown
Contributor

r+ This looks good; we may also want to implement the trait Rng for the object type @Rng:

impl Rng for @Rng { pub fn next(&self) -> u32 { self.next() } }

so that people can use the object type should they choose to (sometimes it's more convenient).

@nikomatsakis

Copy link
Copy Markdown
Contributor

Oh, I see you already did that, I missed it.

bors added a commit that referenced this pull request Apr 24, 2013
From a cursory `git grep` this removes the last part of `core` that requires on `@` (other than `io` and the task local data section).

It renames `RandRes` to ~~StdRng~~ `IsaacRng` and `XorShiftState` to `XorShiftRng` as well as moving their constructors to static methods. To go with this, it adds `rng()` which is designed to be used when the programmer just wants a random number generator, without caring about which exact algorithm is being used.

It also removes all the `gen_int`, `gen_uint`, `gen_char` (etc) methods on `RngUtil` (by moving the defintions to the actual `Rand` instances). The replacement is using `RngUtil::gen`, either type-inferred or with an annotation (`rng.gen::<uint>()`).

I tried to have the `Rng` and `RngUtil` traits exported by `core::prelude` (since `core::rand` (except for `random()`) is useless without them), but this caused [an explosion of (seemingly unrelated) `error: unresolved import`'s](https://gist.github.com/5451839).
@bors bors closed this Apr 24, 2013
@bors
bors merged commit 9860fe1 into rust-lang:incoming Apr 24, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 24, 2020
…ask_to_pedantic

Downgrade `verbose_bit_mask` to pedantic
U007D pushed a commit to U007D/rust-mos that referenced this pull request Aug 21, 2026
6036: Don't re-read open files from disk when reloading a workspace r=kjeremy a=lnicola

Fixes rust-lang#5742
Fixes rust-lang#4263

or so I hope.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants