Skip to content

Strip the crate prefix from scanner names to match kani list - #4903

Open
Tianshu-Huang wants to merge 1 commit into
model-checking:mainfrom
Tianshu-Huang:fix-4868-scanner-crate-prefix
Open

Tianshu-Huang wants to merge 1 commit into
model-checking:mainfrom
Tianshu-Huang:fix-4868-scanner-crate-prefix

Conversation

@Tianshu-Huang

Copy link
Copy Markdown
Contributor

Two Kani outputs disagree on the name of the same function. kani list says ptr::align_offset; the scanner's CSVs say core::ptr::align_offset. Anything that joins the two matches nothing, which is how verify-rust-std's contract metrics have read 0 since its Kani pin moved past rust-lang/rust#149401 (model-checking/verify-rust-std#696 works around it on that side).

The cause is one-sided: that rustc change made def_path_str carry the crate prefix, kani-compiler compensates with strip_local_crate_prefix, and tools/scanner calls name() directly and inherited the prefix.

The fix: the function moves to kani_metadata, which both crates already can depend on, and the scanner routes every name it writes through it. strip_local_crate_prefix stays as a one-line wrapper, so none of its callers change.

The six cases from #696's review are pinned as unit tests in kani_metadata, including the two non-idempotent ones. The scanner test now checks that no CSV name starts with test::; on main it prints test::with_for_loop and fails, with this change it passes. The list, cargo_autoharness_filter, and stubbing suites pass locally; clippy and rustfmt clean.

Resolves #4868

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@Tianshu-Huang
Tianshu-Huang requested review from a team as code owners September 29, 2026 04:41
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Sep 29, 2026
Comment thread kani_metadata/src/lib.rs
/// Every producer of item names that a consumer joins by name (the compiler's
/// metadata and the `scanner` tool's CSVs) must go through this one function,
/// so the two never disagree.
pub fn strip_crate_prefix(name: &str, krate: &str) -> String {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from kani_middle::strip_local_crate_prefix. The loop is unchanged, but the
signature is different. The crate name is a parameter, since this crate can't call local_crate(), and
name is now &str rather than String.

# Names must be crate-relative, as `kani list` reports them, so the two outputs
# can be joined by name (kani#4868). The crate is `test`, so no name may start
# with `test::`.
if grep -q '^test::' *.csv; then

@Tianshu-Huang Tianshu-Huang Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check fails on main. The CSVs there contain test::with_for_loop, so the script prints FAIL. The expected file requires the OK line.

Comment thread tools/scanner/src/lib.rs
/// the local crate name (rust-lang/rust#149401), and the compiler strips it with
/// this same function, so every name the scanner writes goes through here and
/// the two outputs can be joined by name (kani#4868).
pub(crate) fn item_name<T: rustc_public::CrateDef>(def: &T) -> String {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every name the scanner writes goes through this function. If someone later writes name() straight to a CSV without it, the prefix comes back.

# Names must be crate-relative, as `kani list` reports them, so the two outputs
# can be joined by name (kani#4868). The crate is `test`, so no name may start
# with `test::`.
if grep -q '^test::' *.csv; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: match the prefix at any path-component boundary, not only at line start, so a qualified or generic name (<test::T as test::Tr>::m, f::<test::T>) would also trip the check if test.rs ever gains one.

Suggested change
if grep -q '^test::' *.csv; then
if grep -qE '(^|[^[:alnum:]_:])test::' *.csv; then

This branch has not been deployed

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

Labels

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scanner CSVs report crate-prefixed names while kani list does not

2 participants