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 upRestore int/f64 fallback for unconstrained literals #212
Conversation
This comment has been minimized.
This comment has been minimized.
|
cc https://github.com/rust-lang/meeting-minutes/blob/master/workweek-2014-08-18/integer-inference.md (work week notes) |
This comment has been minimized.
This comment has been minimized.
|
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) |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@cmr hmm, interesting point. I had forgotten about things like |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis I agree. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
thestinger
commented
Aug 26, 2014
|
The |
glaebhoerl
reviewed
Aug 26, 2014
|
|
||
| # Detailed design | ||
|
|
||
| Integeral literals are currently type-checked by creating a special |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@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 |
This comment has been minimized.
This comment has been minimized.
thestinger
commented
Aug 27, 2014
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Aug 27, 2014
|
I would like "integer literals" to be accepted for specifying |
This comment has been minimized.
This comment has been minimized.
Valloric
commented
Aug 27, 2014
|
Agreed with @thestinger. A systems language should default to a 32 bit |
This comment has been minimized.
This comment has been minimized.
thestinger
commented
Aug 28, 2014
|
@bluss: I would too, but it's a separate issue from this. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
thestinger
commented
Aug 28, 2014
|
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 |
This comment has been minimized.
This comment has been minimized.
Valloric
commented
Aug 28, 2014
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. |
This comment has been minimized.
This comment has been minimized.
asb
commented
Aug 28, 2014
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
@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 |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
I would be in favor of a warning. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
l0kod
commented
Sep 3, 2014
|
Agreed with @thestinger and @Valloric, the If the initial value is positive, does a default And does the |
l0kod
reviewed
Sep 3, 2014
|
|
||
| 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. |
This comment has been minimized.
This comment has been minimized.
l0kod
Sep 3, 2014
About the int/uint, there is at least the rust-lang/rust#16736 issue (and I bet that other similar bugs will pop).
This comment has been minimized.
This comment has been minimized.
|
@l0kod Unsigned as default will be surprising to many people. |
brson
merged commit 39be6aa
into
rust-lang:master
Sep 3, 2014
This comment has been minimized.
This comment has been minimized.
|
Merged as RFC 56. |
This comment has been minimized.
This comment has been minimized.
UtherII
commented
Sep 5, 2014
|
I support the use of i32 as fallback instead of int, since it is :
|
nikomatsakis commentedAug 26, 2014
•
edited by mbrubeck
Rendered view: https://github.com/rust-lang/rfcs/blob/master/text/0212-restore-int-fallback.md