Bug 206368 - [JSC] add DFG/FTL support for op_to_property_key
Summary: [JSC] add DFG/FTL support for op_to_property_key
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Caitlin Potter (:caitp)
URL:
Keywords: InRadar
Depends on:
Blocks: 195619
  Show dependency treegraph
 
Reported: 2020-01-16 12:20 PST by Caitlin Potter (:caitp)
Modified: 2020-01-18 15:15 PST (History)
12 users (show)

See Also:


Attachments
Patch (23.81 KB, patch)
2020-01-16 12:25 PST, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch v2 (27.76 KB, patch)
2020-01-17 09:37 PST, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch for landing (28.89 KB, patch)
2020-01-17 15:59 PST, 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) 2020-01-16 12:20:35 PST
Add tiered JIT support for op_to_property_key, used by computed class fields. One small part of https://bugs.webkit.org/show_bug.cgi?id=195619
Comment 1 Caitlin Potter (:caitp) 2020-01-16 12:25:57 PST
Created attachment 387942 [details]
Patch
Comment 2 Yusuke Suzuki 2020-01-16 13:41:16 PST
Comment on attachment 387942 [details]
Patch

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

Looks really nice. I would like to have StringObject handling, which is implemented in ToPrimitive too. Then looks perfect.

> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:1394
> +        case ToPropertyKey: {

Let's handle StringObject case as it is done in ToPrimitive (and add tests).
If we detect the input is StringObject and m_graph.canOptimizeStringObjectAccess is true, let's insert a check, and convert it to ToString<>.

> Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:583
> +        }

Let's handle StringObject case too, as it is done in ToPrimitive case.
Comment 3 Saam Barati 2020-01-16 23:52:24 PST
Comment on attachment 387942 [details]
Patch

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

LGTM too. I found one minor perf bug

> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:2530
> +            m_state.setShouldTryConstantFolding(true);

You need to write the code inside DFGConstantFoldingPhase that corresponds to this and actually does the identity conversion.
Comment 4 Caitlin Potter (:caitp) 2020-01-17 09:37:08 PST
Created attachment 388049 [details]
Patch v2
Comment 5 Caitlin Potter (:caitp) 2020-01-17 09:43:28 PST
Comment on attachment 387942 [details]
Patch

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

Thanks very much for the review. I'd like Caio to get the chance to review this as well, and there is probably some room for improvement before I set CQ+

>> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:2530
>> +            m_state.setShouldTryConstantFolding(true);
> 
> You need to write the code inside DFGConstantFoldingPhase that corresponds to this and actually does the identity conversion.

Done

>> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:1394
>> +        case ToPropertyKey: {
> 
> Let's handle StringObject case as it is done in ToPrimitive (and add tests).
> If we detect the input is StringObject and m_graph.canOptimizeStringObjectAccess is true, let's insert a check, and convert it to ToString<>.

Done, but I'm not super confident on it, so please take another look

>> Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:583
>> +        }
> 
> Let's handle StringObject case too, as it is done in ToPrimitive case.

Done (but again, please take another look to make sure the logic I came up with is sound)
Comment 6 Caio Lima 2020-01-17 09:52:10 PST
Comment on attachment 388049 [details]
Patch v2

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

Sorry for the delay here. I just have one minor comment about Prediction propagation.

> Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:580
> +            if (child)

I think we should be able to predict `SpecString | SpecSymbol` even when `child == SpecNone`, given those are the only possible output for `ToPropertyKey`.
Comment 7 Yusuke Suzuki 2020-01-17 14:59:48 PST
Comment on attachment 388049 [details]
Patch v2

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

>> Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:580
>> +            if (child)
> 
> I think we should be able to predict `SpecString | SpecSymbol` even when `child == SpecNone`, given those are the only possible output for `ToPropertyKey`.

No. Prediction propagation phase is iterative. So, getting SpecNone here is not meaning that this is the final result (let's consider loops etc.). Returning `SpecString | SpecSymbol` for SpecNone pollutes type prediction information unnecessarily and produces inefficient generic code.
And, we should return SpecNone for SpecNone, this is better. This phase is not AbstractInterpreter: AI needs to offer proven all possible type, on the other hand, prediction propagation needs to offer "prediction" for efficient execution.
The input = SpecNone typically means this code is never executed. Even though, this type prediction could be merged into the active path later (due to the control flow), and in that case, we pollute the prediction accidentally, and leading to the inefficient code.
Comment 8 Yusuke Suzuki 2020-01-17 15:10:54 PST
Comment on attachment 388049 [details]
Patch v2

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

r=me

> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:1412
> +            if (node->child1()->shouldSpeculateStringObject()
> +                && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
> +                addCheckStructureForOriginalStringObjectUse(StringObjectUse, node->origin, node->child1().node());
> +                fixEdge<StringObjectUse>(node->child1());
> +                node->convertToToString();
> +                return;

Looks nice.

> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:1414
> +            break;

You can also add `node->child1()->shouldSpeculateStringOrStringObject()` case as ToPrimitive is doing.

> Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:1449
> +        if (type & SpecStringObject && m_graph.canOptimizeStringObjectAccess(m_currentNode->origin.semantic))
> +            return mergeSpeculations(type & SpecSymbol, SpecString);

Nice.
Comment 9 Yusuke Suzuki 2020-01-17 15:14:08 PST
Comment on attachment 388049 [details]
Patch v2

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

>>> Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:580
>>> +            if (child)
>> 
>> I think we should be able to predict `SpecString | SpecSymbol` even when `child == SpecNone`, given those are the only possible output for `ToPropertyKey`.
> 
> No. Prediction propagation phase is iterative. So, getting SpecNone here is not meaning that this is the final result (let's consider loops etc.). Returning `SpecString | SpecSymbol` for SpecNone pollutes type prediction information unnecessarily and produces inefficient generic code.
> And, we should return SpecNone for SpecNone, this is better. This phase is not AbstractInterpreter: AI needs to offer proven all possible type, on the other hand, prediction propagation needs to offer "prediction" for efficient execution.
> The input = SpecNone typically means this code is never executed. Even though, this type prediction could be merged into the active path later (due to the control flow), and in that case, we pollute the prediction accidentally, and leading to the inefficient code.

One way to consider about this phase is, "Given this prediction input, what is the minimal possible type prediction which covers the input prediction's use case?"
So, if the prediction input is saying SpecNone, SpecNone is the minimal possible type prediction output which covers the code producing the input's prediction.
Comment 10 Caio Lima 2020-01-17 15:32:14 PST
(In reply to Yusuke Suzuki from comment #9)
> Comment on attachment 388049 [details]
> Patch v2
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=388049&action=review
> 
> >>> Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:580
> >>> +            if (child)
> >> 
> >> I think we should be able to predict `SpecString | SpecSymbol` even when `child == SpecNone`, given those are the only possible output for `ToPropertyKey`.
> > 
> > No. Prediction propagation phase is iterative. So, getting SpecNone here is not meaning that this is the final result (let's consider loops etc.). Returning `SpecString | SpecSymbol` for SpecNone pollutes type prediction information unnecessarily and produces inefficient generic code.
> > And, we should return SpecNone for SpecNone, this is better. This phase is not AbstractInterpreter: AI needs to offer proven all possible type, on the other hand, prediction propagation needs to offer "prediction" for efficient execution.
> > The input = SpecNone typically means this code is never executed. Even though, this type prediction could be merged into the active path later (due to the control flow), and in that case, we pollute the prediction accidentally, and leading to the inefficient code.
> 
> One way to consider about this phase is, "Given this prediction input, what
> is the minimal possible type prediction which covers the input prediction's
> use case?"
> So, if the prediction input is saying SpecNone, SpecNone is the minimal
> possible type prediction output which covers the code producing the input's
> prediction.

Right! Thanks for the clarification.
Comment 11 Caitlin Potter (:caitp) 2020-01-17 15:59:46 PST
Created attachment 388103 [details]
Patch for landing
Comment 12 Caitlin Potter (:caitp) 2020-01-17 16:02:30 PST
Comment on attachment 388049 [details]
Patch v2

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

>> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:1414
>> +            break;
> 
> You can also add `node->child1()->shouldSpeculateStringOrStringObject()` case as ToPrimitive is doing.

Done in the patch for landing. I've added a test, which I hope exercises this path, but hard to be sure.

>>>>> Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:580
>>>>> +            if (child)
>>>> 
>>>> I think we should be able to predict `SpecString | SpecSymbol` even when `child == SpecNone`, given those are the only possible output for `ToPropertyKey`.
>>> 
>>> No. Prediction propagation phase is iterative. So, getting SpecNone here is not meaning that this is the final result (let's consider loops etc.). Returning `SpecString | SpecSymbol` for SpecNone pollutes type prediction information unnecessarily and produces inefficient generic code.
>>> And, we should return SpecNone for SpecNone, this is better. This phase is not AbstractInterpreter: AI needs to offer proven all possible type, on the other hand, prediction propagation needs to offer "prediction" for efficient execution.
>>> The input = SpecNone typically means this code is never executed. Even though, this type prediction could be merged into the active path later (due to the control flow), and in that case, we pollute the prediction accidentally, and leading to the inefficient code.
>> 
>> One way to consider about this phase is, "Given this prediction input, what is the minimal possible type prediction which covers the input prediction's use case?"
>> So, if the prediction input is saying SpecNone, SpecNone is the minimal possible type prediction output which covers the code producing the input's prediction.
> 
> Right! Thanks for the clarification.

+1, thanks a lot for the explanation here.
Comment 13 Caitlin Potter (:caitp) 2020-01-17 16:13:39 PST
Comment on attachment 388049 [details]
Patch v2

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

>>> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:1414
>>> +            break;
>> 
>> You can also add `node->child1()->shouldSpeculateStringOrStringObject()` case as ToPrimitive is doing.
> 
> Done in the patch for landing. I've added a test, which I hope exercises this path, but hard to be sure.

well, I've just now verified that the path is taken in the test, so that's promising.

This doesn't seem like something that would likely be hit in practice, but I guess it's not too expensive to support it. ¯\(°_o)/¯
Comment 14 Caitlin Potter (:caitp) 2020-01-18 09:11:34 PST
I flipped cq+ last night, and reflipped today, but doesn’t seem to be going anywhere
Comment 15 Yusuke Suzuki 2020-01-18 13:45:49 PST
Comment on attachment 388103 [details]
Patch for landing

Reflipped.
Comment 16 Yusuke Suzuki 2020-01-18 13:46:38 PST
cq is currently in migration state from High Sierra => Mojave IIUC. And maybe, in some trouble, not sure whether this is fixed already. Try refliping again now.
Comment 17 WebKit Commit Bot 2020-01-18 14:43:20 PST
The commit-queue encountered the following flaky tests while processing attachment 388103 [details]:

editing/spelling/spellcheck-attribute.html bug 206178 (authors: g.czajkowski@samsung.com, mark.lam@apple.com, and rniwa@webkit.org)
The commit-queue is continuing to process your patch.
Comment 18 WebKit Commit Bot 2020-01-18 14:43:43 PST
The commit-queue encountered the following flaky tests while processing attachment 388103 [details]:

editing/spelling/spellcheck-async-remove-frame.html bug 158401 (authors: morrita@google.com, rniwa@webkit.org, and tony@chromium.org)
The commit-queue is continuing to process your patch.
Comment 19 WebKit Commit Bot 2020-01-18 15:14:02 PST
The commit-queue encountered the following flaky tests while processing attachment 388103 [details]:

editing/spelling/spellcheck-async-remove-frame.html bug 158401 (authors: morrita@google.com, rniwa@webkit.org, and tony@chromium.org)
The commit-queue is continuing to process your patch.
Comment 20 WebKit Commit Bot 2020-01-18 15:14:35 PST
Comment on attachment 388103 [details]
Patch for landing

Clearing flags on attachment: 388103

Committed r254801: <https://trac.webkit.org/changeset/254801>
Comment 21 WebKit Commit Bot 2020-01-18 15:14:37 PST
All reviewed patches have been landed.  Closing bug.
Comment 22 Radar WebKit Bug Importer 2020-01-18 15:15:13 PST
<rdar://problem/58713990>