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
add the align(ptr) charter #43
Conversation
Makes sense! Relatively simple. @rfcbot fcp merge |
Team member @nikomatsakis 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 at most 2 approvals are outstanding), 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. |
#[cfg_attr(target_pointer_width = "16", repr(C, align(2)))] | ||
#[cfg_attr(target_pointer_width = "32", repr(C, align(4)))] | ||
#[cfg_attr(target_pointer_width = "64", repr(C, align(8)))] | ||
pub struct AtomicPtr<T> { | ||
p: UnsafeCell<*mut T>, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is AtomicPtr
defined like this?
UnsafeCell
is #[repr(transparent)]
and AtomicPtr
is #[repr(C)]
; my understanding is that the minimum alignment of AtomicPtr
therefore must be equal to the minimum alignment of *mut _
.
Unless there's a platform in which the minimum alignment of AtomicPtr
must be greater than the minimum alignment of *mut _
, the cfg_attr
s and align(*)
modifiers seem redundant: AtomicPtr
could be annotated with just #[repr(C)]
.
Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you're missing anything.
🔔 This is now entering its final comment period, as per the review above. 🔔 psst @nikomatsakis, I wasn't able to add the |
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. psst @nikomatsakis, I wasn't able to add the |
Hmm… a bit too late now, but I hadn’t noticed that this charter proposal had evolved to define “the general concept of const expressions within an align attribute” as out of scope. It’s not the end of the world, but I’m disappointed: it adds unnecessary complexity to the language (a magic It would also add an edge case if |
I mean, you're right. And another thing is that the open conversation above where it was pointed out that all the align stuff is probably pointless since it'll have the correct alignment anyway. So honestly, this particular project group might be a dud. Then again, if the conclusion of the group is "nothing that's in scope for us turned out to be a good idea", then that's ultimately an okay conclusion. |
@rfcbot concern coordinate-with-const-generics Thanks for suggesting that, @comex! We discussed this in the meeting today, and we should coordinate this with the const eval folks, to figure out if this could use const evaluation so that We might not need const generic support quite yet, though that might be useful at some point. |
FWIW, |
Zulip topic created to check on the feasibility of general const expression usage: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/const.20eval.20within.20attributes |
(I don't think there's a satisfactory, analogous trick for |
|
||
So far, the `align` attribute only allows for an integer literal as the input. This project group aims to add a new alignment input, `ptr`, which is always the value of the local pointer size. | ||
|
||
It has also been suggested that `size` be allowed as an input value, to request that a type have alignment equal to its own size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The align
modifier only sets a minimum alignment. Oddly, Rust doesn't have an ergonomic way to specify the alignment of a type is exactly equal to a value.
You can set a maximum alignment with the packed
modifier, but it's an error to have both align
and packed
annotations on the same type, even if they're not contradictory:
error[E0587]: type has conflicting packed and align representation hints
--> src/main.rs:1:30
|
1 | #[repr(align(1), packed(2))] pub struct Foo;
| ^^^^^^^^^^^^^^^
I think it was unclear what I meant by |
Surprisingly, Using my demo, you could implement what you describe by desugaring this: #[repr(C, align(size))]
struct Foo {
bar: u8,
baz: u16,
} ...to this: #[repr(C)]
struct Foo {
_align: Align<{
#[repr(C)]
struct Foo {
bar: u8,
baz: u8,
}
if let Some(align) = mem::size_of::<Foo>().checked_next_power_of_two() {
align
} else {
usize::MAX
}
}>,
bar: u8,
baz: u16,
} |
We discussed this in the lang team meeting, and we'd like to charter this group, but we believe based on the linked discussions that this should be doable with simple const expressions. @Lokathor proposed to update the charter to account for this. We'll wait for that updated charter, then merge. |
@joshtriplett can you resolve your outstanding concern? |
or are you waiting for the final edits |
I was going to update the charter based on feedback about const eval in the attribute usage and we were going to discuss again. Hopefully I can do that this weekend. |
I no longer have time to work on this, particularly if the solution is going to potentially be more complicated. Discussed at the meeting Oct 5, 2020.
Closes #35 |
This is a charter for #35
Closes #35
RENDERED