-
Notifications
You must be signed in to change notification settings - Fork 1.6k
repr(ordered_fields) #3845
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
Open
RustyYato
wants to merge
42
commits into
rust-lang:master
Choose a base branch
from
RustyYato:repr_ordered_fields
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
repr(ordered_fields) #3845
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
e0cdce8
Create 0000-repr-ordered-fields.md
RustyYato 0637bbf
Add a link to the zullip thread
RustyYato 7e4b0c8
Update RFC with PR number
RustyYato 61ce0f2
Grammer fixes
RustyYato 4fa572e
Update Motivation to include the exact issue from MSVC
RustyYato 755644c
Rework reference level section
RustyYato 0d0a79b
Add description for union layout
RustyYato 4f4bf18
Tabs -> Spaces
RustyYato 063af08
Apply suggestions from code review
RustyYato 0c0e429
discriminant -> tag
RustyYato 9e316ff
Qualify alignment assumptions
RustyYato a1700b6
oops, fix typo
RustyYato d75a497
add `repr(declaration_order)` as a potential spelling
RustyYato 6526f5a
Switch enum tag type to defer to `repr(C)` tag type
RustyYato ed96c1b
Rework edition_2024_repr_c warning from future compat to edition warning
RustyYato 01cfb40
Add lints to summary section
RustyYato f11567c
edition migraiton lint -> edition compatibility lint
RustyYato b17f192
fix code example of layout algorithm for enums
RustyYato 488068e
Add reference to MSVC bug in motivation
RustyYato 93f53a5
Add the suspicious_repr_c lint
RustyYato a2737d5
specify precedence of `suspicious_repr_c` lint
RustyYato bb8a392
minor grammer/punctuation fixes
RustyYato 612b99e
Fix MSVC bug description
RustyYato 283df46
Update text/3845-repr-ordered-fields.md
RustyYato 8fe1576
Update from reviews
RustyYato 489b31a
fix typo
RustyYato a5fb9bc
Fix typo
RustyYato 88f631e
Add AIX to motivation
RustyYato dee831d
Add some description for why it's a problem to conflate the two roles…
RustyYato f007f6f
wording improvements for the motivation
RustyYato 703dcb9
fix typo
RustyYato 2e36454
Apply suggestions from code review
RustyYato 472cae7
Minor rewordings
RustyYato 6c48b17
Add sections to motivation and expand AIX to it's own section
RustyYato 2043a02
try fix intradoc link?
RustyYato 4c81c7c
Minor rewording of motivation section
RustyYato 92eb763
Add unresolved question for `repr(C)` where corrosponding C type does…
RustyYato 9fb58ad
fix link
RustyYato 6a16195
`align` -> `__alignof__` on AIX
RustyYato e7bd72a
Apply suggestions from code review
RustyYato 7d7b01a
update motivation section for AIX
RustyYato 81a1a42
Update AIX section and minor rewording throughout
RustyYato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
Turns out this was not entirely right, see rust-lang/unsafe-code-guidelines#552 (comment). So probably best to remove this paragraph again.
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.
That issue should presumably be addressed in this RFC, no?
repr(C)1-ZSTs need to be passed by pointer, but does that apply torepr(ordered_fields)as well?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 main problem is that we have already specified that all 1-ZST have the same ABI. We need to figure out how to clean that up but I don't think this RFC needs to do that.
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.
This RFC currently specifies that new
repr(C)matches C. That requires breaking the “all 1-ZST have the same ABI” rule. So the RFC either needs to specify that it’s actually “repr(C)matches C except for 1-ZSTs”, or it needs to specify that we are breaking the rule. Can’t have it both waysUh oh!
There was an error while loading. Please reload this page.
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 did see that you claimed this before in rust-lang/unsafe-code-guidelines#552. I'm not sure what this is referencing.
If this is referencing the current implementation where 1-ZSTs are explicitly skipped in the ABI. I'm not seeing any documentation guaranteeing this behavior, so it should be fine to change this.
If this is referencing this: https://internals.rust-lang.org/t/creating-1-zsts-guaranteed-to-have-same-extern-c-abi-as/19399/18
Where you said:
This seems rather subtle, and it should be explicitly documented somewhere (perhaps the Rust reference on type layouts/abi).
And if this is indeed your reasoning, then we could (in future editions) ensure that
#[repr(C)]1-ZSTs are only allowed in a#[repr(transparent)]typeFooif all other types inFooare normal non-#[repr(C)]1-ZSTs. (i.e. treat#[repr(C)]types as if they are not 1-ZSTs for#[repr(transparent)]).Uh oh!
There was an error while loading. Please reload this page.
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.
Yes it is a subtle indirect consequence, as explained at the top of rust-lang/unsafe-code-guidelines#552:
If
ABI(ZST) == ABI( () )andABI(ZST) == ABI([u8; 0])it follows thatABI( () ) == ABI([u8; 0]).Yes we could. Though ABI is a cross-edition concern so it'd only help marginally to do this on new editions only.
But we could try to crater whether just doing a transition for this is realistic...
Uh oh!
There was an error while loading. Please reload this page.
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 assume it would be based on the edition where the
repr(C)1-ZST is defined? I.e., same as everything else in this RFC. Note that, if you have:NoFieldswon’t be a ZST at all onwindows-msvc, so it’s not really much more problematic to sayFoodoesn’t compile onwindows-gnueither.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.
Usually it'd be based on the edition of the crate that the repr(transparent) type is defined in.
Otherwise, bumping the edition of the crate that has the empty C struct could lead to downstream build failures.
Yeah, also see rust-lang/unsafe-code-guidelines#552 (comment).
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.
Well, yes, the whole point of this RFC is that changing the meaning of
repr(C)is a breaking change that must be done over an edition.