Commit Graph

204 Commits

Author SHA1 Message Date
Brian Anderson a5be12ce7e Replace most ~exprs with 'box'. #11779 2014-05-02 23:00:58 -07:00
Steven Fackler b0b7c252d7 Add debug_assert and debug_assert_eq macros
I also switched some `assert!` calls over to `debug_assert!`.

Closes #12049.

RFC: 0015-assert
2014-05-01 19:07:40 -07:00
Richo Healey 919889a1d6 Replace all ~"" with "".to_owned() 2014-04-18 17:25:34 -07:00
Alex Crichton 7d3b0bf391 std: Make ~[T] no longer a growable vector
This removes all resizability support for ~[T] vectors in preparation of DST.
The only growable vector remaining is Vec<T>. In summary, the following methods
from ~[T] and various functions were removed. Each method/function has an
equivalent on the Vec type in std::vec unless otherwise stated.

* slice::OwnedCloneableVector
* slice::OwnedEqVector
* slice::append
* slice::append_one
* slice::build (no replacement)
* slice::bytes::push_bytes
* slice::from_elem
* slice::from_fn
* slice::with_capacity
* ~[T].capacity()
* ~[T].clear()
* ~[T].dedup()
* ~[T].extend()
* ~[T].grow()
* ~[T].grow_fn()
* ~[T].grow_set()
* ~[T].insert()
* ~[T].pop()
* ~[T].push()
* ~[T].push_all()
* ~[T].push_all_move()
* ~[T].remove()
* ~[T].reserve()
* ~[T].reserve_additional()
* ~[T].reserve_exect()
* ~[T].retain()
* ~[T].set_len()
* ~[T].shift()
* ~[T].shrink_to_fit()
* ~[T].swap_remove()
* ~[T].truncate()
* ~[T].unshift()
* ~str.clear()
* ~str.set_len()
* ~str.truncate()

Note that no other API changes were made. Existing apis that took or returned
~[T] continue to do so.

[breaking-change]
2014-04-18 10:06:24 -07:00
Huon Wilson 5b109a1754 Add more type signatures to the docs; tweak a few of them.
Someone reading the docs won't know what the types of various things
are, so this adds them in a few meaningful places to help with
comprehension.

cc #13423.
2014-04-11 23:10:22 +10:00
Huon Wilson a65411e4f7 std,serialize: remove some internal uses of ~[].
These are all private uses of ~[], so can easily & non-controversially
be replaced with Vec.
2014-04-10 15:21:58 -07:00
Jonathan S 9380304169 Add fetch_and, fetch_or, fetch_xor to AtomicInt, AtomicUint 2014-04-03 19:53:43 -05:00
Alex Crichton 9a3d04ae76 std: Switch field privacy as necessary 2014-03-31 15:17:12 -07:00
Brian Anderson 451e8c1c61 Convert most code to new inner attribute syntax.
Closes #2569
2014-03-28 17:12:21 -07:00
Flavio Percoco 81ec1f3c18 Rename Pod into Copy
Summary:
So far, we've used the term POD "Plain Old Data" to refer to types that
can be safely copied. However, this term is not consistent with the
other built-in bounds that use verbs instead. This patch renames the Pod
kind into Copy.

RFC: 0003-opt-in-builtin-traits

Test Plan: make check

Reviewers: cmr

Differential Revision: http://phabricator.octayn.net/D3
2014-03-28 10:34:02 +01:00
Brian Anderson 218461d010 std: Unignore atomic tests 2014-03-24 17:17:46 -07:00
bors cafb7ed6f6 auto merge of #13099 : FlaPer87/rust/master, r=huonw 2014-03-23 07:21:55 -07:00
Flavio Percoco 576e36e674 Register new snapshots 2014-03-23 11:37:31 +01:00
Daniel Micay ae429056ff iter: remove `to_owned_vec`
This needs to be removed as part of removing `~[T]`. Partial type hints
are now allowed, and will remove the need to add a version of this
method for `Vec<T>`. For now, this involves a few workarounds for
partial type hints not completely working.
2014-03-23 05:41:23 -04:00
Alex Crichton 9e66f2c6b4 std: Update atomic documentation to remove 'mut'
It's all no longer necessary
2014-03-20 15:06:34 -07:00
Brian Anderson 61622dd20c std: Remove AtomicU64
Support for this is less universal than for word-size things;
it has no users; i'd rather play it safe.
2014-03-20 13:33:43 -07:00
Brian Anderson 8748322c9b std: Make the generic atomics in `sync::atomics` private
I'm not comfortable exposing public functions that purport to do
atomic operations on arbitrary T.
2014-03-20 13:33:43 -07:00
Brian Anderson eb25c42fc8 std: Make the generic atomics take unsafe pointers
These mutate values behind references that are Freeze, which is not
allowed.
2014-03-20 13:33:43 -07:00
Brian Anderson f3fef9a649 std: Make atomics immutable. #11583
In Rust, the strongest guarantee that `&mut` provides is that the memory
pointed to is *not aliased*, whereas `&`'s guarantees are much weaker:
that the value can be aliased, and may be mutated under proper precautions
(interior mutability).

Our atomics though use `&mut` for mutation even while creating multiple
aliases, so this changes them to use 'interior mutability', mutating
through immutable references.
2014-03-20 09:44:29 -07:00
Flavio Percoco 598fc75c4d Make atomics interior Unsafe<T> 2014-03-20 10:17:29 +01:00
Flavio Percoco 8767c69339 Let ArcData use Unsafe<T> 2014-03-20 10:17:28 +01:00
Daniel Micay ce620320a2 rename std::vec -> std::slice
Closes #12702
2014-03-20 01:30:27 -04:00
bors a39c294155 auto merge of #12954 : brson/rust/atomicdocs, r=alexcrichton
This adds lots of docs to the atomics module. Two of the examples
are using the future atomics API (relying on `Share`) and are ignored temporarily.
I discovered a bug in the way AtomicBool's fetch_nand method is
implemented and fixed it by using the correct value for `true`.
I also fixed the implementation of AcqRel fences (it was only doing
a release barrier), and made a "relaxed" fence a failure.
2014-03-18 21:16:46 -07:00
Jonathan S 168cd3a2f5 Relaxed the memory ordering on the implementation of UnsafeArc 2014-03-18 13:49:45 -07:00
Brian Anderson 749e527be6 std: Improve docs for atomics. Fix two bugs
This adds lots of docs to the atomics module. Two of the examples
are using the future atomics API and are ignored temporarily.
I discovered a bug in the way AtomicBool's fetch_nand method is
implemented and fixed it by using the correct value for `true`.
I also fixed the implementation of AcqRel fences (it was only doing
a release barrier), and made a "relaxed" fence a failure.
2014-03-17 18:27:54 -07:00
Cadence Marseille 13d73e99d6 Remove AtomicFlag
fixes #12943
2014-03-16 18:54:10 -04:00
Jyun-Yan You 6d7e86d099 fix MIPS target
I ignored AtomicU64 methods on MIPS target
because libgcc doesn't implement MIPS32 64-bit atomic operations.
Otherwise it would cause link failure.
2014-03-14 11:13:36 +08:00
Alex Crichton 7858065113 std: Rename Chan/Port types and constructor
* Chan<T> => Sender<T>
* Port<T> => Receiver<T>
* Chan::new() => channel()
* constructor returns (Sender, Receiver) instead of (Receiver, Sender)
* local variables named `port` renamed to `rx`
* local variables named `chan` renamed to `tx`

Closes #11765
2014-03-13 13:23:29 -07:00
Alex Crichton 02882fbd7e std: Change assert_eq!() to use {} instead of {:?}
Formatting via reflection has been a little questionable for some time now, and
it's a little unfortunate that one of the standard macros will silently use
reflection when you weren't expecting it. This adds small bits of code bloat to
libraries, as well as not always being necessary. In light of this information,
this commit switches assert_eq!() to using {} in the error message instead of
{:?}.

In updating existing code, there were a few error cases that I encountered:

* It's impossible to define Show for [T, ..N]. I think DST will alleviate this
  because we can define Show for [T].
* A few types here and there just needed a #[deriving(Show)]
* Type parameters needed a Show bound, I often moved this to `assert!(a == b)`
* `Path` doesn't implement `Show`, so assert_eq!() cannot be used on two paths.
  I don't think this is much of a regression though because {:?} on paths looks
  awful (it's a byte array).

Concretely speaking, this shaved 10K off a 656K binary. Not a lot, but sometime
significant for smaller binaries.
2014-02-28 23:01:54 -08:00
Alex Crichton d5aa795aa5 std: Add cfg(test) to UnsafeArc assertions
This is a ubiquitous type in concurrent code, and the assertions are causing
significant code bloat for simple operations such as reading the pointer
(injecting a failure point, etc).

I am testing executable sizes with no I/O implementations (everything stubbed
out to return nothing), and this took the size of a libnative executable from
328K to 207K (37% reduction in size), so I think that this is one assertion
that's well worth configuring off for now.
2014-02-28 10:46:12 -08:00
Brian Anderson 4d10bdc5b9 std: Move intrinsics to std::intrinsics.
Issue #1457
2014-02-23 01:07:53 -08:00
Huon Wilson 6555b04dd2 Spellcheck library docs. 2014-02-18 08:05:35 +11:00
Corey Richardson 49e11630fa std: clean up ptr a bit 2014-02-15 12:11:41 -05:00
Alex Crichton 0a6b9219d1 Rewrite channels yet again for upgradeability
This, the Nth rewrite of channels, is not a rewrite of the core logic behind
channels, but rather their API usage. In the past, we had the distinction
between oneshot, stream, and shared channels, but the most recent rewrite
dropped oneshots in favor of streams and shared channels.

This distinction of stream vs shared has shown that it's not quite what we'd
like either, and this moves the `std::comm` module in the direction of "one
channel to rule them all". There now remains only one Chan and one Port.

This new channel is actually a hybrid oneshot/stream/shared channel under the
hood in order to optimize for the use cases in question. Additionally, this also
reduces the cognitive burden of having to choose between a Chan or a SharedChan
in an API.

My simple benchmarks show no reduction in efficiency over the existing channels
today, and a 3x improvement in the oneshot case. I sadly don't have a
pre-last-rewrite compiler to test out the old old oneshots, but I would imagine
that the performance is comparable, but slightly slower (due to atomic reference
counting).

This commit also brings the bonus bugfix to channels that the pending queue of
messages are all dropped when a Port disappears rather then when both the Port
and the Chan disappear.
2014-02-11 16:32:00 -08:00
Alex Crichton 47ef20014c Shuffle around ownership in concurrent queues
Beforehand, using a concurrent queue always mandated that the "shared state" be
stored internally to the queues in order to provide a safe interface. This isn't
quite as flexible as one would want in some circumstances, so instead this
commit moves the queues to not containing the shared state.

The queues no longer have a "default useful safe" interface, but rather a
"default safe" interface (minus the useful part). The queues have to be shared
manually through an Arc or some other means. This allows them to be a little
more flexible at the cost of a usability hindrance.

I plan on using this new flexibility to upgrade a channel to a shared channel
seamlessly.
2014-02-11 16:32:00 -08:00
bors acb1ec0b67 auto merge of #11230 : csherratt/rust/cow, r=alexcrichton
This allows patch adds a new arc type that allows for creation of copy-on-write data structures. The idea is that it is safe to mutate any data structure as long as it has only one reference to it. If there are multiple, it requires cloning of the data structure before mutation is possible.
2014-02-04 14:41:36 -08:00
Alex Crichton 6c41192c41 Register new snapshots 2014-02-04 00:06:08 -08:00
Flavio Percoco c6b1bce96f Replace NonCopyable usage with NoPod
cc #10834
2014-02-04 00:15:27 +01:00
Alex Crichton acacfb20fd Various bug fixes and rebase conflicts 2014-02-03 12:05:16 -08:00
Alex Crichton b00147a99b Add an AtomicU64 type to std::sync::atomics
This also generalizes all atomic intrinsics over T so we'll be able to add u8
atomics if we really feel the need to (do we really want to?)
2014-02-03 12:04:30 -08:00
Brendan Zabarauskas 9a3583f06d Make next_power_of_two generic for unsigned integers
Also rename `next_power_of_two_opt` to `checked_next_power_of_two`.
2014-02-01 13:02:53 +11:00
Scott Lawrence 25e7e7f807 Removing do keyword from libstd and librustc 2014-01-29 09:15:41 -05:00
Salem Talha cc61fc0994 Removed all instances of XXX in preparation for relaxing of FIXME rule 2014-01-26 14:42:53 -05:00
Daniel Micay 802d41fe23 libc: switch `free` to the proper signature
This does not attempt to fully propagate the mutability everywhere, but
gives new code a hint to avoid the same issues.
2014-01-22 23:13:53 -05:00
Florian Hahn 2eb4f05850 Replace C types with Rust types in libstd, closes #7313 2014-01-22 19:20:47 +01:00
Simon Sapin e75d0a9b7e [std::vec] Rename .remove_opt() to .remove(), drop the old .remove() behavior 2014-01-21 15:48:47 -08:00
Huon Wilson 39713b8295 Remove unnecessary parentheses. 2014-01-21 22:00:18 +11:00
Flavio Percoco ed7e576d9c Add a generic power function
The patch adds a `pow` function for types implementing `One`, `Mul` and
`Clone` trait.

The patch also renames f32 and f64 pow into powf in order to still have
a way to easily have float powers. It uses llvms intrinsics.

The pow implementation for all num types uses the exponentiation by
square.

Fixes bug #11499
2014-01-17 15:41:26 +01:00
Brendan Zabarauskas 0232fed174 Merge some numeric traits with Real and don't re-export RealExt
The methods contained in `std::num::{Algebraic, Trigonometric, Exponential, Hyperbolic}` have now been moved into `std::num::Real`. This is part of an ongoing effort to simplify `std::num` (see issue #10387).

`std::num::RealExt` has also been removed from the prelude because it is not a commonly used trait.
2014-01-09 15:29:09 +11:00
Colin Sherratt 06a8d59ded Add a copy-on-write container. 2013-12-31 14:31:23 -05:00
Alex Crichton 6cad8f4f14 Test fixes and rebase conflicts
* vec::raw::to_ptr is gone
* Pausible => Pausable
* Removing @
* Calling the main task "<main>"
* Removing unused imports
* Removing unused mut
* Bringing some libextra tests up to date
* Allowing compiletest to work at stage0
* Fixing the bootstrap-from-c rmake tests
* assert => rtassert in a few cases
* printing to stderr instead of stdout in fail!()
2013-12-25 23:10:46 -08:00
Alex Crichton 282f3d99a5 Test fixes and rebase problems
Note that this removes a number of run-pass tests which are exercising behavior
of the old runtime. This functionality no longer exists and is thoroughly tested
inside of libgreen and libnative. There isn't really the notion of "starting the
runtime" any more. The major notion now is "bootstrapping the initial task".
2013-12-24 19:59:53 -08:00
Alex Crichton 018d60509c std: Get stdtest all passing again
This commit brings the library up-to-date in order to get all tests passing
again
2013-12-24 19:59:52 -08:00
Alex Crichton a55c57284d std: Introduce std::sync
For now, this moves the following modules to std::sync

* UnsafeArc (also removed unwrap method)
* mpsc_queue
* spsc_queue
* atomics
* mpmc_bounded_queue
* deque

We may want to remove some of the queues, but for now this moves things out of
std::rt into std::sync
2013-12-24 14:42:00 -08:00