Skip to content

ci(naming-guard): guard every reserved symbol prefix, not three of them - #646

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:fix/naming-guard-widen-prefixes
Aug 4, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:fix/naming-guard-widen-prefixes

Conversation

@vyncint

@vyncint vyncint commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #645. This is the separate discussion you suggested when approving #644.

What was wrong

naming-guard's comment says it rejects any hardcoded reserved prefix and that reserved-oxide-symbols is their single source of truth, but the pattern matched only kernel|device|instantiate. Four of the crate's ten exported symbol constants were unguarded, and now that the guard actually executes, that gap hid exactly one live violation:

crates/cuda-core/src/embedded.rs:236:            Some("cuda_oxide_artifact_anchor_246e25db_linked_0_0_0"),

Coverage before and after:

Constant(s) Segment Before After
KERNEL_PREFIX, LEGACY_KERNEL_PREFIX, KERNEL_SCOPE_LOCAL cuda_oxide_kernel_ yes yes
DEVICE_PREFIX, LEGACY_DEVICE_PREFIX, DEVICE_EXTERN_PREFIX cuda_oxide_device_ yes yes
INSTANTIATE_PREFIX cuda_oxide_instantiate_ yes yes
CONSTANT_PREFIX cuda_oxide_const_ no yes
ARTIFACT_ANCHOR_PREFIX cuda_oxide_artifact_anchor_ no yes
PTX_MERGE_REQUIRED_PREFIX cuda_oxide_ptx_merge_required_ no yes

Why six families and not bare cuda_oxide_

The obvious simplification is to drop the list and match RESERVED_ROOT outright. I measured it: that hits 58 literals, and ~57 belong to a namespace this crate does not own and must not police —

  • pliron op-attribute keys: cuda_oxide_asm_kind, cuda_oxide_debug_local_*, cuda_oxide_op_alignment, cuda_oxide_gep_inbounds
  • rustc --cfg names: cuda_oxide_internal_backend_identity, cuda_oxide_internal_codegen_env
  • dlopen probe symbols: cuda_oxide_probe
  • unique temp-directory names: cuda_oxide_stale_artifacts_*, cuda_oxide_clean_cache_*
  • the generated marker attribute: cuda_oxide_intrinsic_marker

Widening that far would mean ~57 false positives and a pointless refactor. The six symbol families cover all ten constants and produce exactly the one real hit. I put that reasoning in the step comment so the boundary does not have to be re-derived next time.

The dev-dependency

The violation is inside #[cfg(test)] mod tests, so reserved-oxide-symbols goes in [dev-dependencies] and stays out of the shipped cuda-core library. It is already a workspace dependency of llvm-export, cargo-oxide, and mir-lower, so this adds no licensing surface and the Cargo.lock delta is one line.

Verification

CPU-only, no GPU. Guard step extracted from the YAML and run directly:

# Scenario Expected Result
1 Widened guard, embedded.rs fixed pass exit 0
2 Widened guard, violation restored fail exit 1, names file and line
3 Old 3-family pattern vs. that same violation — 0 matches, confirms the blind spot
4 Synthetic violation for each of the six families fail all six caught
5 cuda_oxide_asm_kind / ..._internal_backend_identity / ..._probe pass not flagged

The rebuilt symbol is byte-identical — I temporarily added assert_eq!(anchor, "cuda_oxide_artifact_anchor_246e25db_linked_0_0_0") to the test, confirmed it passed, then removed it. artifact_bundles_from_binary_path_reads_linked_executable also links a real executable carrying the anchor and reads it back, and still passes.

cargo test -p cuda-core --lib: 26 passed / 0 failed. reserved-oxide-symbols: 13 unit + 17 doc tests pass. cargo clippy -p cuda-core --all-targets -- -D warnings clean; cargo fmt --all --check clean.

One unrelated thing I noticed, not touched here

Checking whether CONTRIBUTING's "update dependency-licenses.csv when adding a dependency" applied, I found the CSV lists 11 first-party workspace crates while the workspace has 23 members. Missing: cuda-intrinsics, cuda-intrinsics-gen, cuda-artifact-finalizer, cuda-oxide-codegen, mir-transforms, nvvm-transforms, cargo-oxide, oxide-artifacts, cuda-async, libnvvm-sys, nvjitlink-sys, reserved-oxide-symbols, fuzzer. That predates this change; say the word and I'll file it separately.

The step comment says it rejects any hardcoded reserved prefix and that
reserved-oxide-symbols is their single source of truth, but the pattern
matched only kernel|device|instantiate. That left CONSTANT_PREFIX,
ARTIFACT_ANCHOR_PREFIX and PTX_MERGE_REQUIRED_PREFIX unguarded, and now
that the guard actually executes it was hiding one live violation: the
cuda-core embedded-artifact test hand-wrote an artifact-anchor symbol.

Widen the alternation to the six segments that cover all ten symbol
constants, and route that test through
reserved_oxide_symbols::artifact_anchor_symbol, which produces the same
string byte for byte. The violation sits in `#[cfg(test)] mod tests`, so
reserved-oxide-symbols becomes a dev-dependency and stays out of the
shipped library; it is already a workspace dependency of llvm-export,
cargo-oxide and mir-lower, so the Cargo.lock delta is one line.

The pattern deliberately still does not match bare `cuda_oxide_`. That
word-space also holds pliron op-attribute keys, rustc --cfg names, dlopen
probe symbols and temp-directory names — 57 literals this crate does not
own. The step comment now records that boundary so it does not have to be
re-derived.

Fixes NVIDIA#645

Signed-off-by: Vyncint Ng <[email protected]>
… family

The pattern is anchored to the opening quote, so a hardcoded full
modern prefix ("cuda_oxide_codegen_v1_...") kept its embedded
cuda_oxide_kernel_ segment mid-string where no family could match.
Add codegen_v1 to the alternation (zero false positives tree-wide)
and reword the coverage comment to say precisely which constant each
family catches.
@nihalpasham nihalpasham added bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async) labels Aug 4, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Verified this end to end:

  • ran the widened pattern against main: it finds exactly the one live violation, the artifact-anchor literal in cuda-core's embedded test, so the widening does real work on day one.
  • the rebuilt anchor from artifact_anchor_symbol("linked", "0.0.0") is byte-identical to the removed literal, and cargo test -p cuda-core --lib is green.
  • checked all six families against the ~58 bare-root "cuda_oxide_ literals in the tree: zero false positives, so the documented boundary holds.

I pushed one commit on top:

  • adds codegen_v1 to the alternation. The pattern is quote-anchored, so a hardcoded full modern prefix ("cuda_oxide_codegen_v1_...") would have slipped past all six families. With it, the "covers all ten symbol constants" comment is actually true. Verified zero false positives for the new family as well.

Thanks for finishing what #644 started. Closes #645.

@nihalpasham
nihalpasham merged commit e28248c into NVIDIA:main Aug 4, 2026
33 checks passed
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 host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

naming-guard covers 6 of 10 reserved symbol prefixes, hiding one hardcoded artifact-anchor literal

2 participants