Repository navigation
Autoharness: skip fns whose const {} blocks depend on a substituted type - #4981
acearyanarun wants to merge 3 commits into
Conversation
… 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
|
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? |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
| let callee_args = ty::EarlyBinder::bind(self.tcx, callee_args) | ||
| .instantiate(self.tcx, self.args) | ||
| .skip_normalization(); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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:
- 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. - The branch is behind
main. Please update it. - 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.
|
Thanks for the review, @feliperodri.
Local results (macOS, |

#4820 stopped a
const {}precondition on a const parameter from aborting an autoharness run. As #4826 describes, the same unrecoverableE0080was 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 bareDefIds. 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. Aconst {}block (AnonConstwithNonTypeSystemInline) 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_ZSTare reached by nearly every function over slices and collections. Treating them as preconditions would skip all of those (slice_lenin 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_typepins this).Std skip-count impact (requested in #4826)
kani autoharness --std --listover the nightly-2026-09-25 library, on aarch64-darwin, excludingcore_arch::(on main it crashes on SVE tuples; see #4964):const {}block, e.g.TypeId::of,needs_drop,type_name,RawVec'sconst { assert!(..) },read_unaligned,mem::zeroed.Arbitraryor trait bounds now report the const-block reason, because the check runs first, and are listed under their generic rather than instantiated name.Testing
cargo_autoharness_generics: both shapes from autoharness: E0080 can still abort a run when the substituted *type* decides aconst {}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/expectedupdated for the reworded skip message.script-based-pre90/91 locally.codegen_cachehit anEINTRonechounder parallel load; it passes in isolation and passed in an earlier full run.cargo test -p kani-compiler,clippy -D warnings,kani-fmt --checkall 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.