Closed Bug 1819893 Opened 3 years ago Closed 3 years ago

Add negate node to calc tree to replace the mul_by in sum nodes

Categories

(Core :: CSS Parsing and Computation, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
114 Branch
Tracking Status
firefox114 --- fixed

People

(Reporter: tlouw, Assigned: tlouw)

References

Details

Attachments

(1 file)

Assumption in calc(): x - y == x + (-1y))

This used to work, because multiply and divide was always evaluated at parse time before add and subtract, but the plan is to add a product node so that evaluation happens at "simplify/evaluate" time. Adding the product node avoids us from violating distributivity in newer nodes like sign(). (see bug 1815448)

Example in old code:

// multiply happens at parse time
calc(40px + 10% - 20% / 2) == calc(40px + 10% - 10%)

// multiply now creates a new node
calc(40px + 10% - 20% / 2) == calc(40px + 10% - (20% / 2)) != calc(40px + 10% - 20% / -2)

To fix this we can't *-1 for subtractions any more, so each node in a +/- should keep track of it's own operation. This makes storing the terms in a list very ugly, so the plan is to convert the node into a single operation node. E.g.

Sum(vec<Node>)

changes to:

Sum { left: Node, right: Node, op: AddOrSubtract }

Initially this will cause some additional allocations and deeper stack, but we should be able to inline some operations if they have the same unit/type, etc.

Blocks: 1815448
Depends on: 1823214
Summary: Refactor Sum node in calc() to in support of adding a Product node and to avoid breaking distributivity → Add negate node to calc tree to replace the mul_by in sum nodes

Original plan to create binary sum nodes is not needed as adding negate nodes as suggested by the spec works as well.

Sum nodes would use mul_by to negate nodes to do subtraction, but some
nodes are not distributive. This patch adds a negate node, so that the
operations inside these negate nodes can be resolved first and then the
"subtraction" can be applied.

Assignee: nobody → tlouw
Attachment #9323810 - Attachment description: WIP: Bug 1819893 - Add negate node to use in place of mul_by in sum nodes r=emilio → Bug 1819893 - Add negate node to use in place of mul_by in sum nodes r=emilio
Status: NEW → ASSIGNED
Pushed by tlouw@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/9dc528bebd61 Add negate node to use in place of mul_by in sum nodes r=emilio
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 114 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: