-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Refactor and improve: Arena, TypedArena #27807
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
Conversation
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
cc @gankro particularly for the RawVec changes. |
f515cd8
to
b7410d6
Compare
struct Chunk { | ||
data: Rc<RefCell<Vec<u8>>>, | ||
data: RawVec<u8>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this possibly needs to be RawVec<UnsafeCell<u8>>
since there's effectively a transmute from &Chunk
-> &mut [u8]
in the various allocation methods; however I'm not totally sure it's needed because the Arena ensures non-aliased-ness of everything it hands out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think UnsafeCell can be left out as long as we only use non-aliased or raw pointers. UnsafeCell's docs say:
In general, transmuting an
&T
type into an&mut T
is considered undefined behavior.
I idly wonder if this will slow the typedarena down noticably: it is adding an extra allocation (the That said I imagine it's not noticable. |
ef5f6e9
to
8a08f17
Compare
☔ The latest upstream changes (presumably #28287) made this pull request unmergeable. Please resolve the merge conflicts. |
// We can't directly divide `size`. | ||
self.cap = new_cap; | ||
} | ||
return size >= new_alloc_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit return not needed
\o/ for RawVec helping out even more! All the RawVec-internal stuff seems good, but I don't have the bandwidth to review the Arena stuff, sadly :( |
8a08f17
to
97a168b
Compare
Thanks. Changes are pushed. |
☔ The latest upstream changes (presumably #28306) made this pull request unmergeable. Please resolve the merge conflicts. |
97a168b
to
afa449c
Compare
☔ The latest upstream changes (presumably #28610) made this pull request unmergeable. Please resolve the merge conflicts. |
afa449c
to
92df7ff
Compare
☔ The latest upstream changes (presumably #29026) made this pull request unmergeable. Please resolve the merge conflicts. |
92df7ff
to
e682b3c
Compare
Updated |
|
e682b3c
to
c765391
Compare
Corrected |
☔ The latest upstream changes (presumably #30017) made this pull request unmergeable. Please resolve the merge conflicts. |
@pczarn great, I appreciate that! Although I'm totally cool with it having well-tested unsafe code ;-) I could always do some head-to-head perf testing between the two implementations to see if it's useful. |
270ed4c
to
e2ccc4f
Compare
@bluss: It's deprecated. |
Nominating for libs team discussion re: deprecation. |
Libs team consensus: the deprecation here isn't really relevant, as the crate is already gated by |
📌 Commit e2ccc4f has been approved by |
⌛ Testing commit e2ccc4f with merge 927d22d... |
💔 Test failed - auto-linux-64-nopt-t |
@bors retry |
⌛ Testing commit e2ccc4f with merge d3e5b72... |
💔 Test failed - auto-mac-64-opt |
@bors: retry On Mon, Jan 11, 2016 at 3:07 PM, bors notifications@github.com wrote:
|
⌛ Testing commit e2ccc4f with merge 02dc12b... |
💔 Test failed - auto-linux-64-nopt-t |
@bors: retry On Mon, Jan 11, 2016 at 7:41 PM, bors notifications@github.com wrote:
|
Fixes #18037 "TypedArena cannot handle zero-sized types". Closes #17931 "improve chunk allocation scheme used by Arena / TypedArena". Closes #22847 "TypedArena should implement Send". - N.B. Arena cannot implement Send, since it may contain non-Send values. Closes #18471 "`Arena::alloc_copy_inner` (at least) should be renamed and made public." - Added `Arena::alloc_bytes`. Closes #18261 "support clearing TypedArena with the chunks preserved". - Only the largest chunk is preserved.
} | ||
|
||
struct TypedArenaChunk<T> { | ||
marker: marker::PhantomData<T>, | ||
|
||
/// Pointer to the next arena segment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should be removed, right?
🎊 Thanks so much for persevering on this, @pczarn! |
#[unstable(feature = "rustc_private", | ||
reason = "Private to rustc", issue = "0")] | ||
#[rustc_deprecated(since = "1.6.0-dev", reason = | ||
"The reflection-based arena is superseded by the any-arena crate")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this crate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jethrogb I published it now: https://crates.io/crates/any-arena
Fixes #18037 "TypedArena cannot handle zero-sized types".
Closes #17931 "improve chunk allocation scheme used by Arena / TypedArena".
Closes #22847 "TypedArena should implement Send". - N.B. Arena cannot implement Send, since it may contain non-Send values.
Closes #18471 "
Arena::alloc_copy_inner
(at least) should be renamed and made public." - AddedArena::alloc_bytes
.Closes #18261 "support clearing TypedArena with the chunks preserved". - Only the largest chunk is preserved.