Bug 190671 - The parser should not emit a ApplyFunctionCallDotNode for Reflect.apply.
Summary: The parser should not emit a ApplyFunctionCallDotNode for Reflect.apply.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords: InRadar
Depends on:
Blocks: 190668
  Show dependency treegraph
 
Reported: 2018-10-17 10:49 PDT by Mark Lam
Modified: 2018-10-17 16:58 PDT (History)
11 users (show)

See Also:


Attachments
proposed patch. (3.89 KB, patch)
2018-10-17 11:00 PDT, Mark Lam
ews-watchlist: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews100 for mac-sierra (273.00 KB, application/zip)
2018-10-17 11:35 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews106 for mac-sierra-wk2 (1.18 MB, application/zip)
2018-10-17 11:48 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews124 for ios-simulator-wk2 (190.89 KB, application/zip)
2018-10-17 12:09 PDT, EWS Watchlist
no flags Details
proposed patch. (4.83 KB, patch)
2018-10-17 13:56 PDT, Mark Lam
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Lam 2018-10-17 10:49:07 PDT
The bytecode generator does not currently know how to inline Reflect.apply (see https://bugs.webkit.org/show_bug.cgi?id=190668).  Hence, it's a waste of time to emit the ApplyFunctionCallDotNode since the function check against Function.apply that it will generate will always fail.  It also causes DFG graph dumping to crash.

<rdar://problem/45201145>
Comment 1 Mark Lam 2018-10-17 11:00:55 PDT
Created attachment 352592 [details]
proposed patch.

Let's get some EWS testing first.
Comment 2 Saam Barati 2018-10-17 11:08:13 PDT
Comment on attachment 352592 [details]
proposed patch.

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

> Source/JavaScriptCore/ChangeLog:12
> +        that it will generate will always fail.  It can also cause DFG graph dumping to

I agree with this from a performance perspective. However, it seems like you’re sidestepping a crash. Why does the dumper crash? Seems like that should be fixed
Comment 3 Mark Lam 2018-10-17 11:24:39 PDT
(In reply to Saam Barati from comment #2)
> Comment on attachment 352592 [details]
> proposed patch.
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=352592&action=review
> 
> > Source/JavaScriptCore/ChangeLog:12
> > +        that it will generate will always fail.  It can also cause DFG graph dumping to
> 
> I agree with this from a performance perspective. However, it seems like
> you’re sidestepping a crash. Why does the dumper crash? Seems like that
> should be fixed

It crashed because it's expecting the callee in a CallVariant to be a function or executable of some form.  Because we're creating a ApplyFunctionCallDotNode for Reflect.apply, we end up passing the Reflect object as the callee.  This is wrong, and is the reason the dumper crashed.  We should be passing the first argument of Reflect.apply as the callee instead (when we support inlining Reflect.apply).

Hmmm ... that said, I haven't explored what happens in we can properly inline Reflect.apply later and pass a non-function value as the first argument.  I think we can leave that as an exercise for https://bugs.webkit.org/show_bug.cgi?id=190668.
Comment 4 EWS Watchlist 2018-10-17 11:35:12 PDT
Comment on attachment 352592 [details]
proposed patch.

Attachment 352592 [details] did not pass mac-ews (mac):
Output: https://webkit-queues.webkit.org/results/9638635

Number of test failures exceeded the failure limit.
Comment 5 EWS Watchlist 2018-10-17 11:35:14 PDT
Created attachment 352601 [details]
Archive of layout-test-results from ews100 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews100  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 6 EWS Watchlist 2018-10-17 11:48:08 PDT
Comment on attachment 352592 [details]
proposed patch.

Attachment 352592 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/9638736

Number of test failures exceeded the failure limit.
Comment 7 EWS Watchlist 2018-10-17 11:48:09 PDT
Created attachment 352602 [details]
Archive of layout-test-results from ews106 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 8 Saam Barati 2018-10-17 11:51:36 PDT
(In reply to Mark Lam from comment #3)
> (In reply to Saam Barati from comment #2)
> > Comment on attachment 352592 [details]
> > proposed patch.
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=352592&action=review
> > 
> > > Source/JavaScriptCore/ChangeLog:12
> > > +        that it will generate will always fail.  It can also cause DFG graph dumping to
> > 
> > I agree with this from a performance perspective. However, it seems like
> > you’re sidestepping a crash. Why does the dumper crash? Seems like that
> > should be fixed
> 
> It crashed because it's expecting the callee in a CallVariant to be a
> function or executable of some form.  Because we're creating a
> ApplyFunctionCallDotNode for Reflect.apply, we end up passing the Reflect
> object as the callee.  This is wrong, and is the reason the dumper crashed. 
> We should be passing the first argument of Reflect.apply as the callee
> instead (when we support inlining Reflect.apply).
I don't see how this matters at all that the callee here is Reflect. Seems like any code can trigger this.


> 
> Hmmm ... that said, I haven't explored what happens in we can properly
> inline Reflect.apply later and pass a non-function value as the first
> argument.  I think we can leave that as an exercise for
> https://bugs.webkit.org/show_bug.cgi?id=190668.
Comment 9 EWS Watchlist 2018-10-17 12:09:57 PDT
Comment on attachment 352592 [details]
proposed patch.

Attachment 352592 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/9638622

Number of test failures exceeded the failure limit.
Comment 10 EWS Watchlist 2018-10-17 12:09:59 PDT
Created attachment 352605 [details]
Archive of layout-test-results from ews124 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews124  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 11 Mark Lam 2018-10-17 13:06:08 PDT
(In reply to Saam Barati from comment #8)
> I don't see how this matters at all that the callee here is Reflect. Seems
> like any code can trigger this.

You are right.  I stand corrected.  Will fix.
Comment 12 Mark Lam 2018-10-17 13:56:39 PDT
Created attachment 352635 [details]
proposed patch.

Let's try on the EWS again.
Comment 13 Saam Barati 2018-10-17 16:27:20 PDT
Comment on attachment 352635 [details]
proposed patch.

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

r=me

> Source/JavaScriptCore/ChangeLog:11
> +        https://bugs.webkit.org/show_bug.cgi?id=190668).  Hence, it's a waste of time to
> +        emit the ApplyFunctionCallDotNode since the function check against Function.apply

What you're doing is a heuristic, FWIW. I agree with your change, because it's probably better, but it's still a heuristic. A user could write code where this new heuristic is worse:
```
function Reflect() { ... }
Reflect.apply
```
Comment 14 Mark Lam 2018-10-17 16:31:34 PDT
Thanks for the review.

(In reply to Saam Barati from comment #13)
> > Source/JavaScriptCore/ChangeLog:11
> > +        https://bugs.webkit.org/show_bug.cgi?id=190668).  Hence, it's a waste of time to
> > +        emit the ApplyFunctionCallDotNode since the function check against Function.apply
> 
> What you're doing is a heuristic, FWIW. I agree with your change, because
> it's probably better, but it's still a heuristic. A user could write code
> where this new heuristic is worse:
> ```
> function Reflect() { ... }
> Reflect.apply
> ```

Yes, I thought of that.  My thinking is that if the user wrote code like that, he/she is just asking for it.  For most normal code, I would not expect the user to create a function named Reflect with a member named apply.  So, I opted to go with this heuristic.
Comment 15 WebKit Commit Bot 2018-10-17 16:57:05 PDT
Comment on attachment 352635 [details]
proposed patch.

Clearing flags on attachment: 352635

Committed r237241: <https://trac.webkit.org/changeset/237241>
Comment 16 WebKit Commit Bot 2018-10-17 16:57:07 PDT
All reviewed patches have been landed.  Closing bug.