Add Arbitrary impl for char EscapeUnicode - #4784
Open
wodex1nhaoIeng wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The implementation constructively produces valid iterator states and is covered by focused regression tests.
Pull request overview
Adds Arbitrary support for valid, reachable EscapeUnicode iterator states.
Changes:
- Generates states by nondeterministically consuming escaped characters.
- Adds direct and autoharness regression coverage.
File summaries
| File | Description |
|---|---|
library/kani/src/arbitrary.rs |
Implements Arbitrary for EscapeUnicode. |
tests/kani/char_escape_unicode.rs |
Verifies all possible remaining lengths. |
tests/script-based-pre/autoharness_char_escape_unicode/src/lib.rs |
Adds an autoharness target. |
tests/script-based-pre/autoharness_char_escape_unicode/escape_unicode.sh |
Runs and filters the autoharness result. |
tests/script-based-pre/autoharness_char_escape_unicode/escape_unicode.expected |
Defines expected successful output. |
tests/script-based-pre/autoharness_char_escape_unicode/config.yml |
Configures the script-based test. |
tests/script-based-pre/autoharness_char_escape_unicode/Cargo.toml |
Defines the test crate. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds an
Arbitraryimplementation forstd::char::EscapeUnicode.The implementation generates valid iterator states by starting from an arbitrary
char, callingescape_unicode(), and then nondeterministically consuming a valid number of elements from the front. This lets Kani generate reachableEscapeUnicodestates without constructing the standard library iterator internals directly.Motivation
Automatic harness generation needs to synthesize values for function parameters. Functions that take
std::char::EscapeUnicodecould not be handled because Kani did not know how to generate arbitrary values of that type.This PR adds direct coverage for
kani::any::<std::char::EscapeUnicode>()and a script-based autoharness regression test for a function that takesEscapeUnicodeas an argument.Testing
Ran:
cargo run -p compiletest -- --suite kani --mode kani --force-rerun char_escape_unicode cargo run -p compiletest -- --suite script-based-pre --mode exec --force-rerun autoharness_char_escape_unicode