Repository navigation
Autoharness: configurable bounded-argument bounds, reported in the summary - #4793
feliperodri merged 3 commits into
Conversation
…mmary The bounds that --bounded-arguments generates slice, string and BoundedArbitrary values with were fixed constants, and the summary note did not state them, so a reader could not tell what a bounded result covered. Add --slice-bound, --string-bound and --bounded-arbitrary-bound, defaulting to the current 16/4/4. The defaults move to kani_metadata so that the driver, which prints them, and the compiler, which generates with them, share one definition. The summary note now names the values a run used, and Kani warns when a bound is not below the effective unwinding bound. Resolves model-checking#4751
|
@Tianshu-Huang @acearyanarun @CYJ904 @wodex1nhaoIeng This is the fix for #4751. Feel free to take a look and verify when you get a chance. |
There was a problem hiding this comment.
🟡 Changes recommended
Bound options can be silently ignored, unwind warnings can use the wrong effective value, and the summary misstates BoundedArbitrary semantics.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds configurable bounded-argument limits for autoharness, addressing #4751 by threading bounds through the driver/compiler and reporting them to users.
Changes:
- Adds slice, string, and
BoundedArbitrarybound options. - Warns when bounds reach the configured unwind limit.
- Updates documentation and regression tests for custom/default bounds.
File summaries
| File | Description |
|---|---|
tests/script-based-pre/cargo_autoharness_slices/src/lib.rs |
Clarifies default slice/string bounds. |
tests/script-based-pre/cargo_autoharness_slices/slices.expected |
Updates the summary expectation. |
tests/script-based-pre/cargo_autoharness_bounds/src/lib.rs |
Tests all configurable bounds. |
tests/script-based-pre/cargo_autoharness_bounds/config.yml |
Registers the new script test. |
tests/script-based-pre/cargo_autoharness_bounds/Cargo.toml |
Defines the test crate. |
tests/script-based-pre/cargo_autoharness_bounds/bounds.sh |
Exercises warnings and custom bounds. |
tests/script-based-pre/cargo_autoharness_bounds/bounds.expected |
Captures expected bound behavior. |
tests/script-based-pre/cargo_autoharness_bounded/src/lib.rs |
Updates the renamed default constant. |
tests/script-based-pre/cargo_autoharness_bounded/bounded.expected |
Updates bounded summary output. |
kani-driver/src/session.rs |
Stores bounds in driver sessions. |
kani-driver/src/autoharness/mod.rs |
Passes, warns about, and reports bounds. |
kani-driver/src/args/autoharness_args.rs |
Defines the new CLI options and bound structure. |
kani-compiler/src/kani_middle/transform/automatic.rs |
Applies configured bounds during generation. |
kani-compiler/src/args.rs |
Accepts compiler-side bound flags. |
kani_metadata/src/lib.rs |
Centralizes shared default constants. |
docs/src/reference/experimental/autoharness.md |
Documents configuration and warnings. |
Review details
Suppressed comments (2)
kani-driver/src/args/autoharness_args.rs:43
- An explicitly supplied
--string-boundhas no effect without--bounded-arguments, but the parser accepts it without warning and bounded string harnesses remain skipped. Declare the dependency so this configuration fails clearly instead of being silently ignored.
#[arg(long, default_value_t = AUTOHARNESS_STR_BOUND, value_name = "N")]
kani-driver/src/args/autoharness_args.rs:49
- An explicitly supplied
--bounded-arbitrary-boundis likewise accepted but discarded when--bounded-argumentsis absent, leaving affected functions skipped. Require the enabling option to prevent this silent no-op.
#[arg(long, default_value_t = AUTOHARNESS_BOUNDED_ARBITRARY_BOUND, value_name = "N")]
- Files reviewed: 16/16 changed files
- Comments generated: 3
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Review follow-ups on the configurable bounds. The bound options had no effect unless --bounded-arguments was also passed, so a valid-looking command silently skipped every bounded harness. Make the dependency explicit, as `format` already does for `list` in the same struct, and cover all three directions with unit tests: the option alone is rejected, the option with --bounded-arguments parses, and a default does not stand in for the option being supplied. The unwind warning compared against --default-unwind only, but --unwind takes precedence when CBMC arguments are resolved, c.f. resolve_unwind_value. Automatic harnesses carry no unwind attribute, so those two are the whole precedence at this point. BoundedArbitrary's N is not a total element count: each implementation defines what its bound limits, and the derive passes the same N to every #[bounded] field independently. Report the bound without calling it an element limit. The new script test hit the autoharness default 60s harness timeout on slower CI runners, which the two existing autoharness tests already raise --harness-timeout to avoid.
|
@feliperodri the three review comments are addressed, along with the macOS CI failure.
CI. Rebased onto your merge of main. Locally: |
feliperodri
left a comment
There was a problem hiding this comment.
LGTM. Clean threading of the bounds through metadata → compiler → driver, and I like the requires = "bounded_arguments" relationship plus the unwind-bound warning and the bounds being reported in the summary. Good test and doc coverage. Thanks!
Description
--bounded-argumentsgenerates slice, string andBoundedArbitraryvalues upto fixed bounds of 16, 4 and 4. They were compile-time constants with no way to
override them, and the summary note did not state them, so a reader could not
tell what a bounded result actually covered.
This adds three options to the
autoharnesssubcommand:--slice-bound&[T],&mut [T]--string-bound&str, in bytes--bounded-arbitrary-boundBoundedArbitraryThe defaults are unchanged, so a run that does not pass them behaves as before.
The summary note now names the values the run used:
A bound at or above the effective unwinding bound leaves loops over that
argument partially unwound, so the result no longer holds up to the bound that
was asked for. Kani warns when that happens:
Context
The three defaults move to
kani_metadataaspub const. The driver printsthem and the compiler generates with them, so a copy in each crate would be free
to drift.
AUTOHARNESS_BOUNDED_ANY_BOUNDis renamedAUTOHARNESS_BOUNDED_ARBITRARY_BOUNDto match the new option and the trait itrefers to.
The driver passes the values to the compiler alongside
--autoharness-bounded-arguments. The compiler carries them onAnyModelsnext to
constructor_args, socall_kani_any_for_tyreads them where itpreviously read the constants.
Three notes on scope:
BoundedArbitraryboundhas the same reporting gap, so this makes it configurable as well.
--harness-timeoutas a consideration.This change does not address it. A larger bound costs more solver time and can
still exceed the default 60s harness timeout with no adjustment or warning.
values are stays open.
Option names are open, as the issue notes. The subcommand's own options carry no
autoharness-prefix (c.f.--bounded-arguments) while the compiler flags do,so these follow both conventions. Happy to rename.
Resolved issues
Resolves #4751
Testing
New test
tests/script-based-pre/cargo_autoharness_bounds, one function perbound. Each asserts that its argument never exceeds the bound and covers the
bound itself, run at
--slice-bound 2 --string-bound 2 --bounded-arbitrary-bound 2. The assertions fail at the defaults, so the testcatches a bound that is ignored as well as one that is applied but never
reached. A first
--listrun at--slice-bound 20exercises the warningwithout verifying.
cargo_autoharness_slicesandcargo_autoharness_boundedare updated for thenew note text, and confirm the defaults are unchanged.
Manual testing on x86_64 Linux:
cargo build-dev,cargo fmt --checkcargo clippy --workspace --tests -- -D warnings, and the same withRUSTFLAGS="--cfg=kani_sysroot"cargo test -p kani_metadata -p kani-drivercargo run -p compiletest -- --suite script-based-pre --mode execBy submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 and MIT licenses.