Replace bitflags! in the style crate with a lean crate-local macro - #5
Draft
nicoburns wants to merge 1 commit into
Draft
Replace bitflags! in the style crate with a lean crate-local macro#5nicoburns wants to merge 1 commit into
nicoburns wants to merge 1 commit into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the
bitflags2.x dependency of thestylecrate with a lean crate-localbitflags!macro (style/flags.rs) that generates only the API subset the crate actually uses. The macro keeps the same name and invocation syntax (both the struct-defining andimpl-only forms), so all 55 call sites are unchanged apart from:#[derive(Debug)]inside the invocation drop that derive — the macro always generates aDebugimpl that lists contained flag names (matching bitflags' output, e.g.RestyleHint(RESTYLE_SELF | RECASCADE_SELF));servo/restyle_damage.rsreplaces<ServoRestyleDamage as bitflags::Flags>::Bits::MAXwithu16::MAX.Per type, the macro generates the flag consts, a private
(name, flags)table,empty/all/bits/from_bits/from_bits_truncate/from_bits_retain/is_empty/is_all/intersects/contains/intersection/union/difference/symmetric_difference/complement/insert/remove/toggle/set/iter/iter_names, and the 9 bitwise operator impls — ~120 expanded lines instead of bitflags' ~2,500 (no hidden internal type, forwarding macros, iterator types, Binary/Octal/Hex impls,from_nameparsing, or serde/arbitrary/bytemuck hooks).all()/Debugare table-driven so#[cfg]-gated flags keep working.Only the
stylecrate is converted;selectors/,style_traits/andstylo_dom/still use thebitflagscrate (which also remains a transitive dependency via cssparser), butbitflagsis removed fromstyle/Cargo.toml.Measurements
Environment: Linux x86_64 VM,
rustc 1.99.0-nightly (504869653 2026-08-03),CARGO_INCREMENTAL=0, default (servo) features, dependencies pre-built,touch style/lib.rsbetween runs, 3 runs each.-Zmacro-statsfor thestylecrate (sum of all bitflags-related macro rows):Wall times for the
stylocrate itself (deps warm):cargo +nightly check -p stylocargo +nightly build -p stylo(debug)Honest takeaway: despite the ~90% reduction in macro-expanded code (~124k lines / ~4.6 MB less for the compiler to expand, parse and type-check), the wall-time impact is small — roughly 0.5–1s (~2%) on both check and build, at or near run-to-run noise on this machine. Macro expansion/parsing of the bitflags output evidently isn't a dominant cost for this crate; the bulk of the time goes elsewhere (type checking the crate's own code, codegen, linking metadata).
Testing
cargo +nightly check -p styloandcargo check --workspacepass.cargo check --all-targets -p stylohas 10 pre-existing errors onmain(test code referencingPseudoElement::MozRubyText/FirstLine); the same errors, and no new ones, occur with this change.geckofeature can't be built locally (needs mozbuild); the gecko-cfg'd sites (url/gecko.rs,gecko/*.rs, gecko-only flags invalues/specified/text.rs) were converted textually with care, but are unverified by the compiler.Link to Devin session: https://app.devin.ai/sessions/d53d0b1a1f36492486a5ce4537362adc
Requested by: @nicoburns