-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make (A)Rc
/Weak
allocator_api
APIs more consistent
#119761
Conversation
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@rustbot label -T-libs r? rust-lang/libs-api |
☔ The latest upstream changes (presumably #120496) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment was marked as resolved.
This comment was marked as resolved.
2134c8e
to
c412131
Compare
888f0cf
to
5a23ea9
Compare
This comment has been minimized.
This comment has been minimized.
5a23ea9
to
c3136d9
Compare
@rustbot ready |
c3136d9
to
d86ce86
Compare
☔ The latest upstream changes (presumably #124432) made this pull request unmergeable. Please resolve the merge conflicts. |
* Add `into_raw_with_allocator` on `Rc`/`Weak` * Remove `where A: Clone` from `Rc::assume_init`s, `Rc::unwrap_or_clone`, and `Rc::downcast(_unchecked)` * Add `fn allocator(&self)` to `Rc`/`Weak` for all `T: ?Sized` * Make `TryFrom<Rc<[T]>> for Rc<[T; N]>` allocator-aware
…_clone and From<Vec<T, A>> for Arc<[T], A>
d86ce86
to
9f3dc91
Compare
@BurntSushi Friendly ping (I just realized that the |
I'm not really dialed into the allocator work. Can you find someone who is to review this? Maybe @matthieu-m? |
Alternatively, if this PR can be split up into more digestible chunks, that might help get it reviewed more quickly. |
@BurntSushi From what I can tell, this PR does not require any Allocator specific knowledge, it doesn't actually even introduce any call Allocator methods (it eliminates calls to I think any libs member comfortable with API requests can tackle this review without issue. (I'm neither a libs member, nor am I well-versed in API guidelines) |
I'll probably go ahead and split this into multiple PRs then. I probably won't have time to work on that for a week or so, so I'll leave this open if someone wants to reveiw it until then. |
… r=Mark-Simulacrum Relax allocator requirements on some Rc/Arc APIs. Split out from rust-lang#119761 * Remove `A: Clone` bound from `Rc::assume_init`(s), `Rc::downcast`, and `Rc::downcast_unchecked` (`Arc` methods were already relaxed by rust-lang#120445) * Make `From<Rc<[T; N]>> for Rc<[T]>` allocator-aware (`Arc`'s already is). * Remove `A: Clone` from `Rc/Arc::unwrap_or_clone` Internal changes: * Made `Arc::internal_into_inner_with_allocator` method into `Arc::into_inner_with_allocator` associated fn. * Add private `Rc::into_inner_with_allocator` (to match Arc), so other fns don't have to juggle `ManuallyDrop`.
… r=Mark-Simulacrum Relax allocator requirements on some Rc/Arc APIs. Split out from rust-lang#119761 * Remove `A: Clone` bound from `Rc::assume_init`(s), `Rc::downcast`, and `Rc::downcast_unchecked` (`Arc` methods were already relaxed by rust-lang#120445) * Make `From<Rc<[T; N]>> for Rc<[T]>` allocator-aware (`Arc`'s already is). * Remove `A: Clone` from `Rc/Arc::unwrap_or_clone` Internal changes: * Made `Arc::internal_into_inner_with_allocator` method into `Arc::into_inner_with_allocator` associated fn. * Add private `Rc::into_inner_with_allocator` (to match Arc), so other fns don't have to juggle `ManuallyDrop`.
… r=Mark-Simulacrum Relax allocator requirements on some Rc/Arc APIs. Split out from rust-lang#119761 * Remove `A: Clone` bound from `Rc::assume_init`(s), `Rc::downcast`, and `Rc::downcast_unchecked` (`Arc` methods were already relaxed by rust-lang#120445) * Make `From<Rc<[T; N]>> for Rc<[T]>` allocator-aware (`Arc`'s already is). * Remove `A: Clone` from `Rc/Arc::unwrap_or_clone` Internal changes: * Made `Arc::internal_into_inner_with_allocator` method into `Arc::into_inner_with_allocator` associated fn. * Add private `Rc::into_inner_with_allocator` (to match Arc), so other fns don't have to juggle `ManuallyDrop`.
Rollup merge of rust-lang#124981 - zachs18:rc-allocator-generalize-1, r=Mark-Simulacrum Relax allocator requirements on some Rc/Arc APIs. Split out from rust-lang#119761 * Remove `A: Clone` bound from `Rc::assume_init`(s), `Rc::downcast`, and `Rc::downcast_unchecked` (`Arc` methods were already relaxed by rust-lang#120445) * Make `From<Rc<[T; N]>> for Rc<[T]>` allocator-aware (`Arc`'s already is). * Remove `A: Clone` from `Rc/Arc::unwrap_or_clone` Internal changes: * Made `Arc::internal_into_inner_with_allocator` method into `Arc::into_inner_with_allocator` associated fn. * Add private `Rc::into_inner_with_allocator` (to match Arc), so other fns don't have to juggle `ManuallyDrop`.
…-only, r=Mark-Simulacrum Add `fn into_raw_with_allocator` to Rc/Arc/Weak. Split out from rust-lang#119761 Add `fn into_raw_with_allocator` for `Rc`/`rc::Weak`[^1]/`Arc`/`sync::Weak`. * Pairs with `from_raw_in` (which already exists on all 4 types). * Name matches `Box::into_raw_with_allocator`. * Associated fns on `Rc`/`Arc`, methods on `Weak`s. <details> <summary>Future PR/ACP</summary> As a follow-on to this PR, I plan to make a PR/ACP later to move `into_raw(_parts)` from `Container<_, A: Allocator>` to only `Container<_, Global>` (where `Container` = `Vec`/`Box`/`Rc`/`rc::Weak`/`Arc`/`sync::Weak`) so that users of non-`Global` allocators have to explicitly handle the allocator when using `into_raw`-like APIs. The current behaviors of stdlib containers are inconsistent with respect to what happens to the allocator when `into_raw` is called (which does not return the allocator) | Type | `into_raw` currently callable with | behavior of `into_raw`| | --- | --- | --- | | `Box` | any allocator | allocator is [dropped](https://doc.rust-lang.org/nightly/src/alloc/boxed.rs.html#1060) | | `Vec` | any allocator | allocator is [forgotten](https://doc.rust-lang.org/nightly/src/alloc/vec/mod.rs.html#884) | | `Arc`/`Rc`/`Weak` | any allocator | allocator is [forgotten](https://doc.rust-lang.org/src/alloc/sync.rs.html#1487)(Arc) [(sync::Weak)](https://doc.rust-lang.org/src/alloc/sync.rs.html#2726) [(Rc)](https://doc.rust-lang.org/src/alloc/rc.rs.html#1352) [(rc::Weak)](https://doc.rust-lang.org/src/alloc/rc.rs.html#2993) | In my opinion, neither implicitly dropping nor implicitly forgetting the allocator is ideal; dropping it could immediately invalidate the returned pointer, and forgetting it could unintentionally leak memory. My (to-be) proposed solution is to just forbid calling `into_raw(_parts)` on containers with non-`Global` allocators, and require calling `into_raw_with_allocator`(/`Vec::into_raw_parts_with_alloc`) </details> [^1]: Technically, `rc::Weak::into_raw_with_allocator` is not newly added, as it was modified and renamed from `rc::Weak::into_raw_and_alloc`.
Rollup merge of rust-lang#125093 - zachs18:rc-into-raw-with-allocator-only, r=Mark-Simulacrum Add `fn into_raw_with_allocator` to Rc/Arc/Weak. Split out from rust-lang#119761 Add `fn into_raw_with_allocator` for `Rc`/`rc::Weak`[^1]/`Arc`/`sync::Weak`. * Pairs with `from_raw_in` (which already exists on all 4 types). * Name matches `Box::into_raw_with_allocator`. * Associated fns on `Rc`/`Arc`, methods on `Weak`s. <details> <summary>Future PR/ACP</summary> As a follow-on to this PR, I plan to make a PR/ACP later to move `into_raw(_parts)` from `Container<_, A: Allocator>` to only `Container<_, Global>` (where `Container` = `Vec`/`Box`/`Rc`/`rc::Weak`/`Arc`/`sync::Weak`) so that users of non-`Global` allocators have to explicitly handle the allocator when using `into_raw`-like APIs. The current behaviors of stdlib containers are inconsistent with respect to what happens to the allocator when `into_raw` is called (which does not return the allocator) | Type | `into_raw` currently callable with | behavior of `into_raw`| | --- | --- | --- | | `Box` | any allocator | allocator is [dropped](https://doc.rust-lang.org/nightly/src/alloc/boxed.rs.html#1060) | | `Vec` | any allocator | allocator is [forgotten](https://doc.rust-lang.org/nightly/src/alloc/vec/mod.rs.html#884) | | `Arc`/`Rc`/`Weak` | any allocator | allocator is [forgotten](https://doc.rust-lang.org/src/alloc/sync.rs.html#1487)(Arc) [(sync::Weak)](https://doc.rust-lang.org/src/alloc/sync.rs.html#2726) [(Rc)](https://doc.rust-lang.org/src/alloc/rc.rs.html#1352) [(rc::Weak)](https://doc.rust-lang.org/src/alloc/rc.rs.html#2993) | In my opinion, neither implicitly dropping nor implicitly forgetting the allocator is ideal; dropping it could immediately invalidate the returned pointer, and forgetting it could unintentionally leak memory. My (to-be) proposed solution is to just forbid calling `into_raw(_parts)` on containers with non-`Global` allocators, and require calling `into_raw_with_allocator`(/`Vec::into_raw_parts_with_alloc`) </details> [^1]: Technically, `rc::Weak::into_raw_with_allocator` is not newly added, as it was modified and renamed from `rc::Weak::into_raw_and_alloc`.
Generalize `fn allocator` for Rc/Arc. Split out from rust-lang#119761 - For `Rc`/`Arc`, the existing associated `fn`s are changed to allow unsized pointees. - For `Weak`s, new methods are added. `@rustbot` label +A-allocators
Generalize `fn allocator` for Rc/Arc. Split out from rust-lang#119761 - For `Rc`/`Arc`, the existing associated `fn`s are changed to allow unsized pointees. - For `Weak`s, new methods are added. ``@rustbot`` label +A-allocators
Generalize `fn allocator` for Rc/Arc. Split out from rust-lang#119761 - For `Rc`/`Arc`, the existing associated `fn`s are changed to allow unsized pointees. - For `Weak`s, new methods are added. ```@rustbot``` label +A-allocators
Generalize `fn allocator` for Rc/Arc. Split out from rust-lang#119761 - For `Rc`/`Arc`, the existing associated `fn`s are changed to allow unsized pointees. - For `Weak`s, new methods are added. ````@rustbot```` label +A-allocators
Generalize `fn allocator` for Rc/Arc. Split out from rust-lang#119761 - For `Rc`/`Arc`, the existing associated `fn`s are changed to allow unsized pointees. - For `Weak`s, new methods are added. `````@rustbot````` label +A-allocators
Rollup merge of rust-lang#124980 - zachs18:rc-allocator, r=Amanieu Generalize `fn allocator` for Rc/Arc. Split out from rust-lang#119761 - For `Rc`/`Arc`, the existing associated `fn`s are changed to allow unsized pointees. - For `Weak`s, new methods are added. `````@rustbot````` label +A-allocators
Make
Arc
/sync::Weak
/Rc
/rc::Weak
unstablefeature(allocator_api)
APIs more consistent with other containers (well,Box
), and with each other.fn into_raw_with_allocator
for all.from_raw_in
(which already exists on all 4 types).Box::into_raw_with_allocator
.Rc
/Arc
, methods onWeak
s.fn allocator
for all.Rc
/Arc
, the existing associated fns are changed to allow unsized pointees.Weak
s, methods are added.where A: Clone
bound on (stable)Rc::downcast
anddowncast_unchecked
, (unstable)assume_init
s, and some (stable) trait implsArc::{downcast{,_unchecked}, assume_init}
were changed by Fix someArc
allocator leaks #120445)downcast(_unchecked)
andassume_init
semantically should not require cloning the allocator; they are essentially just ((un)checked) pointer casts.A: Clone
bound fromFrom<Vec<T, A>> for Arc<[T], A>
(Rc
's already didn't have aA: Clone
bound)and(done by Fix someTryFrom<Arc<[T], A>> for Arc<[T; N], A>
Arc
allocator leaks #120445) (see below forRc
)TryFrom<Rc<[T]>> for Rc<[T; N]>
allocator-aware.This is adding 61 new unstable functions, changing the bounds on
63 unstable functions, and changing the (unstable) bounds on75 stable functions, so I think it needs at least a libs-api FCP? If it also needs an ACP I can make one. (If the parts of this PR should be split I can do that too.)@rustbot label +A-allocators +T-libs-api -T-libs
Future PR
As a follow-on to this PR, I plan to make a PR/ACP later to move
into_raw(_parts)
fromContainer<_, A: Allocator>
to onlyContainer<_, Global>
(whereContainer
=Vec
/Box
/Rc
/rc::Weak
/Arc
/sync::Weak
) so that users of non-Global
allocators have to explicitly handle the allocator when usinginto_raw
-like APIs.The current behaviors of stdlib containers are inconsistent with respect to what happens to the allocator when
into_raw
is called (which does not return the allocator)into_raw
currently callable withinto_raw
Box
Vec
Arc
/Rc
/Weak
In my opinion, neither implicitly dropping nor implicitly forgetting the allocator is ideal; dropping it could immediately invalidate the returned pointer, and forgetting it could unintentionally leak memory. My (to-be) proposed solution is to just forbid calling
into_raw(_parts)
on containers with non-Global
allocators, and require callinginto_raw_with_allocator
(/Vec::into_raw_parts_with_alloc
)Footnotes
Technically 5 new and 1 renamed, since
rc::Weak::into_raw_with_allocator
is not newly added, as it was modified and renamed fromrc::Weak::into_raw_and_alloc
. ↩