Skip to content
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

Use MaybeUninit in liballoc #54924

Merged
merged 5 commits into from
Oct 12, 2018
Merged

Use MaybeUninit in liballoc #54924

merged 5 commits into from
Oct 12, 2018

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Oct 9, 2018

All code by @japaric. This is a re-submission of a part of #53508 that hopefully does not regress performance.

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2018
@RalfJung
Copy link
Member Author

RalfJung commented Oct 9, 2018

@bors try

@bors
Copy link
Contributor

bors commented Oct 9, 2018

⌛ Trying commit faa733d with merge 1102565...

bors added a commit that referenced this pull request Oct 9, 2018
Use MaybeUninit in liballoc

All code by @japaric. This is a re-submission of a part of #53508 that hopefully does not regress performance.
@bors
Copy link
Contributor

bors commented Oct 9, 2018

☀️ Test successful - status-travis
State: approved= try=True

@RalfJung
Copy link
Member Author

RalfJung commented Oct 9, 2018

@rust-timer build 1102565

@rust-timer
Copy link
Collaborator

Success: Queued 1102565 with parent b1a137d, comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 1102565

@RalfJung
Copy link
Member Author

RalfJung commented Oct 9, 2018

Looking good, doesn't it?

r? @cramertj

src/liballoc/collections/btree/node.rs Show resolved Hide resolved
@@ -73,7 +73,7 @@ struct LeafNode<K, V> {
/// This node's index into the parent node's `edges` array.
/// `*node.parent.edges[node.parent_idx]` should be the same thing as `node`.
/// This is only guaranteed to be initialized when `parent` is nonnull.
parent_idx: u16,
parent_idx: MaybeUninit<u16>,

/// The number of keys and values this node stores.
///
Copy link
Member

Choose a reason for hiding this comment

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

Can you confirm that despite introducing MaybeUninit we are still the same size? (i.e., same 32-bit word layout as indicated by the comment on len)?

Copy link
Member

Choose a reason for hiding this comment

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

MaybeUninit won't introduce any additional alignment requirements that aren't present in the type it wraps, and will only increase the size of the resulting type as a result of inhibiting niche-filling optimizations (and u16 has not niches, so this shouldn't be an issue).

Copy link
Member Author

Choose a reason for hiding this comment

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

What would be a good way to test this? We have a way to "hack" a static_assert!, but the size alone won't do it here because there's a ptr right before this, so on 64bit system it'll be 2 ptr-words in size at least. And we cannot yet do an offset! macro in CTFE. I could add a debug_assert! to test the offset at run-time?

However, I agree with what @cramertj said and this is repr(C), so I am not expecting any surprises. Still, would be nice to be sure.

@cramertj
Copy link
Member

cramertj commented Oct 9, 2018

r=me with @Mark-Simulacrum 's doc nit fixed.

@RalfJung
Copy link
Member Author

r+'ing as per previous review.

@bors r=cramertj

@bors
Copy link
Contributor

bors commented Oct 11, 2018

📌 Commit e4434be has been approved by cramertj

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 11, 2018
@bors
Copy link
Contributor

bors commented Oct 12, 2018

⌛ Testing commit e4434be with merge 567557f...

bors added a commit that referenced this pull request Oct 12, 2018
Use MaybeUninit in liballoc

All code by @japaric. This is a re-submission of a part of #53508 that hopefully does not regress performance.
@bors
Copy link
Contributor

bors commented Oct 12, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: cramertj
Pushing 567557f to master...

@bors bors merged commit e4434be into rust-lang:master Oct 12, 2018
@RalfJung RalfJung deleted the use-maybe-uninit2 branch November 5, 2018 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants