Commit Graph

29136 Commits

Author SHA1 Message Date
Corey Richardson
e30198d9d4 num: expand crate documentation + add example 2014-05-16 09:55:29 -07:00
Corey Richardson
91fa8e5f2a arena: add docs for Arena 2014-05-16 09:55:29 -07:00
Corey Richardson
30250d3de8 flate: add documentation 2014-05-16 09:55:29 -07:00
Alex Crichton
6959b4f7b0 rustc: Stop calling error! in resolve
These are taken care of with compiler errors later on, no need to spam with
extra unformatted information unconditionally.

Closes #14225
2014-05-16 09:15:51 -07:00
Kevin Butler
6bfe361de2 guide-pointers: minor nits 2014-05-16 15:40:21 +01:00
bors
bbd034c3a6 auto merge of #14237 : alexcrichton/rust/issue-14144, r=cmr
By default, jemalloc is building itself with -g3 if the local compiler supports
it. It looks like this is generating a good deal of debug info that windows
isn't optimizing out (on the order of 18MB). Windows gcc/ld is also not
optimizing this data away, causing hello world to be 18MB in size.

There's no current real need for debugging jemalloc to a great extent, so this
commit manually passes -g1 to override -g3 which jemalloc is using. This is
confirmed to drop the size of executables on windows back to a more reasonable
size (2.0MB, as they were before).

Closes #14144
2014-05-16 02:46:25 -07:00
bors
d92926ca3b auto merge of #14235 : Ryman/rust/simplify_arcs_doc, r=alexcrichton 2014-05-16 01:06:25 -07:00
bors
b545a499fa auto merge of #14115 : alexcrichton/rust/core-fmt, r=brson
This was a more difficult change than I thought it would be, and it is unfortunately a breaking change rather than a drop-in replacement. Most of the rationale can be found in the third commit.

cc #13851
2014-05-15 23:26:26 -07:00
Alex Crichton
2e2160b026 core: Update all tests for fmt movement 2014-05-15 23:22:15 -07:00
Alex Crichton
d12a136b22 std: Fix float tests 2014-05-15 23:22:06 -07:00
Alex Crichton
c365252002 std: Delegate some integer formatting to core::fmt
In an attempt to phase out the std::num::strconv module's string formatting
functionality, this commit reimplements some provided methods for formatting
integers on top of format!() instead of the custom (and slower) implementation
inside of num::strconv.

Primarily, this deprecates int_to_str_bytes_common
2014-05-15 23:22:06 -07:00
Alex Crichton
bcab97a32e core: Implement f32/f64 formatting
This is a migration of the std::{f32, f64}::to_str* functionality to the core
library. This removes the growable `Vec` used in favor of a large stack buffer.
The maximum base 10 exponent for f64 is 308, so a stack buffer of 512 bytes
should be sufficient to store all floats.
2014-05-15 23:22:06 -07:00
Alex Crichton
1de4b65d2a Updates with core::fmt changes
1. Wherever the `buf` field of a `Formatter` was used, the `Formatter` is used
   instead.
2. The usage of `write_fmt` is minimized as much as possible, the `write!` macro
   is preferred wherever possible.
3. Usage of `fmt::write` is minimized, favoring the `write!` macro instead.
2014-05-15 23:22:06 -07:00
Alex Crichton
8767093eb9 std: Rewrite the write! and writeln! macros
These are reimplemented using the new `core::fmt` module.
2014-05-15 23:22:06 -07:00
Alex Crichton
854d95f9ff syntax: Add a macro, format_args_method!()
Currently, the format_args!() macro takes as its first argument an expression
which is the callee of an ExprCall. This means that if format_args!() is used
with calling a method a closure must be used. Consider this code, however:

    format_args!(|args| { foo.writer.write_fmt(args) }, "{}", foo.field)

The closure borrows the entire `foo` structure, disallowing the later borrow of
`foo.field`. To preserve the semantics of the `write!` macro, it is also
impossible to borrow specifically the `writer` field of the `foo` structure
because it must be borrowed mutably, but the `foo` structure is not guaranteed
to be mutable itself.

This new macro is invoked like:

    format_args_method!(foo.writer, write_fmt, "{}", foo.field)

This macro will generate an ExprMethodCall which allows the borrow checker to
understand that `writer` and `field` should be borrowed separately.

This macro is not strictly necessary, with DST or possibly UFCS other
workarounds could be used. For now, though, it looks like this is required to
implement the `write!` macro.
2014-05-15 23:22:06 -07:00
Alex Crichton
00f9263914 std: Add an adaptor for Writer => FormatWriter
This new method, write_fmt(), is the one way to write a formatted list of
arguments into a Writer stream. This has a special adaptor to preserve errors
which occur on the writer.

All macros will be updated to use this method explicitly.
2014-05-15 23:22:06 -07:00
Alex Crichton
3c06a0328a core: Derive Show impls wherever possible
These were temporarily moved to explicit implementations, but now that fmt is in
core it's possible to derive again.
2014-05-15 23:22:06 -07:00
Alex Crichton
27d8ea05a2 core: Implement and export the try! macro
This is used quite extensively by core::fmt
2014-05-15 23:22:06 -07:00
Alex Crichton
f2af4ca3e6 core: Allow formatted failure and assert in core
With std::fmt having migrated, the failure macro can be expressed in its full
glory.
2014-05-15 23:22:06 -07:00
Alex Crichton
c255568652 core: Implement unwrap()/unwrap_err() on Result
Now that std::fmt is in libcore, it's possible to implement this as an inherit
method rather than through extension traits.

This commit also tweaks the failure interface of libcore to libstd to what it
should be, one method taking &fmt::Arguments
2014-05-15 23:22:06 -07:00
Alex Crichton
cf0619383d core: Inherit the std::fmt module
This commit moves all possible functionality from the standard library's string
formatting utilities into the core library. This is a breaking change, due to a
few tweaks in the semantics of formatting:

1. In order to break the dependency on the std::io module, a new trait,
   FormatWriter was introduced in core::fmt. This is the trait which is used
   (instead of Writer) to format data into a stream.
2. The new FormatWriter trait has one method, write(), which takes some bytes
   and can return an error, but the error contains very little information. The
   intent for this trait is for an adaptor writer to be used around the standard
   library's Writer trait.
3. The fmt::write{,ln,_unsafe} methods no longer take &mut io::Writer, but
   rather &mut FormatWriter. Since this trait is less common, all functions were
   removed except fmt::write, and it is not intended to be invoked directly.

The main API-breaking change here is that the fmt::Formatter structure will no
longer expose its `buf` field. All previous code writing directly to `f.buf`
using writer methods or the `write!` macro will now instead use `f` directly.

The Formatter object itself implements the `Writer` trait itself for
convenience, although it does not implement the `FormatWriter` trait. The
fallout of these changes will be in the following commits.

[breaking-change]
2014-05-15 23:22:06 -07:00
Alex Crichton
ba0a984a86 core: Move intrinsic float functionality from std
The Float trait in libstd is quite a large trait which has dependencies on cmath
(libm) and such, which libcore cannot satisfy. It also has many functions that
libcore can implement, however, as LLVM has intrinsics or they're just bit
twiddling.

This commit moves what it can of the Float trait from the standard library into
libcore to allow floats to be usable in the core library. The remaining
functions are now resident in a FloatMath trait in the standard library (in the
prelude now). Previous code which was generic over just the Float trait may now
need to be generic over the FloatMath trait.

[breaking-change]
2014-05-15 23:22:06 -07:00
Alex Crichton
4994f3cd45 test: Move syntax extension tests to cfail-full 2014-05-15 23:22:06 -07:00
bors
84406d438c auto merge of #14213 : kballard/rust/str_from_utf8_result, r=cmr
Change `str::from_utf8_owned()` and `StrBuf::from_utf8()` to return `Result`.

This allows the vector to be recovered when it contains invalid UTF-8.
2014-05-15 21:41:29 -07:00
Kevin Butler
5f4de7197f guide-tasks: Simplify Arc usage to match Arc docs. 2014-05-16 02:32:35 +01:00
bors
632d486401 auto merge of #14196 : chris-morgan/rust/hashmap-mangle, r=cmr
This used to be called `mangle` and was removed when the Robin Hood hash map came along, but it is a useful thing to have in certain situations (I just hit it with my Teepee header representation), so I want it back.

The method is renamed to `find_with_or_insert_with`, also with the parameters swapped to make sense—find and then insert, not insert and then find.

/cc @cgaebel
2014-05-15 17:36:27 -07:00
Chris Morgan
ff98afebf4 Work around parse error caused by #14240. 2014-05-16 10:07:44 +10:00
bors
0481d628b8 auto merge of #14234 : alexcrichton/rust/rollup, r=alexcrichton
Let's try this again!
2014-05-15 15:56:54 -07:00
Alex Crichton
161b50a8e6 mk: Don't build jemalloc with -g3
By default, jemalloc is building itself with -g3 if the local compiler supports
it. It looks like this is generating a good deal of debug info that windows
isn't optimizing out (on the order of 18MB). Windows gcc/ld is also not
optimizing this data away, causing hello world to be 18MB in size.

There's no current real need for debugging jemalloc to a great extent, so this
commit manually passes -g1 to override -g3 which jemalloc is using. This is
confirmed to drop the size of executables on windows back to a more reasonable
size (2.0MB, as they were before).

Closes #14144
2014-05-15 15:45:55 -07:00
Alex Crichton
9a5bbd773c rustc: Fix shadowing private import with reexport
The reexport didn't switch the privacy, so the reexport was actually considered
private, erroneously failing to resolve imports later on.

Closes #14082
2014-05-15 15:32:15 -07:00
Alex Crichton
17df573a2e Test fixes from rollup
Closes #14231 (mk: Don't run benchmarks with `make check`)
Closes #14215 (std: Modify TempDir to not fail on drop. Closes #12628)
Closes #14211 (rustdoc: functions in ffi blocks are unsafe)
Closes #14210 (Make Vec.truncate() resilient against failure in Drop)
Closes #14208 (Make `from_bits` in `bitflags!` safe; add `from_bits_truncate`)
Closes #14206 (Register new snapshots)
Closes #14205 (use sched_yield on linux and freebsd)
Closes #14204 (Add a crate for missing stubs from libcore)
Closes #14203 (shootout-mandelbrot: Either 10-20% or 80-100% improvement.)
Closes #14202 (Add flow-graph visualization (via graphviz) to rustc)
Closes #14201 (Render not_found with an absolute path to the rust stylesheet)
Closes #14200 (std cleanup)
Closes #14189 (Implement cell::clone_ref)
2014-05-15 15:00:27 -07:00
Keegan McAllister
9c35ac5666 Implement cell::clone_ref
Per discussion with @alexcrichton, this is a free function.
2014-05-15 13:50:55 -07:00
Brian Anderson
a0594ebb8b core: Remove the unit module 2014-05-15 13:50:50 -07:00
Brian Anderson
50331595fc std: Delete unused file 2014-05-15 13:50:50 -07:00
Brian Anderson
514fc308b0 std: Remove run_in_bare_thread 2014-05-15 13:50:50 -07:00
Richo Healey
b05af1f6a8 Render not_found with an absolute path to the rust stylesheet 2014-05-15 13:50:45 -07:00
Felix S. Klock II
3aad0e249c Unit tests for flowgraph pretty printing.
Each test works by rendering the flowgraph for the last identified
block we see in expanded pretty-printed output, and comparing it (via
`diff`) against a checked in "foo.dot-expected.dot" file.

Each test post-processes the output to remove NodeIds ` (id=NUM)` so
that the expected output is somewhat stable (or at least independent
of how we assign NodeIds) and easier for a human to interpret when
looking at the expected output file itself.

----

Test writing style notes:

I usually tried to write the tests in a way that would avoid duplicate
labels in the output rendered flow graph, when possible.

The tests that have string literals "unreachable" in the program text
are deliberately written that way to remind the reader that the
unreachable nodes in the resulting graph are not an error in the
control flow computation, but rather a natural consequence of its
construction.
2014-05-15 13:50:42 -07:00
Felix S. Klock II
aaf398f26a Graphviz based flow graph pretty-printing.
Passing `--pretty flowgraph=<NODEID>` makes rustc print a control flow graph.

In pratice, you will also need to pass the additional option:
`-o <FILE>` to emit output to a `.dot` file for graphviz.

(You can only print the flow-graph for a particular block in the AST.)

----

An interesting implementation detail is the way the code puts both the
node index (`cfg::CFGIndex`) and a reference to the payload
(`cfg::CFGNode`) into the single `Node` type that is used for
labelling and walking the graph.  I had once mistakenly thought that I
only wanted the `cfg::CFGNode`, but for labelling, you really want the
cfg index too, rather than e.g. trying to use the `ast::NodeId` as the
label (which breaks down e.g. due to `ast::DUMMY_NODE_ID`).

----

As a drive-by fix, I had to fix `rustc::middle::cfg::construct`
interface to reflect changes that have happened on the master branch
while I was getting this integrated into the compiler.  (The next
commit actually adds tests of the `--pretty flowgraph` functionality,
so that should ensure that the `rustc::middle::cfg` code does not go
stale again.)
2014-05-15 13:50:42 -07:00
Felix S. Klock II
65b65fe448 Bugfixes for rustc::middle::cfg::construct.
1. Only insert non-dummy nodes into the exit map.

2. Revise handling of `break` and `continue` forms so that they are
   not treated as if control falls through to the next node (since it
   does not, it just jumps to the end or start of the loop body).

3. Fixed support for return expression in flow graph construction.
2014-05-15 13:50:42 -07:00
Felix S. Klock II
dbaf300a91 rustc::middle::graph API revisions.
Refine lifetimes in signature for graph node/edge iteration methods.

Added `pub` `node_id` and `edge_id` methods that correspond to
NodeIndex and EdgeIndex `get` methods (note that the inner index is
already `pub` in the struct definitions).  (I decided that `get()`,
used internally, just looks too generic and that client code is
clearer with more explicit method names.)
2014-05-15 13:50:42 -07:00
Felix S. Klock II
7f88cfde18 Add IntoMaybeOwned impl for StrBuf to ease conversion to MaybeOwned. 2014-05-15 13:50:42 -07:00
Felix S. Klock II
39b271f4a3 Add EntryPat and NodePat variants to ast_map.
Add `EntryPat` and `NodePat` variants to ast_map, so that lookups for
id 1 in `let S{val: _x /* pat 2 */} /* pat 1 */ = ...` will actually
resolve to the pattern `S{ ... }`, rather than "unknown node", in a
function like `node_id_to_str`.
2014-05-15 13:50:42 -07:00
Kevin Butler
b9e4fcbf04 shootout-mandelbrot: Precalc initial values & use SIMD in the main loop. +80-100% 2014-05-15 13:50:39 -07:00
Kevin Butler
03f48534b3 shootout-mandlebrot: calculate two bits of the result per inner loop, +10-15% 2014-05-15 13:50:39 -07:00
Alex Crichton
a7bee7b05d Add a crate for missing stubs from libcore
The core library in theory has 0 dependencies, but in practice it has some in
order for it to be efficient. These dependencies are in the form of the basic
memory operations provided by libc traditionally, such as memset, memcmp, etc.
These functions are trivial to implement and themselves have 0 dependencies.

This commit adds a new crate, librlibc, which will serve the purpose of
providing these dependencies. The crate is never linked to by default, but is
available to be linked to by downstream consumers. Normally these functions are
provided by the system libc, but in other freestanding contexts a libc may not
be available. In these cases, librlibc will suffice for enabling execution with
libcore.

cc #10116
2014-05-15 13:50:37 -07:00
Daniel Micay
e043644cea use sched_yield on linux and freebsd
pthread_yield is non-standard, while sched_yield is POSIX

The Linux documentation recommends using the standard function. This is
the only feature we're currently using that's present in glibc but not
in musl.
2014-05-15 13:50:36 -07:00
Alex Crichton
8211539114 Register new snapshots 2014-05-15 13:50:34 -07:00
Aaron Turon
912a9675c0 Make from_bits in bitflags! safe; add from_bits_truncate
Previously, the `from_bits` function in the `std::bitflags::bitflags`
macro was marked as unsafe, as it did not check that the bits being
converted actually corresponded to flags.

This patch changes the function to check against the full set of
possible flags and return an `Option` which is `None` if a non-flag bit
is set. It also adds a `from_bits_truncate` function which simply zeros
any bits not corresponding to a flag.

This addresses the concern raised in https://github.com/mozilla/rust/pull/13897
2014-05-15 13:50:33 -07:00
Kevin Ballard
d547de998d Make Vec.truncate() resilient against failure in Drop
If a vector element fails in Drop, Vec needs to make sure it doesn't try
to re-drop any elements it already dropped.
2014-05-15 13:50:29 -07:00
Corey Richardson
4bcc4d76a0 rustdoc: functions in ffi blocks are unsafe
Fixes #14188
2014-05-15 13:50:28 -07:00