Skip to content

Add: codestyle rule on pto:: qualification in kernels - #1549

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:docs/codestyle-pto-qualification
Jul 28, 2026
Merged

Add: codestyle rule on pto:: qualification in kernels#1549
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:docs/codestyle-pto-qualification

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Kernel sources carry two conventions, and nothing recorded which one new code should follow — so the split propagates by whichever file an author happened to copy from:

Convention Where Shape
Qualified, no using-directive collectives kernels (tests/st/worker/collectives, some examples/workers/l3) pto::Stride<…>
Bare + using namespace pto; older scene-test kernels Stride<…>

Each is internally consistent, so neither is a defect on its own. Rule 11 names qualification as the direction — it is the only spelling that compiles whether or not a using-directive is in scope, and a file-scope using namespace is what most style guides steer away from.

Deliberately incremental, in the same shape as rule 10: new kernels qualify and do not add the directive; existing bare files are not defects and need no churn.

The load-bearing part is the half-qualified ban

Shape, Stride, Tile and GlobalTensor all live in namespace pto, so qualifying one and leaving its siblings bare produces:

using DynShapeDim5 = Shape<1, 1, 1, vRows, vCols>;
using DynStridDim5 = pto::Stride<1, 1, 1, kTCols_, 1>;

which reads worse than either consistent state. A half-qualified file is a defect where a fully bare one is not.

This is not hypothetical. An earlier revision of #1547 rewrote Stride across 24 files and left Shape alone; a reviewer caught the adjacent-line mixture and it was reverted. The rule exists so the next person does not repeat it.

No repo-wide sweep, with the measurement that rules it out

As of 2026-07-28, the 142 files carrying using namespace pto; contain roughly 3,200 bare uses:

Name Bare uses
Tile 2080
GlobalTensor 796
Shape 211
Stride 137

Rewriting them is purely stylistic, would touch every kernel in the repo, collide with every in-flight branch, and risk regex damage to member aliases and comments for no functional gain. Unifying in one go needs its own decision plus a lint rule (e.g. google-build-using-namespace) to hold the line — otherwise it drifts back.

Note also that stripping qualification is not a safe inverse: 12 files use pto:: and have no using-directive, directly or transitively — 9 of them in tests/st/worker/collectives. Bare names would not compile there.

Verification

  • Every number in the rule re-measured against the tree at commit time
  • markdownlint-cli2 clean (v0.20.0, the version pre-commit pins)
  • Documentation only — no code changes

Kernel sources carry two conventions. The collectives kernels qualify
(pto::Stride<...>) and use no using-directive; the older scene-test
kernels open with `using namespace pto;` and use bare names. Each is
internally consistent, and nothing recorded which one new code should
follow, so the split propagates by whichever file an author copied from.

Rule 11 names qualification as the direction, because it is the only
spelling that compiles whether or not a using-directive is in scope, and
because a file-scope `using namespace` is what most style guides steer
away from. New kernels qualify and do not add the directive; existing
bare files are not defects and need no churn.

The load-bearing part is the constraint that a file is qualified
completely or not at all. Shape, Stride, Tile and GlobalTensor all live
in namespace pto, so qualifying one and leaving its siblings bare yields
adjacent lines that read worse than either consistent state. That is a
real failure mode rather than a hypothetical: an earlier revision of
PR hw-native-sys#1547 rewrote Stride across 24 files and left Shape alone, and the
resulting mixture is why it was reverted.

A repo-wide sweep is ruled out with the measurement that rules it out:
the 142 files carrying the directive hold roughly 3,200 bare uses, of
which Tile alone is 2080. Rewriting them would touch every kernel,
collide with every in-flight branch, and risk regex damage for no
functional gain. Unifying the tree in one go needs its own decision plus
a lint rule to hold the line.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@ChaoWao, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41b6320b-60e3-45ae-a502-db84edee6c26

📥 Commits

Reviewing files that changed from the base of the PR and between 40b6329 and 350f805.

📒 Files selected for processing (1)
  • .claude/rules/codestyle.md

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.

@ChaoWao
ChaoWao merged commit f0bd241 into hw-native-sys:main Jul 28, 2026
14 checks passed
@ChaoWao
ChaoWao deleted the docs/codestyle-pto-qualification branch July 28, 2026 09:14
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