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 upPolicy for assumptions about the size of `usize` #1748
Comments
durka
referenced this issue
Sep 12, 2016
Closed
RangeInclusive<usize> shouldn't impl ExactSizeIterator #36386
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Sep 13, 2016
|
Let's see if we can narrow the bounds just a little.
|
This comment has been minimized.
This comment has been minimized.
|
Makes good sense to me. Those proposals still leave the question of what to do about
|
nrc
added
the
T-lang
label
Sep 13, 2016
This comment has been minimized.
This comment has been minimized.
Gate impls on
It would make porting simpler because incorrect range assumptions and overflows will be caught at compile time. |
This comment has been minimized.
This comment has been minimized.
|
Caught at compile time when you're porting. If we put in |
This comment has been minimized.
This comment has been minimized.
|
@durka Impls like |
This comment has been minimized.
This comment has been minimized.
|
I like the idea of having a lint if an impl is selected that's tagged with |
This comment has been minimized.
This comment has been minimized.
oyvindln
commented
Sep 14, 2016
I don't know about wider types, but |
This comment has been minimized.
This comment has been minimized.
comex
commented
Sep 14, 2016
|
Maybe a set of special purpose lints? #[allow(assume_usize_ge_32_bits)]
#[allow(assume_usize_le_64_bits)]The standard library really should provide some way to safely cast under such assumptions, whether From or something else. If it doesn't, most people won't avoid making them; they'll just hide them in |
This comment has been minimized.
This comment has been minimized.
Are we actually confident this is a reasonable assumption over the next 50 years? I guess if it becomes untrue we can make a breaking change. |
aturon
added
the
I-nominated
label
Sep 27, 2016
This comment has been minimized.
This comment has been minimized.
|
Nominated for lang team discussion. |
nikomatsakis
removed
the
I-nominated
label
Oct 6, 2016
This comment has been minimized.
This comment has been minimized.
|
I wrote up the @rust-lang/lang team discussion in this internals thread. |
This comment has been minimized.
This comment has been minimized.
|
cc #1868 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
https://en.wikibooks.org/wiki/C_Programming/stdint.h#Integers_wide_enough_to_hold_pointers claims that |
This comment has been minimized.
This comment has been minimized.
eternaleye
commented
Jul 9, 2017
|
@SimonSapin: I checked the C standards, because the linked page cites the manpage, which might have been overconstrained (both C and POSIX apply constraints to some types and constants).
So yes, C's |
durka
referenced this issue
Jul 19, 2017
Closed
`time::Instant` is a different size of different platforms #43332
pitdicker
referenced this issue
Dec 14, 2017
Merged
Select "SimpleRand" over generic "Rand" for backwards compatibility #71
This comment has been minimized.
This comment has been minimized.
|
PR rust-lang/rust#49305 includes:
|
SimonSapin
referenced this issue
Mar 28, 2018
Closed
Tracking issue for platform-dependent-API TryFrom impls involving usize/isize #49415
This comment has been minimized.
This comment has been minimized.
scottjmaddox
commented
Dec 13, 2018
|
Perhaps all Making this work (or at least work efficiently) might require an extension to |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Dec 13, 2018
|
A possible way forward: Define some new submodules, e.g. No new language features would be required. |
This comment has been minimized.
This comment has been minimized.
|
Unfortunately, the idea doesn't work because |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Dec 13, 2018
Keep in mind that those modules wouldn't exist for targets that don't meet the limits. |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Dec 13, 2018
|
Oh, I see, you're saying that the conversions would still be possible even if the program didn't have the |
This comment has been minimized.
This comment has been minimized.
|
But when they do there's no way to enforce the requirement to import them.
The impls are visible regardless. I can't think of a way to do this with
imports, but maybe there is some hack with generics and specialization or
something.
…On Thu, Dec 13, 2018 at 12:11 AM Brian Smith ***@***.***> wrote:
Unfortunately, the idea doesn't work because impls don't respect module
scope like that. A portability lint is the way to go.
Keep in mind that those modules *wouldn't exist* for targets that don't
meet the limits.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1748 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n463tqs3icNe7eB3OyT_HZLI1z5yks5u4eFrgaJpZM4J6_rn>
.
|
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Mar 21, 2019
|
I see that Also note that there are attempts to define a "maximum object size" and so far many people have suggested that |
briansmith
referenced this issue
Mar 21, 2019
Open
Are raw pointers to sized types usable in C FFI ? #99
This comment has been minimized.
This comment has been minimized.
There is no conversion here, even implicit. A |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Mar 21, 2019
You and I are saying the same thing in different ways. The point is that this works for most, but not all, platforms: fn foo(n: usize) -> libc::size_t { n }In rust-lang/unsafe-code-guidelines#99 at least one person claimed that that code isn't guaranteed to work for all targets because sometimes |
This comment has been minimized.
This comment has been minimized.
I agree that this is incompatible with the way the (This is somewhat besides the point, but what are some platforms where |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Mar 21, 2019
A 64-bit CHERI-based platform will have 256-bit or 128-bit pointers and 64-bit (Also potentially the ordering of I am particularly interested in Rust supporting these security-oriented ABIs in the future as they become practical. |
This comment has been minimized.
This comment has been minimized.
|
Note that we can only control the maximum allowed size of Rust objects (
AFAICT this would only mean that the maximum allowed size of |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Mar 25, 2019
Sure, in theory you could define the maximum object size to be |
This comment has been minimized.
This comment has been minimized.
The exact same can be argued of |
durka commentedSep 12, 2016
•
edited
When in the course of
humanrusty events, something incoreorstddepends on the actual width ofusize/isize, there are currently (at least) two policies in place:usizemay be as narrow as 8 bits.usize: From<u8> + !From<u16>usizeis at least 32 bits wide (as it is on all current officially supported platforms).Range<u32>: ExactSizeIteratorLet me know if I missed any other corners of the standard library which make assumptions (identical to one of these or not).
As these policies are in conflict, it seems like one or both of them should be changed. In principle, we can't remove trait implementations from
Range<u32>and the like, so we could just declaretarget_pointer_width-liberalism to be the law of the land. However, this will make it difficult to port Rust to a 16-bit system. In doing such porting, trait implementations likeFrom<u32> for usizeandExactSizeIterator for Range<u32>would need to be gated by a#[cfg]. But, this would make it difficult to port Rust code from, say, a 32-bit target to a 16-bit target, because some code would stop compiling (N.B. this is already potentially the case, because literals given for enum variants are interpreted asisizeliterals).So, what should we do?