Repository navigation
Restructure and update the autoharness reference page - #4991
Conversation
Move the existing content under the new section layout without changing its wording, and add placeholder comments for the content that is still missing. Also fix the link to the mined invariants section, whose anchor did not match the generated heading id. Towards model-checking#4979
|
@acearyanarun @wodex1nhaoIeng the skeleton is up: the current page moved into Felipe's structure, no wording changes yet. Could you take a look and say whether the layout works for you? If it does, there are three parts to fill in so we don't edit the same lines:
|
Describe what a successful automatic harness does not cover: single monomorphization, bounded arguments, and the opt-in constructor and mined-invariant modes. Add an "Other limitations" subsection for the under-approximations that apply by default without a marker in the summary table, including the closure side effects reported in model-checking#4994. Towards model-checking#4979
Fill in the "Selecting functions" section of the autoharness reference page (towards model-checking#4979): include/exclude pattern matching against instantiated names, --list/--format, the full list of skip reasons, and generic instantiation, including Fn-bound parameters and the SIMD and const-generic restrictions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UFzbxD33o5GHieAP36Da8B
Describe the default harness timeout and unwinding bound, when Kani reminds the user of them, and how to read the selected/skipped tables, the summary table, and its "(bounded)" and "(ctor)" markers. Towards model-checking#4979
Describe the --std option, its path requirement, and that the alloc-dependent argument models are unavailable when verifying the standard library. Also note that concrete playback is not supported. Towards model-checking#4979
Show how the driver and the compiler split the work, from option handling through function selection, harness generation and code generation to running CBMC and printing the summary. Towards model-checking#4979
Update the overview and usage text that still said every argument must implement Arbitrary, align the variadic skip reason with the code, spell "autoharness" consistently, and link the Fn-bound closure models to the closure soundness caveat (model-checking#4994). Towards model-checking#4979
Fill in the bound options, contract preconditions, layout niches, UB and panic checks, contract postconditions and --check-invariants, and smooth out the mined-invariants text split by the restructure. Towards model-checking#4979
Reword the --std model availability note, and make the nested-slice and constructor-generics limits more precise. Towards model-checking#4979
Under --constructor-args, values of a type with its own Arbitrary implementation are still filtered by mined invariants, but the harness is not marked "(ctor)" (model-checking#4995). Say so in the constructor and mined invariant sections, the summary table, and the soundness caveats. Towards model-checking#4979
|
did you review these changes? do they seem helpful? @acearyanarun @Tianshu-Huang @wodex1nhaoIeng @srivatsansamraj |
There was a problem hiding this comment.
🟢 Approval recommended
Only a minor, non-blocking section-link correction remains in this documentation-only change.
1 open issue
What changed in this PR
Updates the autoharness reference to reflect current implementation and organize guidance around selecting functions, generating inputs, and interpreting verification results.
Changes:
- Documents supported argument models, generic instantiation, skip reasons, and CLI options.
- Explains verification defaults, result markers, and soundness limitations.
- Adds a contributor-oriented overview of the driver/compiler pipeline.
| File | Description |
|---|---|
docs/src/reference/experimental/autoharness.md |
Reorganizes and expands the autoharness reference, including modeling limits and architecture. |
Review effort: Balanced
Tianshu-Huang
left a comment
There was a problem hiding this comment.
I checked the page against main and everything matches, and all the #4979 items are in. The anchors are fine too, Yanjun is right about the en dash. Approving.
|
Looks good to me, but since I contributed some commits to this PR, I’m not sure whether it would be appropriate for me to review it. |
|
Hi Felipe, yes, I reviewed the updated documentation, particularly the function-selection and skip-reason sections I contributed to. I noticed two minor improvements: some CLI flags in headings render as en dashes, and the function-selection order could be clarified to include the comptime and no-body checks. Neither appears blocking. Overall, the changes look good to me! |
feliperodri
left a comment
There was a problem hiding this comment.
Thanks for the restructure. The headings follow the structure proposed in #4979, and the claims I spot-checked against the code are accurate (generic instantiation candidates and limits, skip reasons, default timeout/unwind, --list and --std behavior, unbounded slice/Vec models, mined-invariant limits, Fn model shapes).
Requesting changes for the following, in priority order:
- Add the visual overview (inline comment on the "Selecting functions" heading). This is the main change I'd like to see.
- Fix the imprecise selection-order sentence (inline comment).
- Make the two fragile heading anchors robust (inline comments).
- Confirm the docs build. Only the "Auto Label" check has reported on this PR, so no CI job has built the book. Please run
mdbook build docslocally and confirm there are no new warnings and no broken links, or get the docs workflow approved to run. - Optional, not blocking: the page is now ~790 lines. Consider a follow-up that splits it into overview, argument generation, and soundness pages.
I'll re-review once these are addressed.
Describe the selection checks in the order automatic_harness_partition runs them: Kani-internal and compile-time-only functions are rejected before generic instantiation, followed by the body, proof-harness, include/exclude, variadic and argument checks. State that the skip-reason table follows this order. Rename the bounded-arguments, constructor-args and --list headings so their ids no longer depend on how mdBook treats "--" and other punctuation, and update all links. This also removes the near-duplicate with the "Bounded arguments" soundness caveat.
Add the three-phase SELECT / GENERATE / VERIFY & REPORT diagram from model-checking#4979 before "Selecting functions", with links to the section for each phase, the soundness caveats and the architecture section. The diagram marks mined invariants as applying only under --constructor-args, as the page describes.
… docs/autoharness-restructure
Render the diagram as a raw HTML <pre> block so the box titles can link to their sections, as asked in review, and drop the separate link list. Restore the diagram text to the model-checking#4979 original apart from the mined invariants line.
|
Thanks for the careful review! All items are addressed:
|
…rguments (model-checking#5064) This fixes model-checking#4811, an issue in the Autoharness milestone. **Priority: Low (L3, a coverage gap under 100 functions).** This adds automatic harnesses, under `--bounded-arguments`, for 27 standard-library functions that take `CharArraySearcher`, `CharArrayRefSearcher` or `CharSliceSearcher` arguments; nothing fails while it waits. With `--bounded-arguments`, autoharness can now generate `CharArraySearcher<'_, N>`, `CharArrayRefSearcher<'_, '_, N>` and `CharSliceSearcher<'_, '_>` arguments, by value, `&` or `&mut`. These are the searchers for `[char; N]`, `&[char; N]` and `&[char]` patterns in `core::str::pattern`. ### Changes 1. New `kani_core` models build the searcher through the public `Pattern::into_searcher` API over a bounded nondeterministic haystack (from `any_str_ref`, string bound) and a nondeterministic needle (`[char; N]`, or a `&[char]` of up to the slice bound for `CharSliceSearcher`). They then advance it a nondeterministic number of steps from each end, so that searchers in partially advanced states are also generated. 2. `multi_char_eq_searcher_kind` identifies the three types by definition path and is shared by the eligibility check and harness generation. 3. The searchers' `Debug::fmt` methods are verified as ordinary functions rather than through the formatting-trait model, since the searcher needs harness-owned storage. 4. The storage-array construction of the slice/str branches is factored into `build_any_array_storage_ref`. The needle storage of `CharArrayRefSearcher` and `CharSliceSearcher` is generated with a single `kani::any()` call (`build_any_whole_array_storage_ref`), so a large `N` does not grow the harness body. 5. The reference page and the `--slice-bound`/`--string-bound` help text document the new argument types. ### Testing 1. New test `cargo_autoharness_multichareq_searcher`: 7 harnesses, 6 pass and 1 fails as expected, and all 33 cover properties are satisfied. It takes about 4 minutes locally with `--string-bound 4 --slice-bound 4`; the slowest harness (`char_slice_value`) takes about 70s. The script uses `--harness-timeout 10m` rather than the usual 5m because that harness came close to the 5m limit on `macos-15-intel`. Timing is driven by the string bound (haystack size): lowering the slice bound from 4 to 2 made no measurable difference, and a string bound of 3 would drop 4-byte UTF-8 characters from the haystack. 2. All 42 autoharness regression tests pass. `cargo fmt --check` and `cargo clippy --workspace --tests -- -D warnings` pass. ### Results on verify-std 1. With `--bounded-arguments`, all 27 functions listed in model-checking#4811 now get harnesses (9 per searcher type). The other 23 functions in `pattern.rs` (`CharPredicateSearcher`, `CharSearcher`, `StrSearcher`) are still skipped and are out of scope here. 2. Verifying the 27 harnesses (release build, string bound 4, slice bound 16, 10-minute timeout each): 8 fail and 19 time out. 3. The 8 failures are the preconditions of `char::from_u32_unchecked` and `hint::unreachable_unchecked`, caused by model-checking#5030 (`&str` from `any_str_ref` can be invalid UTF-8 under verify-std). CBMC traces for `CharArraySearcher::haystack` and `CharArraySearcher::next` confirm this: the haystack bytes are mis-validated by `from_utf8`, and the failures occur while the model advances the searcher, before the function under test runs. For `next`, the call graph shows the `unreachable_unchecked` check is reachable only from UTF-8 decoding. The other 6 fail on the same two checks and very likely share the cause, but I did not trace them individually. ### Notes 1. This PR and model-checking#4991 both edit `docs/src/reference/experimental/autoharness.md`. I'll resolve the conflict in whichever merges second. 2. Related: model-checking/verify-rust-std#722 adds hand-written harnesses for these searchers and builds haystacks with `encode_utf8`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
The autoharness reference page was restructured on main (model-checking#4991). Move this branch's reference-count documentation into the new structure: a sentence under "Box, Rc and Arc", a "(refcount)" entry under "Summary table and markers", and a "Reference counts" subsection under "Soundness caveats".
…king#5070) > **Draft — Local validation complete; CI and maintainer review pending.** The pinned nightly toolchain was installed successfully on macOS. The compiler build, unit tests, regression tests, formatting, and Clippy checks all passed locally. This PR contains only the independent reporting change. Shared-state tests requiring model-checking#4788 remain separate. ## Summary AutoHarness-generated `Rc`/`Arc` values have finitely modeled reference counts, but current AutoHarness output describes these harnesses as verifying "all possible inputs" without identifying that limitation. This PR makes the limitation visible without disabling default `Rc`/`Arc` support. - Adds an independent `HarnessMetadata::is_refcount_bounded` caveat. - Marks affected harnesses `(refcount)` in the AutoHarness summary, adds an explanatory note, and qualifies the per-function progress message. - Exposes `is_refcount_bounded` in `--export-json`, including schema, fixtures, and RFC documentation updates. - Adds tests for the marker, metadata compatibility, JSON reporting, type nesting, and non-vacuous uniquely owned states. - Documents the finite-model limitation and remaining caveats. **This PR does not change any `Rc`/`Arc` generator.** ## Why this matters Today, generated `Rc`/`Arc` values are uniquely owned (`strong_count == 1`, `weak_count == 0`). PR model-checking#4788 proposes additional shared-ownership states (`strong_count` in `{1, 2}` and `weak_count` in `{0, 1}`). Neither model covers all exact count values a caller may supply, so a successful verification result needs to communicate that limitation. A function checking, for example, `Rc::strong_count(&x) > 2` can still depend on unmodeled states. The existing `(bounded)` marker is gated by `--bounded-arguments`; reusing it would prevent default generation of `Rc`/`Arc` arguments. The new `(refcount)` caveat is separate and non-gating. ## Implementation - The compiler inspects generated argument types, following references, arrays, tuples, ADT fields and generic arguments, while skipping `PhantomData`. It deliberately errs toward warning on uncertain nesting rather than silently omitting a caveat. - The metadata field defaults to `false` when absent in older serialized metadata. - The driver adds a summary marker and note, plus an explicit qualification when printing individual verification progress. - JSON export includes the field, and the schema and fixtures are updated. - Regression tests check direct and nested types, the `AnyRc`/`AnyArc` reporting paths, negative controls, and coverage expectations for uniquely owned states. The type-based detection may flag types whose generation cannot actually produce an `Rc`/`Arc`. The warning does not claim complete modeling. It also does not cover manual harnesses using `kani::any()`. ## Difference from model-checking#4788 | | model-checking#4788 | This PR | |---|---|---| | Focus | Generate additional `Rc`/`Arc` ownership states | Report the finite modeling limitation | | Code | `Rc`/`Arc` arbitrary-value generators | Compiler metadata, driver output, JSON export, docs | | Dependency | Core generator change | Independent of model-checking#4788 | Shared-state regression cases that *depend* on model-checking#4788 are intentionally excluded from this PR; they can be contributed when the generator change lands. ## Testing **Passed locally on macOS using nightly-2026-10-23:** - `cargo build-dev` — passed, including `kani-compiler`. - `cargo test -p kani-driver -p kani_metadata` — 214 driver tests and 4 metadata tests passed; 2 documentation tests passed, 1 ignored. - `cargo run -p compiletest -- --suite json-handler --mode exec autoharness-refcount` — 1 passed, 0 failed. - `cargo run -p compiletest -- --suite script-based-pre --mode exec --force-rerun cargo_autoharness_smart_pointers` — 1 passed, 0 failed. - `cargo run -p compiletest -- --suite script-based-pre --mode exec --force-rerun autoharness` — 42 passed, 0 failed. - `./scripts/kani-fmt.sh --check` — passed. - `cargo clippy --workspace --tests -- -D warnings` — passed. - `RUSTFLAGS="--cfg=kani_sysroot" cargo clippy --workspace -- -D warnings` — passed. The broader AutoHarness suite includes the smart-pointer test, so these counts overlap. **Pending:** GitHub CI and maintainer review. The shared-ownership regression tests depending on model-checking#4788 are intentionally excluded. ## Related work Part of model-checking#4752. Related: model-checking#4788 (generator), model-checking#4958 (aliasing metadata), and model-checking#4991 (AutoHarness documentation restructure; may require rebase/conflict resolution). By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WddFow1MppHhSFwg9HdZCz --------- Co-authored-by: Felipe R. Monteiro <[email protected]>
…ng#5112) ### Problem `kani autoharness` / `cargo kani autoharness` set a default loop-unwinding bound of 20 and a harness timeout of 60s so that automatic harnesses don't hang. `KaniSession::add_default_bounds` did this by writing into the session-wide `VerificationArgs` (`args.default_unwind` and `args.harness_timeout`). Every harness verified in the run reads those fields. That includes the manual `#[kani::proof]` / `#[kani::proof_for_contract]` harnesses, which autoharness also verifies: - `resolve_unwind_value` resolves `--unwind` > `#[kani::unwind]` > `--default-unwind`. A manual harness without `#[kani::unwind]` therefore got `--unwind 20`. A manual harness whose loops need more than 20 iterations passes under `cargo kani` but fails with `unwinding assertion loop N` under `cargo kani autoharness`. This is the hifitime `kani_harness_Epoch_now` failure from model-checking#5103. `--include-pattern` does not help, because it only selects which functions get automatic harnesses, and manual harnesses always run. - The timeout has the same problem. `run_cbmc_piped` and `run_terminal_timeout` read `args.harness_timeout`, so every manual harness in an autoharness run was killed after 60s, even though `cargo kani` sets no timeout by default. A slow but correct manual harness was reported as a timeout failure. ### Change The autoharness defaults now live in two new `KaniSession` fields, `autoharness_default_unwind` and `autoharness_harness_timeout`, and no longer go into `VerificationArgs`. They are applied per harness, only when `HarnessMetadata::is_automatically_generated` is set: - `resolve_unwind_value(args, harness, autoharness_default_unwind)` keeps the existing precedence and adds the autoharness default as the last fallback, for automatic harnesses only: `--unwind` > `#[kani::unwind]` > `--default-unwind` > autoharness default. - The new `resolve_harness_timeout(args, harness, autoharness_harness_timeout)` returns `--harness-timeout` if passed. Otherwise it returns the autoharness default for automatic harnesses only. `run_cbmc` resolves the timeout once and passes it to `run_cbmc_piped` / `run_terminal_timeout`. Existing behavior is preserved where it should be: - An explicit `--unwind`, `--default-unwind` or `--harness-timeout` still applies to every harness, manual or automatic, exactly as before. - A manual harness's `#[kani::unwind]` still beats `--default-unwind`. - Automatic harnesses still get 20 / 60s by default. Since they never carry `#[kani::unwind]`, their resolved bound is the same as before in every case. I checked the other readers of these values: - `warn_if_bounds_reach_unwind` is about automatic harnesses' bounded arguments, so it now takes the autoharness default into account explicitly. It warns in exactly the same cases as before. - `--export-json`: `resolved_unwind` goes through `resolve_unwind_value`. It now reports 20 for automatic harnesses (unchanged) and the true bound for manual ones (previously a misreported 20). The run-level `harness_timeout_s` still reports 60 for an autoharness run without `--harness-timeout`, as before. That value describes the automatic harnesses; manual harnesses in such a run now have no timeout. - The `--unwind`-in-`--cbmc-args` conflict check (`natives_unwind`) runs during argument validation, before `add_default_bounds`, so it never saw the injected 20 and is unaffected. User-facing text: the autoharness failure note now reads "sets default --harness-timeout of 60s and --default-unwind of 20 for automatic harnesses". The six `.expected` files containing it are updated to match. In the autoharness reference page, the "Default settings" section now says that both defaults apply only to automatic harnesses, and that explicit options still apply to every harness. On the timeout, I chose to scope it rather than leave it global. It is the same bug: a manual harness's result in an autoharness run should match its result under `cargo kani`, and a hidden 60s cap breaks that just as much as a hidden unwind bound does. Keeping it global would also leave the two defaults inconsistent with each other and with the summary note. ### Testing New script-based test `tests/script-based-pre/cargo_autoharness_default_bounds_scope`. The crate has two functions that get automatic harnesses (loops of 10 and 30 iterations) and three manual harnesses: a 30-iteration loop with no `#[kani::unwind]`, one with `#[kani::unwind(31)]`, and one with `#[kani::unwind(5)]`. The script runs autoharness three times and checks each harness's verdict: - Defaults (`--include-pattern 'loop_'`, mirroring the issue). The manual harness without an unwind attribute passes. The automatic 30-iteration harness still fails under the default of 20, and the 10-iteration one passes. `#[kani::unwind(31)]` passes and `#[kani::unwind(5)]` fails, so the attribute still wins. - `--default-unwind 10`. Applies to manual and automatic harnesses alike: the manual unattributed harness and the automatic 10-iteration harness now fail. The attributes still win. - `--default-unwind 40`. Overrides the autoharness default for automatic harnesses: the automatic 30-iteration harness now passes. `--unwind` requires `--harness`, and `--harness` never selects automatic harnesses, so `--unwind` is covered by the unit tests below rather than by the script. New unit tests: - `call_cbmc::tests::autoharness_default_unwind_is_scoped_to_automatic_harnesses`: the full precedence matrix for manual and automatic harnesses, with and without the autoharness default, including `--unwind` and `--default-unwind`. - `call_cbmc::tests::autoharness_timeout_is_scoped_to_automatic_harnesses`: the same for `--harness-timeout`. - `frontend::schema_utils::tests::resolve_effective_unwind_tests::autoharness_default_unwind_is_reported_for_automatic_harnesses_only`: the `--export-json` `resolved_unwind`. Existing `resolve_unwind_value` / `resolve_effective_unwind` tests are updated for the new parameter. ### Results Run on macOS with the pinned toolchain (`nightly-2026-10-23`), with the change on top of `e8afed3`. Rebasing onto the current `main` changed only `docs/src/reference/experimental/autoharness.md`, which conflicted with the restructured page from model-checking#4991. The code and tests are identical to what was run. On the rebased branch, `cargo test -p kani-driver` (211 passed), `cargo clippy -p kani-driver --tests -- -D warnings` and `cargo fmt --check -p kani-driver` were re-run with stable Rust and passed. - `cargo build-dev`: passed. - `cargo test -p kani-driver`: 211 passed, including the three new unit tests. - `compiletest --suite script-based-pre --mode exec cargo_autoharness_default_bounds_scope` (the new test): passed. - Existing suites, all passed: - script-based-pre `autoharness`: 43 tests, including the new test and five of the six tests whose `.expected` note was reworded; - script-based-pre `autoderive`: 2 tests, including `autoderive_arbitrary_enums`, the sixth; - `json-handler`: 7 tests. - `./scripts/kani-fmt.sh --check`, `cargo clippy --workspace --tests -- -D warnings` and `RUSTFLAGS="--cfg=kani_sysroot" cargo clippy --workspace -- -D warnings`: passed. - Interaction with model-checking#5070, which also changes autoharness output: the code merges without conflicts. On a local merge of the two branches, `cargo test -p kani-driver` passes (217 tests), as do the script-based-pre `autoharness` and `json-handler` suites. Not run: the full `./scripts/kani-regression.sh` and Linux. Both are left to CI. The timeout scoping is covered by the unit test only. An integration test would need a harness that runs for more than 60 s. Fixes model-checking#5103 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Felipe R. Monteiro <[email protected]>

Resolves #4979.
This rewrites the autoharness reference page (
docs/src/reference/experimental/autoharness.md) to match the implementation onmain, following the structure proposed in #4979: selecting functions, generating harnesses (arguments, assumptions, checks), verifying and reading results, soundness caveats, and an architecture overview for contributors.How the items in #4979 are addressed:
Vec: new "Primitive slices and Vec" section; "Bounded Arguments" and "Arguments Implementing Arbitrary" now distinguish the primitive unbounded models from the bounded generators.Fn-bound generics: "Generic Functions" (instantiation) and "Fn-bound closures" (the model and its limits).Box/Rc/Arc: new "Box, Rc and Arc" section.--stdin "Usage",--list --formatin "Listing functions (--list)", and the bound flags in "Bounded Arguments".The soundness caveats are now collected in one section: single monomorphization, aliasing between arguments, bounded arguments, vacuous constructors, and the mined-invariant heuristic. That section also has an "Other limitations" subsection that is not in the proposed structure. It lists the under-approximations that apply by default without a marker in the summary table. Happy to drop or move it if you prefer.
While writing the page we found and reported two issues, both described in the caveats:
Fn-bound closure models have no side effects, so callbacks that modify shared state are not covered.--constructor-args, mined-invariant filtering of a type with its ownArbitraryimplementation is not marked "(ctor)".Other fixes:
Arbitrary.Notes for review:
--alias-arguments.Contributors:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.