Skip to content

Add Arbitrary implementation for std::ascii::EscapeDefault - #4782

Open
acearyanarun wants to merge 2 commits into
model-checking:mainfrom
acearyanarun:arbitrary-ascii-escape-default
Open

Add Arbitrary implementation for std::ascii::EscapeDefault#4782
acearyanarun wants to merge 2 commits into
model-checking:mainfrom
acearyanarun:arbitrary-ascii-escape-default

Conversation

@acearyanarun

Copy link
Copy Markdown

Summary

Adds an Arbitrary implementation for std::ascii::EscapeDefault.

EscapeDefault was previously unsupported by Autoharness because Kani could not generate arbitrary values for the type. This implementation constructs a valid EscapeDefault and nondeterministically consumes elements from the front and back so that Kani can represent fresh, partially consumed, and exhausted iterator states.

This allows Autoharness to automatically generate and verify harnesses for functions that take std::ascii::EscapeDefault as an argument.

Testing

Added a Kani proof that checks generated EscapeDefault values have at most four remaining elements and confirms that all remaining lengths from 0 through 4 are reachable.

Local verification with CBMC 6.11.0:

  • 0 verification failures
  • 5 of 5 cover properties satisfied
  • VERIFICATION:- SUCCESSFUL

Also added a script-based Autoharness regression test confirming that:

consume_escape_default(std::ascii::EscapeDefault)

is selected by Autoharness and successfully verified.

The script-based-pre regression suite was also run successfully during development.

Motivation

The Autoharness analyzer reports functions being skipped when argument types do not implement Arbitrary. Adding support for EscapeDefault removes that limitation for this type and increases the set of functions eligible for automatic verification.

@acearyanarun
acearyanarun requested review from a team as code owners September 7, 2026 00:29
@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 7, 2026
@acearyanarun

Copy link
Copy Markdown
Author

@Tianshu-Huang @CYJ904 @wodex1nhaoIeng @srivatsansamraj

Opened the Kani PR for the std::ascii::EscapeDefault Arbitrary implementation. Feel free to take a look when you get a chance.

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.

🟡 Changes recommended

The proof must cover observable front- and back-consumed states to protect the core two-ended generation logic.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds Arbitrary support for std::ascii::EscapeDefault, enabling Autoharness verification for functions using this iterator.

Changes:

  • Generates fresh, partially consumed, and exhausted iterator states.
  • Adds Kani proof and Autoharness regression coverage.
  • Requires direction-specific coverage for front and back consumption.
File summaries
File Description
tests/script-based-pre/autoharness_ascii_escape_default/src/lib.rs Adds the Autoharness target function.
tests/script-based-pre/autoharness_ascii_escape_default/escape_default.sh Runs and filters Autoharness output.
tests/script-based-pre/autoharness_ascii_escape_default/escape_default.expected Defines expected successful output.
tests/script-based-pre/autoharness_ascii_escape_default/config.yml Configures the regression test.
tests/script-based-pre/autoharness_ascii_escape_default/Cargo.toml Defines the test crate.
tests/kani/ascii_escape_default.rs Tests remaining lengths, but lacks direction-specific state coverage.
library/kani/src/arbitrary.rs Implements Arbitrary for EscapeDefault.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +15 to +19
kani::cover!(count == 0);
kani::cover!(count == 1);
kani::cover!(count == 2);
kani::cover!(count == 3);
kani::cover!(count == 4);
@CYJ904

CYJ904 commented Sep 7, 2026

Copy link
Copy Markdown

Verified locally on CBMC 6.11.0 — matches the PR description (VERIFICATION:- SUCCESSFUL, 5/5 cover properties, ~0.78s).

Two suggestions, building on Copilot's comment:

  1. Direction-specific coverage: current covers only check total remaining count (0–4), so front=2,back=0 and front=1,back=1 are indistinguishable. Worth adding covers for mixed front+back states specifically, since that's the logic actually being tested.

  2. Content correctness: the proof checks a count invariant but not that remaining elements match expected values after consumption — a next()/next_back() bookkeeping bug could still pass if the count happens to stay in bounds.

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.

3 participants