Repository navigation
Description
Summary
Two hygiene regression tests are silently disarmed by renaming KERNEL_SCOPE_LOCAL. Both spell the constant's value as a Rust identifier, so nothing ties them back to the constant: rename it and the fixtures stop colliding with the macro's generated bindings, which means they keep passing while testing nothing.
The fixtures:
| Fixture | What it declares | What it proves |
|---|---|---|
crates/cuda-macros/tests/pass/kernel_launch_context_api.rs:27 |
a parameter named cuda_oxide_kernel_scope_246e25db_storage |
the Span::mixed_site() storage binding from kernel_scope_spec (lib.rs:4609) survives a same-text user binding |
crates/rustc-codegen-cuda/examples/const_generic/src/main.rs:55 |
a const generic named cuda_oxide_kernel_scope_246e25db |
call_site_ident_avoiding_item (lib.rs:4547) takes its rename path |
Their whole purpose is to collide. Once the constant no longer matches, they become ordinary unrelated names and the hygiene they exist to check goes unexercised — with a green result.
Demonstration
Changing one character of the constant:
-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
test result: ok. 2 passed; 0 failed
test result: ok. 1 passed; 0 failed
test result: ok. 5 passed; 0 failedNothing anywhere notices. hash_value_is_pinned — the test whose doc comment says "Changing this constant is a breaking-change ... and must be done deliberately" — does not cover it.
Contributing cause: two of ten constants are unpinned
hash_value_is_pinned asserts 8 constants and all_prefixes_share_reserved_root enumerates the same 8. The crate exports 10:
- pinned:
KERNEL_PREFIX,LEGACY_KERNEL_PREFIX,DEVICE_PREFIX,LEGACY_DEVICE_PREFIX,DEVICE_EXTERN_PREFIX,INSTANTIATE_PREFIX,CONSTANT_PREFIX,PTX_MERGE_REQUIRED_PREFIX - not pinned:
KERNEL_SCOPE_LOCAL,ARTIFACT_ANCHOR_PREFIX
ARTIFACT_ANCHOR_PREFIX is at least pinned indirectly — artifact_anchor_symbol_is_sanitized_and_reserved asserts exact output strings that embed it. KERNEL_SCOPE_LOCAL has no such backstop anywhere in the workspace.
Worth noting the contrast in the same fixture: lines 36–40 of kernel_launch_context_api.rs spell KERNEL_PREFIX as identifiers too (cuda_oxide_codegen_v1_cuda_oxide_kernel_246e25db_simple), but those are referenced, so renaming KERNEL_PREFIX breaks the build. The hygiene bindings are only declared, so they fail open.
Proposed fix
- Pin
KERNEL_SCOPE_LOCALandARTIFACT_ANCHOR_PREFIXinhash_value_is_pinned, with a comment naming both fixtures so a rename tells you what has to move with it. - Add both to
all_prefixes_share_reserved_root— a test named "all prefixes" that covers 8 of 10. - Add a
cuda-macrosunit test that reads both fixtures withinclude_str!and asserts they still spell theKERNEL_SCOPE_LOCAL-derived names. This makes the coupling machine-checked rather than relying on someone remembering, and is the part that would have caught this from the start.
For (3), include_str! sits inside #[cfg(test)], so it is stripped from non-test builds — verified with cargo build -p cuda-macros. Both files are git-tracked, so they are present in any CI checkout. One half reaches across into crates/rustc-codegen-cuda/examples/; if you would rather not have that coupling, dropping it still leaves (1) catching the rename and naming the example.
Verification
CPU-only, no GPU or toolkit needed beyond the usual bindgen header.
- With the fix in place and the constant intact:
reserved-oxide-symbols13 unit + 17 doc pass;cuda-macros92 lib (91 + the new test) + all four trybuild suites pass. - With the fix in place and the constant renamed to
..._deadbeef, both new checks fail loudly:hash_value_is_pinnedfails at the new assertion.hygiene_fixtures_still_collide_with_the_generated_scope_namesfails withtests/pass/kernel_launch_context_api.rs must bind \cuda_oxide_kernel_scope_deadbeef_storage` ...`, naming the exact binding the fixture now needs.
cargo clippy -p reserved-oxide-symbols -p cuda-macros --all-targets -- -D warningsandcargo fmt --all --checkare clean.- No new dependencies, so
Cargo.lockis untouched. The change is confined to two files and does not overlap ci(naming-guard): guard every reserved symbol prefix, not three of them #646.
Activity
test(reserved-oxide-symbols): pin the constants two hygiene fixtures …