Skip to content

test(reserved-oxide-symbols): pin the constants two hygiene fixtures depend on - #648

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:test/pin-kernel-scope-local
Aug 4, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:test/pin-kernel-scope-local

Conversation

@vyncint

@vyncint vyncint commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #647. Branched from main and touches only two files, so it does not overlap #646.

What was wrong

Two hygiene regressions spell KERNEL_SCOPE_LOCAL's value as a Rust identifier, and nothing tied either back to the constant:

Fixture Declares Proves
crates/cuda-macros/tests/pass/kernel_launch_context_api.rs:27 parameter cuda_oxide_kernel_scope_246e25db_storage the Span::mixed_site() storage binding (lib.rs:4609) survives a same-text user binding
crates/rustc-codegen-cuda/examples/const_generic/src/main.rs:55 const generic cuda_oxide_kernel_scope_246e25db call_site_ident_avoiding_item (lib.rs:4547) takes its rename path

Their whole point is to collide. Rename the constant and they become ordinary unrelated names — the hygiene goes unexercised, and everything stays green:

-pub const KERNEL_SCOPE_LOCAL: &str = "cuda_oxide_kernel_scope_246e25db";
+pub const KERNEL_SCOPE_LOCAL: &str = "cuda_oxide_kernel_scope_deadbeef";
$ cargo test -p reserved-oxide-symbols --all-targets
test result: ok. 13 passed; 0 failed
$ cargo test -p cuda-macros --all-targets
test result: ok. 91 passed; 0 failed     # lib
test result: ok. 1 passed; 0 failed      # trybuild pass suite, incl. the hygiene fixture
...

The contributing cause: hash_value_is_pinned — whose doc comment says changing these "must be done deliberately" — asserted 8 of the crate's 10 constants, and all_prefixes_share_reserved_root enumerated the same 8. KERNEL_SCOPE_LOCAL and ARTIFACT_ANCHOR_PREFIX were absent. ARTIFACT_ANCHOR_PREFIX at least had an indirect backstop via the exact-output asserts in artifact_anchor_symbol_is_sanitized_and_reserved; KERNEL_SCOPE_LOCAL had none anywhere in the workspace.

Worth noting the contrast inside that same fixture: lines 36–40 also spell KERNEL_PREFIX as identifiers, but those are referenced, so a rename breaks the build. The hygiene bindings are only declared, so they fail open.

What this changes

  1. Pin KERNEL_SCOPE_LOCAL and ARTIFACT_ANCHOR_PREFIX in hash_value_is_pinned, with a comment naming both fixtures so a rename says what must move with it.
  2. Enumerate both in all_prefixes_share_reserved_root, so the test named "all prefixes" covers all ten.
  3. Add hygiene_fixtures_still_collide_with_the_generated_scope_names to cuda-macros, which reads both fixtures via include_str! and asserts they still spell the KERNEL_SCOPE_LOCAL-derived names. This makes the coupling machine-checked instead of relying on memory, and is the part that would have caught this on day one.

Verification

CPU-only, no GPU.

With the constant intact: reserved-oxide-symbols 13 unit + 17 doc pass; cuda-macros 92 lib (91 + the new test) plus all four trybuild suites pass.

With the constant renamed to ..._deadbeef, both new checks now fail loudly:

test tests::hash_value_is_pinned ... FAILED
  assertion `left == right` failed  (reserved-oxide-symbols/src/lib.rs:605)

test tests::hygiene_fixtures_still_collide_with_the_generated_scope_names ... FAILED
  tests/pass/kernel_launch_context_api.rs must bind
  `cuda_oxide_kernel_scope_deadbeef_storage` so `generated_storage_name_is_hygienic`
  exercises the mixed-site hygiene of the generated storage binding

cargo clippy -p reserved-oxide-symbols -p cuda-macros --all-targets -- -D warnings and cargo fmt --all --check are clean. No new dependencies, so Cargo.lock is untouched.

Two notes for review

The cross-crate include_str!. One half of (3) reads crates/rustc-codegen-cuda/examples/const_generic/src/main.rs from cuda-macros. It sits inside #[cfg(test)], so it is stripped from non-test builds — confirmed with cargo build -p cuda-macros — and both files are git-tracked, so they exist in any CI checkout. If you would rather not have that coupling, dropping just that assertion still leaves (1) failing on a rename and naming the example explicitly.

Guard compatibility. The new literals live in crates/reserved-oxide-symbols/, which naming-guard excludes, so this is clean under both the current pattern and #646's widened one — I checked both.

…depend on

Two hygiene regressions spell KERNEL_SCOPE_LOCAL's value as a Rust
identifier: a parameter named `{KERNEL_SCOPE_LOCAL}_storage` in
cuda-macros' trybuild pass suite, and a const generic named
KERNEL_SCOPE_LOCAL in the const_generic example. Their purpose is to
collide with the bindings `#[kernel]` injects, so mixed-site hygiene and
`call_site_ident_avoiding_item`'s rename path are exercised.

Nothing tied either fixture back to the constant. Renaming it left both
suites green — 13 passing in reserved-oxide-symbols, 91 plus every
trybuild suite in cuda-macros — because once the names no longer match
there is simply nothing left to collide with, so the hygiene goes
unchecked while still reporting success. `hash_value_is_pinned` asserted
eight of the crate's ten constants and covered neither
KERNEL_SCOPE_LOCAL nor ARTIFACT_ANCHOR_PREFIX, and
all_prefixes_share_reserved_root enumerated the same eight.

Pin both missing constants and enumerate them, and add a cuda-macros test
that reads the two fixtures with include_str! and asserts they still
spell the derived names. A rename now fails in both crates and the
cuda-macros message names the exact binding each fixture needs. The
include_str! calls sit inside #[cfg(test)], so non-test builds are
unaffected.

Fixes NVIDIA#647

Signed-off-by: Vyncint Ng <[email protected]>
@nihalpasham nihalpasham added bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Aug 4, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Confirmed the fail-open, then the fix:

  • renamed only the KERNEL_SCOPE_LOCAL definition locally: hash_value_is_pinned fails with the exact left/right diff, and the new coupling test fails naming the fixture file that must move with the rename. Both tripwires work; before this PR that rename sailed through green.
  • cargo test -p reserved-oxide-symbols -p cuda-macros --all-targets is green, including the trybuild fixtures.
  • clean under both the current naming-guard pattern and ci(naming-guard): guard every reserved symbol prefix, not three of them #646's widened one, so landing order was free.

Thanks for the clean, test-only fix. Closes #647.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup codegen Device code-generation pipeline (Rust MIR to IR to PTX)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Renaming KERNEL_SCOPE_LOCAL silently disarms two hygiene regression tests

2 participants