Skip to content
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

Specify bit validity and padding of some types #1

Closed
wants to merge 442 commits into from
Closed

Conversation

joshlf
Copy link
Owner

@joshlf joshlf commented Aug 11, 2023

Specify the bit validity and padding of the primitive numeric types, bool, char, and pointer and reference types.

Closes rust-lang#1291

Havvy and others added 30 commits August 14, 2022 00:47
…e-cast-documentation

#[non_exhaustive] on variant blocks cross-crate as casts
allow to quickly edit a page directly on github
Update examples of what implements `Termination`
The reference currently states that "[t]he size of a value is always a multiple of its alignment." This might be taken to imply that a type's size is greater than or equal to its alignment. This commit clarifies that 0 is a valid multiple; zero-sized types have 0 size and nonzero alignment.
* fix "typo" when declaring semantics of `return` from within async block
* remove confusing false comment from the example
Clarify reference on async blocks
This was mostly mechanical. There are only two things of note:

1. A couple sentences ended with commas instead of periods. I changed
   them to periods. They were both in the Binding Modes section, so I
   assume they were added together.

2. In the static/dynamic behavior for or patterns, for two sections, I
   separated lines based on commas instead of the one really large
   sentence they are.
Remove `ne` from derive example
ehuss and others added 29 commits July 8, 2023 15:11
…ever

Remove doc of unstable feature of never type
Say that division by zero for primitive types panics
…r-change

Make unsafe keyword docs less confusing
Operator expressions: make the note about division by zero clearer.
I personally found this description of UB confusing, since the use of
"reached" suggests that UB only happens for read bytes, and the
definition of immutability is not given, allowing for multiple
interpretations: does the "data" have to be immutable from the first
read? From the creation of the reference? Between reads from the
immutable accessor, but not otherwise? etc.

This clarifies the actual UB conditions, based on this Zulip
interaction:
https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/What.20exactly.20are.20.22immutable.22.20and.20.22reached.22.20in.20shared.20ref.20UB.3F
and this reference discussion:
rust-lang#1227
in two ways:
  * The definition of "data" is clarified to be stated in terms of
    bytes, in a way that should avoid ambiguity about which bytes are
    considered. Based on the GH issue, this clarification should also
    allow for use of a `*mut` pointer through a shared reference, which
    is not in itself UB. Based on the Zulip issue, the definition
    includes padding bytes, which may be surprising.
  * The definition of immutability & mutation for a set of bytes is
    clarified to mean forbidding *all* non-0-byte writes.
This is part of the feedback on rust-lang#1385.

Ralf made the point that the immutability definition could be restated
solely in terms of bytes, which has the added benefit of no longer
requiring the note on padding (since it's a natural consequence of the
byte version.)

The new wording for shared references also clarifies the case of mutable
references behind shared ones, and reintroduces some of the transitivity
property that I removed in my previous commit. The wording is separate
from that for immutable bindings, since those don't have transitive
immutability.

This also bumps the definition of bytes pointed to by references and
pointers into its own subsection, so that it can be linked to by the UB
definition, to avoid duplication.

Co-authored-by: Ralf Jung <[email protected]>
These changes should preserve the meaning of the contents.

Co-authored-by: Ralf Jung <[email protected]>
…arification

Clarify UB around immutability & mutation
Fix merge queue building twice.
Clearly specify the `instruction_set` effects
compile_fail is a dangerous thing to use since it doesn't validate which
error is generated (it could be something like a typo).
Specify the bit validity and padding of the primitive numeric 
types, bool, char, and pointer and reference types.

Closes rust-lang#1291
@joshlf joshlf closed this Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Describe bit validity and padding for primitive types