Commit graph

495 commits

Author SHA1 Message Date
bors
64b0277643 Auto merge of #29454 - stepancheg:vec-reserve, r=bluss
Before this patch `reserve` function allocated twice as requested
amount elements (not twice as capacity).  It leaded to unnecessary
excessive memory usage in scenarios like this:

```
let mut v = Vec::new();
v.push(17);
v.extend(0..10);
println!("{}", v.capacity());
```

`Vec` allocated 22 elements, while it could allocate just 11.

`reserve` function must have a property of keeping `push` operation
cost (which calls `reserve`) `O(1)`. To achieve this `reserve` must
exponentialy grow its capacity when it does reallocation.

There's better strategy to implement `reserve`:

```
let new_capacity = max(current_capacity * 2, requested_capacity);
```

This strategy still guarantees that capacity grows at `O(1)` with
`reserve`, and fixes the issue with `extend`.

Patch imlpements this strategy.
2015-10-30 22:23:41 +00:00
Stepan Koltsov
46068c9daf Fix excessive memory allocation in RawVec::reserve
Before this patch `reserve` function allocated twice as requested
amount elements (not twice as capacity).  It leaded to unnecessary
excessive memory usage in scenarios like this:

```
let mut v = Vec::new();
v.push(17);
v.extend(0..10);
println!("{}", v.capacity());
```

`Vec` allocated 22 elements, while it could allocate just 11.

`reserve` function must have a property of keeping `push` operation
cost (which calls `reserve`) `O(1)`. To achieve this `reserve` must
exponentialy grow its capacity when it does reallocation.

There's better strategy to implement `reserve`:

```
let new_capacity = max(current_capacity * 2, requested_capacity);
```

This strategy still guarantees that capacity grows at `O(1)` with
`reserve`, and fixes the issue with `extend`.

Patch imlpements this strategy.
2015-10-31 00:17:16 +03:00
Alexis Beingessner
e351595c61 don't use drop_in_place as an intrinsic 2015-10-30 11:24:54 -04:00
Alexis Beingessner
e72c226bed expose drop_in_place as ptr::drop_in_place 2015-10-30 10:54:25 -04:00
Simon Sapin
4e8b8707bf Typo fix
… I think.
2015-10-30 01:00:39 +09:00
Andrew Paseltiner
6031a58a20 Remove some trivial transmutes
`rbml::writer::Encoder::unsafe_clone` had no users across the entire
repo.
2015-10-17 20:29:49 -04:00
Andrew Paseltiner
d6bd8d8491 Add Shared pointer and have {Arc, Rc} use it
This change has two consequences:

1. It makes `Arc<T>` and `Rc<T>` covariant in `T`.

2. It causes the compiler to reject code that was unsound with respect
to dropck. See compile-fail/issue-29106.rs for an example of code that
no longer compiles. Because of this, this is a [breaking-change].

Fixes #29037.
Fixes #29106.
2015-10-16 18:35:31 -04:00
Matt Brubeck
11e65ebe31 Fix minor error in Arc docs
The text says it's a vector of floats, but the code actually uses a vector of integers.  The type of the Vec doesn't really matter, so I just cut it from the text.
2015-10-15 13:52:51 -07:00
Andrew Paseltiner
1162b3752c Correct spelling in docs 2015-10-13 09:44:11 -04:00
Ahmed Charles
5dcd406188 Run rustfmt on liballoc. 2015-10-11 22:11:59 -07:00
bors
87cd2c0827 Auto merge of #28861 - pnkfelix:fsk-nonparam-dropck-issue28498, r=arielb1
implement RFC 1238: nonparametric dropck.

cc #28498 

cc @nikomatsakis
2015-10-10 00:39:29 +00:00
Felix S. Klock II
34076bc0c9 Added the param-blindness attribute to Rc and Arc.
This was proven necessary after I added `Rc` and `Arc` to the rpass
test `dropck_legal_cycles.rs`; see PR #28929.
2015-10-09 18:10:52 +02:00
Felix S. Klock II
d778e57bf6 Add RFC 1238's unsafe_destructor_blind_to_params (UGEH) where needed.
I needed it in `RawVec`, `Vec`, and `TypedArena` for `rustc` to
bootstrap; but of course that alone was not sufficient for `make
check`.

Later I added `unsafe_destructor_blind_to_params` to collections, in
particular `LinkedList` and `RawTable` (the backing representation for
`HashMap` and `HashSet`), to get the regression tests exercising
cyclic structure from PR #27185 building.

----

Note that the feature is `dropck_parametricity` (which is not the same
as the attribute's name). We will almost certainly vary our strategy
here in the future, so it makes some sense to have a not-as-ugly name
for the feature gate. (The attribute name was deliberately selected to
be ugly looking.)
2015-10-06 14:16:49 +02:00
Alex Crichton
db76ac7330 std: Add AsRef/AsMut impls to Box/Rc/Arc
These common traits were left off originally by accident from these smart
pointers, and a past attempt (#26008) to add them was later reverted (#26160)
due to unexpected breakge (#26096) occurring. The specific breakage in worry is
the meaning of this return value changed:

    let a: Box<Option<T>> = ...;
    a.as_ref()

Currently this returns `Option<&T>` but after this change it will return
`&Option<T>` because the `AsRef::as_ref` method shares the same name as
`Option::as_ref`. A [crater report][crater] of this change, however, has shown
that the fallout of this change is quite minimal. These trait implementations
are "the right impls to add" to these smart pointers and would enable various
generalizations such as those in #27197.

[crater]: https://gist.github.com/anonymous/0ba4c3512b07641c0f99

This commit is a breaking change for the above reasons mentioned, and the
mitigation strategies look like any of:

    Option::as_ref(&a)
    a.as_ref().as_ref()
    (*a).as_ref()
2015-10-02 08:57:48 -07:00
bors
e7a73881e9 Auto merge of #28610 - nrc:fmt6, r=brson 2015-09-25 19:06:02 +00:00
Eduard Burtescu
f293ea28b4 Remove the deprecated box(PLACE) syntax. 2015-09-24 18:00:08 +03:00
Nick Cameron
459f7720b9 Better function calls 2015-09-24 11:32:01 +12:00
Nick Cameron
06812c2999 manual fixups 2015-09-24 10:57:28 +12:00
Nick Cameron
8f51c8d687 rustfmt liballoc 2015-09-24 10:00:54 +12:00
Vadim Petrochenkov
50e42ea9f7 Correctly walk import lists in AST visitors 2015-09-17 14:13:12 +03:00
Alex Crichton
f0b1326dc7 std: Stabilize/deprecate features for 1.4
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the
libs team decision for all library features this cycle.

Stabilized APIs:

* `<Box<str>>::into_string`
* `Arc::downgrade`
* `Arc::get_mut`
* `Arc::make_mut`
* `Arc::try_unwrap`
* `Box::from_raw`
* `Box::into_raw`
* `CStr::to_str`
* `CStr::to_string_lossy`
* `CString::from_raw`
* `CString::into_raw`
* `IntoRawFd::into_raw_fd`
* `IntoRawFd`
* `IntoRawHandle::into_raw_handle`
* `IntoRawHandle`
* `IntoRawSocket::into_raw_socket`
* `IntoRawSocket`
* `Rc::downgrade`
* `Rc::get_mut`
* `Rc::make_mut`
* `Rc::try_unwrap`
* `Result::expect`
* `String::into_boxed_slice`
* `TcpSocket::read_timeout`
* `TcpSocket::set_read_timeout`
* `TcpSocket::set_write_timeout`
* `TcpSocket::write_timeout`
* `UdpSocket::read_timeout`
* `UdpSocket::set_read_timeout`
* `UdpSocket::set_write_timeout`
* `UdpSocket::write_timeout`
* `Vec::append`
* `Vec::split_off`
* `VecDeque::append`
* `VecDeque::retain`
* `VecDeque::split_off`
* `rc::Weak::upgrade`
* `rc::Weak`
* `slice::Iter::as_slice`
* `slice::IterMut::into_slice`
* `str::CharIndices::as_str`
* `str::Chars::as_str`
* `str::split_at_mut`
* `str::split_at`
* `sync::Weak::upgrade`
* `sync::Weak`
* `thread::park_timeout`
* `thread::sleep`

Deprecated APIs

* `BTreeMap::with_b`
* `BTreeSet::with_b`
* `Option::as_mut_slice`
* `Option::as_slice`
* `Result::as_mut_slice`
* `Result::as_slice`
* `f32::from_str_radix`
* `f64::from_str_radix`

Closes #27277
Closes #27718
Closes #27736
Closes #27764
Closes #27765
Closes #27766
Closes #27767
Closes #27768
Closes #27769
Closes #27771
Closes #27773
Closes #27775
Closes #27776
Closes #27785
Closes #27792
Closes #27795
Closes #27797
2015-09-11 09:48:48 -07:00
Tshepang Lekhonkhobe
355847f5c1 doc: reduce indentation of examples to 4 spaces
Also, add trailing commas
2015-09-03 22:08:47 +02:00
Simon Sapin
c408b78633 Move the Borrow and BorrowMut traits to libcore. 2015-08-22 13:58:39 +02:00
bors
94ee3b5a54 Auto merge of #27871 - alexcrichton:stabilize-libcore, r=aturon
These commits move libcore into a state so that it's ready for stabilization, performing some minor cleanup:

* The primitive modules for integers in the standard library were all removed from the source tree as they were just straight reexports of the libcore variants.
* The `core::atomic` module now lives in `core::sync::atomic`. The `core::sync` module is otherwise empty, but ripe for expansion!
* The `core::prelude::v1` module was stabilized after auditing that it is a subset of the standard library's prelude plus some primitive extension traits (char, str, and slice)
* Some unstable-hacks for float parsing errors were shifted around to not use the same unstable hacks (e.g. the `flt2dec` module is now used for "privacy").


After this commit, the remaining large unstable functionality specific to libcore is:

* `raw`, `intrinsics`, `nonzero`, `array`, `panicking`, `simd` -- these modules are all unstable or not reexported in the standard library, so they're just remaining in the same status quo as before
* `num::Float` - this extension trait for floats needs to be audited for functionality (much of that is happening in #27823)  and may also want to be renamed to `FloatExt` or `F32Ext`/`F64Ext`.
* Should the extension traits for primitives be stabilized in libcore?

I believe other unstable pieces are not isolated to just libcore but also affect the standard library.

cc #27701
2015-08-22 09:59:07 +00:00
bors
e9b74a9017 Auto merge of #27860 - m4rw3r:rustdoc_unstable_feature_issue, r=alexcrichton
Implemented #27759 

Example:

![screen shot 2015-08-16 at 21 45 17](https://cloud.githubusercontent.com/assets/108100/9295040/1fb24d50-4460-11e5-8ab8-81ac5330974a.png)
2015-08-22 08:16:53 +00:00
Alexis Beingessner
4c8d75fd9b don't do deprecations yet 2015-08-19 15:52:12 -07:00
Alexis Beingessner
dfa4bca889 Rework Arc for FCP of #27718
* Add previously omitted function `Arc::try_unwrap(Self) -> Result<T, Self>`
* Move `arc.downgrade()` to `Arc::downgrade(&Self)` per conventions.
* Deprecate `Arc::weak_count` and `Arc::strong_count` for raciness. It is almost
  impossible to correctly act on these results without a CAS loop on the actual
  fields.
* Rename `Arc::make_unique` to `Arc::make_mut` to avoid uniqueness terminology
  and to clarify relation to `Arc::get_mut`.
2015-08-19 15:52:12 -07:00
Alexis Beingessner
635f7360b6 Rework Rc for FCP of #27718
* Add `Rc::would_unwrap(&Self) -> bool` to introspect whether try_unwrap would succeed,
  because it's destructive (unlike get_mut).
* Move `rc.downgrade()` to `Rc::downgrade(&Self)` per conventions.
* Deprecate `Rc::weak_count` and `Rc::strong_count` for questionable utility.
* Deprecate `Rc::is_unique` for questionable semantics (there are two kinds of
  uniqueness with Weak pointers in play).
* Rename `rc.make_unique()` to `Rc::make_mut(&mut Self)` per conventions, to
  avoid uniqueness terminology, and to clarify the relation to `Rc::get_mut`.
2015-08-19 15:52:12 -07:00
Alex Crichton
0c849de1a2 core: Move atomic into a new sync module
This mirrors the same hierarchy in the standard library.
2015-08-17 14:03:32 -07:00
Martin Wernstål
7fdbe69996 rustdoc: Added issue_tracker_base_url annotations to crates 2015-08-16 22:15:26 +02:00
Alex Crichton
6734c933b5 alloc: Add issues for all unstable features 2015-08-15 18:09:16 -07:00
Dylan McKay
7ebc5e5134 Reduce libcore/liballoc's dependence on pointer sizes 2015-08-15 19:19:13 +12:00
Alex Crichton
45bf1ed1a1 rustc: Allow changing the default allocator
This commit is an implementation of [RFC 1183][rfc] which allows swapping out
the default allocator on nightly Rust. No new stable surface area should be
added as a part of this commit.

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

Two new attributes have been added to the compiler:

* `#![needs_allocator]` - this is used by liballoc (and likely only liballoc) to
  indicate that it requires an allocator crate to be in scope.
* `#![allocator]` - this is a indicator that the crate is an allocator which can
  satisfy the `needs_allocator` attribute above.

The ABI of the allocator crate is defined to be a set of symbols that implement
the standard Rust allocation/deallocation functions. The symbols are not
currently checked for exhaustiveness or typechecked. There are also a number of
restrictions on these crates:

* An allocator crate cannot transitively depend on a crate that is flagged as
  needing an allocator (e.g. allocator crates can't depend on liballoc).
* There can only be one explicitly linked allocator in a final image.
* If no allocator is explicitly requested one will be injected on behalf of the
  compiler. Binaries and Rust dylibs will use jemalloc by default where
  available and staticlibs/other dylibs will use the system allocator by
  default.

Two allocators are provided by the distribution by default, `alloc_system` and
`alloc_jemalloc` which operate as advertised.

Closes #27389
2015-08-14 15:13:10 -07:00
Alex Crichton
8d90d3f368 Remove all unstable deprecated functionality
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-12 14:55:17 -07:00
Alex Crichton
837ae4f3d4 rollup merge of #27678: alexcrichton/snapshots
* Lots of core prelude imports removed
* Makefile support for MSVC env vars and Rust crates removed
* Makefile support for morestack removed
2015-08-11 22:42:22 -07:00
Alex Crichton
737397c584 rollup merge of #27622: eefriedman/https-url
Also fixes a few outdated links.
2015-08-11 22:11:25 -07:00
Alex Crichton
938099a7eb Register new snapshots
* Lots of core prelude imports removed
* Makefile support for MSVC env vars and Rust crates removed
* Makefile support for morestack removed
2015-08-11 15:11:13 -07:00
Eli Friedman
bbbfed2f93 Use https URLs to refer to rust-lang.org where appropriate.
Also fixes a few outdated links.
2015-08-09 14:28:46 -07:00
Tobias Bucher
22ec5f4af7 Replace many uses of mem::transmute with more specific functions
The replacements are functions that usually use a single `mem::transmute` in
their body and restrict input and output via more concrete types than `T` and
`U`. Worth noting are the `transmute` functions for slices and the `from_utf8*`
family for mutable slices. Additionally, `mem::transmute` was often used for
casting raw pointers, when you can already cast raw pointers just fine with
`as`.
2015-08-09 22:05:22 +02:00
Alex Crichton
5cccf3cd25 syntax: Implement #![no_core]
This commit is an implementation of [RFC 1184][rfc] which tweaks the behavior of
the `#![no_std]` attribute and adds a new `#![no_core]` attribute. The
`#![no_std]` attribute now injects `extern crate core` at the top of the crate
as well as the libcore prelude into all modules (in the same manner as the
standard library's prelude). The `#![no_core]` attribute disables both std and
core injection.

[rfc]: https://github.com/rust-lang/rfcs/pull/1184
2015-08-03 17:23:01 -07:00
bors
87055a68c3 Auto merge of #27371 - Gankro:str-clone, r=alexcrichton
This is a minor [breaking-change], as it changes what
`boxed_str.to_owned()` does (previously it would deref to `&str` and
call `to_owned` on that to get a `String`). However `Box<str>` is such an
exceptionally rare type that this is not expected to be a serious
concern. Also a `Box<str>` can be freely converted to a `String` to
obtain the previous result anyway.
2015-07-30 10:25:23 +00:00
bors
db2af71d59 Auto merge of #27174 - Gankro:rc-sat, r=alexcrichton
See https://internals.rust-lang.org/t/rc-is-unsafe-mostly-on-32-bit-targets-due-to-overflow/2120 for detailed discussion of this problem.
2015-07-30 05:54:55 +00:00
Alexis Beingessner
3e954a8cb2 implement Clone for Box<str>, closes #27323
This is a minor [breaking-change], as it changes what
`boxed_str.to_owned()` does (previously it would deref to `&str` and
call `to_owned` on that to get a `String`). However `Box<str>` is such an
exceptionally rare type that this is not expected to be a serious
concern. Also a `Box<str>` can be freely converted to a `String` to
obtain the previous behaviour anyway.
2015-07-29 18:43:01 -07:00
Alexis Beingessner
22e2100458 make Arc mem::forget safe 2015-07-29 17:05:40 -07:00
Alexis Beingessner
1ffe3453cb make Rc mem::forget safe 2015-07-29 17:05:40 -07:00
Steve Klabnik
a368adf8e5 Rollup merge of #27326 - steveklabnik:doc_show_use, r=Gankro
In spirit with https://internals.rust-lang.org/t/should-we-keep-including-obvious-imports-in-code-examples/2217, show the feature flags we're using in examples.

(also one instance of 'use')
2015-07-29 10:30:34 -04:00
bors
ba9224f354 Auto merge of #26934 - reem:boxed-slice-clone, r=Gankro
Closes #25097
2015-07-28 19:36:26 +00:00
bors
5b72fa42d4 Auto merge of #27309 - eddyb:snapshot-infdef, r=alexcrichton
FreeBSD i386 snapshot is missing, failed tests (possibly spurious).
r? @alexcrichton
2015-07-28 08:51:21 +00:00
Jonathan Reem
e24423091f Implement Clone for Box<[T]> where T: Clone
Closes #25097
2015-07-28 01:43:17 -07:00
Alex Crichton
b3aa1a6d4a std: Deprecate a number of unstable features
Many of these have long since reached their stage of being obsolete, so this
commit starts the removal process for all of them. The unstable features that
were deprecated are:

* cmp_partial
* fs_time
* hash_default
* int_slice
* iter_min_max
* iter_reset_fuse
* iter_to_vec
* map_in_place
* move_from
* owned_ascii_ext
* page_size
* read_and_zero
* scan_state
* slice_chars
* slice_position_elem
* subslice_offset
2015-07-27 16:38:25 -07:00