Skip to content

ci: resolve function values and reject opaque Used by re-exports - #3311

Merged
inureyes merged 2 commits into
lablup:mainfrom
Jaeyeong-CHOI:ci/3219-used-by-caller-gaps
Nov 26, 2026
Merged

inureyes merged 2 commits into
lablup:mainfrom
Jaeyeong-CHOI:ci/3219-used-by-caller-gaps

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Closes #3219

  1. Preserve the source location of each import and resolve local aliases, including a name brought in by a glob and rebound with as. The direct create_causal_mask as ccm fixture already appeared in the base report, but at the first unrelated import. It now appears at the matching import on line 2. The fixture’s src/models annotation accounts for the file. A glob-derived alias outside a named roster passed on the base and now fails.
  2. Count bare function values under a glob. In the assignment and .map(...) fixtures, the base checker reported only the explicitly imported callback. The updated checker reports all three files. Separate cases exercise shadowing by a parameter or local and a reference after the local’s block ends.
  3. Reject re-exports at the declaration. Named, aliased and glob re-exports have fixture coverage, including restricted visibility. The checker docstring and code guidelines explain how to keep the import resolvable at the caller.
  4. Remove create_causal_mask_roster_count_matches_repo and its private helpers. The checker compares the recorded count with the annotation’s literal grep output.
  5. Explain comment and test matches in the count diagnostic. Adding a comment to a fifteenth fixture file now identifies the count drift and suggests a grep -v filter or a count update.

Verification on macOS

  • make verify-used-by passed the repository check and all 32 fixture cases. The same fixture script against the base checker exited 1 with ten failed assertions or case outcomes.
  • cargo test -p mlxcel-core --lib utils passed 77 tests with Rust 1.97.1 and MLXCEL_BUILD_METAL=OFF. cargo check and cargo fmt --check passed.
  • ShellCheck, Bash and Python syntax checks, Ruff with the repository’s Python configuration, and git diff --check passed. With its own defaults, Ruff 0.17.6 reported the eight base regex-flag findings and one nested-condition style finding.

The checker still collects block-local imports per file and does not parse complex binding patterns. The full Rust suite, GPU execution and hosted CI were not verified.

@inureyes inureyes added status:review Under review type:chore Maintenance tasks (build, CI, etc.) priority:low Low priority labels Nov 24, 2026
@inureyes inureyes self-assigned this Nov 24, 2026
The re-export rule rejected `pub use` of a scoped function and a glob of its module, but `pub use mlxcel_core::utils;`, `pub use mlxcel_core::utils as shared;` and `pub use mlxcel_core::*;` passed, and each gives downstream callers a path the checker cannot resolve. A public `use` of the scoped module or of one of its ancestors now fails at the re-export. Files with a public `use` are kept past the substring pre-filter, since such a file need not spell any scoped name.

A generic helper called with a turbofish under a glob import (`fused_add_rms_norm::<N>(..)`) was not counted as a use. `::<` now counts as a value delimiter.

The docstring and guidelines also record that a glob-visible name rebound by a `for`, `match`, closure or tuple pattern counts as a use, which fails closed.
@inureyes

Copy link
Copy Markdown
Member

Summary

The PR covers all five items of #3219. The review found two false negatives in the new caller and re-export resolution, and one hardening commit fixes both: c6f7f3a97 (fix: reject module re-exports and see turbofish calls in used-by).

Reviewed (PR + issues)

Findings

  1. MEDIUM, false negative (item 3). The re-export rule rejected pub use of a scoped function and pub use <module>::*, but these passed: pub use mlxcel_core::utils;, pub use mlxcel_core::utils as shared; and pub use mlxcel_core::*;. Each one gives downstream callers a path (facade::shared::create_causal_mask(..)) that the checker cannot resolve, which is the case the issue asked to fail on. Two things caused the miss. The rule only matched a function target or a glob of the module itself. Also, the substring pre-filter skipped any file that spells neither a scoped function name nor *, and for other crates any file that does not spell utils/layers.
  2. LOW, false negative. Under a glob import, a turbofish call fused_add_rms_norm::<N>(..) was not counted, because ::< was not a value delimiter. layers.rs has generic scoped functions (fused_add_rms_norm, graph_add_rms_norm). This gap was already in the base checker.
  3. LOW, documented limit (not fixed). Under a glob import, a scoped name rebound by a for, match, closure or tuple pattern and then used as a value (for silu in v { s += silu; }) now counts as a use. The base checker only counted name(. This fails closed. Once ci: gate small Used by rosters and retire the shared-helper debt #3312 sets the threshold to zero, it would force a non-caller into a roster. The current tree has no such case.

Fixes

  • c6f7f3a97: a public use whose target is the scoped module, or an ancestor of it, now fails at the re-export with re-exports scoped module ... as a module or re-exports mlxcel_core, which contains scoped module .... A file with a public use is no longer dropped by the pre-filter (new PUB_USE_RE). VALUE_FOLLOW_RE accepts ::<. The docstring Limits and the guidelines' "does not catch" list record finding 3.
  • New fixture cases re-export-module, re-export-crate-glob and turbofish. Against the PR's checker, all three fail ("3 case(s) failed"). With the fix, they pass.

Security review

The change is a CI checker with no workflow edits. It reads repository files only and runs the annotation's grep through the existing restricted re-runner. No new subprocess, network or secret use.

Performance review

check_used_by.py on the current tree takes 4.0 s, against 3.4 s before the pre-filter change, because files with a pub use are now lexed. That is acceptable for a seconds-scale job.

Validation

  • PR head: python3 scripts/ci/check_used_by.py OK, and bash scripts/ci/check_used_by_test.sh passes all cases.
  • PR head plus fix, squash-merged onto main 36129ebb3: the checker reports OK (625 caller-file references, 3093 Rust files), and the test script passes.
  • Combined with ci: gate small Used by rosters and retire the shared-helper debt #3312 on main: make verify-used-by passes, with 35 fixture cases and used-by: OK, 76 top-level pub fn in 2 shared files, 55 annotated, 625 caller-file references resolved, 3093 Rust files scanned.
  • cargo fmt --all -- --check is clean. git diff --check is clean. Python and Bash syntax checks pass. Ruff 0.17.6 defaults report the same 9 findings as the PR head, and no new ones.
  • The Rust change removes create_causal_mask_roster_count_matches_repo and its private helpers from #[cfg(test)] mod tests only. cargo check -p mlxcel-core --features cuda --lib --tests passes on the combined tree.
  • Merge note: after either PR is squash-merged, the other conflicts only in docs/code-guidelines.md, in the "What it does not catch" list. Resolve it by dropping the "Functions with 12 or fewer callers" bullet and ci: gate small Used by rosters and retire the shared-helper debt #3312's old re-export bullet, and keeping ci: resolve function values and reject opaque Used by re-exports #3311's re-export bullets.

@inureyes
inureyes merged commit da2acea into lablup:main Nov 26, 2026
33 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 26, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:low Low priority status:done Completed type:chore Maintenance tasks (build, CI, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: Close caller-resolution gaps in check_used_by.py

2 participants