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

Issue 2676083002: Connect fasta's scanner to the analyzer-derived scanner tests in front_end. (Closed)

Created:
3 years, 10 months ago by Paul Berry
Modified:
3 years, 10 months ago
CC:
reviews_dartlang.org, dart-fe-team+reviews_google.com
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Connect fasta's scanner to the analyzer-derived scanner tests in front_end. Failing tests are currently marked with "@failingTest" to prevent breaking buildbots. I've marked the issues I'm aware of with "TODO(paulberry,ahe)". Peter and I need to triage these issues--some of them may not be necessary to fix due to the fact that fasta replaces the parser as well. We will follow up with CLs that either fix the issues or remove the TODO comments as appropriate. R=ahe@google.com Committed: https://github.com/dart-lang/sdk/commit/04f19f6bfb458daebbd7e4015ca1c53bc6b3e43e

Patch Set 1 #

Total comments: 19
Unified diffs Side-by-side diffs Delta from patch set Stats (+587 lines, -9 lines) Patch
M pkg/front_end/test/scanner_test.dart View 5 chunks +587 lines, -9 lines 19 comments Download

Messages

Total messages: 11 (3 generated)
Paul Berry
https://codereview.chromium.org/2676083002/diff/1/pkg/front_end/test/scanner_test.dart File pkg/front_end/test/scanner_test.dart (right): https://codereview.chromium.org/2676083002/diff/1/pkg/front_end/test/scanner_test.dart#newcode23 pkg/front_end/test/scanner_test.dart:23: defineReflectiveTests(ScannerTest); Note that this test file now tests both ...
3 years, 10 months ago (2017-02-03 23:10:36 UTC) #2
ahe
Exciting stuff! I've added a few notes, they are not really comments about the code, ...
3 years, 10 months ago (2017-02-04 09:48:19 UTC) #3
Paul Berry
No need to respond to this before Monday--I just wanted to put my thoughts down ...
3 years, 10 months ago (2017-02-04 14:57:55 UTC) #4
ahe
First of all: LGTM! Generally, I expect replies to code reviews within a business day ...
3 years, 10 months ago (2017-02-06 11:01:21 UTC) #5
Paul Berry
https://codereview.chromium.org/2676083002/diff/1/pkg/front_end/test/scanner_test.dart File pkg/front_end/test/scanner_test.dart (right): https://codereview.chromium.org/2676083002/diff/1/pkg/front_end/test/scanner_test.dart#newcode207 pkg/front_end/test/scanner_test.dart:207: // TODO(paulberry,ahe): Fasta doesn't support generic method comment syntax. ...
3 years, 10 months ago (2017-02-06 13:46:54 UTC) #6
Paul Berry
Committed patchset #1 (id:1) manually as 04f19f6bfb458daebbd7e4015ca1c53bc6b3e43e (presubmit successful).
3 years, 10 months ago (2017-02-06 13:54:23 UTC) #8
Siggi Cherem (dart-lang)
very exciting to see this go by and to see the general discussion! I had ...
3 years, 10 months ago (2017-02-06 23:51:29 UTC) #10
Paul Berry
3 years, 10 months ago (2017-02-07 13:56:12 UTC) #11
Message was sent while issue was closed.
https://codereview.chromium.org/2676083002/diff/1/pkg/front_end/test/scanner_...
File pkg/front_end/test/scanner_test.dart (right):

https://codereview.chromium.org/2676083002/diff/1/pkg/front_end/test/scanner_...
pkg/front_end/test/scanner_test.dart:249: // TODO(paulberry,ahe): "[]" should be
parsed as a single token.
On 2017/02/06 23:51:29, Siggi Cherem (dart-lang) wrote:
> On 2017/02/06 13:46:54, Paul Berry wrote:
> > On 2017/02/06 11:01:20, ahe wrote:
> > > On 2017/02/04 14:57:55, Paul Berry wrote:
> > > > On 2017/02/04 09:48:19, ahe wrote:
> > > > > Note: [] and []= are tokenized as a single token only after the
built-in
> > > > > identifier "operator".
> > > > > 
> > > > > See:
> > > > > 
> > > > >
> > > >
> > >
> >
>
https://github.com/dart-lang/sdk/blob/master/pkg/front_end/lib/src/fasta/scan...
> > > > 
> > > > Interesting.  The behavior of the analyzer scanner is to lex "[]" and
> "[]="
> > as
> > > > single tokens wherever they appear.  On the downside, this complicates
the
> > > > analyzer parser slightly, since it means that it must recognize both
`[]`
> > and
> > > > `[` `]` as empty list expressions.  On the upside, it makes it easier
for
> > the
> > > > analyzer parser to recover from errors like this: 
> > > > 
> > > > class Foo {
> > > >   int [](int index) => 0;
> > > > }
> > > > 
> > > > (Analyzer reports the error "Operator declarations must be preceeded by
> the
> > > > keyword 'operator'.").  If we wanted to get this error recovery behavior
> > with
> > > > fasta's lexer, there would be more parser work.  On the other hand,
maybe
> > > that's
> > > > ok, because the extra parser work would be all along an error handling
> code
> > > path
> > > > anyway.  And admittedly, this particular error recovery corner case is
> > > probably
> > > > extremely rare in practice.
> > > 
> > > I agree. A corner case with the dart2js/fasta approach is that if you
write
> > > something like this:
> > > 
> > > main() {
> > >   var operator = ["Hello, World!"];
> > >   print(operator[]); // Forgot 0 here.
> > > }
> > > 
> > > The fasta/dart2js parser won't recover well.
> > > 
> > > My gut feeling is that the analyzer's approach is superior here.
> > > 
> > > > In my mind this issue is simple enough that it's probably not worth
> > > discussing,
> > > > but since it's the first one that came up, let's use it as a practice
run
> > and
> > > > see how the discussion goes.  Once we get into a groove we shouldn't
need
> to
> > > > talk through every single detail.
> > > > 
> > > > I can see a few possible ways to resolve this:
> > > > 
> > > > (1) Change analyzer's parser and scanner to be like Fasta's, and
implement
> > > extra
> > > > logic in analyzer's parser to keep the error recovery behavior.  This
> would
> > > > carry little benefit (it would make the unit test behavior line up, but
> not
> > > > change the user experience other than a possible tiny performance
> > > improvement). 
> > > > And it would all be wasted effort assuming we switch to Fasta in the
long
> > > term.
> > > > 
> > > > (2) Change analyzer's parser and scanner to be like Fasta's, and don't
> worry
> > > > about the error recovery behavior.  This is also wasted effort, though
> > > probably
> > > > less effort than (1).
> > > > 
> > > > (3) Change fasta's parser and scanner to be like analyzer's.  This gets
us
> > the
> > > > nice error recovery behavior, at the expense of some coding effort and a
> > > > possible performance drop (though my intuition is that it would
> unmeasurably
> > > > small).  This is probably not worth it either, given how rare the error
> > > recovery
> > > > corner case is.
> > > 
> > > I agree, I don't even think the performance of fasta is necessarily better
> in
> > > this case.
> > > 
> > > > (4) Keep fasta's scanner as is, and implement logic in its parser to
> handle
> > > the
> > > > error recovery corner case.  Again, probably not worth it, given how
rare
> > the
> > > > error recovery corner case.
> > > > 
> > > > (5) Change nothing.  Fasta code stays simple and efficent, and the only
> > > > user-visible effect is that this particular error recovery case stops
> being
> > > > addressed.
> > > > 
> > > > I personally lean toward (5).  In which case I think the right thing to
do
> > is
> > > > (a) keep the "@failingTest" override, but change the comment to explain
in
> a
> > > > sentence or two why we're ok with Fasta failing this test.  (b) add a
test
> > (or
> > > > tests) validating Fasta's behavior, along with a "@failingTest" override
> for
> > > > analyzer's scanner.  (c) after we've transitioned to Fasta and removed
> > > > analyzer's scanner, we can remove the failing test if we choose to.
> > > > 
> > > > I don't care which one of us does (a) and (b)--it should only take a few
> > > > minutes.
> > > 
> > > I think I see a slightly different option: create a subclass of
> > > `fasta.StringScanner` that overrides tokenizeOpenSquareBracket to behave
as
> > the
> > > analyzer expects. This should have no impact on fasta at all, so we can
just
> > do
> > > this in general, and later look at deciding which approach is the best
long
> > term
> > > (in this case, I think it's the dartanalyzer's).
> > 
> > SGTM.
> 
> A small question: could we annotate somehow these tests that highlights a
> difference we expect to be visible in error recovery?
> 
> Once we have a way of running error recovery tests, I'd suggest just adding a
> test there, but for now, maybe a small comment with a grep-able text? or
filing
> a short bug with a new label (e.g. fasta-recovery)?

I've filed an issue: https://github.com/dart-lang/sdk/issues/28665
I'll follow up with a CL that links to the issue from this test.

Powered by Google App Engine
This is Rietveld 408576698