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

Change integer fallback RFC to suggest `i32` instead of `int` as the fallback #452

Merged
merged 6 commits into from Dec 25, 2014

Conversation

Projects
None yet
@tbu-
Copy link
Contributor

tbu- commented Nov 7, 2014

@1fish2

This comment has been minimized.

Copy link

1fish2 commented on text/0212-restore-int-fallback.md in cd464e9 Nov 7, 2014

For this use, I suggest that int is worse than i32 on 16-bit architectures. The range of i16 is too small in practice to select without careful analysis.

This comment has been minimized.

Copy link
Owner Author

tbu- replied Nov 7, 2014

As I don't want this PR to get filled with extra noise, I'll just say that there doesn't exist a 16-bit architecture Rust is targeting right now.

@1fish2

This comment has been minimized.

Copy link

1fish2 commented on text/0212-restore-int-fallback.md in cd464e9 Nov 7, 2014

Yes! In selecting the fallback type, we should rule out platform-dependent types due to portability bugs.

We can rule out unsigned types because the values sometimes need to be signed. Rule out i8 and i16 since they're too small to use without careful analysis.

That leaves i32 and i64. There's a weaker case here. i32 is faster. Many programmers will expect the default to be i32 from their past experience from other languages and most C/C++ calling conventions, where i32 has worked well.

This comment has been minimized.

Copy link
Owner Author

tbu- replied Nov 7, 2014

i32 is reasonable sized for common "don't care" use cases. If the programmer needs 64bit they should already be thinking about integer sizes.

@P1start

This comment has been minimized.

Copy link
Contributor

P1start commented Nov 7, 2014

Changing the fallback to i32 seems a bit pointless if int still represents a pointer-sized integer: the name int will be the type people will use for integers simply because of the name. IMO the fallback should always be int, but int should be redefined to be a 32-bit integer (but not a synonym of i32), and int and uint should be renamed to something like index and uindex (or whatever).

@thestinger

This comment has been minimized.

Copy link

thestinger commented Nov 8, 2014

@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 i32 type is very clearly named and would be a better type inference default than a pointer-size integer only useful for computing pointer offsets within objects. I don't think it's a good idea to have a hardware integer type without a name communicating the size.

@P1start

This comment has been minimized.

Copy link
Contributor

P1start commented Nov 8, 2014

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 int, they just want any integer type that is reasonable for arithmetic and so on. Forcing them to consider the size has upsides, but it also can get in the way when it doesn’t really matter.

It’s just an idea, really: having a redundant integer type is certainly a bit weird. I certainly don’t think int and uint’s names should stay, though, if we change the fallback to something else.

@arcto

This comment has been minimized.

Copy link

arcto commented Nov 8, 2014

I think this discussion is deviating from the issue: should integer fallback go to the specific size i32 or to the system's pointer size?

I'm for having a specific size (i32) for the reasons presented in the RFC, most importantly portability, predictability.

@thestinger

This comment has been minimized.

Copy link

thestinger commented Nov 8, 2014

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.

A hardware integer type with no particular size is not useful. The only suitable integer type in that case would be a big integer.

A lot of the time when people write int, they just want any integer type that is reasonable for arithmetic and so on.

Hardware integer types are not "reasonable" for arithmetic. They are bounded, and using them correctly requires considering the overflow cases.

Forcing them to consider the size has upsides, but it also can get in the way when it doesn’t really matter.

There aren't cases where the size doesn't matter beyond an integer being abused as a boolean.

@dobkeratops

This comment has been minimized.

Copy link

dobkeratops commented Nov 8, 2014

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
type MyIndex = min<int,i32>;

int is whats used for indexing - but does associated types make it easier to get the desired index from the collection now?
(personally I want a Vec with parameterised index, since on 64bit machines I still usually want 32bit indices.. 32bits x 16byte structures is enough to fill memory on many target devices. Vec<T,Index=int>

@Gankro

This comment has been minimized.

Copy link
Contributor

Gankro commented Nov 8, 2014

@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.

@tbu-

This comment has been minimized.

Copy link
Contributor Author

tbu- commented Nov 8, 2014

@P1start

Changing the fallback to i32 seems a bit pointless if int still represents a pointer-sized integer.

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.

@Kimundi

This comment has been minimized.

Copy link
Member

Kimundi commented Nov 9, 2014

+1, falling back to a concrete, clearly defined integer size seems to be less problematic than falling back to the systems pointer size.

@comex

This comment has been minimized.

Copy link

comex commented Nov 9, 2014

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 int) now give you integers of different sizes. And if int is to become 32-bit then this textual change is not necessary anyway.

@tbu-

This comment has been minimized.

Copy link
Contributor Author

tbu- commented Nov 9, 2014

@comex No matter whether int changes or not, this RFC discusses why the current pointer-sized int is unsuitable for integer fallback. If you want other int stuff changed (I also do), please do so in another RFC.

@Ericson2314

This comment has been minimized.

Copy link
Contributor

Ericson2314 commented Nov 13, 2014

+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 int anduint`, and using a index-ish/pointer-ish name instead, will make those NOT being the fallback more understandable, but that is a separate discussion.

@1fish2 1fish2 referenced this pull request Nov 13, 2014

Closed

RFC: Renaming int/uint #464

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Nov 17, 2014

The PR seems to change the mode of text/0401-coercions.md, it probably shouldn't.

@tbu-

This comment has been minimized.

Copy link
Contributor Author

tbu- commented Nov 19, 2014

@nick29581 Fixed.

@rkjnsn

This comment has been minimized.

Copy link
Contributor

rkjnsn commented Nov 20, 2014

👍 if we have to have a fallback, I think i32 makes the most sense.

@tbu-

This comment has been minimized.

Copy link
Contributor Author

tbu- commented Dec 14, 2014

@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.

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Dec 14, 2014

@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.

@Valloric

This comment has been minimized.

Copy link

Valloric commented Dec 15, 2014

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.

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Dec 23, 2014

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...

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Dec 23, 2014

At least conceptually, it should be merged, yes. I haven't read the exact text in a while.

@nrc nrc referenced this pull request Dec 25, 2014

Closed

Restore int fallback #16968

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Dec 25, 2014

Merging, r=nikomatsakis

nrc added a commit that referenced this pull request Dec 25, 2014

Merge pull request #452 from tbu-/pr_inti32
Change RFC #212 (integer fallback) to use `i32` instead of `int` as the fallback

@nrc nrc merged commit da7d52e into rust-lang:master Dec 25, 2014

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Dec 25, 2014

Since this modifies an existing RFC, there is no new tracking issue, instead we will continue to use issue 16968

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.