Skip to content

LibWeb: Move the cascade, compute core, computed values, and calc() to Rust - #10772

Merged
awesomekling merged 59 commits into
LadybirdBrowser:masterfrom
awesomekling:cv-rs-3
Jul 21, 2026
Merged

LibWeb: Move the cascade, compute core, computed values, and calc() to Rust#10772
awesomekling merged 59 commits into
LadybirdBrowser:masterfrom
awesomekling:cv-rs-3

Conversation

@awesomekling

Copy link
Copy Markdown
Member

This series moves the core of the style system into Rust: the storage model for computed style, the cascade and property computation control flow, and all of calc(). Rust ends up owning the data and the algorithms, with C++ shrinking to leaf callbacks around the GC heap and the DOM. The first commit gives the CSS Rust code its own libweb_css_rust crate at Libraries/LibWeb/CSS/Rust, so the rest of the series lands in a CSS-owned crate.

ComputedValues is sharded into 23 copy-on-write style value groups (7 inherited, 16 reset) behind a new StyleStructRef. Setters compare before writing and clone a payload only on first real mutation, so elements share group payloads with their parent, and with per-group default payloads for everything they never set. Cloning a style becomes 23 atomic refcount bumps instead of a deep copy. Payload ownership moves to Rust the way Stylo drives Gecko's nsStyle structs: Rust owns allocation and lifecycle, C++ reads fields inline through cbindgen-mirrored layouts. When a restyle ends with every payload shared with the old style, the per-longhand style diff (previously the hottest entry in a StyleBench profile) is skipped entirely.

The Rust style computation core now drives the cascade and the property loop: iteration in computation order, logical alias mapping, the inherit-or-initial decision, shorthand expansion, the cascaded property store, declaration application, and css-cascade-5 origin ordering, plus post-computation adjustments (effective overflow, text-align: match-parent, automatic box type transformations) and a growing set of per-property computed-value rules (the interdependent font cluster with a bit-exact CSSPixels port, border widths, corner shapes, position-area, the monospace font-size recascade). CascadedProperties is now a thin shell holding the GC-managed declaration sources Rust cannot own, and C++ remains as leaf callbacks for GC-touching side effects and not-yet-ported properties.

calc() is backed by an immutable, refcounted Rust calculation tree: the numeric type algebra, operations, simplification, resolution, serialization, equality, random(), typed-OM reification and absolutization all run over it, with verbatim css-values-4 spec text carried alongside the code. Construction is native too: the parser, typed-OM, interpolation, and the anchor(), edge, basic-shape and tree-counting resolvers build the tree through a small CalcNodeRef handle builder, and the entire C++ CalculationNode hierarchy is deleted. Two commits fix latent parity bugs found by A/B comparison against the C++ implementation, each with a regression test, and audit commits delete everything the ports orphaned.

Parity across the FFI is pinned by unit tests comparing the generated metadata tables, shorthand expansions, logical alias mappings, CSSPixels arithmetic, length resolution and the numeric type algebra against their C++ counterparts, so the two sides cannot drift silently. New web tests cover group sharing (via internals.styleGroupSharingInfo()), round() strategies, font-feature-settings ordering and position-area computation.

Together with the Rust selector engine, this leaves Rust owning selector matching, the style value graph, computed style storage, the cascade, and calc. The atomically refcounted storage and immutable trees are the substrate parallel restyling needs, and they are what a future Rust layout engine can consume directly instead of marshalling computed style back out of C++. Commits are individually buildable; some are big, and the remaining FFI seams shrink as more of the style system moves over.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1fe4c3f6-4dc0-4b9f-a3b8-e305a543c35f

📥 Commits

Reviewing files that changed from the base of the PR and between a8caa47 and 3db0092.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (164)
  • Cargo.toml
  • Libraries/LibWeb/Animations/TimeValue.cpp
  • Libraries/LibWeb/CMakeLists.txt
  • Libraries/LibWeb/CSS/CSSMathClamp.cpp
  • Libraries/LibWeb/CSS/CSSMathClamp.h
  • Libraries/LibWeb/CSS/CSSMathInvert.cpp
  • Libraries/LibWeb/CSS/CSSMathInvert.h
  • Libraries/LibWeb/CSS/CSSMathMax.cpp
  • Libraries/LibWeb/CSS/CSSMathMax.h
  • Libraries/LibWeb/CSS/CSSMathMin.cpp
  • Libraries/LibWeb/CSS/CSSMathMin.h
  • Libraries/LibWeb/CSS/CSSMathNegate.cpp
  • Libraries/LibWeb/CSS/CSSMathNegate.h
  • Libraries/LibWeb/CSS/CSSMathProduct.cpp
  • Libraries/LibWeb/CSS/CSSMathProduct.h
  • Libraries/LibWeb/CSS/CSSMathSum.cpp
  • Libraries/LibWeb/CSS/CSSMathSum.h
  • Libraries/LibWeb/CSS/CSSNumericValue.h
  • Libraries/LibWeb/CSS/CSSUnitValue.cpp
  • Libraries/LibWeb/CSS/CSSUnitValue.h
  • Libraries/LibWeb/CSS/CascadedProperties.cpp
  • Libraries/LibWeb/CSS/CascadedProperties.h
  • Libraries/LibWeb/CSS/Clip.h
  • Libraries/LibWeb/CSS/ColumnCount.h
  • Libraries/LibWeb/CSS/ComputedProperties.cpp
  • Libraries/LibWeb/CSS/ComputedProperties.h
  • Libraries/LibWeb/CSS/ComputedValues.cpp
  • Libraries/LibWeb/CSS/ComputedValues.h
  • Libraries/LibWeb/CSS/EasingFunction.h
  • Libraries/LibWeb/CSS/Filter.h
  • Libraries/LibWeb/CSS/Interpolation.cpp
  • Libraries/LibWeb/CSS/Length.h
  • Libraries/LibWeb/CSS/NumericType.cpp
  • Libraries/LibWeb/CSS/NumericType.h
  • Libraries/LibWeb/CSS/Parser/Parser.h
  • Libraries/LibWeb/CSS/Parser/ValueParsing.cpp
  • Libraries/LibWeb/CSS/Rust/Cargo.toml
  • Libraries/LibWeb/CSS/Rust/build.rs
  • Libraries/LibWeb/CSS/Rust/cbindgen.toml
  • Libraries/LibWeb/CSS/Rust/src/calc.rs
  • Libraries/LibWeb/CSS/Rust/src/cascaded_properties.rs
  • Libraries/LibWeb/CSS/Rust/src/computed_values.rs
  • Libraries/LibWeb/CSS/Rust/src/css_pixels.rs
  • Libraries/LibWeb/CSS/Rust/src/css_tokenizer.rs
  • Libraries/LibWeb/CSS/Rust/src/lib.rs
  • Libraries/LibWeb/CSS/Rust/src/property_metadata.rs
  • Libraries/LibWeb/CSS/Rust/src/selector_engine.rs
  • Libraries/LibWeb/CSS/Rust/src/style_compute.rs
  • Libraries/LibWeb/CSS/Rust/src/style_value.rs
  • Libraries/LibWeb/CSS/RustStyleBridge.cpp
  • Libraries/LibWeb/CSS/RustStyleBridge.h
  • Libraries/LibWeb/CSS/StyleComputeFFI.h
  • Libraries/LibWeb/CSS/StyleComputer.cpp
  • Libraries/LibWeb/CSS/StyleComputer.h
  • Libraries/LibWeb/CSS/StyleStructRef.h
  • Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AbstractNonMathCalcFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/AnchorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AngleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderImageSliceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusRectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CalcNodeRef.h
  • Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorInterpolationMethodStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorMixStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContrastColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/DisplayStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EasingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EmptyOptionalStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GuaranteedInvalidStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/KeywordStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LightDarkStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpacityValueStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OverflowClipMarginStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PercentageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RandomValueSharingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RatioStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RepeatStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
  • Libraries/LibWeb/CSS/StyleValues/SuperellipseStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TreeCountingFunctionStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/TreeCountingFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TupleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnicodeRangeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h
  • Libraries/LibWeb/DOM/Element.cpp
  • Libraries/LibWeb/Forward.h
  • Libraries/LibWeb/Internals/Internals.cpp
  • Libraries/LibWeb/Internals/Internals.h
  • Libraries/LibWeb/Internals/Internals.idl
  • Libraries/LibWeb/Layout/FormattingContext.cpp
  • Libraries/LibWeb/Rust/Cargo.toml
  • Libraries/LibWeb/Rust/build.rs
  • Libraries/LibWeb/Rust/src/lib.rs
  • Meta/Generators/generate_libweb_css_math_functions.py
  • Meta/Generators/generate_libweb_css_property_id.py
  • Meta/Generators/generate_libweb_css_units.py
  • Tests/LibWeb/CMakeLists.txt
  • Tests/LibWeb/TestLengthAbsolutizeParity.cpp
  • Tests/LibWeb/TestNumericTypeParity.cpp
  • Tests/LibWeb/TestStylePropertyMetadataParity.cpp
  • Tests/LibWeb/TestStyleStructRef.cpp
💤 Files with no reviewable changes (82)
  • Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorInterpolationMethodStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PercentageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RepeatStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GuaranteedInvalidStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RandomValueSharingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusRectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/DisplayStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorMixStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/KeywordStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LightDarkStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContrastColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RatioStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
  • Libraries/LibWeb/CSS/ComputedProperties.h
  • Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/AngleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h
  • Libraries/LibWeb/Rust/Cargo.toml
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OverflowClipMarginStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/SuperellipseStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EasingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderImageSliceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h
  • Libraries/LibWeb/CSS/NumericType.cpp
  • Libraries/LibWeb/Rust/src/lib.rs
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnicodeRangeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpacityValueStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TupleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EmptyOptionalStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h
🚧 Files skipped from review as they are similar to previous changes (70)
  • Libraries/LibWeb/CSS/CSSUnitValue.h
  • Cargo.toml
  • Libraries/LibWeb/CSS/Rust/Cargo.toml
  • Libraries/LibWeb/CSS/CSSMathClamp.h
  • Libraries/LibWeb/CSS/CSSMathSum.h
  • Libraries/LibWeb/CSS/CSSMathMin.h
  • Libraries/LibWeb/CSS/CSSMathNegate.h
  • Libraries/LibWeb/CSS/Filter.h
  • Tests/LibWeb/CMakeLists.txt
  • Libraries/LibWeb/CSS/CSSMathMax.h
  • Libraries/LibWeb/CSS/CSSMathProduct.h
  • Libraries/LibWeb/Internals/Internals.h
  • Libraries/LibWeb/Forward.h
  • Libraries/LibWeb/CSS/CSSMathClamp.cpp
  • Libraries/LibWeb/CSS/Clip.h
  • Libraries/LibWeb/CSS/StyleComputeFFI.h
  • Libraries/LibWeb/CSS/Rust/cbindgen.toml
  • Libraries/LibWeb/CSS/Length.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp
  • Libraries/LibWeb/CSS/CSSMathInvert.h
  • Libraries/LibWeb/CSS/CSSMathSum.cpp
  • Libraries/LibWeb/Internals/Internals.idl
  • Libraries/LibWeb/CSS/CSSMathInvert.cpp
  • Libraries/LibWeb/Animations/TimeValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/AbstractNonMathCalcFunctionStyleValue.h
  • Libraries/LibWeb/CSS/CSSMathNegate.cpp
  • Libraries/LibWeb/CSS/CSSNumericValue.h
  • Libraries/LibWeb/CSS/StyleComputer.h
  • Libraries/LibWeb/CSS/Rust/src/selector_engine.rs
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.cpp
  • Libraries/LibWeb/CSS/CSSMathMin.cpp
  • Libraries/LibWeb/CSS/CSSMathMax.cpp
  • Tests/LibWeb/TestNumericTypeParity.cpp
  • Libraries/LibWeb/CSS/Rust/src/css_pixels.rs
  • Libraries/LibWeb/CMakeLists.txt
  • Libraries/LibWeb/CSS/ColumnCount.h
  • Libraries/LibWeb/CSS/Parser/Parser.h
  • Libraries/LibWeb/CSS/EasingFunction.h
  • Libraries/LibWeb/CSS/StyleValues/CalcNodeRef.h
  • Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.cpp
  • Libraries/LibWeb/Layout/FormattingContext.cpp
  • Libraries/LibWeb/CSS/Rust/src/lib.rs
  • Libraries/LibWeb/CSS/StyleValues/TreeCountingFunctionStyleValue.h
  • Libraries/LibWeb/CSS/Rust/src/property_metadata.rs
  • Libraries/LibWeb/CSS/Rust/build.rs
  • Libraries/LibWeb/DOM/Element.cpp
  • Libraries/LibWeb/Internals/Internals.cpp
  • Libraries/LibWeb/CSS/CascadedProperties.h
  • Libraries/LibWeb/CSS/Rust/src/cascaded_properties.rs
  • Libraries/LibWeb/CSS/Rust/src/computed_values.rs
  • Meta/Generators/generate_libweb_css_units.py
  • Meta/Generators/generate_libweb_css_math_functions.py
  • Libraries/LibWeb/Rust/build.rs
  • Libraries/LibWeb/CSS/StyleStructRef.h
  • Libraries/LibWeb/CSS/Interpolation.cpp
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
  • Libraries/LibWeb/CSS/ComputedProperties.cpp
  • Libraries/LibWeb/CSS/Rust/src/style_value.rs
  • Libraries/LibWeb/CSS/CSSUnitValue.cpp
  • Libraries/LibWeb/CSS/CascadedProperties.cpp
  • Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h
  • Libraries/LibWeb/CSS/Parser/ValueParsing.cpp
  • Libraries/LibWeb/CSS/ComputedValues.h
  • Libraries/LibWeb/CSS/Rust/src/calc.rs
  • Libraries/LibWeb/CSS/Rust/src/css_tokenizer.rs
  • Libraries/LibWeb/CSS/StyleComputer.cpp
  • Libraries/LibWeb/CSS/Rust/src/style_compute.rs

📝 Walkthrough

Walkthrough

This PR adds a Rust CSS computation crate and migrates calculation trees, cascade storage, style computation, computed-value grouping, and style-value dependency checks to Rust-backed FFI. It also adds C++/Rust parity tests and browser tests for migrated CSS behavior.

Changes

CSS Rust migration

Layer / File(s) Summary
Rust crate, generated metadata, and FFI build wiring
Cargo.toml, Libraries/LibWeb/CSS/Rust/*, Libraries/LibWeb/CMakeLists.txt, Libraries/LibWeb/Rust/*
Adds the CSS Rust crate, generated metadata and bindings, tokenizer, CSS pixel arithmetic, and static-library integration.
Calculation tree and parser migration
Libraries/LibWeb/CSS/StyleValues/CalcNodeRef.h, Libraries/LibWeb/CSS/Rust/src/calc.rs, Libraries/LibWeb/CSS/Parser/*, Libraries/LibWeb/CSS/CSSMath*.cpp, Meta/Generators/generate_libweb_css_math_functions.py
Replaces C++ calculation nodes with Rust-backed CalcNodeRef trees, optional parser results, Rust type determination, simplification, serialization, resolution, and equality.
Cascade and style computation
Libraries/LibWeb/CSS/Rust/src/cascaded_properties.rs, Libraries/LibWeb/CSS/Rust/src/style_compute.rs, Libraries/LibWeb/CSS/StyleComputer.cpp, Libraries/LibWeb/CSS/CascadedProperties.*
Moves cascade storage, shorthand expansion, longhand computation, alias mapping, and selected property computations behind Rust FFI callbacks.
Computed-value grouping and sharing
Libraries/LibWeb/CSS/ComputedValues.*, Libraries/LibWeb/CSS/StyleStructRef.h, Libraries/LibWeb/CSS/Rust/src/computed_values.rs, Libraries/LibWeb/DOM/Element.cpp, Libraries/LibWeb/Internals/*
Adds grouped payloads, copy-on-write references, equality-based mutation, payload sharing, computed-value statistics, and sharing introspection.
Style-value and layout integration
Libraries/LibWeb/CSS/StyleValues/*, Libraries/LibWeb/Layout/FormattingContext.cpp, Libraries/LibWeb/CSS/Interpolation.cpp, Libraries/LibWeb/Animations/TimeValue.cpp
Routes style-value independence, current-color checks, anchor detection, length absolutization, interpolation, and calculation construction through Rust-backed nodes and helpers.
Validation and expected outputs
Tests/LibWeb/*, Tests/LibWeb/Text/*
Adds parity and lifecycle tests and updates browser-test inputs and expected outputs for calculations, property metadata, style sharing, statistics, font settings, and position-area mapping.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly matches the changeset and summarizes the Rust style-system and calc() migration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
Libraries/LibWeb/CSS/Rust/src/calc.rs (1)

2603-2610: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse percentage_leaf_type_for instead of re-deriving the leaf type.

This exact match block is duplicated here and in rust_calc_node_numeric_type (Lines 3600-3606), and already exists as the helper percentage_leaf_type_for (Lines 2402-2412) used by rust_calc_node_determine_type. Reusing the helper keeps the three sites from drifting.

♻️ Suggested reuse
-    let resolve_as = resolve_as_from_fields(*has_percentages_resolve_as, *resolve_as_is_number, *resolve_as_base);
-    let mut percentage_leaf_type = CalcNumericType::default();
-    match resolve_as {
-        Some(ResolveAs::Base(base)) => {
-            percentage_leaf_type.exponents[base as usize] = Some(1);
-            percentage_leaf_type.percent_hint = Some(base);
-        }
-        _ => percentage_leaf_type.exponents[BASE_TYPE_PERCENT] = Some(1),
-    }
+    let resolve_as = resolve_as_from_fields(*has_percentages_resolve_as, *resolve_as_is_number, *resolve_as_base);
+    let percentage_leaf_type = percentage_leaf_type_for(resolve_as);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Libraries/LibWeb/CSS/Rust/src/calc.rs` around lines 2603 - 2610, Replace the
duplicated percentage leaf type construction in the surrounding function with
the existing percentage_leaf_type_for helper, passing the current resolve_as
value. Preserve the resulting CalcNumericType behavior for both ResolveAs::Base
and the fallback case, and leave rust_calc_node_numeric_type unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Libraries/LibWeb/CSS/CascadedProperties.cpp`:
- Around line 24-32: Update CascadedProperties to prevent copying of its owning
raw pointer m_store, following the companion CascadedProperties.h review
guidance. Add the appropriate copy-protection declarations or otherwise make the
class non-copyable, while preserving the existing constructor and destructor
ownership behavior.

In `@Libraries/LibWeb/CSS/ComputedValues.h`:
- Around line 1581-1582: Correct the `ComputedValues` default member initializer
for `y` to use `InitialValues::y()` instead of `InitialValues::x()`, while
leaving the `x` initializer unchanged.

In `@Libraries/LibWeb/CSS/Rust/src/style_compute.rs`:
- Around line 537-547: Update the exponent calculation in the math-depth scaling
logic around e so it uses the positive numeric difference b - a rather than
converting the comparison to a boolean. Preserve zero for non-positive
differences, and pass the full depth delta to size_ratio.powf so larger gaps
scale by the correct number of levels.

---

Nitpick comments:
In `@Libraries/LibWeb/CSS/Rust/src/calc.rs`:
- Around line 2603-2610: Replace the duplicated percentage leaf type
construction in the surrounding function with the existing
percentage_leaf_type_for helper, passing the current resolve_as value. Preserve
the resulting CalcNumericType behavior for both ResolveAs::Base and the fallback
case, and leave rust_calc_node_numeric_type unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7dd5b0d0-fca0-4680-8db4-f354a1a316c3

📥 Commits

Reviewing files that changed from the base of the PR and between 3b05450 and 89f4f06.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (175)
  • Cargo.toml
  • Libraries/LibWeb/Animations/TimeValue.cpp
  • Libraries/LibWeb/CMakeLists.txt
  • Libraries/LibWeb/CSS/CSSMathClamp.cpp
  • Libraries/LibWeb/CSS/CSSMathClamp.h
  • Libraries/LibWeb/CSS/CSSMathInvert.cpp
  • Libraries/LibWeb/CSS/CSSMathInvert.h
  • Libraries/LibWeb/CSS/CSSMathMax.cpp
  • Libraries/LibWeb/CSS/CSSMathMax.h
  • Libraries/LibWeb/CSS/CSSMathMin.cpp
  • Libraries/LibWeb/CSS/CSSMathMin.h
  • Libraries/LibWeb/CSS/CSSMathNegate.cpp
  • Libraries/LibWeb/CSS/CSSMathNegate.h
  • Libraries/LibWeb/CSS/CSSMathProduct.cpp
  • Libraries/LibWeb/CSS/CSSMathProduct.h
  • Libraries/LibWeb/CSS/CSSMathSum.cpp
  • Libraries/LibWeb/CSS/CSSMathSum.h
  • Libraries/LibWeb/CSS/CSSNumericValue.h
  • Libraries/LibWeb/CSS/CSSUnitValue.cpp
  • Libraries/LibWeb/CSS/CSSUnitValue.h
  • Libraries/LibWeb/CSS/CascadedProperties.cpp
  • Libraries/LibWeb/CSS/CascadedProperties.h
  • Libraries/LibWeb/CSS/Clip.h
  • Libraries/LibWeb/CSS/ColumnCount.h
  • Libraries/LibWeb/CSS/ComputedProperties.cpp
  • Libraries/LibWeb/CSS/ComputedProperties.h
  • Libraries/LibWeb/CSS/ComputedValues.cpp
  • Libraries/LibWeb/CSS/ComputedValues.h
  • Libraries/LibWeb/CSS/EasingFunction.h
  • Libraries/LibWeb/CSS/Filter.h
  • Libraries/LibWeb/CSS/Interpolation.cpp
  • Libraries/LibWeb/CSS/NumericType.cpp
  • Libraries/LibWeb/CSS/NumericType.h
  • Libraries/LibWeb/CSS/Parser/Parser.h
  • Libraries/LibWeb/CSS/Parser/ValueParsing.cpp
  • Libraries/LibWeb/CSS/Rust/Cargo.toml
  • Libraries/LibWeb/CSS/Rust/build.rs
  • Libraries/LibWeb/CSS/Rust/cbindgen.toml
  • Libraries/LibWeb/CSS/Rust/src/calc.rs
  • Libraries/LibWeb/CSS/Rust/src/cascaded_properties.rs
  • Libraries/LibWeb/CSS/Rust/src/computed_values.rs
  • Libraries/LibWeb/CSS/Rust/src/css_pixels.rs
  • Libraries/LibWeb/CSS/Rust/src/css_tokenizer.rs
  • Libraries/LibWeb/CSS/Rust/src/lib.rs
  • Libraries/LibWeb/CSS/Rust/src/property_metadata.rs
  • Libraries/LibWeb/CSS/Rust/src/selector_engine.rs
  • Libraries/LibWeb/CSS/Rust/src/style_compute.rs
  • Libraries/LibWeb/CSS/Rust/src/style_value.rs
  • Libraries/LibWeb/CSS/StyleComputeFFI.h
  • Libraries/LibWeb/CSS/StyleComputer.cpp
  • Libraries/LibWeb/CSS/StyleComputer.h
  • Libraries/LibWeb/CSS/StyleStructRef.h
  • Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AbstractNonMathCalcFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/AnchorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AngleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderImageSliceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusRectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CalcNodeRef.h
  • Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorInterpolationMethodStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorMixStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContrastColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/DisplayStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EasingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EmptyOptionalStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GuaranteedInvalidStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/KeywordStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LightDarkStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpacityValueStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OverflowClipMarginStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PercentageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RandomValueSharingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RatioStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RepeatStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
  • Libraries/LibWeb/CSS/StyleValues/SuperellipseStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TreeCountingFunctionStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/TreeCountingFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TupleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnicodeRangeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h
  • Libraries/LibWeb/DOM/Element.cpp
  • Libraries/LibWeb/Forward.h
  • Libraries/LibWeb/Internals/Internals.cpp
  • Libraries/LibWeb/Internals/Internals.h
  • Libraries/LibWeb/Internals/Internals.idl
  • Libraries/LibWeb/Layout/FormattingContext.cpp
  • Libraries/LibWeb/Rust/Cargo.toml
  • Libraries/LibWeb/Rust/build.rs
  • Libraries/LibWeb/Rust/src/lib.rs
  • Meta/Generators/generate_libweb_css_math_functions.py
  • Meta/Generators/generate_libweb_css_property_id.py
  • Meta/Generators/generate_libweb_css_units.py
  • Tests/LibWeb/CMakeLists.txt
  • Tests/LibWeb/TestLengthAbsolutizeParity.cpp
  • Tests/LibWeb/TestNumericTypeParity.cpp
  • Tests/LibWeb/TestStylePropertyMetadataParity.cpp
  • Tests/LibWeb/TestStyleStructRef.cpp
  • Tests/LibWeb/Text/expected/css/calc-font-props-computed.txt
  • Tests/LibWeb/Text/expected/css/calc-math-depth-computed.txt
  • Tests/LibWeb/Text/expected/css/calc-round-strategy-roundtrip.txt
  • Tests/LibWeb/Text/expected/css/computed-values-group-sharing.txt
  • Tests/LibWeb/Text/expected/css/computed-values-stats.txt
  • Tests/LibWeb/Text/expected/css/font-feature-settings-computed.txt
  • Tests/LibWeb/Text/expected/css/position-area-computed.txt
  • Tests/LibWeb/Text/input/css/calc-font-props-computed.html
  • Tests/LibWeb/Text/input/css/calc-math-depth-computed.html
  • Tests/LibWeb/Text/input/css/calc-round-strategy-roundtrip.html
  • Tests/LibWeb/Text/input/css/computed-values-group-sharing.html
  • Tests/LibWeb/Text/input/css/computed-values-stats.html
  • Tests/LibWeb/Text/input/css/font-feature-settings-computed.html
  • Tests/LibWeb/Text/input/css/position-area-computed.html
💤 Files with no reviewable changes (84)
  • Libraries/LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RepeatStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpacityValueStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RatioStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TupleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusRectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorInterpolationMethodStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp
  • Libraries/LibWeb/CSS/NumericType.cpp
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/DisplayStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AngleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/SuperellipseStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EmptyOptionalStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h
  • Libraries/LibWeb/Rust/Cargo.toml
  • Libraries/LibWeb/Forward.h
  • Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OverflowClipMarginStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RandomValueSharingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PercentageStyleValue.h
  • Libraries/LibWeb/CSS/ComputedProperties.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LightDarkStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/GuaranteedInvalidStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ColorFunctionStyleValue.h
  • Libraries/LibWeb/Rust/src/lib.rs
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnicodeRangeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/KeywordStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderImageSliceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EasingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContrastColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorMixStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.h

Comment on lines +24 to 32
CascadedProperties::CascadedProperties()
: m_store(ComputedValuesFFI::rust_cascaded_properties_create())
{
return adopt_ref(*new CascadedProperties);
}

void CascadedProperties::revert_property(PropertyID property_id, Important important, CascadeOrigin cascade_origin)
CascadedProperties::~CascadedProperties()
{
auto it = m_properties.find(property_id);
if (it == m_properties.end())
return;
auto& entries = it->value;
entries.remove_all_matching([&](auto& entry) {
// https://drafts.csswg.org/css-cascade-5/#author-presentational-hint-origin
// For the purpose of cascading this author presentational hint origin is treated as an independent origin, but
// for the purpose of the revert keyword it is considered part of the author origin.
auto origin_matches = entry.origin == cascade_origin
|| (cascade_origin == CascadeOrigin::Author && entry.origin == CascadeOrigin::AuthorPresentationalHint);
return entry.property.property_id == property_id
&& entry.property.important == important
&& origin_matches;
});
if (entries.is_empty()) {
m_contained_properties_cache.set(to_underlying(property_id), false);
m_properties.remove(it);
}
ComputedValuesFFI::rust_cascaded_properties_destroy(m_store);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

m_store is a raw owning pointer without copy protection — see companion comment on CascadedProperties.h for the fix.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Libraries/LibWeb/CSS/CascadedProperties.cpp` around lines 24 - 32, Update
CascadedProperties to prevent copying of its owning raw pointer m_store,
following the companion CascadedProperties.h review guidance. Add the
appropriate copy-protection declarations or otherwise make the class
non-copyable, while preserving the existing constructor and destructor ownership
behavior.

Comment thread Libraries/LibWeb/CSS/ComputedValues.h Outdated
Comment on lines +1581 to +1582
LengthPercentage x { InitialValues::x() };
LengthPercentage y { InitialValues::x() };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Copy-paste typo: y seeded from InitialValues::x().

y should default from InitialValues::y(). The values happen to coincide (both 0) today, so it is currently unobservable, but it is a latent divergence from what create() stores via set_y() (property Y) and defeats default-payload sharing if the two initials ever differ.

🐛 Proposed fix
         LengthPercentage x { InitialValues::x() };
-        LengthPercentage y { InitialValues::x() };
+        LengthPercentage y { InitialValues::y() };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
LengthPercentage x { InitialValues::x() };
LengthPercentage y { InitialValues::x() };
LengthPercentage x { InitialValues::x() };
LengthPercentage y { InitialValues::y() };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Libraries/LibWeb/CSS/ComputedValues.h` around lines 1581 - 1582, Correct the
`ComputedValues` default member initializer for `y` to use `InitialValues::y()`
instead of `InitialValues::x()`, while leaving the `x` initializer unchanged.

Comment on lines +537 to +547
// 3. Let E be B - A > 0.
let e = f64::from(b - a > 0);
// FIXME: 4. If the inherited first available font has an OpenType MATH table:
// - If A <= 0 and B >= 2 then multiply S by scriptScriptPercentScaleDown
// and decrement E by 2.
// - Otherwise if A = 1 then multiply S by scriptScriptPercentScaleDown /
// scriptPercentScaleDown and decrement E by 1.
// - Otherwise if B = 1 then multiply S by scriptPercentScaleDown and
// decrement E by 1.
// 5. Multiply S by C^E.
scale *= size_ratio.powf(e);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find the C++ math-depth font-size scaling to confirm parity intent.
rg -nP -C4 'InvertScaleFactor|scriptScriptPercentScaleDown|size_ratio|0\.71' --type=cpp Libraries/LibWeb/CSS

Repository: LadybirdBrowser/ladybird

Length of output: 162


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant Rust implementation and nearby context.
sed -n '500,570p' Libraries/LibWeb/CSS/Rust/src/style_compute.rs

# Find math-depth/font-size related code and tests in the repo.
rg -n -C 3 'math-depth|scriptScriptPercentScaleDown|scriptPercentScaleDown|size_ratio|powf\(e\)|powf\(' Libraries -g '!**/target/**'

# Look for any mirrored C++ implementation or spec comments around the same logic.
rg -n -C 3 'Let E be B - A|B - A|math depth|math-depth' Libraries -g '!**/target/**'

Repository: LadybirdBrowser/ladybird

Length of output: 29775


Use the math-depth delta as the exponent Libraries/LibWeb/CSS/Rust/src/style_compute.rs:537-547
e should be the positive depth difference, not a boolean. With f64::from(b - a > 0), any gap larger than 1 still scales by 0.71^1, which is wrong for cases like math-depth: add(2).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Libraries/LibWeb/CSS/Rust/src/style_compute.rs` around lines 537 - 547,
Update the exponent calculation in the math-depth scaling logic around e so it
uses the positive numeric difference b - a rather than converting the comparison
to a boolean. Preserve zero for non-positive differences, and pass the full
depth delta to size_ratio.powf so larger gaps scale by the correct number of
levels.

@awesomekling
awesomekling force-pushed the cv-rs-3 branch 2 times, most recently from 5b428f1 to a90bc56 Compare July 20, 2026 20:14

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Libraries/LibWeb/CSS/StyleValues/AbstractNonMathCalcFunctionStyleValue.h`:
- Around line 13-19: Include CalcNodeRef.h in
AbstractNonMathCalcFunctionStyleValue.h before declaring
resolve_to_calculation_node, and remove the CalcNodeRef forward declaration if
it is no longer needed. Keep the existing Optional<CalcNodeRef> return type
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 96135c6d-6f5b-47c2-9212-9b36a7a56106

📥 Commits

Reviewing files that changed from the base of the PR and between 5b428f1 and a90bc56.

📒 Files selected for processing (169)
  • Libraries/LibWeb/Animations/TimeValue.cpp
  • Libraries/LibWeb/CMakeLists.txt
  • Libraries/LibWeb/CSS/CSSMathClamp.cpp
  • Libraries/LibWeb/CSS/CSSMathClamp.h
  • Libraries/LibWeb/CSS/CSSMathInvert.cpp
  • Libraries/LibWeb/CSS/CSSMathInvert.h
  • Libraries/LibWeb/CSS/CSSMathMax.cpp
  • Libraries/LibWeb/CSS/CSSMathMax.h
  • Libraries/LibWeb/CSS/CSSMathMin.cpp
  • Libraries/LibWeb/CSS/CSSMathMin.h
  • Libraries/LibWeb/CSS/CSSMathNegate.cpp
  • Libraries/LibWeb/CSS/CSSMathNegate.h
  • Libraries/LibWeb/CSS/CSSMathProduct.cpp
  • Libraries/LibWeb/CSS/CSSMathProduct.h
  • Libraries/LibWeb/CSS/CSSMathSum.cpp
  • Libraries/LibWeb/CSS/CSSMathSum.h
  • Libraries/LibWeb/CSS/CSSNumericValue.h
  • Libraries/LibWeb/CSS/CSSUnitValue.cpp
  • Libraries/LibWeb/CSS/CSSUnitValue.h
  • Libraries/LibWeb/CSS/CascadedProperties.cpp
  • Libraries/LibWeb/CSS/CascadedProperties.h
  • Libraries/LibWeb/CSS/Clip.h
  • Libraries/LibWeb/CSS/ColumnCount.h
  • Libraries/LibWeb/CSS/ComputedProperties.cpp
  • Libraries/LibWeb/CSS/ComputedProperties.h
  • Libraries/LibWeb/CSS/ComputedValues.cpp
  • Libraries/LibWeb/CSS/ComputedValues.h
  • Libraries/LibWeb/CSS/EasingFunction.h
  • Libraries/LibWeb/CSS/Filter.h
  • Libraries/LibWeb/CSS/Interpolation.cpp
  • Libraries/LibWeb/CSS/Length.h
  • Libraries/LibWeb/CSS/NumericType.cpp
  • Libraries/LibWeb/CSS/NumericType.h
  • Libraries/LibWeb/CSS/Parser/Parser.h
  • Libraries/LibWeb/CSS/Parser/ValueParsing.cpp
  • Libraries/LibWeb/CSS/Rust/Cargo.toml
  • Libraries/LibWeb/CSS/Rust/build.rs
  • Libraries/LibWeb/CSS/Rust/cbindgen.toml
  • Libraries/LibWeb/CSS/Rust/src/calc.rs
  • Libraries/LibWeb/CSS/Rust/src/cascaded_properties.rs
  • Libraries/LibWeb/CSS/Rust/src/computed_values.rs
  • Libraries/LibWeb/CSS/Rust/src/css_pixels.rs
  • Libraries/LibWeb/CSS/Rust/src/lib.rs
  • Libraries/LibWeb/CSS/Rust/src/property_metadata.rs
  • Libraries/LibWeb/CSS/Rust/src/selector_engine.rs
  • Libraries/LibWeb/CSS/Rust/src/style_compute.rs
  • Libraries/LibWeb/CSS/Rust/src/style_value.rs
  • Libraries/LibWeb/CSS/StyleComputeFFI.h
  • Libraries/LibWeb/CSS/StyleComputer.cpp
  • Libraries/LibWeb/CSS/StyleComputer.h
  • Libraries/LibWeb/CSS/StyleStructRef.h
  • Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AbstractNonMathCalcFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/AnchorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AngleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderImageSliceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusRectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CalcNodeRef.h
  • Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorInterpolationMethodStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorMixStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContrastColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/DisplayStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EasingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EmptyOptionalStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GuaranteedInvalidStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/KeywordStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LightDarkStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpacityValueStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OverflowClipMarginStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PercentageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RandomValueSharingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RatioStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RepeatStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
  • Libraries/LibWeb/CSS/StyleValues/SuperellipseStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TreeCountingFunctionStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/TreeCountingFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TupleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnicodeRangeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h
  • Libraries/LibWeb/DOM/Element.cpp
  • Libraries/LibWeb/Forward.h
  • Libraries/LibWeb/Internals/Internals.cpp
  • Libraries/LibWeb/Internals/Internals.h
  • Libraries/LibWeb/Internals/Internals.idl
  • Libraries/LibWeb/Layout/FormattingContext.cpp
  • Meta/Generators/generate_libweb_css_math_functions.py
  • Meta/Generators/generate_libweb_css_property_id.py
  • Meta/Generators/generate_libweb_css_units.py
  • Tests/LibWeb/CMakeLists.txt
  • Tests/LibWeb/TestLengthAbsolutizeParity.cpp
  • Tests/LibWeb/TestNumericTypeParity.cpp
  • Tests/LibWeb/TestStylePropertyMetadataParity.cpp
  • Tests/LibWeb/TestStyleStructRef.cpp
  • Tests/LibWeb/Text/expected/css/calc-font-props-computed.txt
  • Tests/LibWeb/Text/expected/css/calc-math-depth-computed.txt
  • Tests/LibWeb/Text/expected/css/calc-round-strategy-roundtrip.txt
  • Tests/LibWeb/Text/expected/css/computed-values-group-sharing.txt
  • Tests/LibWeb/Text/expected/css/font-feature-settings-computed.txt
  • Tests/LibWeb/Text/expected/css/position-area-computed.txt
  • Tests/LibWeb/Text/input/css/calc-font-props-computed.html
  • Tests/LibWeb/Text/input/css/calc-math-depth-computed.html
  • Tests/LibWeb/Text/input/css/calc-round-strategy-roundtrip.html
  • Tests/LibWeb/Text/input/css/computed-values-group-sharing.html
  • Tests/LibWeb/Text/input/css/font-feature-settings-computed.html
  • Tests/LibWeb/Text/input/css/position-area-computed.html
💤 Files with no reviewable changes (82)
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnicodeRangeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontSourceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ScrollbarColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AnchorSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderImageSliceStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpacityValueStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RepeatStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorInterpolationMethodStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/ComputedProperties.h
  • Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BorderRadiusRectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GuaranteedInvalidStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/StringStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/KeywordStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LightDarkStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/DisplayStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/SuperellipseStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
  • Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/EasingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TupleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FontStyleStyleValue.h
  • Libraries/LibWeb/Forward.h
  • Libraries/LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RandomValueSharingStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ColorMixStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/PercentageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ContrastColorStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/RectStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OverflowClipMarginStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ImageSetStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/AngleStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.h
  • Libraries/LibWeb/CSS/NumericType.cpp
  • Libraries/LibWeb/CSS/StyleValues/EmptyOptionalStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/RatioStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h
🚧 Files skipped from review as they are similar to previous changes (71)
  • Libraries/LibWeb/CSS/CSSMathClamp.h
  • Libraries/LibWeb/CSS/CSSMathNegate.h
  • Tests/LibWeb/Text/input/css/position-area-computed.html
  • Tests/LibWeb/Text/expected/css/calc-math-depth-computed.txt
  • Libraries/LibWeb/CSS/CSSMathSum.h
  • Tests/LibWeb/Text/expected/css/calc-round-strategy-roundtrip.txt
  • Libraries/LibWeb/CSS/CSSMathMin.h
  • Libraries/LibWeb/CSS/StyleComputeFFI.h
  • Libraries/LibWeb/Internals/Internals.h
  • Tests/LibWeb/Text/expected/css/position-area-computed.txt
  • Libraries/LibWeb/CSS/Rust/Cargo.toml
  • Libraries/LibWeb/Internals/Internals.idl
  • Libraries/LibWeb/CSS/Rust/cbindgen.toml
  • Libraries/LibWeb/CSS/CSSMathProduct.h
  • Tests/LibWeb/Text/input/css/calc-font-props-computed.html
  • Tests/LibWeb/Text/input/css/calc-math-depth-computed.html
  • Tests/LibWeb/Text/input/css/font-feature-settings-computed.html
  • Libraries/LibWeb/CSS/StyleComputer.h
  • Meta/Generators/generate_libweb_css_units.py
  • Libraries/LibWeb/CSS/CSSMathInvert.h
  • Libraries/LibWeb/CSS/ColumnCount.h
  • Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp
  • Tests/LibWeb/Text/expected/css/calc-font-props-computed.txt
  • Libraries/LibWeb/CSS/CSSUnitValue.h
  • Tests/LibWeb/Text/input/css/calc-round-strategy-roundtrip.html
  • Libraries/LibWeb/CSS/Filter.h
  • Tests/LibWeb/Text/expected/css/font-feature-settings-computed.txt
  • Libraries/LibWeb/Animations/TimeValue.cpp
  • Libraries/LibWeb/CSS/CSSMathProduct.cpp
  • Libraries/LibWeb/CSS/CSSMathMax.cpp
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.h
  • Libraries/LibWeb/CSS/EasingFunction.h
  • Libraries/LibWeb/CSS/CSSNumericValue.h
  • Libraries/LibWeb/CSS/CSSMathClamp.cpp
  • Tests/LibWeb/Text/expected/css/computed-values-group-sharing.txt
  • Libraries/LibWeb/CSS/StyleValues/AnchorStyleValue.h
  • Libraries/LibWeb/CSS/CSSMathNegate.cpp
  • Libraries/LibWeb/CSS/StyleValues/TreeCountingFunctionStyleValue.h
  • Libraries/LibWeb/CSS/StyleStructRef.h
  • Libraries/LibWeb/CSS/Rust/src/lib.rs
  • Libraries/LibWeb/CSS/Rust/src/css_pixels.rs
  • Libraries/LibWeb/Layout/FormattingContext.cpp
  • Meta/Generators/generate_libweb_css_property_id.py
  • Libraries/LibWeb/CSS/StyleValues/CalcNodeRef.h
  • Tests/LibWeb/Text/input/css/computed-values-group-sharing.html
  • Libraries/LibWeb/CMakeLists.txt
  • Tests/LibWeb/TestNumericTypeParity.cpp
  • Libraries/LibWeb/CSS/CSSMathMin.cpp
  • Libraries/LibWeb/CSS/Parser/Parser.h
  • Libraries/LibWeb/Internals/Internals.cpp
  • Libraries/LibWeb/DOM/Element.cpp
  • Libraries/LibWeb/CSS/CascadedProperties.h
  • Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.cpp
  • Libraries/LibWeb/CSS/Rust/src/property_metadata.rs
  • Libraries/LibWeb/CSS/Rust/src/computed_values.rs
  • Libraries/LibWeb/CSS/NumericType.h
  • Libraries/LibWeb/CSS/CSSUnitValue.cpp
  • Libraries/LibWeb/CSS/Interpolation.cpp
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
  • Libraries/LibWeb/CSS/Rust/src/cascaded_properties.rs
  • Libraries/LibWeb/CSS/CascadedProperties.cpp
  • Meta/Generators/generate_libweb_css_math_functions.py
  • Libraries/LibWeb/CSS/Rust/build.rs
  • Libraries/LibWeb/CSS/ComputedProperties.cpp
  • Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h
  • Libraries/LibWeb/CSS/Rust/src/calc.rs
  • Libraries/LibWeb/CSS/Parser/ValueParsing.cpp
  • Libraries/LibWeb/CSS/Rust/src/style_value.rs
  • Libraries/LibWeb/CSS/StyleComputer.cpp
  • Libraries/LibWeb/CSS/ComputedValues.h
  • Libraries/LibWeb/CSS/Rust/src/style_compute.rs

Comment thread Libraries/LibWeb/CSS/StyleValues/AbstractNonMathCalcFunctionStyleValue.h Outdated
@github-actions github-actions Bot added the conflicts Pull request has merge conflicts that need resolution label Jul 20, 2026
@github-actions

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@tcl3

tcl3 commented Jul 20, 2026

Copy link
Copy Markdown
Member

The Claude-Session: commit trailers included on some of the commits don't seem to be publicly accessible.

To be honest I'm not sure why Claude tries to include them if this is the default behavior.

@awesomekling
awesomekling marked this pull request as draft July 20, 2026 21:32
@awesomekling
awesomekling force-pushed the cv-rs-3 branch 2 times, most recently from d00b5a9 to 819654c Compare July 20, 2026 22:50
@github-actions github-actions Bot removed the conflicts Pull request has merge conflicts that need resolution label Jul 20, 2026
@github-actions

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@github-actions github-actions Bot added the conflicts Pull request has merge conflicts that need resolution label Jul 20, 2026
The LibWeb Rust crate mixed CSS code (the CSS tokenizer, the selector
engine and the style value data) with the encoding detection used by
the HTML parser. Give the CSS side its own libweb_css_rust crate at
Libraries/LibWeb/CSS/Rust, following the per-subsystem crate layout
already used by HTML/Parser/Rust and ContentBlocker/Rust, so upcoming
style system work lands in a CSS-owned crate from the start.

The original crate keeps the encoding detection and the re-export that
links the HTML tokenizer crate's symbols into the archive. The
generated FFI header names and install locations are unchanged, so no
C++ includes change. The new crate follows the ContentBlocker pattern
for the Rust allocator: it defines one only in static builds, behind
an allocator feature, and otherwise relies on the allocator from
libweb_rust linked into the same library.
Expose process-wide ComputedValues statistics (live instance count and
total instances created) through a new internals API. This is
measurement scaffolding for the upcoming work to shard ComputedValues
into copy-on-write style value groups: later commits will extend the
stats with per-group instance counts and sharing ratios, and tests will
assert that sharing actually happens.

Also add a test exercising the new API.
This is the foundation for sharding ComputedValues into style value
groups that are shared between elements instead of deep-copied.

Copying a StyleStructRef shares the payload with a reference count
bump, and access() clones the payload only when it is shared with
someone else. Default-constructed refs point at one intentionally
leaked default payload per group type, so a default-valued group costs
no allocation at all. The payload layout (refcount header followed by
the value) deliberately matches the Arc layout that a later change
will hand over to Rust ownership.

Setting LIBWEB_STYLE_NO_STRUCT_SHARING in the environment makes copies
deep-copy instead of sharing, for bisecting sharing-related problems.

Covered by unit tests for the sharing, clone-on-write, default
identity, assignment, and value equality semantics.
Move every field of the flat InheritedValues struct into copy-on-write
groups held through StyleStructRefs: table, list, UI, SVG, text and box
values, plus a FontValues group carrying the font properties,
line-height and the math properties. Getter signatures are unchanged.
Setters skip the write entirely when the incoming value matches the
stored one and clone the group payload only on the first real mutation,
so elements share payloads with their parent (and ultimately with the
leaked default payloads) for everything they do not explicitly set.

The inherited box group (visibility, direction, writing-mode,
content-visibility, image-rendering) is deliberately tiny: writing-mode
and direction gate logical property alias resolution during style
diffing, so keeping the group small maximizes the chance that it stays
pointer-identical across a restyle, which a later change exploits to
skip logical alias remapping entirely.

The font cascade list setter compares by value with equals() rather
than by pointer, since the list object is rebuilt per element and
pointer comparison would defeat sharing for the common case where a
child uses exactly the parent's font. The font-variation-settings
setter compares the maps manually because HashMap has no equality
operator. Many value types gain defaulted equality operators for the
unchanged-value checks in the setters.

With this, InheritedValues is nothing but seven StyleStructRefs, so
inheriting from a parent style is seven reference count bumps instead
of a deep copy of every inherited field.
Move every field of the flat NonInheritedValues struct into
copy-on-write groups held through StyleStructRefs: animation and
transition values, grid, SVG reset, anchor, effects, mask, text reset,
content, transform, background, border, alignment and flex,
miscellaneous reset, sizing, surround and box values. Setters follow
the inherited-group pattern: compare before writing and clone the
payload only on the first real mutation.

The animation group is the single biggest allocation win of the
sharding: the flat struct default-initialized around two dozen
one-element Vectors on every ComputedValues, so every element on every
page paid two dozen heap allocations for animation state it almost
never used. Those now live in one shared default payload.

The border Mutator previously handed out mutable BorderData
references, which would have forced a payload clone on every element
regardless of whether anything changed; it is replaced with
set_border_* setters that compare before writing, and the border
materialization in ComputedValues::create() builds the BorderData
locally and passes it in. Many value types gain defaulted equality
operators for the unchanged-value checks.

This completes the ComputedValues sharding: both InheritedValues and
NonInheritedValues are now nothing but StyleStructRefs (7 inherited
and 16 reset groups), so cloning a style is 23 reference count bumps
and elements share group payloads with their parents and with the
leaked defaults for everything they do not explicitly set.
Expose, for each ComputedValues style value group of an element,
whether the payload is shared with the parent element and whether it
is the shared default payload. This makes group sharing regressions
visible in tests instead of only in memory profiles.

The accompanying test records the current truth, which already exposes
sharing bugs: the animation, grid, mask, transform and inherited list
groups are cloned for every element even when completely unstyled,
because the values create() produces for them never compare equal to
the default payload (empty round-trip style value vectors versus
populated ones, pointer-compared counter styles, and mask layers built
with different field defaults). Follow-up commits will fix these; the
test expectations will change from false to true as they land.
After building an element's ComputedValues, adopt group payloads from
the element it inherits style from wherever the values compare equal,
and likewise adopt payloads from the element's previous style
generation, so an element whose new style matches its old style goes
back to sharing storage with it.

The sharing introspection test exposed that six groups were cloned for
every element, styled or not, because the value create() produces for
an unstyled element never compared equal to the group's default
payload: empty timing-function round-trip vectors versus the initial
easing value, null mask images and pixel-length positions versus the
initial none value and percentage positions, grid track lists carrying
parser bookkeeping flags, a length transform-origin z component versus
a percentage default, fill materialized as an SVGPaint versus an empty
Optional, and InitialValues::color_interpolation() disagreeing with
Properties.json. Give StyleStructRef a make_default_payload_value()
hook to seed those groups exactly as create() would, and correct the
color-interpolation initial value. Values that can never match a
process-wide default, like scope-resolved counter styles, share down
the tree from the root through the parent adoption instead.

Payload adoption also feeds the style diff:
compute_required_invalidation() reconstructed and compared two style
values for every longhand on every restyled element, the single
hottest entry in a StyleBench profile. When every group payload ends
up shared and neither style carries animated values, equal payloads
mean equal computed values for every longhand, and the whole
reconstruct-and-compare loop is skipped.

Adoption demands observable identity, not semantic equality: Ratio
compares proportionally (1 / 2 equals 0.5 / 1) but ratios serialize as
written, which made aspect-ratio transitions fail to start when a
proportionally-equal payload was adopted. AspectRatio therefore
compares ratio components exactly, and FontValues gets a hand-written
equality operator. Setting LIBWEB_VERIFY_STYLE_DIFF_FAST_PATH runs the
full diff loop as well and verifies it agrees whenever the fast path
claims a no-op; the full test-web suite passes with the verifier
enabled. The sharing test asserts that an unstyled child shares every
inherited group payload with its parent.
Add a computed_values module to the CSS Rust crate that owns the
allocation, layout and destruction of ComputedValues style group
payloads, and reimplement StyleStructRef over it. Each group registers
a vtable with the payload size, alignment and C++ callbacks for
default construction, copy construction and destruction, the same way
Stylo drives Gecko's nsStyle structs; Rust treats the payloads as
opaque blobs.

The atomic reference count lives in a header placed immediately before
the payload, sized to preserve the payload's alignment. Reads stay
inline field accesses and sharing stays an inline atomic on the
header, so the hot paths gain no FFI calls; only cloning for mutation,
building the leaked per-group default payloads (now built by Rust at
first use and marked immortal by a reference count sentinel), and
freeing the last reference cross the boundary. The reference counts
are now atomic, which future parallel style computation requires
anyway.

The StyleStructRef unit tests use real group types, so they exercise
the FFI layout and lifecycle contract end to end, alongside a Rust
unit test for the layout and lifecycle rules.
Move the layout of the inherited box and table groups into the Rust
crate: the repr(C) structs in computed_values.rs are now the source of
truth, the C++ group types derive from the cbindgen mirrors and only
add the initial values and an equality operator, and the lens getters
and setters convert between the C++ enums and the stored underlying
values, following the established opaque-integer enum convention.
Non-enum scalar fields cross the boundary as their raw
representations, with the border spacings stored as raw CSSPixels
fixed-point values that the lens reconstructs through
CSSPixels::from_raw(). Static assertions pin the layered C++ types to
the mirrored layouts, and the StyleStructRef unit tests convert their
stored-value expectations accordingly.

Rust gains a typed view of the payloads, which both anchors the layout
in the exported ABI and is how Rust-side style computation will read
and write group payloads. These are the first two of the per-group
layout flips; the remaining groups follow the same pattern.
The Rust style computation core needs the property metadata that the
C++ side generates from Properties.json: identifier bounds, inherited
flags, the property computation order and the requires-computation
levels. Generate equivalent tables into the Rust crate from the same
JSON, replicating the C++ generator's identifier assignment (Custom,
then shorthands, inherited longhands and non-inherited longhands in
JSON order, skipping legacy aliases) including the logical-alias
metadata resolution through LogicalPropertyGroups.json and the
programmatically populated all shorthand.

A new parity unit test compares every table against the C++-generated
equivalents through small FFI accessors, so the two generators cannot
drift; it immediately caught the computation-order tail following
JSON iteration order across all longhands rather than grouped by
inheritance. The C++ metadata functions gain WEB_API so the test can
link against them.
Add the first piece of the Rust style computation core: length
absolutization. A style_compute module resolves absolute, font-relative
and viewport-relative lengths to pixels exactly as the C++
implementation does, with the length unit table generated from
Units.json (unit codes are the alphabetical index, matching the C++
LengthUnit enum, and absolute units carry their canonical px ratio).
LengthStyleValue::absolutized() now routes through the Rust core;
container-relative units report themselves unhandled and fall back to
the C++ resolution.

The context mirror carries the font metrics as unrounded CSS pixel
values and the viewport-dependency flags, and the result reports
whether viewport metrics were consumed so the caller can record the
dependency, matching the C++ flag semantics exactly.

A parity test compares the Rust resolution bit-exactly against
Length::to_px_without_rounding across every supported unit, including
the dependency-flag behavior. That exactness requires serde_json's
float_roundtrip feature, since the canonical ratios in Units.json have
more decimal digits than a double and the fast parse rounds them
differently than the C++ generator's emission. The generated unit and
property metadata functions gain WEB_API so the parity tests can link.
Port the interdependent font-ordering cluster at the head of the
property computation order to the Rust style computation core:
font-weight (the number passthrough, the normal and bold keyword
mappings, and the bolder/lighter relative weight chart reading the
inherited weight), font-width (the keyword percentage table),
font-size (the absolute and relative size keyword tables, the
percentage-of-inherited resolution and the MathML math-depth scaling
procedure), math-depth (the auto-add rule against the inherited
math-style, integer values and the inherited fallback) and line-height
(the normal/length/number passthroughs and the percentage-of-font-size
resolution). Calc values and the add() function form report themselves
unhandled and keep resolving in the C++ callers, and the C++ size
mapping helpers stay for the monospace font-size recascade until that
ports too.

Keyword codes are now generated into the Rust crate from
Keywords.json, following the C++ Keyword enum assignment (Invalid is
zero, then array order), which every further keyword-based compute
helper uses.

The font-size keyword tables require CSSPixels fixed-point arithmetic,
so the crate gains a bit-exact CssPixels port: 6 fractional bits in an
i32, float conversion rounding half to even with i32 saturation (the
C++ path goes through x87 fistp in the default rounding mode),
multiplication rounding the cut-off fraction half away from zero when
more fraction bits follow and half to even otherwise, and the
fraction-to-value conversion truncating. A parity test compares every
operation against the C++ implementation across rounding edge cases
and a deterministic pseudo-random grid.

StyleValue gains a public accessor for its Rust-owned data so
StyleComputer can hand values to the Rust core, and the crate's unit
tests stub the C++ release callbacks that retained style value members
invoke on drop, since the standalone test binary has no C++ side.
Port the border and outline width computation (the thin/medium/thick
line-width keywords, absolute length conversion and the border-width
snapping procedure), the corner-shape keyword-to-superellipse
parameter mapping, and the position-area logical-to-short keyword
mapping to the Rust style computation core. Calc lengths keep
resolving in the C++ caller, which also keeps interning the
superellipse value for round since it is the corner-shape initial
value, and the position-area two-value list plumbing stays in the C++
shim. The now-unused C++ line-width keyword helper is removed.
The Rust style computation core now iterates every longhand in
computation order and calls back into C++ for the per-property work
that has not moved into the core yet; the former loop body becomes a
lambda invoked through a captureless trampoline. This inverts control
of the property computation loop: the iteration and computation
ordering are owned by the Rust core, and each further port shrinks the
C++ callback stage by stage.

The inherit-or-initial decision moves into the core along with the
loop: the missing-value inheritance default, the inherit and unset
cascade keywords, and the currentcolor special case for the color
property, with the cascade spec text carried along. The C++ loop body
keeps applying the side effects (the shadow-root inheritance signal,
inherited animated value copying and the builder flags) and the
initial-value fallback line stays as before, driven by the decision's
use-initial flag when no inheritance fetch happened.

Property identifier constants are now generated into the Rust crate by
name, like the keyword codes, so the core can refer to specific
properties directly.
Marshal the generated logical-alias mappings into the Rust style
computation core as flat tables, one physical property per (longhand,
writing-mode, direction) triple in the forward direction and likewise
for the reverse, built once from the C++ generated mapping functions
themselves so the two sides cannot drift. The property computation
loop resolves both directions of the logical pairing through the Rust
mapping, and the metadata parity test compares every triple of both
tables.
Routing specified-time simplification through the Rust core removed
the last callers of the per-node evaluation machinery: the
with_simplified_children and run_operation_if_possible virtuals and
all their implementations, the min/max, trigonometric, and mod/rem
family helpers, try_get_value_with_canonical_unit, try_get_number,
negated, is_in_canonical_unit, and the numeric-leaf string helpers.
CalculationResult itself is gone too; its Value variant was the only
part still load-bearing, and it survives as the NumericValue alias
that calculation node construction uses.
The layout code walked the C++ calculation tree to decide whether an
inset or size value contains an anchor() function. Replace the walk
with CalculatedStyleValue::contains_anchor_function, which reads the
Rust tree through the node read API, leaving math-function composition
in CalculationNode::from_style_value as the only remaining reader of
the stored C++ tree.
Math-function composition through CalculationNode::from_style_value
and the debug dump were the last readers of a calculated value's
stored C++ tree. Both now materialize from the Rust tree on demand,
under the value's own calculation context, which is what its nodes
were typed under when it was created.

With no readers left, calculated style value data no longer retains a
C++ calculation tree at all. Trees built by the parser, typed-OM, and
interpolation are transient construction artifacts now: converted once
into the Rust tree at value creation and released. The
RetainedCalculationNode shim and its unref bridge go away with the
field. Absolutization benefits directly: its simplified Rust root
transfers straight into the new value's data through a from-rust-root
construction path instead of being materialized into C++ nodes and
converted back.
The font-weight, font-stretch, font-size, line-height and math-depth
property computations fell back to the C++ caller whenever their value
was a calc(), the last "resolved by the C++ caller" seams in those
helpers. Resolve them in the calc core instead, through a no-context
resolver equivalent to a C++ resolution against an empty context: the
callbacks for non-math functions, relative-color channels, and
random() all fail, matching the empty CalculationResolutionContext the
callers passed.

The resolver reuses the post-simplification resolution tail factored
out of rust_calc_resolve, with typed wrappers that apply the same
matches_number and matches_percentage checks the C++ helpers did.
line-height gains a result type distinguishing a resolved pixel length
from a unitless number multiplier, since a calc there can produce
either; font-size resolves lengths against the inherited font size as
the percentage basis; and math-depth rounds to the nearest integer
toward +inf on a .5 fraction, matching round_to_nearest_integer. The
add() function form of math-depth still resolves in C++, since reading
its wrapped integer needs shell traversal the math-depth entry does
not carry, and the C++ helpers keep their resolve fallbacks for the
residual cases the core cannot resolve to the expected type.
The C++ calc machinery carried verbatim css-values-4 spec text for the
serialize-a-calculation-tree and serialize-a-math-function algorithms,
the calc-keyword simplification step, and the round() lower/upper
multiple selection, along with AD-HOC notes referencing csswg-drafts
issues 11588 and 11783. Bring that text over to the Rust calc module so
the port keeps the same spec traceability as the code it replaced.
When one axis of a position-area value is span-all, the value computes
to a single logical keyword drawn from the other axis. That remapping
was two eight-case C++ switches; move the keyword-to-keyword decision
into the style computation core through a new remap entry, following
the split already used for the short-keyword mapping where Rust decides
and C++ constructs the KeywordStyleValue. Behavior is unchanged: a
span-all pair that matches no arm falls through to the absolutized
value exactly as the old default branches did.
The flow decides per longhand whether a value's computed value depends
on inherited font metrics. Three of its terms are property-specific:
font-weight bolder/lighter, font-size
percentage/calc/larger/smaller/math, and line-height percentage/calc.
Fold those into a single callback-free core function keyed on the
property id, with the percentage-in-calc check running over the Rust
calculation tree directly. The two property-agnostic terms,
depends-on-current-color and computational independence, stay as the
value's own operations, which already run in the core one level down.

The check that gates the monospace font-size recascade moves the same
way: a font-family value list of exactly one entry that is the
monospace keyword, read through the nested value's shell pointer with
the data_of callback used by the other value-data predicates.
Port three more computed-value rules to the style computation core.

The computed value of font-feature-settings and
font-variation-settings deduplicates the tags with the later
occurrence taking precedence, then sorts them ascending by tag; the
core works over the entry indices and calls back for the tag
comparisons, since the tags are interned fly strings it does not read
directly, and C++ marshals the indices, provides the comparison
primitives, and builds the reordered list.

The normal keyword for letter-spacing and word-spacing computes to a
zero length, and any other value is already the computed value, with
C++ constructing the zero length from the core's decision.

For font-style, build.rs now generates keyword_to_<enum> mappings for
every CSS enum from the same Enums.json the C++ generator reads, so
the two cannot drift, with alias entries mapping to the aliased
member's value. A bare font-style keyword maps through the generated
table to a font-style keyword the C++ side constructs into a
FontStyleStyleValue, with the FontStyleKeyword discriminants pinned by
static_asserts; this arm is reached when StylePropertyMap sets a
keyword directly, since font-style otherwise parses straight to a
FontStyleStyleValue.
An audit for functions that lost their last caller during the port
turned up three families of dead code.

The C++ calculation nodes kept their per-node equals,
contains_percentage, and reify virtuals even though calculated value
equality, percentage queries, and typed-OM reification all read the
Rust tree now; only dump() and the construction-time accessors are
still used. Remove those implementations across the node hierarchy
along with the operator-node classifiers, name(), the numeric leaf's
infinite-or-NaN and negativity helpers, and the NonFiniteValue enum,
all of which served only the deleted C++ evaluation and serialization
machinery.

The CascadedProperties shell kept per-method wrappers (set_property,
revert_property, revert_layer_property, style_property,
property_with_higher_priority) whose callers disappeared when
declaration application moved into the Rust store, which now performs
those operations internally. Remove the wrappers and their matching
FFI exports, plus two more exports that lost their C++ callers to
later stages of the port: rust_compute_longhand_decision, subsumed by
the flow orchestration entry, and rust_calc_node_create_numeric_number,
subsumed by the dimension construction entry.

The style group typed-view exports stay: they are what anchors the
mirrored group struct layouts in the generated FFI header.

The audit also found three accessors that were dead even before this
branch: CascadedProperties::property_source,
ComputedProperties::for_each_anchor_name, and the
cached_computed_font_list accessor. They go too; the backing font
list cache member stays, used by computed_font_list itself.
CalcNodeRef is a move-only owner of one strong reference to a Rust
calculation node, with factories mirroring the FFI construction
surface, the calc-constant keyword mapping, a Rust-backed
determine-the-type query, and a handle-based simplify entry alongside
the C++-tree one. CalculatedStyleValue::create gains an overload
taking a built root directly.

This is the seam for making every calc() producer build the Rust tree
natively: the parser, typed-OM, interpolation, and the non-math
function resolvers switch to it next, after which the C++
CalculationNode hierarchy loses its last purpose (construction) and
can be deleted.
The math function parser and 'parse a calculation' constructed C++
CalculationNodes, converted once into the Rust tree at calculated
value creation. Build CalcNodeRefs directly instead: the generated
parse_math_function emits CalcNodeRef factory calls with argument
types checked through the Rust determine-the-type entry, the leaf and
operator conversion in convert_to_calculation_node produces handles,
and parse-time simplification keeps the handle end to end through the
handle-based simplify entry, so no C++ tree is built or materialized
anywhere in the parse path.
The CSSNumericValue create_calculation_node virtuals and the
out-of-range clamp wrapping in CSSUnitValue built C++ nodes; they now
produce CalcNodeRefs, and the animation TimeValue conversion asks the
Rust tree for its type instead of the node.
Port the remaining C++ calculation tree producers to CalcNodeRefs:
interpolation's weighted contribution sums and compositing sums (with
the result type now determined over the built tree, equivalent to the
added_to of the operand types), the anchor() and tree counting
function resolvers behind AbstractNonMathCalcFunctionStyleValue, the
edge keyword flipping, the basic-shape 100%-minus wrapping, the
animation TimeValue conversion, and the bare anchor() inset wrapping
in layout. A ref-based from_style_value contributes a calculated
value's own Rust tree by retaining its root instead of materializing
C++ nodes.
Every calc() producer now builds the Rust calculation tree directly,
so the C++ node hierarchy had no purpose left. Delete all 29 node
classes together with the C++-to-Rust conversion walk, the
materializer that rebuilt C++ nodes from the Rust tree, the C++-tree
overloads of CalculatedStyleValue creation and tree simplification,
the creation-time type computation helpers, and the caller-less
debug dump. Calculated style values are now backed purely by the
Rust tree from parse to computed value.
Deleting the C++ CalculationNode hierarchy took the last callers of
several more things: the calc read-API FFI exports that only the
deleted materializer walked (channel keyword, round strategy,
progress no-clamp and non-math-function type accessors), the
keyword-code parity accessor nothing tests anymore,
NumericType::has_consistent_type_with and the never-instantiated
NumericType formatter, CalculatedStyleValue's frequency resolver,
dimension predicate and an orphaned declaration, a never-instantiated
interpolation helper template, and stale includes in the calculated
value header and implementation, with the enums include moving to
CalcNodeRef.h, which is what actually uses it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants