Commit Graph

311 Commits

Author SHA1 Message Date
Simon Sapin
c516eee503 Move std::cell::clone_ref to a clone associated function on std::cell::Ref
... and generalize the bounds on the value type.
2015-05-28 23:01:36 +02:00
Eduard Burtescu
377b0900ae Use const fn to abstract away the contents of UnsafeCell & friends. 2015-05-27 11:19:03 +03:00
Steven Fackler
e161d5cf73 Stabilize debug builders for 1.2.0 2015-05-19 21:57:39 -07:00
Nick Cameron
5d4cce6cec Rebasing 2015-05-13 14:35:53 +12:00
bors
67ba6dcf68 Auto merge of #24612 - lifthrasiir:flt2dec, r=pnkfelix
This is a direct port of my prior work on the float formatting. The detailed description is available [here](https://github.com/lifthrasiir/rust-strconv#flt2dec). In brief,

* This adds a new hidden module `core::num::flt2dec` for testing from `libcoretest`. Why is it in `core::num` instead of `core::fmt`? Because I envision that the table used by `flt2dec` is directly applicable to `dec2flt` (cf. #24557) as well, which exceeds the realm of "formatting".
* This contains both Dragon4 algorithm (exact, complete but slow) and Grisu3 algorithm (exact, fast but incomplete).
* The code is accompanied with a large amount of self-tests and some exhaustive tests. In particular, `libcoretest` gets a new dependency on `librand`. For the external interface it relies on the existing test suite.
* It is known that, in the best case, the entire formatting code has about 30 KBs of binary overhead (judged from strconv experiments). Not too bad but there might be a potential room for improvements.

This is rather large code. I did my best to comment and annotate the code, but you have been warned.

For the maximal availability the original code was licensed in CC0, but I've also dual-licensed it in MIT/Apache as well so there should be no licensing concern.

This is [breaking-change] as it changes the float output slightly (and it also affects the casing of `inf` and `nan`). I hope this is not a big deal though :)

Fixes #7030, #18038 and #24556. Also related to #6220 and #20870.

## Known Issues

- [x] I've yet to finish `make check-stage1`. It does pass main test suites including `run-pass` but there might be some unknown edges on the doctests.
- [ ] Figure out how this PR affects rustc.
- [ ] Determine which internal routine is mapped to the formatting specifier. Depending on the decision, some internal routine can be safely removed (for instance, currently `to_shortest_str` is unused).
2015-05-09 14:56:56 +00:00
Kang Seonghoon
3d34e177dd core: use banker's rounding for the exact mode in flt2dec.
For the shortest mode the IEEE 754 decoder already provides
an exact rounding range accounting for banker's rounding,
but it was not the case for the exact mode. This commit alters
the exact mode algorithm for Dragon so that any number ending at
`...x5000...` with even `x` and infinite zeroes will round to
`...x` instead of `...(x+1)` as it was. Grisu is not affected
by this change because this halfway case always results in
the failure for Grisu.
2015-05-06 21:11:14 +09:00
Kang Seonghoon
a641b05fda core: updated for the master changes.
The master no longer has `std::num::Float`, so a generic `ldexp` is
not readily available. `DecodableFloat::ldexpi` works around this.
2015-05-06 14:22:26 +09:00
Kang Seonghoon
97ea7c14ba core: fixed a slight bug.
The bug involves the incorrect logic for `core::num::flt2dec::decoder`.
This makes some numbers in the form of 2^n missing one final digits,
which breaks the bijectivity criterion. The regression tests have been
added, and f32 exhaustive test is rerun to get the updated result.
2015-05-06 14:22:26 +09:00
Kang Seonghoon
8a195f0754 core: fixed typos and revised comments in flt2dec. 2015-05-06 14:22:20 +09:00
Kang Seonghoon
f9bfda0a6f core: tweaked flt2dec to match the casing of the older formatting code. 2015-05-06 14:21:48 +09:00
Kang Seonghoon
c82da7a54b core: added core::num::flt2dec for floating-point formatting.
This is a fork of the flt2dec portion of rust-strconv [1] with
a necessary relicensing (the original code was licensed CC0-1.0).
Each module is accompanied with large unit tests, integrated
in this commit as coretest::num::flt2dec. This module is added
in order to replace the existing core::fmt::float method.

The forked revision of rust-strconv is from 2015-04-20, with a commit ID
9adf6d3571c6764a6f240a740c823024f70dc1c7.

[1] https://github.com/lifthrasiir/rust-strconv/
2015-05-06 14:19:37 +09:00
Steven Allen
3fcbc31489 Optimize iterator adapters.
Specifically, make count, nth, and last call the corresponding methods
on the underlying iterator where possible. This way, if the underlying
iterator has an optimized count, nth, or last implementations (e.g.
slice::Iter), these methods will propagate these optimizations.

Additionally, change Skip::next to take advantage of a potentially
optimized nth method on the underlying iterator.
2015-05-05 14:17:23 -04:00
bors
1a60dc4fc4 Auto merge of #24737 - P1start:dst-cell, r=alexcrichton
This + DST coercions (#24619) would allow code like `Rc<RefCell<Box<Trait>>>` to be simplified to `Rc<RefCell<Trait>>`.
2015-05-03 17:22:09 +00:00
bors
f6574c5b04 Auto merge of #25006 - alexcrichton:unstable-indexing, r=aturon
These implementations were intended to be unstable, but currently the stability
attributes cannot handle a stable trait with an unstable `impl` block. This
commit also audits the rest of the standard library for explicitly-`#[unstable]`
impl blocks. No others were removed but some annotations were changed to
`#[stable]` as they're defacto stable anyway.

One particularly interesting `impl` marked `#[stable]` as part of this commit
is the `Add<&[T]>` impl for `Vec<T>`, which uses `push_all` and implicitly
clones all elements of the vector provided.

Closes #24791

[breaking-change]
2015-05-01 22:54:09 +00:00
P1start
57d8289754 Make UnsafeCell, RefCell, Mutex, and RwLock accept DSTs
This + DST coercions (#24619) would allow code like `Rc<RefCell<Box<Trait>>>` to
be simplified to `Rc<RefCell<Trait>>`.
2015-05-02 10:03:35 +12:00
Alex Crichton
b1976f1f6e std: Remove index notation on slice iterators
These implementations were intended to be unstable, but currently the stability
attributes cannot handle a stable trait with an unstable `impl` block. This
commit also audits the rest of the standard library for explicitly-`#[unstable]`
impl blocks. No others were removed but some annotations were changed to
`#[stable]` as they're defacto stable anyway.

One particularly interesting `impl` marked `#[stable]` as part of this commit
is the `Add<&[T]>` impl for `Vec<T>`, which uses `push_all` and implicitly
clones all elements of the vector provided.

Closes #24791
2015-05-01 10:40:46 -07:00
bors
613109db1b Auto merge of #24720 - critiqjo:stepby-sizehint, r=alexcrichton
`Iterator::size_hint` can be easily implemented for `StepBy`.
#23708
2015-05-01 16:42:19 +00:00
critiqjo
2a8fc9b02c iterator: Add StepBy::size_hint method
Fixes `Step::steps_between` implementations by integer types
to correctly handle `by != 1`.
2015-05-01 14:10:08 +05:30
Tamir Duberstein
f7947bc936 Unstub some tests 2015-04-28 21:23:28 -07:00
Tamir Duberstein
8073af7399 Tests need not be public 2015-04-28 21:22:58 -07:00
Tamir Duberstein
cd5abe7635 Remove unused variable 2015-04-28 21:22:06 -07:00
bors
c48b499ea3 Auto merge of #24888 - tamird:snapshot, r=alexcrichton
r? @alexcrichton cc @brson
2015-04-29 02:16:01 +00:00
Tamir Duberstein
69abc12b00 Register new snapshots 2015-04-28 17:23:45 -07:00
bors
c4b23aec4c Auto merge of #24865 - bluss:range-size, r=alexcrichton
core: Fix size_hint for signed integer `Range<T>` iterators

There was an overflow bug in .size_hint() for signed iterators, which
produced an hilariously incorrect size or an overflow panic.

Incorrect size is a serious bug since the iterators are marked
ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when
the collection tries to preallocate too much).

> (-1i8..127).size_hint()
(18446744073709551488, Some(18446744073709551488))

Bug found using quickcheck.

Fixes #24851
2015-04-29 00:15:22 +00:00
bors
97d4e76c20 Auto merge of #24701 - Stebalien:slice, r=alexcrichton
Instead of using the O(n) defaults, define O(1) shortcuts. I also copied (and slightly modified) the relevant tests from the iter tests into the slice tests just in case someone comes along and changes them in the future.

Partially implements  #24214.
2015-04-27 22:46:48 +00:00
Ulrik Sverdrup
95be21df47 core: Fix size_hint for signed integer Range<T> iterators
There was an overflow bug in .size_hint() for signed iterators, which
produced an hilariously incorrect size or an overflow panic.

Incorrect size is a serious bug since the iterators are marked
ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when
the collection tries to preallocate too much).

All signed range iterators were affected.

> (-1i8..127).size_hint()
(18446744073709551488, Some(18446744073709551488))

Bug found using quickcheck.

Fixes #24851
2015-04-27 21:14:43 +02:00
Johannes Oertel
07cc7d9960 Change name of unit test sub-module to "tests".
Changes the style guidelines regarding unit tests to recommend using a
sub-module named "tests" instead of "test" for unit tests as "test"
might clash with imports of libtest.
2015-04-24 23:06:41 +02:00
Steven Allen
de8c79a535 Implement O(1) slice::Iter methods.
Instead of using the O(n) defaults, define O(1) shortcuts.
2015-04-22 17:17:24 -04:00
Alex Crichton
a568a7f9f2 std: Bring back f32::from_str_radix as an unstable API
This API was exercised in a few tests and mirrors the `from_str_radix`
functionality of the integer types.
2015-04-21 15:23:54 -07:00
Piotr Czarnecki
13bc8afa4b Model lexer: Fix remaining issues 2015-04-21 12:02:12 +02:00
kwantam
29d1252e4d deprecate Unicode functions that will be moved to crates.io
This patch
1. renames libunicode to librustc_unicode,
2. deprecates several pieces of libunicode (see below), and
3. removes references to deprecated functions from
   librustc_driver and libsyntax. This may change pretty-printed
   output from these modules in cases involving wide or combining
   characters used in filenames, identifiers, etc.

The following functions are marked deprecated:

1. char.width() and str.width():
   --> use unicode-width crate

2. str.graphemes() and str.grapheme_indices():
   --> use unicode-segmentation crate

3. str.nfd_chars(), str.nfkd_chars(), str.nfc_chars(), str.nfkc_chars(),
   char.compose(), char.decompose_canonical(), char.decompose_compatible(),
   char.canonical_combining_class():
   --> use unicode-normalization crate
2015-04-16 17:03:05 -04:00
Alex Crichton
700e627cf7 test: Fixup many library unit tests 2015-04-14 10:14:19 -07:00
Ben Ashford
faef52a847 Fix for #23150 2015-04-10 13:19:14 +01:00
bors
e4f9ddb878 Auto merge of #24180 - huonw:optimise-max-etc, r=alexcrichton
The main change in this patch is removing the use of `Option` inside the
inner loops of those functions to avoid comparisons where one branch
will only trigger on the first pass through the loop.

The included benchmarks go from:

    test bench_max    ... bench:       372 ns/iter (+/- 118)
    test bench_max_by ... bench:       428 ns/iter (+/- 33)
    test bench_max_by2 ... bench:      7128 ns/iter (+/- 326)

to:

    test bench_max    ... bench:       317 ns/iter (+/- 64)
    test bench_max_by ... bench:       356 ns/iter (+/- 270)
    test bench_max_by2 ... bench:      1387 ns/iter (+/- 183)

Problem noticed in http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
2015-04-10 07:54:18 +00:00
Huon Wilson
c2258d6d04 Optimise Iterator::{max, max_by, min, min_by}.
The main change in this patch is removing the use of `Option` inside the
inner loops of those functions to avoid comparisons where one branch
will only trigger on the first pass through the loop.

The included benchmarks go from:

    test bench_max    ... bench:       372 ns/iter (+/- 118)
    test bench_max_by ... bench:       428 ns/iter (+/- 33)
    test bench_max_by2 ... bench:      7128 ns/iter (+/- 326)

to:

    test bench_max    ... bench:       317 ns/iter (+/- 64)
    test bench_max_by ... bench:       356 ns/iter (+/- 270)
    test bench_max_by2 ... bench:      1387 ns/iter (+/- 183)

Problem noticed in http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
2015-04-10 14:42:17 +10:00
bors
dd6c4a8f15 Auto merge of #23293 - tbu-:pr_additive_multiplicative, r=alexcrichton
Previously it could not be implemented for types outside `libcore/iter.rs` due
to coherence issues.
2015-04-08 00:42:10 +00:00
Tobias Bucher
97f24a8596 Make sum and product inherent methods on Iterator
In addition to being nicer, this also allows you to use `sum` and `product` for
iterators yielding custom types aside from the standard integers.

Due to removing the `AdditiveIterator` and `MultiplicativeIterator` trait, this
is a breaking change.

[breaking-change]
2015-04-08 00:26:35 +02:00
bors
b2e65ee6e4 Auto merge of #23952 - Kimundi:more_string_pattern, r=alexcrichton
This adds the missing methods and turns `str::pattern` in a user facing module, as per RFC.

This also contains some big internal refactorings:
- string iterator pairs are implemented with a central macro to reduce redundancy 
- Moved all tests from `coretest::str` into `collectionstest::str` and left a note to prevent the two sets of tests drifting apart further.

See https://github.com/rust-lang/rust/issues/22477
2015-04-07 00:57:08 +00:00
Marvin Löbel
c29559d28a Moved coretest::str tests into collectiontest::str 2015-04-05 18:52:58 +02:00
Marvin Löbel
c04f22a667 Refactored core::str::pattern to become a user-facing module and hide away
CharEq.
2015-04-05 18:52:57 +02:00
bors
fc98b19cf7 Auto merge of #23832 - petrochenkov:usize, r=aturon
These constants are small and can fit even in `u8`, but semantically they have type `usize` because they denote sizes and are almost always used in `usize` context. The change of their type to `u32` during the integer audit led only to the large amount of `as usize` noise (see the second commit, which removes this noise).

This is a minor [breaking-change] to an unstable interface.

r? @aturon
2015-04-03 04:29:52 +00:00
Alex Crichton
9edbf42a34 rollup merge of #23945: pnkfelix/gate-u-negate
Feature-gate  unsigned unary negate.

Discussed in weekly meeting here: https://github.com/rust-lang/meeting-minutes/blob/master/weekly-meetings/2015-03-31.md#feature-gate--expr

and also in the internals thread here: http://internals.rust-lang.org/t/forbid-unsigned-integer/752
2015-04-01 18:36:21 -07:00
Alex Crichton
f86318d63c Test fixes and rebase conflicts, round 2
Conflicts:
	src/libcore/num/mod.rs
2015-04-02 02:07:51 +02:00
Alex Crichton
e98dce3e00 std: Changing the meaning of the count to splitn
This commit is an implementation of [RFC 979][rfc] which changes the meaning of
the count parameter to the `splitn` function on strings and slices. The
parameter now means the number of items that are returned from the iterator, not
the number of splits that are made.

[rfc]: https://github.com/rust-lang/rfcs/pull/979

Closes #23911
[breaking-change]
2015-04-01 13:29:42 -07:00
Alex Crichton
4f643d79fc rollup merge of #23863: pnkfelix/arith-oflo-const-eval
const_eval : add overflow-checking for {`+`, `-`, `*`, `/`, `<<`, `>>`}.

One tricky detail here: There is some duplication of labor between `rustc::middle::const_eval` and `rustc_trans::trans::consts`. It might be good to explore ways to try to factor out the common structure to the two passes (by abstracting over the particular value-representation used in the compile-time interpreter).

----

Update: Rebased atop #23841

Fix #22531

Fix #23030

Fix #23221

Fix #23235
2015-03-31 18:06:35 -07:00
Felix S. Klock II
8d54ea3ec9 Fallout from changes for overflow-checking during constant evaluation. 2015-04-01 02:56:07 +02:00
Alex Crichton
3422be3666 rollup merge of #23288: alexcrichton/issue-19470
This is a deprecated attribute that is slated for removal, and it also affects
all implementors of the trait. This commit removes the attribute and fixes up
implementors accordingly. The primary implementation which was lost was the
ability to compare `&[T]` and `Vec<T>` (in that order).

This change also modifies the `assert_eq!` macro to not consider both directions
of equality, only the one given in the left/right forms to the macro. This
modification is motivated due to the fact that `&[T] == Vec<T>` no longer
compiles, causing hundreds of errors in unit tests in the standard library (and
likely throughout the community as well).

Closes #19470
[breaking-change]
2015-03-31 15:59:35 -07:00
Alex Crichton
d4a2c94180 std: Clean out #[deprecated] APIs
This commit cleans out a large amount of deprecated APIs from the standard
library and some of the facade crates as well, updating all users in the
compiler and in tests as it goes along.
2015-03-31 15:49:57 -07:00
Alex Crichton
5cf126ae2f std: Remove #[old_orphan_check] from PartialEq
This is a deprecated attribute that is slated for removal, and it also affects
all implementors of the trait. This commit removes the attribute and fixes up
implementors accordingly. The primary implementation which was lost was the
ability to compare `&[T]` and `Vec<T>` (in that order).

This change also modifies the `assert_eq!` macro to not consider both directions
of equality, only the one given in the left/right forms to the macro. This
modification is motivated due to the fact that `&[T] == Vec<T>` no longer
compiles, causing hundreds of errors in unit tests in the standard library (and
likely throughout the community as well).

cc #19470
[breaking-change]
2015-03-31 13:39:14 -07:00
Alex Crichton
acd48a2b3e std: Standardize (input, output) param orderings
This functions swaps the order of arguments to a few functions that previously
took (output, input) parameters, but now take (input, output) parameters (in
that order).

The affected functions are:

* ptr::copy
* ptr::copy_nonoverlapping
* slice::bytes::copy_memory
* intrinsics::copy
* intrinsics::copy_nonoverlapping

Closes #22890
[breaking-change]
2015-03-30 14:08:40 -07:00