Skip to content

Renaming KERNEL_SCOPE_LOCAL silently disarms two hygiene regression tests #647

Closed

Description

@vyncint

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 failed

Nothing 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

  1. Pin KERNEL_SCOPE_LOCAL and ARTIFACT_ANCHOR_PREFIX in hash_value_is_pinned, with a comment naming both fixtures so a rename tells you what has to move with it.
  2. Add both to all_prefixes_share_reserved_root — a test named "all prefixes" that covers 8 of 10.
  3. Add a cuda-macros unit test that reads both fixtures with include_str! and asserts they still spell the KERNEL_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-symbols 13 unit + 17 doc pass; cuda-macros 92 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_pinned fails at the new assertion.
    • hygiene_fixtures_still_collide_with_the_generated_scope_names fails with tests/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 warnings and cargo fmt --all --check are clean.
  • No new dependencies, so Cargo.lock is 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

  1. added
    bug
    build-related
    codegen
    on Aug 4, 2026
  2. added a commit that references this issue on Aug 4, 2026
    760bf7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbuild-relatedcodegen

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions