Bug 170844 - [JSC] use ExpressionErrorClassifier for AwaitExpression operand
Summary: [JSC] use ExpressionErrorClassifier for AwaitExpression operand
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Caitlin Potter (:caitp)
URL:
Keywords:
Depends on:
Blocks: 170732
  Show dependency treegraph
 
Reported: 2017-04-13 20:56 PDT by Caitlin Potter (:caitp)
Modified: 2017-04-14 12:50 PDT (History)
7 users (show)

See Also:


Attachments
Patch (2.54 KB, patch)
2017-04-13 20:57 PDT, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch (2.91 KB, patch)
2017-04-14 07:12 PDT, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch (2.80 KB, patch)
2017-04-14 08:08 PDT, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch (3.05 KB, patch)
2017-04-14 12:02 PDT, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch for landing (3.05 KB, patch)
2017-04-14 12:02 PDT, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch for landing (3.05 KB, patch)
2017-04-14 12:06 PDT, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Caitlin Potter (:caitp) 2017-04-13 20:56:41 PDT
[JSC] use ExpressionErrorClassifier for AwaitExpression operand
Comment 1 Caitlin Potter (:caitp) 2017-04-13 20:57:09 PDT
Created attachment 307087 [details]
Patch
Comment 2 Sam Weinig 2017-04-14 00:08:38 PDT
Comment on attachment 307087 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307087&action=review

> Source/JavaScriptCore/ChangeLog:9
> +        * parser/Parser.cpp:
> +        (JSC::Parser<LexerType>::parseAwaitExpression):

The changelog should ideally include information about why this change is being made. Just from the patch and the test, it isn't immediately clear what is being fixed.
Comment 3 Caitlin Potter (:caitp) 2017-04-14 07:12:25 PDT
Created attachment 307112 [details]
Patch
Comment 4 Caitlin Potter (:caitp) 2017-04-14 08:08:07 PDT
Created attachment 307114 [details]
Patch
Comment 5 Saam Barati 2017-04-14 08:29:54 PDT
Comment on attachment 307114 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307114&action=review

> Source/JavaScriptCore/parser/Parser.cpp:3558
> +    ExpressionErrorClassifier classifier(this);

Does this change the error message that's produced?
Comment 6 Caitlin Potter (:caitp) 2017-04-14 09:10:36 PDT
Comment on attachment 307114 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307114&action=review

>> Source/JavaScriptCore/parser/Parser.cpp:3558
>> +    ExpressionErrorClassifier classifier(this);
> 
> Does this change the error message that's produced?

No, it still produces "Unexpected token '=>'"
Comment 7 Saam Barati 2017-04-14 09:47:06 PDT
Comment on attachment 307114 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307114&action=review

>>> Source/JavaScriptCore/parser/Parser.cpp:3558
>>> +    ExpressionErrorClassifier classifier(this);
>> 
>> Does this change the error message that's produced?
> 
> No, it still produces "Unexpected token '=>'"

I'm confused then what the point of this is? What does ExpressionErrorClassifier do?
Comment 8 Caitlin Potter (:caitp) 2017-04-14 09:59:25 PDT
(In reply to Saam Barati from comment #7)
> Comment on attachment 307114 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=307114&action=review
> 
> >>> Source/JavaScriptCore/parser/Parser.cpp:3558
> >>> +    ExpressionErrorClassifier classifier(this);
> >> 
> >> Does this change the error message that's produced?
> > 
> > No, it still produces "Unexpected token '=>'"
> 
> I'm confused then what the point of this is? What does
> ExpressionErrorClassifier do?

The classifier records hints that indicate which cover grammar productions to try. It allows the parser to skip cover grammars in some cases.
Comment 9 Saam Barati 2017-04-14 10:08:21 PDT
Comment on attachment 307114 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=307114&action=review

>>>>> Source/JavaScriptCore/parser/Parser.cpp:3558
>>>>> +    ExpressionErrorClassifier classifier(this);
>>>> 
>>>> Does this change the error message that's produced?
>>> 
>>> No, it still produces "Unexpected token '=>'"
>> 
>> I'm confused then what the point of this is? What does ExpressionErrorClassifier do?
> 
> The classifier records hints that indicate which cover grammar productions to try. It allows the parser to skip cover grammars in some cases.

Ok, I just read the code to see what this does. I'm still a bit confused why this is needed for correctness. Can you explain that a bit more? What's the issue you're fixing?
Comment 10 Caitlin Potter (:caitp) 2017-04-14 10:21:24 PDT
(In reply to Saam Barati from comment #9)
> Comment on attachment 307114 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=307114&action=review
> 
> >>>>> Source/JavaScriptCore/parser/Parser.cpp:3558
> >>>>> +    ExpressionErrorClassifier classifier(this);
> >>>> 
> >>>> Does this change the error message that's produced?
> >>> 
> >>> No, it still produces "Unexpected token '=>'"
> >> 
> >> I'm confused then what the point of this is? What does ExpressionErrorClassifier do?
> > 
> > The classifier records hints that indicate which cover grammar productions to try. It allows the parser to skip cover grammars in some cases.
> 
> Ok, I just read the code to see what this does. I'm still a bit confused why
> this is needed for correctness. Can you explain that a bit more? What's the
> issue you're fixing?

Inside parseUnaryExpression, we eventually reach parseMemberExpression(), and see `async()` followed by a `=>` token.

In an AssignmentExpression context rather than a UnaryExpression context, this would mean "parse the async arrow function cover grammar", so it records a hint to do that. But the AssignmentExpression started with `await` rather than `async`, so restoring the save point to parse the cover grammar fails this assertion and crashes.

The goal is to prevent the branch that leads to that assertion from being parsed at all. This is done by adding another hint recording scope, which allows the hint to be discarded properly.

parseAssignmentExpression uses the hint to determine which arrow function cover grammar to parse, rather than trying both.
Comment 11 Saam Barati 2017-04-14 10:23:32 PDT
(In reply to Caitlin Potter (:caitp) from comment #10)
> (In reply to Saam Barati from comment #9)
> > Comment on attachment 307114 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=307114&action=review
> > 
> > >>>>> Source/JavaScriptCore/parser/Parser.cpp:3558
> > >>>>> +    ExpressionErrorClassifier classifier(this);
> > >>>> 
> > >>>> Does this change the error message that's produced?
> > >>> 
> > >>> No, it still produces "Unexpected token '=>'"
> > >> 
> > >> I'm confused then what the point of this is? What does ExpressionErrorClassifier do?
> > > 
> > > The classifier records hints that indicate which cover grammar productions to try. It allows the parser to skip cover grammars in some cases.
> > 
> > Ok, I just read the code to see what this does. I'm still a bit confused why
> > this is needed for correctness. Can you explain that a bit more? What's the
> > issue you're fixing?
> 
> Inside parseUnaryExpression, we eventually reach parseMemberExpression(),
> and see `async()` followed by a `=>` token.
> 
> In an AssignmentExpression context rather than a UnaryExpression context,
> this would mean "parse the async arrow function cover grammar", so it
> records a hint to do that. But the AssignmentExpression started with `await`
> rather than `async`, so restoring the save point to parse the cover grammar
> fails this assertion and crashes.
> 
> The goal is to prevent the branch that leads to that assertion from being
> parsed at all. This is done by adding another hint recording scope, which
> allows the hint to be discarded properly.
> 
> parseAssignmentExpression uses the hint to determine which arrow function
> cover grammar to parse, rather than trying both.

Gotcha. Can you add this explanation to the changelog?
Comment 12 Saam Barati 2017-04-14 10:23:41 PDT
Comment on attachment 307114 [details]
Patch

r=me
Comment 13 Caitlin Potter (:caitp) 2017-04-14 10:36:23 PDT
(In reply to Saam Barati from comment #11)
> (In reply to Caitlin Potter (:caitp) from comment #10)
> > (In reply to Saam Barati from comment #9)
> > > Comment on attachment 307114 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=307114&action=review
> > > 
> > > >>>>> Source/JavaScriptCore/parser/Parser.cpp:3558
> > > >>>>> +    ExpressionErrorClassifier classifier(this);
> > > >>>> 
> > > >>>> Does this change the error message that's produced?
> > > >>> 
> > > >>> No, it still produces "Unexpected token '=>'"
> > > >> 
> > > >> I'm confused then what the point of this is? What does ExpressionErrorClassifier do?
> > > > 
> > > > The classifier records hints that indicate which cover grammar productions to try. It allows the parser to skip cover grammars in some cases.
> > > 
> > > Ok, I just read the code to see what this does. I'm still a bit confused why
> > > this is needed for correctness. Can you explain that a bit more? What's the
> > > issue you're fixing?
> > 
> > Inside parseUnaryExpression, we eventually reach parseMemberExpression(),
> > and see `async()` followed by a `=>` token.
> > 
> > In an AssignmentExpression context rather than a UnaryExpression context,
> > this would mean "parse the async arrow function cover grammar", so it
> > records a hint to do that. But the AssignmentExpression started with `await`
> > rather than `async`, so restoring the save point to parse the cover grammar
> > fails this assertion and crashes.
> > 
> > The goal is to prevent the branch that leads to that assertion from being
> > parsed at all. This is done by adding another hint recording scope, which
> > allows the hint to be discarded properly.
> > 
> > parseAssignmentExpression uses the hint to determine which arrow function
> > cover grammar to parse, rather than trying both.
> 
> Gotcha. Can you add this explanation to the changelog?

Sure.

Hows this, does this seem clear/understandable?

```
        In parseAssignmentExpression(), several cover grammars are handled, and
        use ExpressionErrorClassifier to record hints about which grammars to
        try.

        In parseAwaitExpression(), the hints recorded during parsing of the
        operand need to be discarded, because if they propagate to the outer
        parseAssignmentExpression(), the hints will lead the parser down invalid
        branches that should be skipped, but are not.

        This change adds an additional ExpressionErrorClassifier to
        parseAwaitExpression(), in order to discard hints recorded by the
        operand.
```
Comment 14 Caitlin Potter (:caitp) 2017-04-14 12:02:18 PDT
Created attachment 307129 [details]
Patch
Comment 15 Caitlin Potter (:caitp) 2017-04-14 12:02:32 PDT
Created attachment 307130 [details]
Patch for landing
Comment 16 WebKit Commit Bot 2017-04-14 12:03:17 PDT
Comment on attachment 307130 [details]
Patch for landing

Rejecting attachment 307130 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-03', 'validate-changelog', '--check-oops', '--non-interactive', 307130, '--port=mac']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit

ChangeLog entry in JSTests/ChangeLog contains OOPS!.

Full output: http://webkit-queues.webkit.org/results/3535149
Comment 17 Caitlin Potter (:caitp) 2017-04-14 12:06:11 PDT
Created attachment 307131 [details]
Patch for landing
Comment 18 Caitlin Potter (:caitp) 2017-04-14 12:06:48 PDT
(In reply to WebKit Commit Bot from comment #16)
> Comment on attachment 307130 [details]
> Patch for landing
> 
> Rejecting attachment 307130 [details] from commit-queue.
> 
> Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch',
> '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-03',
> 'validate-changelog', '--check-oops', '--non-interactive', 307130,
> '--port=mac']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit
> 
> ChangeLog entry in JSTests/ChangeLog contains OOPS!.
> 
> Full output: http://webkit-queues.webkit.org/results/3535149

webkit-patch workflow remains very confusing T_T
Comment 19 WebKit Commit Bot 2017-04-14 12:50:27 PDT
Comment on attachment 307131 [details]
Patch for landing

Clearing flags on attachment: 307131

Committed r215370: <http://trac.webkit.org/changeset/215370>
Comment 20 WebKit Commit Bot 2017-04-14 12:50:29 PDT
All reviewed patches have been landed.  Closing bug.