Skip to content

refactor(parser): simplify ModifierFlags#20738

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/03-23-refactor_parser_simplify_modifierflags_
Mar 26, 2026
Merged

refactor(parser): simplify ModifierFlags#20738
graphite-app[bot] merged 1 commit intomainfrom
om/03-23-refactor_parser_simplify_modifierflags_

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Mar 25, 2026

The types for modifiers were confusing. We had ModifierFlags type defined with bitflags! macro, and ModifierKind enum which represents the different possible flags.

The two types weren't statically related, and consuming code needed to manually relate the two e.g. pairing usage of ModifierFlags::DECLARE with ModifierKind::Declare. This is unnecessarily complicated, and error-prone.

This PR turns ModifierFlags into a wrapper around a u16 and adds methods to construct, query, and set bits in the set by passing a ModifierKind or a set of ModifierKinds. Consuming code now only has one type to deal with which is the single source of truth about what modifiers are available - ModifierKind.

Code is more verbose in some places, but personally I think this more explicit style is clearer. ModifierFlags::new is a const function, so even sizeable calls e.g. ModifierFlags::new([ModifierKind::Public, ModifierKind::Private, ModifierKind::Protected]) is boiled down to a static u16 at compile time. It compiles down to the same as the bitflags! version.

This change also enables #20742, which improves the storage of Modifiers.

Copy link
Copy Markdown
Member Author

overlookmotel commented Mar 25, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-parser Area - Parser C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Mar 25, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 25, 2026

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing om/03-23-refactor_parser_simplify_modifierflags_ (5aee74c) with main (caf8231)2

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (5aee74c) during the generation of this report, so caf8231 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@graphite-app graphite-app bot changed the base branch from om/03-23-refactor_parser_import_from_std_at_top_level to graphite-base/20738 March 25, 2026 17:35
@overlookmotel overlookmotel marked this pull request as ready for review March 25, 2026 18:10
Copilot AI review requested due to automatic review settings March 25, 2026 18:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the parser’s modifier tracking to make ModifierKind the single source of truth by replacing the bitflags!-based ModifierFlags with a compact u16 bitfield wrapper and ModifierKind-centric constructors/query APIs, simplifying call sites and reducing the chance of mismatched flag/kind pairs.

Changes:

  • Replaced bitflags! ModifierFlags with a u16-backed ModifierFlags wrapper plus new/all_except/contains/with/without APIs.
  • Updated parser call sites to construct/check allowed modifiers via ModifierKind arrays instead of |, !, and from(...) conversions.
  • Adjusted diagnostics helper text generation and accessor-specific “allowed modifiers” computation to use the new APIs.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/oxc_parser/src/modifiers.rs Introduces new ModifierFlags bitfield wrapper and updates modifier parsing/verification to use ModifierKind-based operations.
crates/oxc_parser/src/diagnostics.rs Updates allowed-modifier help text logic and accessor modifier diagnostics to use count()/without().
crates/oxc_parser/src/ts/types.rs Updates verify_modifiers call sites to use ModifierFlags::new / all_except.
crates/oxc_parser/src/ts/statement.rs Updates verify_modifiers call sites to use ModifierKind-based flag construction.
crates/oxc_parser/src/js/statement.rs Updates TS enum const-modifier construction to use ModifierFlags::new([Const]).
crates/oxc_parser/src/js/object.rs Imports ModifierKind and updates async modifier verification to ModifierFlags::new([Async]).
crates/oxc_parser/src/js/module.rs Updates abstract modifier construction for export default class handling.
crates/oxc_parser/src/js/function.rs Updates constructor/function allowed-modifier sets to ModifierFlags::new([...]).
crates/oxc_parser/src/js/class.rs Updates multiple modifier allow/deny sets to new/all_except and refactors one diagnostic helper to a const ALLOWED.

@overlookmotel overlookmotel force-pushed the om/03-23-refactor_parser_simplify_modifierflags_ branch from 09b7760 to 3eb377b Compare March 25, 2026 19:01
@overlookmotel overlookmotel changed the base branch from graphite-base/20738 to om/03-23-refactor_parser_import_from_std_at_top_level March 25, 2026 19:02
@graphite-app graphite-app bot changed the base branch from om/03-23-refactor_parser_import_from_std_at_top_level to graphite-base/20738 March 25, 2026 19:06
@graphite-app graphite-app bot force-pushed the om/03-23-refactor_parser_simplify_modifierflags_ branch from 3eb377b to a590ebe Compare March 25, 2026 19:11
@graphite-app graphite-app bot force-pushed the graphite-base/20738 branch from e8a9a3c to 14868fb Compare March 25, 2026 19:11
@graphite-app graphite-app bot changed the base branch from graphite-base/20738 to main March 25, 2026 19:11
@graphite-app graphite-app bot force-pushed the om/03-23-refactor_parser_simplify_modifierflags_ branch from a590ebe to 6587e2d Compare March 25, 2026 19:12
@overlookmotel overlookmotel force-pushed the om/03-23-refactor_parser_simplify_modifierflags_ branch from 6587e2d to 33e028e Compare March 25, 2026 19:13
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Mar 26, 2026

Merge activity

The types for modifiers were confusing. We had `ModifierFlags` type defined with `bitflags!` macro, and `ModifierKind` enum which represents the different possible flags.

The two types weren't statically related, and consuming code needed to manually relate the two e.g. pairing usage of `ModifierFlags::DECLARE` with `ModifierKind::Declare`. This is unnecessarily complicated, and error-prone.

This PR turns `ModifierFlags` into a wrapper around a `u16` and adds methods to construct, query, and set bits in the set by passing a `ModifierKind` or a set of `ModifierKind`s. Consuming code now only has one type to deal with which is the single source of truth about what modifiers are available - `ModifierKind`.

Code is more verbose in some places, but personally I think this more explicit style is clearer. `ModifierFlags::new` is a const function, so even sizeable calls e.g. `ModifierFlags::new([ModifierKind::Public, ModifierKind::Private, ModifierKind::Protected])` is boiled down to a static `u16` at compile time. It compiles down to the same as the `bitflags!` version.

This change also enables #20742, which improves the storage of `Modifiers`.
@graphite-app graphite-app bot force-pushed the om/03-23-refactor_parser_simplify_modifierflags_ branch from 33e028e to 5aee74c Compare March 26, 2026 13:08
@graphite-app graphite-app bot merged commit 5aee74c into main Mar 26, 2026
35 checks passed
@graphite-app graphite-app bot deleted the om/03-23-refactor_parser_simplify_modifierflags_ branch March 26, 2026 13:12
graphite-app bot pushed a commit that referenced this pull request Mar 26, 2026
Pure refactor. Rename `ModifierFlags` to `ModifierKinds`. This type represents a collection of `ModifierKind`s, and after #20738 it's no longer implemented as `bitflags!`, so the name is no longer appropriate.

This PR is pure renaming - rename the type, and variables that hold the type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants