Commit Graph

45550 Commits

Author SHA1 Message Date
Alisdair Owens
de26d5e712 add diagnostics for E0221 2015-08-14 20:21:24 +01:00
bors
e7261f3ab6 Auto merge of #27641 - nikomatsakis:soundness-rfc-1214, r=nrc
This PR implements the majority of RFC 1214. In particular, it implements:

- the new outlives relation
- comprehensive WF checking

For the most part, new code receives warnings, not errors, though 3 regressions were found via a crater run. 

There are some deviations from RFC 1214. Most notably:

- we still consider implied bounds from fn ret; this intersects other soundness issues that I intend to address in detail in a follow-up RFC. Fixing this without breaking a lot of code probably requires rewriting compare-method somewhat (which is probably a good thing).
- object types do not check trait bounds for fear of encountering `Self`; this was left as an unresolved question in RFC 1214, but ultimately feels inconsistent.

Both of those two issues are highlighted in the tracking issue, https://github.com/rust-lang/rust/issues/27579. #27579 also includes a testing matrix with new tests that I wrote -- these probably duplicate some existing tests, I tried to check but wasn't quite sure what to look for. I tried to be thorough in testing the WF relation, at least, but would welcome suggestions for missing tests.

r? @nrc (or perhaps someone else?)
2015-08-14 15:26:09 +00:00
Niko Matsakis
7f8942c18d Correct nits from @nrc 2015-08-14 09:26:19 -04:00
bors
0649b16ade Auto merge of #27822 - arielb1:inline-round-take-2, r=Gankro
This speeds up rustc on #25916 from 1.36±0.022s to 1.326±0.025s

Tests pass locally (even on 32-bit :-)

r? @Gankro
2015-08-14 07:11:07 +00:00
bors
e907fab178 Auto merge of #27821 - dhuseby:manual_snapshots_1af31d4, r=alexcrichton
@alexcrichton please upload these snapshots when landing this patch:

https://github.com/dhuseby/rust-manual-snapshots/raw/master/rust-stage0-2015-08-11-1af31d4-bitrig-x86_64-739e0635cd5a1b3635f1457aae3ef6390ea9a7a8.tar.bz2
https://github.com/dhuseby/rust-manual-snapshots/raw/master/rust-stage0-2015-08-11-1af31d4-freebsd-i386-3cd4a44fb97b3135be3d1b760bea604a381e85dc.tar.bz2
https://github.com/dhuseby/rust-manual-snapshots/raw/master/rust-stage0-2015-08-11-1af31d4-freebsd-x86_64-de1f36592bac0eeb90c049a8421246652c511b9e.tar.bz2
2015-08-14 05:40:44 +00:00
bors
741a19f8ef Auto merge of #27816 - steveklabnik:for_chrisbot, r=alexcrichton
reported by @chris-code here: https://github.com/rust-lang/rust/issues/24486#issuecomment-130812460
2015-08-14 04:09:57 +00:00
bors
033e127066 Auto merge of #27786 - alexcrichton:start-testing-msvc, r=brson
* An apparent bug in VS 2013's implementation of the `exp2` function is worked
  around in one of flt2dec's tests.

Turns out this was the only fix necessary!
2015-08-14 02:38:29 +00:00
bors
e2bebf32fa Auto merge of #27696 - bluss:into-boxed-str, r=alexcrichton
Rename String::into_boxed_slice -> into_boxed_str

This is the name that was decided in rust-lang/rfcs#1152, and it's
better if we say “boxed str” for `Box<str>`.

The old name `String::into_boxed_slice` is deprecated.
2015-08-14 01:06:37 +00:00
bors
82b89645fb Auto merge of #27684 - alexcrichton:remove-deprecated, r=aturon
This commit removes all unstable and deprecated functions in the standard
library. A release was recently cut (1.3) which makes this a good time for some
spring cleaning of the deprecated functions.
2015-08-13 23:32:30 +00:00
Dave Huseby
fe5336b04d Fixes #27805 - adds missing snapshots for Bitrig and FreeBSD 2015-08-13 13:45:04 -07:00
bors
a4066271b7 Auto merge of #27758 - nathankleyn:diagnostics-386, r=Manishearth
This adds detailed diagnostics for E0386, 'cannot assign to data in an
immutable container'.

This is part of rust-lang/rust#24407.

r? @Manishearth
2015-08-13 20:37:18 +00:00
Steve Klabnik
e4266803cb Fix broken link to Wilson
reported by @chris-code here: https://github.com/rust-lang/rust/issues/24486#issuecomment-130812460
2015-08-13 15:42:14 -04:00
arielb1
21eae93550 Mark round_up_to_next as inline
This speeds up rustc on #25916 from 1.36±0.022s to 1.326±0.025s

Tests pass locally (even on 32-bit :-)
2015-08-13 22:23:26 +03:00
bors
7b7fc67dd4 Auto merge of #27625 - wthrowe:find, r=alexcrichton
New enough find on Linux doesn't support "-perm +..." and suggests
using "-perm /..." instead, but that doesn't work on Windows.
Hopefully all platforms are happy with this expanded version.

I don't have access to a Windows development system to test this, so someone needs to verify that this actually works there before merging.

Closes #19981.
2015-08-13 16:09:22 +00:00
Alex Crichton
60ac0d85b9 Get make check working on MSVC
* An apparent bug in VS 2013's implementation of the `exp2` function is worked
  around in one of flt2dec's tests.
2015-08-13 09:02:38 -07:00
bors
bb954cfa75 Auto merge of #27307 - rkruppe:dec2flt, r=pnkfelix
Completely rewrite the conversion of decimal strings to `f64` and `f32`. The code is intended to be absolutely positively completely 100% accurate (when it doesn't give up). To the best of my knowledge, it achieves that goal. Any input that is not rejected is converted to the floating point number that is closest to the true value of the input. This includes overflow, subnormal numbers, and underflow to zero. In other words, the rounding error is less than or equal to 0.5 units in the last place. Half-way cases (exactly 0.5 ULP error) are handled with half-to-even rounding, also known as banker's rounding.

This code implements the algorithms from the paper [How to Read Floating Point Numbers Accurately][paper] by William D. Clinger, with extensions to handle underflow, overflow and subnormals, as well as some algorithmic optimizations.

# Correctness

With such a large amount of tricky code, many bugs are to be expected. Indeed tracking down the obscure causes of various rounding errors accounts for the bulk of the development time. Extensive tests (taking in the order of hours to run through to completion) are included in `src/etc/test-float-parse`: Though exhaustively testing all possible inputs is impossible, I've had good success with generating millions of instances from various "classes" of inputs. These tests take far too long to be run by @bors so contributors who touch this code need the discipline to run them. There are `#[test]`s, but they don't even cover every stupid mistake I made in course of writing this.

Another aspect is *integer* overflow. Extreme (or malicious) inputs could cause overflow both in the machine-sized integers used for bookkeeping throughout the algorithms (e.g., the decimal exponent) as well as the arbitrary-precision arithmetic. There is input validation to reject all such cases I know of, and I am quite sure nobody will *accidentally* cause this code to go out of range. Still, no guarantees.

# Limitations

Noticed the weasel words "(when it doesn't give up)" at the beginning? Some otherwise well-formed decimal strings are rejected because spelling out the value of the input requires too many digits, i.e., `digits * 10^abs(exp)` can't be stored in a bignum. This only applies if the value is not "obviously" zero or infinite, i.e., if you take a near-infinity or near-zero value and add many pointless fractional digits. At least with the algorithm used here, computing the precise value would require computing the full value as a fraction, which would overflow. The precise limit is `number_of_digits + abs(exp) > 375` but could be raised almost arbitrarily. In the future, another algorithm might lift this restriction entirely.

This should not be an issue for any realistic inputs. Still, the code does reject inputs that would result in a finite float when evaluated with unlimited precision. Some of these inputs are even regressions that the old code (mostly) handled, such as `0.333...333` with 400+ `3`s. Thus this might qualify as [breaking-change].

# Performance

Benchmarks results are... tolerable. Short numbers that hit the fast paths (`f64` multiplication or shortcuts to zero/inf) have performance in the same order of magnitude as the old code tens of nanoseconds. Numbers that are delegated to Algorithm Bellerophon (using floats with 64 bit significand, implemented in software) are slower, but not drastically so (couple hundred nanoseconds).

Numbers that need the AlgorithmM fallback (for `f64`, roughly everything below 1e-305 and above 1e305) take far, far longer, hundreds of microseconds. Note that my implementation is not quite as naive as the expository version in the paper (it needs one to four division instead of ~1000), but division is fundamentally pretty expensive and my implementation of it is extremely simple and slow.

All benchmarks run on a mediocre laptop with a i5-4200U CPU under light load.

# Binary size

Unfortunately the implementation needs to duplicate almost all code: Once for `f32` and once for `f64`. Before you ask, no, this cannot be avoided, at least not completely (but see the Future Work section). There's also a precomputed table of powers of ten, weighing in at about six kilobytes.

Running a stage1 `rustc` over a stand-alone program that simply parses pi to `f32` and `f64` and outputs both results reveals that the overhead vs. the old parsing code is about 44 KiB normally and about 28 KiB with LTO. It's presumably half of that + 3 KiB when only one of the two code paths is exercised.

| rustc options                 | old       | new       | delta         |
|---------------------------    |---------  |---------  |-----------    |
| [nothing]                     | 2588375   | 2633828   | 44.39 KiB     |
| -O                            | 2585211   | 2630688   | 44.41 KiB     |
| -O -C lto                     | 1026353   | 1054981   | 27.96 KiB     |
| -O -C lto -C link-args=-s     | 414208    | 442368    | 27.5 KiB      |

# Future Work

## Directory layout

The `dec2flt` code uses some types embedded deeply in the `flt2dec` module hierarchy, even though nothing about them it formatting-specific. They should be moved to a more conversion-direction-agnostic location at some point.

## Performance

It could be much better, especially for large inputs. Some low-hanging fruit has been picked but much more work could be done. Some specific ideas are jotted down in `FIXME`s all over the code.

## Binary size

One could try to compress the table further, though I am skeptical. Another avenue would be reducing the code duplication from basically everything being generic over `T: RawFloat`. Perhaps one can reduce the magnitude of the duplication by pushing the parts that don't need to know the target type into separate functions, but this is finicky and probably makes some code read less naturally.

## Other bases

This PR leaves `f{32,64}::from_str_radix` alone. It only replaces `FromStr` (and thus `.parse()`). I am convinced that `from_str_radix` should not exist, and have proposed its [deprecation and speedy removal][deprecate-radix]. Whatever the outcome of that discussion, it is independent from, and out of scope for, this PR.

Fixes #24557
Fixes #14353

r? @pnkfelix

cc @lifthrasiir @huonw 

[paper]: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.4152
[deprecate-radix]: https://internals.rust-lang.org/t/deprecate-f-32-64-from-str-radix/2405
2015-08-13 13:29:38 +00:00
Ulrik Sverdrup
bec64090a7 Rename String::into_boxed_slice -> into_boxed_str
This is the name that was decided in rust-lang/rfcs#1152, and it's
better if we say “boxed str” for `Box<str>`.

The old name `String::into_boxed_slice` is deprecated.
2015-08-13 14:02:00 +02:00
Nathan Kleyn
b0b2952189 Improve interior mutability example for E0386. 2015-08-13 10:17:56 +01:00
Nathan Kleyn
75c6428e1b Add details about types with interior mutability to E0386.
Types with interior mutability like `Cell` and `RefCell` can be used to
skirt the restriction on mutating mutable values inside an immutable
container.
2015-08-13 10:17:56 +01:00
Nathan Kleyn
55752a4bde Add detailed diagnostics for E0386.
This adds detailed diagnostics for E0386, 'cannot assign to data in an
immutable container'.
2015-08-13 10:17:56 +01:00
Niko Matsakis
401a243552 astconv.rs: extended ast_ty_to_ty debugging 2015-08-13 05:10:56 -04:00
bors
e9205a20a8 Auto merge of #27803 - Manishearth:rollup, r=Manishearth
- Successful merges: #27699, #27757
- Failed merges:
2015-08-13 08:47:22 +00:00
Manish Goregaokar
0f3fada118 Rollup merge of #27757 - AlisdairO:diagnostics366, r=Manishearth
As title :-)
Part of #24407.

r? @Manishearth
2015-08-13 14:17:06 +05:30
Manish Goregaokar
9d0bca42e0 Rollup merge of #27699 - nathankleyn:diagnostics-383, r=Manishearth
This adds detailed diagnostics for `E0383`, 'partial reinitialization of
uninitialized structure'.

This is part of rust-lang/rust#24407.

r? @Manishearth
2015-08-13 14:17:06 +05:30
Nathan Kleyn
67c7fd710b Improve code examples for E0383 long diagnostic. 2015-08-13 09:11:06 +01:00
Nathan Kleyn
9c0d2b2465 Add detailed diagnostics for E0383.
This adds detailed diagnostics for E0383, 'partial reinitialization of
uninitialized structure'.

This is part of rust-lang/rust#24407.
2015-08-13 09:06:29 +01:00
bors
ea3cd022ef Auto merge of #27762 - alexcrichton:fix-libc, r=aturon
The corrected signature of `ioctl` broke some crates on crates.io, and it's not
currently worth the major version bump of libc, so for now keep the old
signature around for crates.io builds only with a comment to remove it at a
future date.

This should allow libc on crates.io to update to the master version in-tree.
I've verified that this was the only breakage of substance between the version
libc is currently built with and today's master branch.
2015-08-13 07:07:34 +00:00
bors
2da80ef114 Auto merge of #27693 - nagisa:remutex-docs, r=alexcrichton
Initial version of PR had an DerefMut implementation, which was later removed
because it may cause mutable reference aliasing.

Suggest how to implement mutability with reentrant mutex and remove the claim we
implement DerefMut.
2015-08-13 05:30:13 +00:00
bors
b2aef9d58b Auto merge of #27789 - chriskrycho:remove_pandoc_references, r=steveklabnik
Per @steveklabnik's comment [here](https://github.com/rust-lang/cargo/issues/739#issuecomment-130085860), the Pandoc components of the Makefile are no longer used, and as such the corresponding components of the documentation are out of date.

  - I've removed the Pandoc (and therefore also LaTeX) elements of the makefile and confirmed that the build proceeds correctly.
  - I updated the documentation to reference `rustdoc` and  of Pandoc.

r? @steveklabnik
2015-08-13 03:52:10 +00:00
Chris Krycho
75f7a68ffa doc/readme: replace references to Pandoc with rustdoc. 2015-08-12 22:29:05 -04:00
bors
aed55dcd57 Auto merge of #27763 - wthrowe:debug-docs, r=alexcrichton
When --cfg ndebug changed to -C debug-assertions the documentation was
updated to reflect the new name, but not that the meaning was
reversed.
2015-08-13 02:10:28 +00:00
Niko Matsakis
33200a369a expr_use_visitor: Remove FIXME that is no longer needed (and in fact
causes errors, post rebase). Issue #27592 is still alive and well,
whatever it is.
2015-08-12 20:59:01 -04:00
Niko Matsakis
e1fa00bced add regression test for #27592. Fixes #27592. 2015-08-12 20:58:47 -04:00
bors
021389f6ad Auto merge of #27652 - alex-ozdemir:iter, r=bluss
Provides a custom implementation of Iterator methods `count`, `nth`, and `last` for the structures `slice::{Windows,Chunks,ChunksMut}` in the core module.

These implementations run in constant time as opposed to the default implementations which run in linear time.

Addresses Issue #24214 

r? @aturon
2015-08-13 00:26:29 +00:00
William Throwe
43f6c2fab7 Correct debug! documentation
When --cfg ndebug changed to -C debug-assertions the documentation was
updated to reflect the new name, but not that the meaning was
reversed.
2015-08-12 19:19:31 -04:00
William Throwe
904e428dba Whitelist .pp files in tidy-binaries
Pretty-printed files sometimes start with #![some_feature], which
looks like a shebang line and confuses Windows builds into thinking
they are executables.
2015-08-12 19:08:22 -04:00
bors
82169afba7 Auto merge of #27698 - arielb1:foreign-type-import, r=alexcrichton
Fixes #22968
Probably fixes #27602 (the issue needs a reproduction)

r? @alexcrichton
2015-08-12 22:42:12 +00:00
Alex Crichton
872f8c3234 libc: Fix backcompat with crates.io version
The corrected signature of `ioctl` broke some crates on crates.io, and it's not
currently worth the major version bump of libc, so for now keep the old
signature around for crates.io builds only with a comment to remove it at a
future date.

This should allow libc on crates.io to update to the master version in-tree.
I've verified that this was the only breakage of substance between the version
libc is currently built with and today's master branch.
2015-08-12 15:32:36 -07:00
Niko Matsakis
9f3f69efab regionck.rs: experimentally adopt a more conservative strategy for
projection outlives relations that prefers not to add extract edges to
region graph
2015-08-12 17:58:58 -04:00
Niko Matsakis
ad700abea4 ty.rs: document/cleanup required_region_bounds a bit 2015-08-12 17:58:58 -04:00
Niko Matsakis
fda9b83960 regionck.rs: add a delayed_span_bug call to validate an asserrtion 2015-08-12 17:58:58 -04:00
Niko Matsakis
213326cddd outlives.rs: correct typo 2015-08-12 17:58:58 -04:00
Niko Matsakis
c106dd449c traits/error_reporting.rs: always note obligation cause 2015-08-12 17:58:58 -04:00
Niko Matsakis
157422a0c7 Update test error messages based on changes to wfcheck; also, break
apart the tests that tested many things at once.
2015-08-12 17:58:58 -04:00
Niko Matsakis
2b2a113638 check/wf.rs: change to use correct span and older WF algorithm;
at the time I reinstituted the old code, I hadn't given up yet and
brought back the implicator.
2015-08-12 17:58:58 -04:00
Niko Matsakis
a7c9a15e0e outlives.rs: remove use of ty.walk and replace with recursive of
ty.walk_shallow, add add'l comments.
2015-08-12 17:58:58 -04:00
Niko Matsakis
a264440ab0 outlives: convert outlives to use an exhaustive match, for better
reliability.
2015-08-12 17:58:57 -04:00
Niko Matsakis
9c5cfea43d traits: consider whether origin is RFC1214 when caching, ensuring
that the test rfc1214-warn-and-error.rs reports an error
2015-08-12 17:58:57 -04:00
Niko Matsakis
fb1b6fca36 regionck.rs: correct misuse of ty.regions() rather than regions()
and add a test that was (incorrectly) failing to compile with
existing code
2015-08-12 17:58:57 -04:00
Niko Matsakis
c9a49f93ac regionck.rs: remove dead fn type_strictly_outlives 2015-08-12 17:58:57 -04:00