Skip to content

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

Merged
merged 10 commits into from
Jan 11, 2016
Merged

Conversation

pczarn
Copy link
Contributor

@pczarn pczarn commented Aug 13, 2015

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.

@rust-highfive
Copy link
Contributor

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@huonw
Copy link
Member

huonw commented Aug 13, 2015

cc @gankro particularly for the RawVec changes.

struct Chunk {
data: Rc<RefCell<Vec<u8>>>,
data: RawVec<u8>,
Copy link
Member

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.

Copy link
Contributor Author

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.

@huonw
Copy link
Member

huonw commented Aug 13, 2015

I idly wonder if this will slow the typedarena down noticably: it is adding an extra allocation (the Vec of chunks) and more indirection to get to the elements of the last chunk (have to index the vector and then dereference, instead of just a straight dereference).

That said I imagine it's not noticable.

@pczarn pczarn force-pushed the arena-internals branch 5 times, most recently from ef5f6e9 to 8a08f17 Compare August 14, 2015 17:49
@bors
Copy link
Collaborator

bors commented Sep 8, 2015

☔ 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit return not needed

@Gankra
Copy link
Contributor

Gankra commented Sep 8, 2015

\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 :(

@pczarn
Copy link
Contributor Author

pczarn commented Sep 8, 2015

Thanks. Changes are pushed.

@bors
Copy link
Collaborator

bors commented Sep 11, 2015

☔ The latest upstream changes (presumably #28306) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Collaborator

bors commented Sep 25, 2015

☔ The latest upstream changes (presumably #28610) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Collaborator

bors commented Oct 14, 2015

☔ The latest upstream changes (presumably #29026) made this pull request unmergeable. Please resolve the merge conflicts.

@pczarn
Copy link
Contributor Author

pczarn commented Oct 26, 2015

Updated

@Gankra
Copy link
Contributor

Gankra commented Oct 26, 2015

rustc: x86_64-unknown-linux-gnu/stage2/test/arenatest-x86_64-unknown-linux-gnu

src/libarena/lib.rs:610:29: 610:59 error: box expression syntax is experimental; you can call `Box::new` instead. (see issue #27779)

src/libarena/lib.rs:610             let _: Box<_> = box Point { x: 1, y: 2, z: 3 };

                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/libarena/lib.rs:610:29: 610:59 help: add #![feature(box_syntax)] ```to the crate attributes to enable

error: aborting due to previous error

@pczarn
Copy link
Contributor Author

pczarn commented Nov 18, 2015

Corrected

@bors
Copy link
Collaborator

bors commented Nov 25, 2015

☔ The latest upstream changes (presumably #30017) made this pull request unmergeable. Please resolve the merge conflicts.

@shepmaster
Copy link
Member

@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.

@pczarn
Copy link
Contributor Author

pczarn commented Jan 6, 2016

@bluss: It's deprecated. :shipit: 🎉

@aturon
Copy link
Member

aturon commented Jan 6, 2016

Nominating for libs team discussion re: deprecation.

@aturon aturon added I-nominated T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed I-nominated labels Jan 6, 2016
@aturon
Copy link
Member

aturon commented Jan 8, 2016

Libs team consensus: the deprecation here isn't really relevant, as the crate is already gated by rustc_private.

@bluss
Copy link
Member

bluss commented Jan 8, 2016

Thank you @aturon. Let's go again!

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 8, 2016

📌 Commit e2ccc4f has been approved by bluss

@bors
Copy link
Collaborator

bors commented Jan 8, 2016

⌛ Testing commit e2ccc4f with merge 927d22d...

@bors
Copy link
Collaborator

bors commented Jan 8, 2016

💔 Test failed - auto-linux-64-nopt-t

@bluss
Copy link
Member

bluss commented Jan 10, 2016

@bors retry

@bors
Copy link
Collaborator

bors commented Jan 11, 2016

⌛ Testing commit e2ccc4f with merge d3e5b72...

@bors
Copy link
Collaborator

bors commented Jan 11, 2016

💔 Test failed - auto-mac-64-opt

@alexcrichton
Copy link
Member

@bors: retry

On Mon, Jan 11, 2016 at 3:07 PM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-mac-64-opt
http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/7619


Reply to this email directly or view it on GitHub
#27807 (comment).

@bors
Copy link
Collaborator

bors commented Jan 11, 2016

⌛ Testing commit e2ccc4f with merge 02dc12b...

@bors
Copy link
Collaborator

bors commented Jan 11, 2016

💔 Test failed - auto-linux-64-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

On Mon, Jan 11, 2016 at 7:41 PM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-linux-64-nopt-t
http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/7595


Reply to this email directly or view it on GitHub
#27807 (comment).

@bors
Copy link
Collaborator

bors commented Jan 11, 2016

⌛ Testing commit e2ccc4f with merge dfaddb7...

bors added a commit that referenced this pull request Jan 11, 2016
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.
@bors bors merged commit e2ccc4f into rust-lang:master Jan 11, 2016
}

struct TypedArenaChunk<T> {
marker: marker::PhantomData<T>,

/// Pointer to the next arena segment.
Copy link
Contributor

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?

@Gankra
Copy link
Contributor

Gankra commented Jan 12, 2016

🎊

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")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this crate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.