Bug 239019

Summary: calc(): Serialize top level min/max/hypot as calc()
Product: WebKit Reporter: Nikos Mouchtaris <nmouchtaris>
Component: New BugsAssignee: Nikos Mouchtaris <nmouchtaris>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, macpherson, menard, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
darin: review+
Patch none

Description Nikos Mouchtaris 2022-04-08 16:14:17 PDT
calc(): Serialize top level min/max/hypot as calc()
Comment 1 Nikos Mouchtaris 2022-04-08 16:19:11 PDT
Created attachment 457124 [details]
Patch
Comment 2 Darin Adler 2022-04-11 14:31:26 PDT
Comment on attachment 457124 [details]
Patch

fast/css/calc-parsing.html is failing and some other two; we should review once we have a patch with all tests passing
Comment 3 Nikos Mouchtaris 2022-04-11 14:50:49 PDT
Created attachment 457289 [details]
Patch
Comment 4 Nikos Mouchtaris 2022-04-14 13:05:54 PDT
Created attachment 457645 [details]
Patch
Comment 5 Darin Adler 2022-04-14 13:50:24 PDT
Comment on attachment 457645 [details]
Patch

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

> Source/WebCore/css/calc/CSSCalcOperationNode.h:75
> +    void makeTopLevelCalc() { m_operator = CalcOperator::Add; }

Needs a comment explaining why the way to make something a top-level call is to set the operator to add, since that's not obvious from the name. I might move the body out of the class to the bottom of the header just to make room for the comment.

    void makeTopLevelCalc();

...

inline void CSSCalcOperationNode::makeTopLevelCalc()
{
    // Top level calc nodes where we need not preserve the function are changed into add nodes because that’s the best way to make them serialize as "calc(xxx)" and also evaluate them efficiently.
    <<<or whatever the comment should say>>>
    m_operator = CaclOperator::Add;
}
Comment 6 Darin Adler 2022-04-14 13:51:14 PDT
Comment on attachment 457645 [details]
Patch

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

>> Source/WebCore/css/calc/CSSCalcOperationNode.h:75
>> +    void makeTopLevelCalc() { m_operator = CalcOperator::Add; }
> 
> Needs a comment explaining why the way to make something a top-level call is to set the operator to add, since that's not obvious from the name. I might move the body out of the class to the bottom of the header just to make room for the comment.
> 
>     void makeTopLevelCalc();
> 
> ...
> 
> inline void CSSCalcOperationNode::makeTopLevelCalc()
> {
>     // Top level calc nodes where we need not preserve the function are changed into add nodes because that’s the best way to make them serialize as "calc(xxx)" and also evaluate them efficiently.
>     <<<or whatever the comment should say>>>
>     m_operator = CaclOperator::Add;
> }

Also, these can be private rather than public, I think. And the inline function bodies could be in the .cpp file rather than in the .h file if they are only used there.
Comment 7 Nikos Mouchtaris 2022-04-14 14:03:19 PDT
Created attachment 457646 [details]
Patch
Comment 8 Nikos Mouchtaris 2022-04-14 14:04:13 PDT
(In reply to Darin Adler from comment #5)
> Comment on attachment 457645 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457645&action=review
> 
> > Source/WebCore/css/calc/CSSCalcOperationNode.h:75
> > +    void makeTopLevelCalc() { m_operator = CalcOperator::Add; }
> 
> Needs a comment explaining why the way to make something a top-level call is
> to set the operator to add, since that's not obvious from the name. I might
> move the body out of the class to the bottom of the header just to make room
> for the comment.
> 
>     void makeTopLevelCalc();
> 
> ...
> 
> inline void CSSCalcOperationNode::makeTopLevelCalc()
> {
>     // Top level calc nodes where we need not preserve the function are
> changed into add nodes because that’s the best way to make them serialize as
> "calc(xxx)" and also evaluate them efficiently.
>     <<<or whatever the comment should say>>>
>     m_operator = CaclOperator::Add;
> }

Fixed.
Comment 9 Nikos Mouchtaris 2022-04-14 14:04:24 PDT
(In reply to Darin Adler from comment #6)
> Comment on attachment 457645 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457645&action=review
> 
> >> Source/WebCore/css/calc/CSSCalcOperationNode.h:75
> >> +    void makeTopLevelCalc() { m_operator = CalcOperator::Add; }
> > 
> > Needs a comment explaining why the way to make something a top-level call is to set the operator to add, since that's not obvious from the name. I might move the body out of the class to the bottom of the header just to make room for the comment.
> > 
> >     void makeTopLevelCalc();
> > 
> > ...
> > 
> > inline void CSSCalcOperationNode::makeTopLevelCalc()
> > {
> >     // Top level calc nodes where we need not preserve the function are changed into add nodes because that’s the best way to make them serialize as "calc(xxx)" and also evaluate them efficiently.
> >     <<<or whatever the comment should say>>>
> >     m_operator = CaclOperator::Add;
> > }
> 
> Also, these can be private rather than public, I think. And the inline
> function bodies could be in the .cpp file rather than in the .h file if they
> are only used there.

Fixed.
Comment 10 Darin Adler 2022-04-14 14:04:53 PDT
Comment on attachment 457646 [details]
Patch

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

> Source/WebCore/css/calc/CSSCalcOperationNode.h:74
> +    bool shouldNotPreserveFunction() const { return isMinOrMaxNode() || isHypotNode(); }

I think this can also be private.
Comment 11 Nikos Mouchtaris 2022-04-14 14:16:12 PDT
Created attachment 457647 [details]
Patch
Comment 12 Nikos Mouchtaris 2022-04-14 14:17:02 PDT
(In reply to Darin Adler from comment #10)
> Comment on attachment 457646 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457646&action=review
> 
> > Source/WebCore/css/calc/CSSCalcOperationNode.h:74
> > +    bool shouldNotPreserveFunction() const { return isMinOrMaxNode() || isHypotNode(); }
> 
> I think this can also be private.

Fixed.
Comment 13 EWS 2022-04-14 16:33:52 PDT
Committed r292893 (249663@main): <https://commits.webkit.org/249663@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 457647 [details].
Comment 14 Radar WebKit Bug Importer 2022-04-14 16:34:14 PDT
<rdar://problem/91784817>
Comment 15 Nikos Mouchtaris 2022-04-19 16:05:24 PDT
*** Bug 230365 has been marked as a duplicate of this bug. ***