Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 2043: Add `align_offset` intrinsic (formerly: and `[T]::align_to` function) #44488
Comments
aturon
added
B-RFC-approved
T-libs
labels
Sep 11, 2017
aturon
referenced this issue
Sep 11, 2017
Merged
Add `align_offset` intrinsic and `[T]::align_to` function #2043
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Sep 16, 2017
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 16, 2017
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 16, 2017
TimNN
added
the
C-tracking-issue
label
Sep 17, 2017
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 18, 2017
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Sep 18, 2017
kennytm
referenced this issue
Dec 18, 2017
Merged
Fix the wrong subtraction in align_offset intrinsic. #46812
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Dec 18, 2017
This comment has been minimized.
This comment has been minimized.
|
@oli-obk Is it useful to stabilize |
This comment has been minimized.
This comment has been minimized.
|
Generally yes, because that's the key feature. Align_to is just convenience |
This comment has been minimized.
This comment has been minimized.
|
Alright, then. Let’s stabilize @rfcbot fcp merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 17, 2018
•
|
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
rfcbot
added
the
proposed-final-comment-period
label
Mar 17, 2018
This comment has been minimized.
This comment has been minimized.
|
@rfcbot concern motivation-and-ergonomics The original motivation for these functions (unless it's changed, which it may have!) I believe was for miri and const evaluating various functions. Is that still the main motivation for these functions? If so do we expect that more things to be available on stable once these are stabilized? I'm a little unclear about how and when such an intrinsic would be used so I'm mostly looking to straighten up my own thinking! In particular the clause "If it is not possible to align the pointer, the implementation returns usize::max_value()." I'm having trouble wrapping my head around in how it'd be expected to get used. Is the long term plan to make this a In terms of ergonomics I'd also naively expect a signature like: pub fn align_to(self, align: usize) -> Option<*mut Self>;but would that create the same problems it's trying to avoid? |
This comment has been minimized.
This comment has been minimized.
yes
This will allow making it const fn, which is a separate topic in the future
No matter which computation you use to figure out the number of bytes that you need to offset your pointer in order to make it aligned, you will need to check whether it still points into your buffer. If you have a
No, these operations are fine. The issue is that no matter how many bytes you offset a
You could do that, but then you'd also need an argument for the allocation size. Now that I think about it, that doesn't seem too bad and since you need to check anyway... As long as the intrinsic doesn't have to return an |
This comment has been minimized.
This comment has been minimized.
|
Ok, thanks for the info! It sounds like this function doesn't necessarily unlock anything in the near term as const-things are still pretty unstable? If that's the case I'm personally tempted to leave these as unstable until we've got the const story more fleshed out to see how they fit into the grand scheme of things |
This comment has been minimized.
This comment has been minimized.
|
Oh dear, it has been almost a year since the RFC and it went totally outside my radar, until I really, really needed Thinking about possible implementation approaches, I realised that to implement loop {
x = intrinsics::align_offset(ptr, align);
if (x is aligned to object start) { return }
ptr = x.offset(1);
}So with @oli-obk we decided that it would probably be most prudent to simply change the intrinsic to do such calculation by itself, changing its signature from the current one to |
This comment has been minimized.
This comment has been minimized.
|
I’m almost done with the improved implementation of the
I propose that we change |
This comment has been minimized.
This comment has been minimized.
|
I'm assuming we are talking about elements of the source slice and not the aligned slice. Sgtm |
This comment has been minimized.
This comment has been minimized.
|
I guess I should’ve said in “number of |
This comment has been minimized.
This comment has been minimized.
|
IIRC this was in bytes in the intrinsic because the pointer to align could have a ZST pointee, and always using bytes sidesteps the questions of what to do there. (Not that I'm sure why you'd want to align a |
This comment has been minimized.
This comment has been minimized.
|
FYI implementation for |
bors
added a commit
that referenced
this issue
May 17, 2018
bors
added a commit
that referenced
this issue
May 18, 2018
bors
added a commit
that referenced
this issue
May 18, 2018
Centril
added
the
disposition-merge
label
May 24, 2018
This comment has been minimized.
This comment has been minimized.
|
As another case in point that getting this code right when hand-written is hard: Spot the issue in this code. The problem is that the inner slice is not aligned properly in all cases when it is empty. If we had a stable |
This comment has been minimized.
This comment has been minimized.
|
ping @llogiq |
This comment has been minimized.
This comment has been minimized.
|
This shouldn't happen because we only call the function for larger slices. But I've been wrong in the past, so I wouldn't bet on it. |
crepererum
referenced this issue
Aug 8, 2018
Closed
ARROW-2583: [Rust] Buffer should be typeless #2330
This comment has been minimized.
This comment has been minimized.
|
I’d like to suggest to focus on stabilising The fact that it took me (with a help from another person) months to implement |
This comment has been minimized.
This comment has been minimized.
|
Agreed, the sooner we can get people to use this instead of hand-rolling their own, the better. :) Just one comment on a remark in the implementation PR:
miri cannot guarantee this. So while the implementation should do that, users of this code should NOT rely on the I cannot think of a case where this is require for correctness anyway, is there one? |
This comment has been minimized.
This comment has been minimized.
|
Oh yes, that is true. I’m fine with removing that guarantee from the documentation. |
This comment has been minimized.
This comment has been minimized.
|
So, what would this take? Just open an RFC that stabilizes, and ask for FCP? |
This comment has been minimized.
This comment has been minimized.
|
@RalfJung Yeah, I think a PR to stabilize (with a comment about why) is sufficient. |
This comment has been minimized.
This comment has been minimized.
|
PR submitted: #53754 |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Would a separate function or method for this special case (or maybe even for |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin yeah the API I mentioned above I think would be fine to add and consider stabilizing |
This comment has been minimized.
This comment has been minimized.
|
Is it has the disposition-merge tag since 9 months, which issues needs to be resolved before solving this?
This is exactly my use case. |
This comment has been minimized.
This comment has been minimized.
|
There is still an outstanding concern from @alexcrichton about the ergonomics of the API. |
This comment has been minimized.
This comment has been minimized.
|
Uh, didn't it get stabilized with #53754 ? EDIT: Oh, I guess this tracking issue is about |
This comment has been minimized.
This comment has been minimized.
Yes. |
RalfJung
changed the title
Tracking issue for RFC 2043: Add `align_offset` intrinsic and `[T]::align_to` function
Tracking issue for RFC 2043: Add `align_offset` intrinsic (formerly: and `[T]::align_to` function)
Feb 13, 2019
This comment has been minimized.
This comment has been minimized.
|
@rfcbot resolve motivation-and-ergonomics I don't want to personally be on the hook for blocking this any more |
rfcbot
added
the
final-comment-period
label
Feb 20, 2019
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 20, 2019
|
|
rfcbot
removed
the
proposed-final-comment-period
label
Feb 20, 2019
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 2, 2019
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
aturon commentedSep 11, 2017
•
edited by RalfJung
This is a tracking issue for the RFC "Add
align_offsetintrinsic and[T]::align_tofunction " (rust-lang/rfcs#2043).align_tois stable, so this tracks justalign_offsetnow.Steps:
align_to: #53754Unresolved questions:
sizeof<T>() % sizeof<U>() != 0and in case the expansion is not part of a monomorphisation, since in that casealign_tois statically known to never be effective