-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Document the size of bool #46156
Document the size of bool #46156
Conversation
It is always 1, right? |
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @BurntSushi (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This is historically not guaranteed on purpose rust-lang/rfcs#954
/cc @rust-lang/lang See also rust-lang/rfcs#992 |
Worth noting that rust-lang/rfcs#954 proposed far more than documenting the size, it proposed guaranteeing a encoding of In contrast, guaranteeing a |
The values true=1, false=0 are documented: https://doc.rust-lang.org/reference/behavior-considered-undefined.html |
The reference is not official rust docs and it is not a real reference yet, unfortunately. |
@bluss then remove that statement from the reference. And no it is official documentation. Otherwise why is it on the doc.rust-lang.org domain? |
Nightly version has a better banner and a link to the nursery repo where it's developed: https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html |
Then we should close this PR as writing down the size of bool won't have any weight... is there a list of "decisions that have actually been made and can be trusted"? |
@durka IMO the authoritative Rust documentation is the standard library's documentation, as the guarantees it specifies are part of the library, and therefore part of Rust's stability guarantees. |
Hmm, so the impact of this change would be to put the compile-time-validity of |
So as the ABI of bool seems to be not specified, please see my PR #46176 to lint about bool in FFI usage. |
Perhaps document |
It appears that C doesn't specify the size of |
The ABI of bool is reserved, see these links: * rust-lang/rfcs#954 (comment) * rust-lang#46156 (comment) * rust-lang/rfcs#992 Currently the improper_ctypes lint is inconsistent with that position by treating bools as if they had a specified ABI. To fix this inconsistency, this changes treatment of bools by the lint. This might break some code, so possibly it has to be phased in slowly...
IMO the size of bool should be defined as the same as the size of |
Basically I think we should just accept RFC 954 at this point. |
I added the table in #44648 and checked what people said on IRC around the time. I'm not seeing any reference to I do have a reference PR where I added it though, but it looks like I'll have to remove that line. 😣 About the UB section of the reference — it's immaterial to this discussion. It's stating that the valid values of |
I wonder why should |
That also seems fine. I think the larger thrust of my objective is that we should stop delaying action based on theoretical concerns. There are neither viable optimizations nor major platforms which conflict with specifying the obvious representation of bool. Any solution in which we specify the repr of boolean as what it has been and will always be on major platforms is good. |
hsivonen wrote in a thread that mentioned this PR:
I think that’s a good point, and we should decide that Rust’s |
Nominated for lang team discussion. |
@vojtechkral It would seem that
As an aside, it would be pretty nice to have |
You’re looking for https://crates.io/crates/bit-vec. This is not possible with |
C++ has experience with that, and it turned out to be better as opt-in instead of magic: https://isocpp.org/blog/2012/11/on-vectorbool |
Triage ping @rust-lang/lang! It seems we still haven't got a clear decision... |
Cross-posting from the internals thread: We finally got around to discussing this in the @rust-lang/lang meeting. We had the following questions, perhaps someone may be in a position to answer authoritatively:
Our preference is to define Relevant to this RFC, @SimonSapin or others, do you think that defining |
Additional question for the list:
C |
From N1570, §6.2.5:
§6.3.1.2:
Ie. I believe from the standard's point of view cppreference.com also notes a consequence:
|
(Replying since I’m mentioned by name. “Better” is a big word. I have no idea. I submitted this PR because it had not occurred to be that this could be otherwise.) |
The FCP has been resolved: #46176 (comment) Please merge this now! |
@bors r+ |
📌 Commit 219ba51 has been approved by |
@bors rollup |
Document the size of bool
No description provided.