-
Notifications
You must be signed in to change notification settings - Fork 213
Unified collections #200
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
Unified collections #200
Conversation
- Has all of the type inference and disambiguation. - Some of the rules around const. - Does not have the static error rules. - The runtime semantics are there, but won't work for const values. - A bunch of other TODOs.
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.
Looks good! Lots of nitpicky details, but overall I think it's very good.
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
Thinking about the runtime semantics more, I think the way to go is to say that you execute an That termination behavior is a subtype of exectuting a statement (statements can also break, continue or return), so then we can use one specification of the behavior of an Executing an In other words, we just write:
and then we don't need to specify the loops or condition again. DRY, etc. That general section then just needs to say "statement or element" about its body, instead of "statement", but otherwise it doesn't need to change. That avoids the need to duplicate a very complicated piece of semantics (my comments were from memory, there are probably more details). We can do the same for (We might also be able to define |
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.
Looks really good! I've added some comments.
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
Still more to do.
My thoughs on spreads are evolving. If we do that, then there is a constraint that the spreadee in a
should change "assignable to" to "subtype of", and the same for other similar cases. If we remove implicit downcasts in the future, this will happen anyway, we cannot accept a I'm not sure whether we should disallow spreading WDYT? |
I like this idea, but I feel like it's out of scope for this document. When it goes into the real language spec, I would love to dedupe the specification for control flow statements and elements. But for this, I think implementers just need to know what the new behavior is. |
I think that's a reasonable implementation choice, provided the implementation of
Ah, that's an interesting point.
So the idea then is that if you do want to downcast each element, you do it like: var nums = <num>[1, 2, 3];
var ints = <int>[...nums]; // No.
var ints = <int>[...nums.whereType<int>()]; // Yes.
var ints = <int>[for (var n in nums) n as int]; // Yes. I think this is probably where we'll go if we do kill implicit downcasts. But we aren't going to do that yet, so I'm currently leaning towards leaving spread as it is with the understanding that we'll revise it when we get rid of implicit downcasts. Does that sound reasonable?
I don't have strong feelings on this but in Dart today, it feels weird to disallow spreading dynamic, and this proposal should ship pretty soon, so I think the current behavior makes sense with the surrounding language as it is. |
This responds to all of the small-scale feedback on the pull request. There are still a few things here and there I need to take into account. The bigger question about what we want spread to desugar too is still an open question that I want to explore more, but I wanted to get this out first.
These are based on what we discussed at this morning's language meeting.
# Conflicts: # accepted/future-releases/set-literals/feature-specification.md
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
* Reword disambiguation to avoid the confusing mouthful "syntactically known to be", especially because sometimes it relies on context types, which aren't syntax. * Moved some compile-time error checking to a more logical place. * Reworded to make it clear that inference happens even in unambiguous collections.
OK, I think I've responded to everything. I left the Boolean conversion stuff in there because I think it's still useful to handle the " Is there anything else? I'd like to land this soon so the implementers can use it. |
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
Had a thought, on the "everything happens during type inference". We could phrase the entire "figure out whether it's a set or a map" as being type inference.
Dynamic semantics then create a collection matching the static type of the literal, and introduces elements or entries into it (or fails dynamically). Do you think this might be easier to understand, because it's just one group instead of splitting it into two? @eernstg Would it be useful as the spec approach? (I think of type inference as assigning a context type and a static type to each expression, and some type arguments to expressions that have left those out). |
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
OK, I removed the references to "Boolean conversion" and specified the behavior explicitly. (I probably could have done so in a more terse way, but I think what I have works.) Let me know if there's any other changes you'd like to see. |
This is the first of several CLs updating the parser and its listeners to conform to the unified collection spec: dart-lang/language#200 Change-Id: I7750bc4b029f3963b2df77dab3630775ce921bba Reviewed-on: https://dart-review.googlesource.com/c/93740 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
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.
Hi Bob,
sorry about the delay, I had an interview and other stuff in the morning.
I suggested a handful of changes, most of them near-typo fixes.
Apart from that, it's about making sure that leaf elements
includes only the elements that we want, making sure that we apply the inference step when needed (in particular: on literals with 'unknown static type'), and then there are a couple of locations where we need to ascertain that there are no improper circularities in the definition. With those things in mind, I think it would be useful to get buy-in from Lasse on Monday so I'll just keep this as a 'comment' review.
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
accepted/future-releases/unified-collections/feature-specification.md
Outdated
Show resolved
Hide resolved
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.
LGTM!
This is the second of several CLs updating the parser and its listeners to conform to the unified collection spec: dart-lang/language#200 Change-Id: I5c277d05a3726a3f5a40823cf878f025167340e6 Reviewed-on: https://dart-review.googlesource.com/c/93741 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
... and no longer generate handleLiteralSet or handleLiteralMap. In addition, a new hasSetEntry parameter has been added to the handleLiteralSetOrMap event generated by the parser to support existing behavior. Once all listeners have implemented unified collections and that feature is enabled by default, the hasSetEntry parameter can be removed. This is the third of several CLs updating the parser and its listeners to conform to the unified collection spec: dart-lang/language#200 Change-Id: Ia305eab1f720658f357ac4102b0b0c8128d16997 Reviewed-on: https://dart-review.googlesource.com/c/93963 Reviewed-by: Brian Wilkerson <[email protected]>
One more thing that we might want to include: As far as I can see, there is a missing dynamic error for a number of cases. We have this:
but there is no such sentence for the |
OK, here's my attempt to pull together a unified proposal for set literals, spread, and control flow. The basic process was:
Take type inference and disambiguation from the doc Leaf and Lasse put together. I renamed a few things, mostly around "part" -> "element", since "part" already means something in Dart.
Take some grammar changes from that doc but mostly pull them from the spread and control flow proposals since those were more comprehensive. (The doc didn't have C-style for, etc.) Simplified it where I could.
Take the static error checking from the spread and control flow docs, and maybe the set literal one? I don't recall now.
Take const stuff from the doc and the proposals. Right now, it does not separately specify how to produce a const value. I think the runtime semantics are general enough to work for that, with some modifications spelled out in the proposal.
Take runtime semantics from my two proposals since I think those were the most complete.
Let me know what you think!