-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Change integer fallback RFC to suggest i32
instead of int
as the fallback
#452
Conversation
Changing the fallback to |
@P1start: I don't understand why we would want redundant integer type... especially if it wasn't just an alias and forced the usage of casts. The |
What I mean is that there’s an advantage of having an integer type that is just ‘an’ integer type, and not any size in particular. (It could still be 32 bits, but that would not be much more than an implementation detail. There could be an attribute, for example, to change its size.) A lot of the time when people write It’s just an idea, really: having a redundant integer type is certainly a bit weird. I certainly don’t think |
I think this discussion is deviating from the issue: should integer fallback go to the specific size I'm for having a specific size ( |
A hardware integer type with no particular size is not useful. The only suitable integer type in that case would be a big integer.
Hardware integer types are not "reasonable" for arithmetic. They are bounded, and using them correctly requires considering the overflow cases.
There aren't cases where the size doesn't matter beyond an integer being abused as a boolean. |
I think there's a lot of merit to making int "at least 32bits", many programmers expect it; even on 16bit machines, 32bit values were common... 16bit machines weren't limited to 64k ram,etc. There were/are also 16bit architectures that were basically logically 32bits, its just 16bit arithmetic happens to be faster. But you'd need another type which is 'definitely the pointer size' But imagine if you could select types at compile time: type MyInt = max<int,i32>; //std::whatever::min<A,B> is some builtin that selects the smallest int is whats used for indexing - but does associated types make it easier to get the desired index from the collection now? |
@thestinger I think the argument is about offering better type semantics for integer-sizedness. Define int/uint as a synonym for i32/u32 (move old int/uint to some other name), and promote them for programming "in the small" (where overflowing an i32 is rarely a concern-- especially if you're just using them as opaque values for some generic code), and as a way to advertise that the size of the number has not been seriously reflected on. Sort of like stubbing out types. |
@P1start
It is not, for the reasons laid out in the RFC text: it is more correct for the cases where the fallback applies. You are free to open an RFC for the other cases (I would appreciate it), but please don't go offtopic here. |
+1, falling back to a concrete, clearly defined integer size seems to be less problematic than falling back to the systems pointer size. |
I'm not sure it's as off topic as you suggest. Shipping one without the other would, in my opinion, leave the language buggy: two cases that programmers would expect to produce a "generic integer type" (a number without context, and a type called |
@comex No matter whether |
+1. In my view, you shouldn't rely on integer fallback unless you are programming in the small, and I cannot foresee nobody programming in the small on a 16-bit architecture. Getting rid of |
The PR seems to change the mode of text/0401-coercions.md, it probably shouldn't. |
@nick29581 Fixed. |
👍 if we have to have a fallback, I think |
@nick29581 Since there's still no negative feedback, can I expect something to happen here? In my opinion we have a clear argument for this RFC (without negative responses!), yet it's still not merged. |
@tbu we (the Rust team) spent some time discussing this at the work week, we've got to do some more haggling over the details (aka, consensus building :-) ), expect news soon. |
This would be a great change. 32bit ints are faster than 64bit ints for all the reasons listed in the RFC changes, but just having the default int pinned down to a specific size and not having it architecture-dependent is a massive bonus to Rust's claim of aiming for robust code. Compiling code on two different architectures should not lead to hard-to-track-down bugs. |
See this post for more thoughts from the Rust team. I think this means I can merge this RFC, but I should double check first... |
At least conceptually, it should be merged, yes. I haven't read the exact text in a while. |
Merging, r=nikomatsakis |
Change RFC #212 (integer fallback) to use `i32` instead of `int` as the fallback
Since this modifies an existing RFC, there is no new tracking issue, instead we will continue to use issue 16968 |
Rich diff