-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Neither the Dart Docs (API) nor Language Docs prominently explain JS Number semantics #42924
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
Comments
@kwalrath @mit-mit @leafpetersen - any opinions on where to add this? Update the tour? I'd prefer we describe ints / numbers as platform specific and then detail native and web semantics and differences. |
The language specification has an appendix here. The description there is of course detailed / low-level as well, so the need to describe it in the language tour or a similar location remains. |
The FAQ is a little outdated and hard to find, but maybe we could include the information there as well? Technical detail aside, the spec also isn't a convenient resource to point people to because users have to pull and compile the spec from source. (By the way, should publishing an updated spec here be part of the release process?) Also, the appendices don't currently show up in the table of contents, so I for one wasn't even aware the spec mentioned JS number semantics at all. |
How about we document the non-web version in the language tour, pointing out that the web version has different semantics, and linking to a place under dart.dev/web that goes into these semantics. (That assumes that 80% of developers won't care about the differences; if that's wrong, then maybe we should say more/all in the language tour.) As to how we document this, below is the original content from https://spec.dart.dev/DartLangSpecDraft.pdf. How can we simplify this to be understandable and useful to the majority of developers who need this information? I suspect that we might want to add some examples, so even if we simplify the text, this might end up longer than the spec version. Appendix: Integer ImplementationsThe int type represents integers. The specification is written with 64-bit two’s This introduces a number of differencs [sic]:
|
It's just that the top of the FAQ says it was last updated over a year ago and the very first question points to the Dart 1 spec, so I wasn't sure if we were still actively maintaining it as a resource. It's also a little tricky to find (without Googling "dart faq") - I think the shortest path from dart.dev requires you to click on "Docs", expand the "Resources" menu on the left, and find it nestled between "Code of conduct" and "History". |
I'd like to make sure we don't give folks the impression that Dart on the Web isn't "real" Dart. I personally think of it more akin to platform specific |
@fishythefish wrote:
The 'In-progress specification' section does actually have a link to a PDF which is updated whenever the LaTeX source is updated, which is also the document that @kwalrath mentioned. I used a link into the source because it is difficult to link to a specific location in a PDF file. Note that this appendix is just about to be updated to describe the actual behavior of bit operations (it's unsigned rather than signed), cf. #42892. @vsmenon wrote:
That would be a very nice approach to take. However, it goes somewhat deep. For instance, |
@eernstg wrote:
Does the newly spec'ed behavior work out when compiling to JS? I had understood to be largely orthogonal: it doesn't say anything about precision, and it's about static typing. Are the runtime types we produce on the Web sound wrt the static types in the spec? |
Yes, but it depends on the details of the treatment of numbers for JS compilation, and it's a property which can't be captured by normal type systems that an
Yes. |
Oh, awesome, I knew we had the 2.2 version; I didn't realize we had an updated one on the site as well. |
I should reorg that page to make the in-progress spec easier to find. |
This is not true on any platform that we ship. On every platform that I'm aware of, int has multiple subtypes. I'm highly skeptical that our treatment of numbers is incompatible with there being a common implementation type which implements both the |
@leafpetersen wrote:
The specified constraint is that
Implementations may still have representations that differ (such as SMIs and heap allocated integers), but I believe that there is no way for a Dart program to associate those representations with a proper subtype of
I think it is compatible, which is the reason why I said 'yes' in response to the question about soundness for numbers. Let's call that common (very special) type But type systems cannot capture this property (except perhaps for Coq style dependent types with a detailed description of IEEE 754 addition etc, but anything similar to the Dart type system definitely cannot capture it). So we could replace the IEEE 754 addition by some other computation where 1 plus 1 yields 3.14, and it would then be unsound to give That's the reason why I'm saying that we don't have a nice, well-specifiable language design space where we can just say "here are a couple of rules about |
I think the overall goals here are: This might not belong in the spec. |
I'd be happy to cover it in the language tour or somewhere else on dart.dev, but I need the right simple, helpful words to use. We can always refer to this issue for the full discussion. Anyone interested in helping me get the words? Or in creating a PR yourself? (Just click the doc link at the upper right of the appropriate page...) |
I can do that. I think it would be helpful to describe native numbers and JS numbers separately, and then the part about what Dart programmers can assume could be extracted from that. I'll get in touch via email. |
Yes, pretty much. We plan to publish that article within a month. Then I'll be able to update the docs to summarize and refer to it. |
OK, thanks! Then I won't worry about this unless I hear more. |
@kwalrath I think this can be closed now. |
It indeed can; we now have https://dart.dev/guides/language/numbers |
An internal user newer to Dart had filed a bug ~roughly to the following:
I actually sort of flailed around for 10-15 minutes assuming we had docs to explain this and largely failed.
... none of these really mention anything about our number semantics.
int
does mention:... but I think honestly this is way too low-level to be useful to most users, at least as the only documentation provided..
Sources I used when helping define the problem:
@nshahan did mention the following:
https://dart.dev/guides/language/language-tour#numbers
... but that only mentions:
... which again, isn't quite what I would hope we would present to users potentially new to both Dart and JS.
(At one point we also had a lint for
is double
, but I don't see that anywhere anymore)The text was updated successfully, but these errors were encountered: