Skip to content

Autoharness: skip fns whose const {} blocks depend on a substituted type - #4981

Open
acearyanarun wants to merge 3 commits into
model-checking:mainfrom
acearyanarun:autoharness-issue-4826
Open

acearyanarun wants to merge 3 commits into
model-checking:mainfrom
acearyanarun:autoharness-issue-4826

Conversation

@acearyanarun

Copy link
Copy Markdown
Contributor

#4820 stopped a const {} precondition on a const parameter from aborting an autoharness run. As #4826 describes, the same unrecoverable E0080 was still reachable when the substituted type decides the block: either a const parameter reaching it through a type argument (inner::<[u8; N]>()) or a block guarded on a type parameter alone (const { [..][size_of::<T>()] }). Both abort the entire run.

The change

The reachability walk now carries (DefId, GenericArgsRef), expressed in terms of the candidate's own parameters, instead of bare DefIds. It follows calls, reified fn items, closures and coroutines whose instantiated arguments mention a type or const parameter. Instantiations with concrete arguments are still not followed. A const {} block (AnonConst with NonTypeSystemInline) counts as a possible precondition when its instantiated arguments mention a type or const parameter.

One deliberate departure from the issue's suggested direction: other unevaluated constants still count only when they mention a const parameter. Generic associated constants like <T as SizedTypeProperties>::IS_ZST are reached by nearly every function over slices and collections. Treating them as preconditions would skip all of those (slice_len in the test pins this boundary).

Carrying instantiated arguments is mostly about precision: a caller that reaches a guarded callee only through a concrete type is no longer skipped (concrete_second_type pins this).

Std skip-count impact (requested in #4826)

kani autoharness --std --list over the nightly-2026-09-25 library, on aarch64-darwin, excluding core_arch:: (on main it crashes on SVE tuples; see #4964):

  • Generated: 20,868 → 20,790 (−78, 0 gained). Every lost function reaches a type-dependent const {} block, e.g. TypeId::of, needs_drop, type_name, RawVec's const { assert!(..) }, read_unaligned, mem::zeroed.
  • The other changed skip rows are relabeling. Functions already skipped for missing Arbitrary or trait bounds now report the const-block reason, because the check runs first, and are listed under their generic rather than instantiated name.
  • The 1024-body search limit was never hit (checked with temporary instrumentation).

Testing

  • New cases in cargo_autoharness_generics: both shapes from autoharness: E0080 can still abort a run when the substituted *type* decides a const {} block #4826, a type-parameter variant, and three must-still-verify boundaries (concrete type argument, a concrete argument passed through an intermediate call, generic associated constants). The two boundary tests that pin design choices fail under their targeted mutations.
  • autoharness_comptime_intrinsic/expected updated for the reworded skip message.
  • script-based-pre 90/91 locally. codegen_cache hit an EINTR on echo under parallel load; it passes in isolation and passed in an earlier full run.
  • cargo test -p kani-compiler, clippy -D warnings, kani-fmt --check all pass.

Resolves #4826

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

… type

model-checking#4820 skips a const-generic candidate when it can reach a `const {}`
block parameterized by a const parameter, because a failing block makes
rustc emit an unrecoverable E0080 that aborts the whole autoharness run.
The same abort was still reachable in two shapes (model-checking#4826):

- a const parameter reaching the block through a type argument, as in
  `inner::<[u8; N]>()`, since only `GenericArgKind::Const` arguments
  were considered when following calls; and
- a block guarded on a type parameter alone, as in
  `const { assert!(size_of::<T>() >= 4) }`.

The reachability walk now carries each body's generic arguments,
instantiated in terms of the candidate's own parameters, instead of bare
`DefId`s, and follows calls, reified fn items, closures and coroutines
whose arguments mention any type or const parameter. Instantiations with
concrete arguments are still not followed. A `const {}` block counts as a
possible precondition when its instantiated arguments mention a type or
const parameter. Other unevaluated constants still count only when they
mention a const parameter: generic associated constants such as
`<T as SizedTypeProperties>::IS_ZST` are reached by most functions over
slices and collections, and treating them as preconditions would skip
those functions too.

Resolves model-checking#4826
@acearyanarun
acearyanarun requested review from a team as code owners October 6, 2026 08:42
@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 Oct 6, 2026
@acearyanarun

Copy link
Copy Markdown
Contributor Author

Hey @CYJ904 @Tianshu-Huang @wodex1nhaoIeng @srivatsansamraj, I opened #4981 for Milestone 33 / #4826. Can you guys take a look when you get a chance and sanity check the fix + numbers?

@feliperodri feliperodri added [C] Bug This is a bug. Something isn't working. [F] Crash Kani crashed Z-Autoharness Issue related to autoharness subcommand labels Nov 6, 2026
@feliperodri feliperodri added this to the Autoharness milestone Nov 6, 2026
@feliperodri
feliperodri requested a balanced review from Copilot November 6, 2026 18:51
@feliperodri feliperodri self-assigned this Nov 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Updates autoharness’s generic reachability analysis to conservatively skip harness generation when type-/const-substituted instantiations could trigger unrecoverable const-eval failures (E0080), including when const {} blocks are decided by substituted types.

Changes:

  • Track and propagate (DefId, GenericArgsRef) through the reachability walk to preserve instantiated generic-argument information.
  • Treat const {} (AnonConst + NonTypeSystemInline) as a possible precondition when its instantiated arguments mention a type or const parameter (while keeping other unevaluated consts gated on const parameters only).
  • Extend script-based-pre tests and update expected outputs/messages accordingly.
File Description
tests/​script-based-pre/​cargo_autoharness_generics/​src/​lib.rs Adds regression/boundary tests for type-dependent const {} paths and call-chain propagation.
tests/​script-based-pre/​cargo_autoharness_generics/​generics.expected Updates expected skip/verify rows and new numbering/order.
tests/​script-based-pre/​autoharness_comptime_intrinsic/​expected Updates expected skip message text for const {} precondition reporting.
kani-compiler/​src/​kani_middle/​codegen_units.rs Implements new reachability representation and const-precondition detection logic.

Review effort: Lite

return false;
};
args_mention_const_param(uneval.args)
let uneval_args = ty::EarlyBinder::bind(tcx, uneval.args).instantiate(tcx, args);

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.

On the toolchain this repository pins (nightly-2026-11-11), this call is correct and compiles: cargo build-dev and cargo test -p kani-compiler pass on this branch. In that toolchain, rustc_type_ir/src/binder.rs:349 defines

impl<I: Interner, T: TypeFoldable<I>> EarlyBinder<I, T> {
    pub fn bind(cx: I, value: T) -> EarlyBinder<I, T> {

so bind takes the interner first, and the one-argument form wouldn't compile here. main's own calls in this file (EarlyBinder::bind(tcx, spec.inputs)) use the same two-argument form.

Comment on lines +611 to +613
let callee_args = ty::EarlyBinder::bind(self.tcx, callee_args)
.instantiate(self.tcx, self.args)
.skip_normalization();

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.

Same as the thread on line 586: on the pinned nightly-2026-11-11, EarlyBinder::bind takes the interner first (pub fn bind(cx: I, value: T)), and this call compiles; cargo build-dev passes on this branch.

@feliperodri feliperodri left a comment

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.

The approach is right: the reachability walk now carries instantiated generic arguments, so a const {} block that depends on a substituted type is caught. The skip numbers are precise: 78 functions lost, none gained.

Before merge:

  1. Copilot says ty::EarlyBinder::bind(tcx, ...) doesn't match rustc's API (lines 586 and 613). Please confirm it compiles on the pinned toolchain, and reply on the threads.
  2. The branch is behind main. Please update it.
  3. Three jobs are cancelled. Please re-run them.

main is now on nightly-2026-11-11 (model-checking#5157), which removed
`ty::GenericArgsRef`. The conflict is with model-checking#5157's signature change to
`args_mention_const_param`, which this branch replaces with
`args_mention_param`; keep this branch's version and use
`ty::GenericArgs` for the walker's argument types, as model-checking#5157 does elsewhere.
@acearyanarun

acearyanarun commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @feliperodri.

  • EarlyBinder::bind(tcx, …): this is correct on the pinned toolchain. nightly-2026-11-11 defines pub fn bind(cx: I, value: T) in rustc_type_ir/src/binder.rs:349, and cargo build-dev compiles both call sites. I've replied on the two threads.
  • Behind main: merged main (60c631e, no force-push). Upgrade the Rust toolchain to nightly-2026-11-11 #5157 moved main to nightly-2026-11-11 and removed ty::GenericArgsRef, so the walker now uses ty::GenericArgs. The only conflict was Upgrade the Rust toolchain to nightly-2026-11-11 #5157's change to args_mention_const_param, which this PR replaces.

Local results (macOS, nightly-2026-11-11): cargo build-dev, cargo test -p kani-compiler (48), cargo_autoharness_generics, autoharness_comptime_intrinsic, the autoharness suite (48), kani-fmt --check and both CI clippy commands all pass.

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

[C] Bug This is a bug. Something isn't working. [F] Crash Kani crashed Z-Autoharness Issue related to autoharness subcommand 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.

autoharness: E0080 can still abort a run when the substituted *type* decides a const {} block

3 participants