Skip to content

Crate split phase 3a: funnel all values -> engine accesses through computed::Context methods - #9

Draft
nicoburns wants to merge 4 commits into
devin/1785852309-crate-split-2from
devin/1785852309-crate-split-3
Draft

Crate split phase 3a: funnel all values -> engine accesses through computed::Context methods#9
nicoburns wants to merge 4 commits into
devin/1785852309-crate-split-2from
devin/1785852309-crate-split-3

Conversation

@nicoburns

@nicoburns nicoburns commented Aug 4, 2026

Copy link
Copy Markdown
Member

Summary

First slice of the stylo_values extraction (stacked on #7): make values::computed::Context the single chokepoint between value-computation code and the engine layers above it, so the future ComputationContext trait boundary is exactly the set of inherent methods on Context.

  • style/values/** no longer pokes into context.builder, context.style() or context.device() directly. All such accesses (~40 sites) go through new narrow Context methods:

    impl<'a> Context<'a> {
        fn effective_zoom(&self) -> Zoom;
        fn writing_mode(&self) -> WritingMode;
        fn inherited_writing_mode(&self) -> WritingMode;
        fn parent_writing_mode_property(&self) -> WritingModeProperty;
        fn parent_text_align(&self) -> TextAlign;
        fn parent_color(&self) -> AbsoluteColor;
        fn parent_font_weight(&self) -> FontWeight;
        fn parent_font_size_keyword_info(&self) -> KeywordInfo;
        fn parent_math_depth(&self) -> i8;
        fn parent_math_style_is_compact(&self) -> bool;
        fn font_size(&self, base: FontBaseSize) -> FontSize;
        fn line_height(&self, base: LineHeightBase) -> NonNegativeLength;
        fn default_line_height(&self) -> NonNegativeLength;
        fn base_size_for_font_size_keyword(&self) -> Length;
        fn add_flags(&self, flags: ComputedValueFlags);
        fn note_writing_mode_dependency(&self);
        fn note_color_scheme_dependency(&self);
        fn color_scheme(&self) -> ColorSchemeFlags;
        fn is_dark_color_scheme(&self) -> bool;
        fn system_color(&self, c: SystemColor) -> AbsoluteColor;   // servo
        fn system_nscolor(&self, c: SystemColor) -> u32;           // gecko
        fn body_text_color(&self) -> AbsoluteColor;
        fn root_font_size/root_line_height/root_font_metrics_{ex,ch,cap,ic}(&self) -> Length;
        fn app_units_per_device_pixel(&self) -> i32;
        fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel>;
        fn is_supported_mime_type(&self, mime: &str) -> bool;
        fn chrome_rules_enabled_for_document(&self) -> bool;
    }

    All method bodies are the exact expressions previously inlined at the call sites (no behavior change); e.g. FontBaseSize::resolve now just delegates to context.font_size(*self).

  • Move the element-context support types down so Context's fields stop pointing at the dom/context layers:

    • ElementContext, DummyElementContext, AttributeTracker, AttributeReferences, TreeCountingCaches, TreeCountingResultstylo_common::element_context (re-exported from their old style::dom / style::context / values::computed paths).
    • The old blanket impl<T: TElement> ElementContext for T can't move (orphan rule) and is replaced by a TElementContext<E>(pub E) adapter in style::dom, used at the single coercion site in properties::cascade.
    • PrecomputedHasher/PrecomputedHashMap/PrecomputedHashSetstyle_traits::precomputed_hash (re-exported from style::selector_map).
  • Redirect values/ imports of already-moved types to their real homes: LonghandId/LogicalGroupId etc. from style_traits::property_ids, CorsMode from style_traits::rule_types, QuirksMode from selectors::matching, and SpecifiedWritingMode from logical_geometry::WritingModeProperty instead of the generated longhands::writing_mode alias.

After this, the only remaining values -> upper layer couplings are inside computed::Context/animated::Context/resolved::Context themselves (StyleBuilder, ComputedValues, Device, Stylist, container-query support types) plus a handful of property-ID parse entry points — i.e. the surface that the actual crate boundary will have to abstract.

Verified with cargo check --workspace and cargo test --workspace --exclude stylo (stylo test target fails on main for a preexisting pseudo-element issue).

Link to Devin session: https://app.devin.ai/sessions/5d2d6be20e724623bdc1bcf7e1687af1
Requested by: @nicoburns

@nicoburns nicoburns self-assigned this Aug 4, 2026
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

1 participant