Skip to content

Crate split phase 3c: untangle StyleBuilder's Stylist and Device upward references - #11

Draft
nicoburns wants to merge 1 commit into
devin/1785852309-crate-split-4from
devin/1785852309-crate-split-5
Draft

Crate split phase 3c: untangle StyleBuilder's Stylist and Device upward references#11
nicoburns wants to merge 1 commit into
devin/1785852309-crate-split-4from
devin/1785852309-crate-split-5

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

Removes three of the upward references that block extracting the generated "types half" (style structs / ComputedValues / StyleBuilder, see #10) into a future stylo_values crate:

1. StyleBuilder.stylist no longer names Stylist. All the value-computation layer ever does with it is look up registered custom properties, so:

// values::computed (low layer)
pub trait CustomPropertyRegistry {
    fn get_custom_property_registration(&self, name: &Atom) -> &Descriptors;
    fn get_custom_property_initial_values(&self) -> &ComputedCustomProperties;
}

// StyleBuilder (generated types half)
- pub stylist: Option<&'a Stylist>,
+ pub stylist: Option<&'a dyn computed::CustomPropertyRegistry>,

Stylist implements the trait; the custom-property substitution chain (custom_properties::substitute*, UnparsedValue::substitute_variables, container-query custom-property comparisons) now takes &dyn CustomPropertyRegistry, resolving env() through the computed context's device instead of stylist.device(). The two cascade sites that need the concrete Stylist (cascade_rules for visited styles, variable substitution) use Cascade's own stylist field instead of going through the builder. Context::new_for_initial_at_property_value takes (device, registry, quirks_mode) instead of &Stylist.

2. Device no longer names GeckoElement (the DOM-layer wrapper): Device::calc_line_height and ResolvedElementInfo.element take the raw gecko_bindings::structs::Element reference (which lives at the bottom of the graph); the wrapper was only ever unwrapped to that pointer for FFI. style/device/ now has zero references to upper layers (stylist, rule tree, stylesheets, DOM wrappers), so it can move down with the types half.

3. The gecko system_font module is generated in the types half (properties::system_font, extracted from gecko.mako.rs into system_font.mako.rs), with a compat re-export at properties::gecko::system_font. This makes Context.cached_system_font's type live below the property machinery.

Remaining knots for extraction (next phase): ComputedValues.rules: Option<StrongRuleNode> (rule tree depends on PropertyDeclarationBlock) and PseudoElement placement.

Validated with cargo check --workspace, cargo test --workspace --exclude stylo (the stylo test target has a pre-existing failure on main), and gecko template rendering.

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

- StyleBuilder.stylist is now Option<&dyn CustomPropertyRegistry>, a
  narrow trait defined next to computed::Context; Stylist implements it.
  Cascade code that needs the concrete Stylist uses Cascade's own field.
- The custom-property substitution machinery takes the registry trait,
  resolving env() through the computed context's device.
- Device no longer names GeckoElement: calc_line_height and
  ResolvedElementInfo take the raw bindings Element reference.
- The gecko system_font module is generated in the types half
  (properties::system_font), re-exported from properties::gecko.
@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