Skip to content

refactor(util): avoid usingnamespace in Bitflags#329

Merged
DonIsaac merged 2 commits intomainfrom
don/refactor/bitflags-usingnamespace
Nov 28, 2025
Merged

refactor(util): avoid usingnamespace in Bitflags#329
DonIsaac merged 2 commits intomainfrom
don/refactor/bitflags-usingnamespace

Conversation

@DonIsaac
Copy link
Owner

@DonIsaac DonIsaac commented Nov 28, 2025

Part of #323

Gets rid of usingnamespace usage with Bitflags. usingnamespace has been removed in Zig 0.15.0.

Summary by CodeRabbit

  • Refactor
    • Restructured internal bitflag utility exports for improved API clarity and maintainability across semantic modules.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added the A-semantic Area - semantic analysis label Nov 28, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

Walkthrough

This pull request refactors how bitflag utilities are exposed across multiple modules. It replaces Zig's usingnamespace mechanism with explicit public constant aliases, converting namespace-level imports into individual named exports (Flag, Repr, empty, all, isEmpty, intersects, contains, merge, set, not, eql, repr, format, jsonStringify). The underlying bitflag functionality remains unchanged; only the public API exposure pattern is altered.

Changes

Cohort / File(s) Summary
Semantic module bitflag API refactoring
src/Semantic/Reference.zig, src/Semantic/Scope.zig, src/Semantic/Symbol.zig
Replaces pub usingnamespace util.Bitflags(Flags) with an explicit mixin pattern: creates local BitflagsMixin and re-exports 14 public constants (Flag, Repr, empty, all, isEmpty, intersects, contains, merge, set, not, eql, repr, format, jsonStringify).
Bitflags utility and test updates
src/util/bitflags.zig, src/util/bitflags_test.zig
Converts bitflag exposure in example and test structs (Position, TestFlags, PaddedFlags) from pub usingnamespace to explicit public constant aliases derived from internal BitflagsMixin.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

  • Highly repetitive refactoring pattern applied consistently across all affected files
  • Pattern verification is straightforward; each file follows identical transformation
  • No behavioral logic changes or complex reasoning required per file
  • May require cross-referencing the bitflags utility to confirm all 14 exports are consistent

Suggested labels

A-linter

Poem

🐰 The namespace takes a bow,
As constants claim the stage right now,
Flags once mixed are now made clear—
Each little export takes a cheer!
Bitwise logic shines on through,
Made explicit, bright and true.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: refactoring the Bitflags utility to eliminate usingnamespace usage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch don/refactor/bitflags-usingnamespace

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.67%. Comparing base (f660cf9) to head (4be1f87).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #329      +/-   ##
==========================================
- Coverage   91.67%   91.67%   -0.01%     
==========================================
  Files          91       91              
  Lines        7809     7808       -1     
==========================================
- Hits         7159     7158       -1     
  Misses        650      650              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/util/bitflags_test.zig (1)

14-28: Test structs correctly refactored.

Both TestFlags and PaddedFlags properly demonstrate the explicit export pattern. The consistent application across padded and unpadded variants validates the approach.

Optional maintenance consideration: The 14-line export boilerplate must be kept in sync across all usage sites if the Bitflags API evolves. Consider whether a compile-time check or codegen helper could reduce this maintenance burden in the future, though this is not urgent for this PR.

Also applies to: 38-52

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f660cf9 and 4be1f87.

📒 Files selected for processing (5)
  • src/Semantic/Reference.zig (1 hunks)
  • src/Semantic/Scope.zig (1 hunks)
  • src/Semantic/Symbol.zig (1 hunks)
  • src/util/bitflags.zig (3 hunks)
  • src/util/bitflags_test.zig (2 hunks)
🔇 Additional comments (5)
src/Semantic/Reference.zig (1)

55-69: LGTM! Clean refactor for Zig 0.15.0 compatibility.

The explicit public constant pattern correctly replaces usingnamespace while maintaining the same public API surface. All Bitflags members are properly exposed.

src/Semantic/Scope.zig (1)

43-57: LGTM! Consistent refactor applied.

The explicit export pattern is correctly applied, mirroring the approach in Reference.zig.

src/util/bitflags.zig (2)

5-29: Well-documented migration pattern.

The updated example clearly demonstrates the new explicit export pattern, which will help users migrate their own code away from usingnamespace.


195-197: Test correctly demonstrates the new pattern.

The Position struct update validates that the explicit export approach works correctly.

src/Semantic/Symbol.zig (1)

130-144: LGTM! Refactor correctly applied.

All Bitflags members are properly exposed through explicit public constants.

@DonIsaac DonIsaac merged commit cf52a34 into main Nov 28, 2025
18 checks passed
@DonIsaac DonIsaac deleted the don/refactor/bitflags-usingnamespace branch November 28, 2025 03:45
sammyjoyce pushed a commit to sammyjoyce/zlint that referenced this pull request Jan 9, 2026
Part of DonIsaac#323 

Gets rid of `usingnamespace` usage with Bitflags. `usingnamespace` has
been removed in Zig 0.15.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-semantic Area - semantic analysis

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant