Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Issue 2690553002: Added generic method syntax to language specification.

Created:
3 years, 10 months ago by eernst
Modified:
3 years, 9 months ago
CC:
reviews_dartlang.org, floitsch
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Added generic method syntax to language specification.

Patch Set 1 #

Total comments: 32

Patch Set 2 : Added informal spec #

Patch Set 3 : Review response #

Total comments: 37
Unified diffs Side-by-side diffs Delta from patch set Stats (+253 lines, -24 lines) Patch
M docs/language/dart.sty View 1 2 1 chunk +3 lines, -0 lines 0 comments Download
M docs/language/dartLangSpec.tex View 1 2 16 chunks +143 lines, -24 lines 12 comments Download
A docs/language/informal/generic-method-syntax.md View 1 1 chunk +107 lines, -0 lines 25 comments Download

Messages

Total messages: 6 (1 generated)
eernst
Added generic method syntax specification to dartLangSpec.tex. The basic idea is to introduce a notion ...
3 years, 10 months ago (2017-02-10 08:54:42 UTC) #2
Lasse Reichstein Nielsen
https://codereview.chromium.org/2690553002/diff/1/docs/language/dartLangSpec.tex File docs/language/dartLangSpec.tex (right): https://codereview.chromium.org/2690553002/diff/1/docs/language/dartLangSpec.tex#newcode620 docs/language/dartLangSpec.tex:620: Functions include function declarations (\ref{functionDeclarations}), methods (\ref{instanceMethods}, \ref{staticMethods}), getters ...
3 years, 10 months ago (2017-02-13 10:26:32 UTC) #3
eernst
Review response https://codereview.chromium.org/2690553002/diff/1/docs/language/dartLangSpec.tex File docs/language/dartLangSpec.tex (right): https://codereview.chromium.org/2690553002/diff/1/docs/language/dartLangSpec.tex#newcode620 docs/language/dartLangSpec.tex:620: Functions include function declarations (\ref{functionDeclarations}), methods (\ref{instanceMethods}, ...
3 years, 10 months ago (2017-02-14 11:26:44 UTC) #4
Lasse Reichstein Nielsen
After reading it, I have the nagging feeling that some things are said more than ...
3 years, 9 months ago (2017-03-06 09:45:15 UTC) #5
Lasse Reichstein Nielsen
3 years, 9 months ago (2017-03-06 15:09:34 UTC) #6
https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
File docs/language/dartLangSpec.tex (right):

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:620: Functions can be introduced by declarations
of functions (\ref{functionDeclarations}), methods (\ref{instanceMethods},
\ref{staticMethods}), getters (\ref{getters}), setters (\ref{setters}), and
constructors (\ref{constructors}); and they can be introduced by function
literals (\ref{functionExpressions}).
"Functions can be introduce by declarations of functions" sounds odd and
circular.
I think it would be better as:
"Functions can be introduced by function declarations (...), method
decalarations (...), ..."
It makes it clear that a "function declaration" is not a function itself, it's a
"declaration", whereas "declarations of functions" separates the two.

To make it slightly shorter, maybe:
"Functions can be introduced by function declarations (...), function
expressions (...), and by declarations of setters (...), ... , and constructors
(...)".

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:623: All function declarations include a
signature, and some include a body.
Here "function declarations" looks like it only refers to
\ref{functionDeclarations} - and the suggested rewrite above just makes it
worse.

Maybe "All declarations of functions ... " (because here it talks about the
declarations above that introduced the functions).

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:625: The formal parameter part optionally
specifies the formal type parameter list of the function, and it specifies its
formal parameter list.
"formal type parameter list" - that wording rubs me the wrong way. Maybe because
it emphasizes the "list", which is a grammatical concept. Maybe just "its formal
type parameters".
Similarly for its formal parameters, which are not a list (unless optional
parameters are considered a single element?)

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:712: The current scope for the function's
signature is the scope that encloses the formal parameter scope.
The type parameter list is part of the signature, so that sentence doesn't seem
correct (or is it recursively the current scope for itself?)

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:2482: \item If $id$ occurs as \code{$e$ \IS{}
$id$} or \code{$e$ \IS{}! $id$} for some expression $e$, or if $id$ occurs as a
type literal, a compile-time error occurs.
Should we include `on` clauses?

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:2482: \item If $id$ occurs as \code{$e$ \IS{}
$id$} or \code{$e$ \IS{}! $id$} for some expression $e$, or if $id$ occurs as a
type literal, a compile-time error occurs.
I'm actually not sure what a "type literal" really is. I can't find a definition
in the spec (only references to it), but I'm guessing that it only applies to
class names, not type variables. (That's probably contrary to something I've
said earlier, but the more you read, the less you know :)
Or maybe it is a type literal, and the distinction is between "type literal" and
"constant type literal". Not sure.

So, just to be safe, "as a type literal" -> "as an identifier expression".

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:2490: This is also the case when they are used as
type arguments, both in type annotations and in instance creation expressions.
and in things like `x is Foo<T>`, which is neither annotation nor instance
creation - either just say that it's everywhere, expand the list to be
exhaustive, or say that it's just examples. This is commentary anyway.

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:2499: Finally, it could silently introduce bugs
into correct programs if we had chosen to let type literals evaluate to a fixed
value, e.g., \DYNAMIC{}.
The "finally" here sounds like it's a separate thing, but isn't it just the
conclusion to the previous sentence. That is, maybe change "Finally" to "So"?

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:3776: The actual type arguments passed to $f$, if
any, have no effect.
That sounds like you actually pass something. As I read the previous text, you
actually ignore the type arguments and don't pass anything. So maybe: "passed to
$f$" -> "in the invocation of $f$" (it's the syntactic occurrence we refer to,
it has no semantics).

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:3886: In this situation, the expression is always
parsed as a generic function invocation.
The ambiguity is not just in argument lists, it's everywhere you have
comma-separated expressions. That also includes list literals and for-loop
increments.

var x = [a<b,c>(d)]
for (;; a<b,c(d));  // Admittedly useless, but we should be consistent.

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:3892: %   argumentPart in the grammar.
We should specify which programs are valid, and what they mean.

If we have a disambiguation rule that is different from the paragraph above
(which is clear and precise - and doesn't match this disabmiguation rule), then
we need to write it *instead* of the previous paragraph.


We can take the easy way out (which is what we did above) and say that whenever
there is a parsing ambiguity where one option is a generic method invocation, we
resolve it to the generic function invocation. The problem is that it doesn't
help parsing very much - it has to actually parse both versions and only reduce
when you have successfully parsed a function invocation. Something like 
  foo<bar,baz.qux>(42) 
is a function invocation but 
  foo<bar,baz.qux.fip>(42) 
is not (baz.qux.fib can't be a "type").

On the other hand, specifying the rule that:
  e1<e2,e3>(  
where < and > are matching, always implies a method invocation
... requires us to *specify* what it means for < and > to be matching, in such a
way that we don't miss foo<int,List<int>>(42) which ends in the token '>>' not
'>'. I would prefer not to define this (what if e2 contains List<int>, what if
e2 contains a << operator, what if e2 contains a + operator, what about
f(x<<y,z>>(w)), what about f(x < a << 2, y >> 3 > (4))?)

It's also annoying that  foo((a)<(b), (c)>(d))  is taken as an (invalid)
function invocation when it so obviously isn't. That expression only matches one
production, and we want to somehow disallow it. The "if there is an ambiguity"
rule can't do that since there is no ambiguity.

What do the current implementations do?

I think we should stay with the "if there is ambiguity, prefer invocation" and
let parsers use the "matching < and > followed by (" as a hint to which parsing
to try first, with an option to backtrack and try again.

https://codereview.chromium.org/2690553002/diff/40001/docs/language/dartLangS...
docs/language/dartLangSpec.tex:3895: An example is \code{f(a<B, C>($d$))}, which
may be an invocation of \code{f} passing two actual arguments of type
\code{bool}, or an invocation of \code{f} passing the result returned by an
invocation of the generic function \code{a}.
Nitpick: You don't know the type is `bool`, operator< is user definable.

Powered by Google App Engine
This is Rietveld 408576698