-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Make Rc<T>::deref
and Arc<T>::deref
zero-cost
#132553
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
base: master
Are you sure you want to change the base?
Conversation
b283c44
to
ae36f44
Compare
This comment has been minimized.
This comment has been minimized.
Would it potentially enable those types to have an ffi compatible ABI? So that they could be returned and passed directly from /to ffi function, like |
This comment has been minimized.
This comment has been minimized.
I think in theory it is possible, at least for sized types, but I am not familiar with how to formally make it so. |
ae36f44
to
0d6165f
Compare
This comment has been minimized.
This comment has been minimized.
0d6165f
to
98edd5b
Compare
This comment has been minimized.
This comment has been minimized.
r? libs |
98edd5b
to
8beb51d
Compare
This comment has been minimized.
This comment has been minimized.
8beb51d
to
d7879fa
Compare
This comment has been minimized.
This comment has been minimized.
d7879fa
to
317aa0e
Compare
@EFanZh Is this ready for review? If so, please un-draft the PR. |
@joboet: The source code part is mostly done, but I haven’t finished updating LLDB and CDB pretty printers. The CI doesn’t seem to run those tests. |
No worries! I just didn't want to keep you waiting in case you had forgotten to change the state. |
f243654
to
1308bf6
Compare
This comment has been minimized.
This comment has been minimized.
ac5a4e6
to
41d9c4c
Compare
This comment has been minimized.
This comment has been minimized.
41d9c4c
to
9d4fbaf
Compare
@thaliaarchi: Do you mean the allocation functions? I have checked those functions, most functions are used more than once, and the function that are used once are used for unifying non-generic codes used in generic functions. @rustbot ready |
☔ The latest upstream changes (presumably #133572) made this pull request unmergeable. Please resolve the merge conflicts. |
a72c6d5
to
2ae47dd
Compare
☔ The latest upstream changes (presumably #140378) made this pull request unmergeable. Please resolve the merge conflicts. |
2ae47dd
to
7999ed8
Compare
☔ The latest upstream changes (presumably #140726) made this pull request unmergeable. Please resolve the merge conflicts. |
This PR is way too large for me to review. Is there any way you could split this up? E.g. by moving the |
@joboet: The majority codes are in
|
Alternatively, an approach to consider, if splitting horizontally isn’t feasible, you could split it vertically: Split it into a commit history of discrete, atomic steps progressing towards the goal of the PR. Even if it needs to be merged all at once, this can aid reviewing. I know the Rust project prefers smaller PRs, though, so that should be preferred if possible, but the approaches could be combined. |
That sounds very reasonable! |
7999ed8
to
369a658
Compare
369a658
to
d51458a
Compare
@joboet: I have split this PR into two commits:
|
d51458a
to
22c49c6
Compare
Make `Rc<T>::deref` zero-cost This PR makes `Rc::deref` zero-cost by changing the internal pointer so that it points to the value directly instead of the allocation. This is split out from #132553, which will also make `Arc::deref` zero-cost.
Currently,
Rc<T>
andArc<T>
store pointers toRcInner<T>
andArcInner<T>
. This PR changes the pointers so that they point toT
directly instead.This is based on the assumption that we access the
T
value more frequently than accessing reference counts. With this change, accessing the data can be done without offsetting pointers fromRcInner<T>
andArcInner<T>
to their contained data. This change might also enables some possibly useful future optimizations, such as:&[Rc<T>]
into&[&T]
within O(1) time.&[Rc<T>]
intoVec<&T>
utilizingmemcpy
.&Option<Rc<T>>
intoOption<&T>
without branching.Rc<T>
andArc<T>
FFI compatible types whereT: Sized
.