Uh oh!
There was an error while loading. Please reload this page.
Implement [T]::align_to - #50319
Conversation
rust-highfive
commented
Apr 29, 2018
r? @BurntSushi (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Why is the signature of this function changed? From the diff it doesn't look like you really need the ownership.
There was a problem hiding this comment.
Generating a call to the language item will terminate the block being passed in, so using that block further makes no sense. Passing ownership models this pretty well.
There was a problem hiding this comment.
Is this just a refactoring or necessary for the new align_offset? If it's just refactoring I prefer this being separated into its own commit.
There was a problem hiding this comment.
Without the new This change is necessary for implementation of align_offset this change is not necessary.align_offset itself.
nagisa
commented
May 3, 2018
I’ll probably redo the PR slightly to not use an intrinsic at all – miri will still be able to detect calls to this by looking at langitem defid of the function. |
oli-obk
commented
May 3, 2018
I think we already do that for some u128 lowerings |
f27ddd1 to
9b7a579CompareSo, adapting the code was pretty easy, however it seems to have a hard hit on code quality in debug builds. Most notably, constant propagation is not active, so the dead code is not removed, making what should essentially be I’m still going to go with this, because all the issues can be fixed with some const evaluation at a later date. |
scottmcm
commented
May 5, 2018
I recall that this approach caused some problems with the i128 stuff, since it could get inlined and disappear. (It'd be nice, now that MIRI is merged, so go back and redo the lowering functions as const fn so they wouldn't need to be special at eval time, though last I tried intrinsics couldn't be marked |
nagisa
commented
May 5, 2018
const functions can’t do conditional code yet due to #49146. |
bors
commented
May 6, 2018
☔ The latest upstream changes (presumably #50466) made this pull request unmergeable. Please resolve the merge conflicts. |
emilyalbini
commented
May 10, 2018
Ping from triage @BurntSushi! This PR needs your review. |
nagisa
commented
May 10, 2018
Perhaps somebody else from the @rust-lang/libs wants to volunteer to review this? |
emilyalbini
commented
May 14, 2018
Ping from triage! This PR needs a review, can @BurntSushi or someone else from @rust-lang/libs review this? |
alexcrichton
commented
May 16, 2018
This seems like it's a lot of unstable internal details that are unlikely to be stabilized soon so I'm not necessarily reviewing too too closely. @oli-obk does this overall change look ok to you? I think you were one of the original proponents for the intrinsic, right? |
oli-obk
commented
May 16, 2018
Yes, I already talked with @nagisa every now and then about it and have reviewed the current state last week. This is fine with me, though I can't grok the math, the tests look like it works out.
I created the rfc and initial impl. We still need this for miri to continue working. |
alexcrichton
commented
May 16, 2018
@bors: r+ |
bors
commented
May 16, 2018
📌 Commit cdc5f33 has been approved by |
bors
commented
May 17, 2018
⌛ Testing commit cdc5f334616211a3620a2a50239ec11c7b56afa1 with merge 5c5dc122a7cc2ed813958e12c595f67c4ea5c8cd... |
bors
commented
May 17, 2018
💔 Test failed - status-appveyor |
Keep only the language item. This removes some indirection and makes codegen worse for debug builds, but simplifies code significantly, which is a good tradeoff to make, in my opinion. Besides, the codegen can be improved even further with some constant evaluation improvements that we expect to happen in the future.
nagisa
commented
May 17, 2018
@bors r=alexcrichton |
bors
commented
May 17, 2018
📌 Commit 59bb0fe has been approved by |
bors
commented
May 18, 2018
⌛ Testing commit 59bb0fe with merge ccd0949aa5b6b143c3f16f7324c19868de26ad2b... |
bors
commented
May 18, 2018
💔 Test failed - status-travis |
rust-highfive
commented
May 18, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
rust-highfive
commented
May 18, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
nagisa
commented
May 18, 2018
I don’t get this failure. The log just… stops… as if somebody flicked the power switch in Travis’ data centre. |
kennytm
commented
May 18, 2018
@bors retry |
bors
commented
May 18, 2018
Implement [T]::align_to Note that this PR deviates from what is accepted by RFC slightly by making `align_offset` to return an offset in elements, rather than bytes. This is necessary to sanely support `[T]::align_to` and also simply makes more sense™. The caveat is that trying to align a pointer of ZST is now an equivalent to `is_aligned` check, rather than anything else (as no number of ZST elements will align a misaligned ZST pointer). It also implements the `align_to` slightly differently than proposed in the RFC to properly handle cases where size of T and U aren’t co-prime. Furthermore, a promise is made that the slice containing `U`s will be as large as possible (contrary to the RFC) – otherwise the function is quite useless. The implementation uses quite a few underhanded tricks and takes advantage of the fact that alignment is a power-of-two quite heavily to optimise the machine code down to something that results in as few known-expensive instructions as possible. Currently calling `ptr.align_offset` with an unknown-at-compile-time `align` results in code that has just a single "expensive" modulo operation; the rest is "cheap" arithmetic and bitwise ops. cc #44488@oli-obk As mentioned in the commit message for align_offset, many thanks go to Chris McDonald.
bors
commented
May 19, 2018
☀️ Test successful - status-appveyor, status-travis |

Note that this PR deviates from what is accepted by RFC slightly by making
align_offsetto return an offset in elements, rather than bytes. This is necessary to sanely support[T]::align_toand also simply makes more sense™. The caveat is that trying to align a pointer of ZST is now an equivalent tois_alignedcheck, rather than anything else (as no number of ZST elements will align a misaligned ZST pointer).It also implements the
align_toslightly differently than proposed in the RFC to properly handle cases where size of T and U aren’t co-prime.Furthermore, a promise is made that the slice containing
Us will be as large as possible (contrary to the RFC) – otherwise the function is quite useless.The implementation uses quite a few underhanded tricks and takes advantage of the fact that alignment is a power-of-two quite heavily to optimise the machine code down to something that results in as few known-expensive instructions as possible. Currently calling
ptr.align_offsetwith an unknown-at-compile-timealignresults in code that has just a single "expensive" modulo operation; the rest is "cheap" arithmetic and bitwise ops.cc #44488@oli-obk
As mentioned in the commit message for align_offset, many thanks go to Chris McDonald.