-
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
Restore int/f64 fallback for unconstrained literals #212
Conversation
cc https://github.com/rust-lang/meeting-minutes/blob/master/workweek-2014-08-18/integer-inference.md (work week notes) |
The advantage here over what we used to do is that it only does the fallback when the type is unconstrained, rather than the "early" fallback that we used to do. (+1 ofc) |
👍 Very much in favor of this. |
@cmr hmm, interesting point. I had forgotten about things like |
@nikomatsakis I agree. |
Another alternative is to allow specifying the default on a per-module basis as Haskell does, or perhaps even per-scope. I remember this had tricky interactions with recursive modules, but maybe that was only because of global type inference (which Rust doesn't have)? It could also probably be added later in a backwards compatible way. As for the particular default: what about |
The |
|
||
# Detailed design | ||
|
||
Integeral literals are currently type-checked by creating a special |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integer or Integral...
@thestinger the performance impact was addressed by @glaebhoerl : "I'm not sure if the performance impact would be meaningful for these "programming in the small" use cases, and a different type can be specified explicitly, anyways." I would be inclined to consider i64 as the the default. Especially since the |
I don't think a type without hardware support makes sense as a default. It's significantly slower (20-100%) when it does have hardware support, but it's actually emulated in software on a 32-bit CPU. On a 16-bit architecture, it would not exist at all without a significant amount of effort. It's typical to have an implementation of double-width integers (64-bit on 32-bit, 128-bit on 64-bit) but not quad-width - it would be so incredibly slow. Rust has already experienced a lot of bad PR due to |
The current situation is that there is no default, and programs with unconstrained integer literals are rejected. My belief is that we do currently qualify as a systems language. I don't think it's possible to become less of a systems language by accepting strictly more programs, no matter what the default is. To put it another way: I don't think the choice of default is particularly consequential, for reasons outlined in the RFC. |
I would like "integer literals" to be accepted for specifying |
Agreed with @thestinger. A systems language should default to a 32 bit |
@bluss: I would too, but it's a separate issue from this. |
On Tue, Aug 26, 2014 at 11:40:19PM -0700, Daniel Micay wrote:
I don't. I think this is actually quite unfair to say. As Felix and |
It's another issue that people are going to run into while trying the language that will give them a bad impression of the performance. It's already necessary to use |
In a way, that's even scarier. People will unwittingly hit it by accident on that one rare occasion and then it will become a Rust "gotcha" people will write blog posts about to warn others. If there's ever an Effective Rust book along the lines of Effective C++, I imagine it will have a rule like "always fully specify your integers, don't use the fallback." IMO one of the critical questions one must ask oneself when designing a language feature is "will any part of this design at some point be called a 'gotcha'." This whole fallback-to-a-slow-integer idea fails that test miserably. |
@Valloric I do see this argument. I suppose it comes down to whether it's seen as problematic that most users of 'Rust in the large' will have a recommended set of lints? You could argue having flexible lints (and the ability to add new syntax extensions and lints on a per-codebase basis) is an advantage of Rust and something that hopefully allows it to scale down for small pieces of code or tests as well as up to very large codebases. |
Could we feature gate fallback? Having to explicitly enable the feature for programming in the small might defeat the purpose, but I'd agree avoiding gotchas is more important. |
@Ericson2314 I think feature-gating it completely removes the entire point of fallback, as you already suggested. For what it's worth, I agree with @Valloric. I used to think that the fallback should be |
Well, it is still easier to enable a feature gate once, than add suffixes in many places in your code when programming in the small. I'd guess I'd be fine with the a lint (as some suggested) being on by default too---a few warnings should not inhibit programming in the small too much. |
A feature that always produces a warning is not an appropriate feature. Programming "in the small" should not lead to ignoring a bunch of warnings. |
Actually, I think features that produce warnings are great. Holes and differed type errors with newer GHC allow one to program in an uninterrupted, while reminding you that you should clean them up later via a warning as they make your program bomb. You have the convenience and unimpeded flow of developing with scripting languages, with the safety of statically typed ones because you are reminded of every potential bug you introduce. I view this as the same sort of feature: defaulting to some integer type is a code smell in systems languages. In fact with checked arithmetic (also good for prototyping, though not exclusively that), the wrong integer type could also make your program bomb just like these GHC features. But for prototyping or programming in the small, it is an acceptable temporary shortcut. |
I would be in favor of a warning. |
On review I would like like to hear niko's thoughts on on this suggestion from @glaebhoerl
An attribute could be very nice here, especially w.r.t. future proofing future options for literal handling |
Agreed with @thestinger and @Valloric, the If the initial value is positive, does a default And does the |
|
||
To our knowledge, there has not been a single bug exposed by removing | ||
the fallback to the `int` type. Moreover, such bugs seem to be | ||
extremely unlikely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the int
/uint
, there is at least the rust-lang/rust#16736 issue (and I bet that other similar bugs will pop).
@l0kod Unsigned as default will be surprising to many people. |
Merged as RFC 56. |
I support the use of i32 as fallback instead of int, since it is :
|
Change RFC #212 (integer fallback) to use `i32` instead of `int` as the fallback
Rendered view: https://github.com/rust-lang/rfcs/blob/master/text/0212-restore-int-fallback.md