Skip to content

Autoharness: generate &Wtf8 values with unpaired surrogates - #4862

Merged
tautschnig merged 2 commits into
model-checking:mainfrom
srivatsansamraj:wtf8-surrogates
Sep 30, 2026
Merged

tautschnig merged 2 commits into
model-checking:mainfrom
srivatsansamraj:wtf8-surrogates

Conversation

@srivatsansamraj

Copy link
Copy Markdown
Contributor

&Wtf8 arguments now include unpaired surrogate code points. The model keeps the longest well-formed WTF-8 prefix of its nondeterministic storage, the way any_str_ref does for UTF-8. It no longer converts the output of the &str model.

WTF-8 differs from UTF-8 in one row of the byte table: after ED, the second byte may also be A0..=BF, which encodes a surrogate. One sequence stays excluded: a lead surrogate (ED A0..=AF ..) directly followed by a trail surrogate (ED B0..=BF ..). Well-formed WTF-8, which Wtf8::from_bytes_unchecked requires, writes that pair as the four-byte encoding of one supplementary code point, so the model ends the prefix there. Every well-formed string up to the bound is still generated: a string of length k arises from storage whose byte at k does not continue it.

core has no WTF-8 validator, so the check is written out in the model. Continuation bytes are checked by index, which leaves no inner loop for symbolic execution to unwind. With this model the three harnesses in cargo_autoharness_wtf8 take 10 to 11 s each, against 15 to 17 s with the &str-based one (one run each).

Tests:

  • tests/expected/wtf8-surrogates calls the model at a bound of 6, which holds two surrogates. It asserts that no lead surrogate is followed by a trail surrogate. It covers a string ending in a lead surrogate, one starting with a trail surrogate, and a trail followed by a lead. With the previous model the three covers are unsatisfiable, and without the pair check the assertion fails.
  • cargo_autoharness_wtf8 gains a cover for an unpaired surrogate, unsatisfiable before this change.
  • The docs no longer say surrogates are excluded.

This builds on #4809. Only the last commit is new here.

Resolves #4859

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@srivatsansamraj
srivatsansamraj requested review from a team as code owners September 24, 2026 20:40
@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 24, 2026
@feliperodri feliperodri added the Z-Autoharness Issue related to autoharness subcommand label Sep 25, 2026
@srivatsansamraj
srivatsansamraj force-pushed the wtf8-surrogates branch 2 times, most recently from f66e7bc to 0053120 Compare September 28, 2026 07:00
@feliperodri
feliperodri requested a balanced review from Copilot September 30, 2026 00:23

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.

Copilot review overview

🟢 Approval recommended

The implementation and regression coverage are sound, with only minor stale compiler comments remaining.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
What changed in this PR

Adds bounded autoharness generation for well-formed &Wtf8 values, including unpaired surrogates.

Changes:

  • Introduces a dedicated WTF-8 prefix validator and model.
  • Integrates the model into autoharness generation.
  • Adds regression tests and documentation updates.
File Description
tests/​script-based-pre/​cargo_autoharness_wtf8/​wtf8.sh Runs autoharness integration checks.
tests/​script-based-pre/​cargo_autoharness_wtf8/​wtf8.expected Defines expected verification output.
tests/​script-based-pre/​cargo_autoharness_wtf8/​src/​lib.rs Exercises generated &Wtf8 values.
tests/​script-based-pre/​cargo_autoharness_wtf8/​config.yml Configures the script-based test.
tests/​script-based-pre/​cargo_autoharness_wtf8/​Cargo.toml Defines the test crate.
tests/​expected/​wtf8-surrogates/​main.rs Verifies surrogate handling and well-formedness.
tests/​expected/​wtf8-surrogates/​expected Records expected surrogate-test results.
library/​kani/​src/​lib.rs Enables internal WTF-8 APIs.
library/​kani_core/​src/​arbitrary.rs Implements bounded WTF-8 generation.
kani-compiler/​src/​kani_middle/​transform/​automatic.rs Generates autoharness arguments through the new model.
kani-compiler/​src/​kani_middle/​mod.rs Recognizes core::wtf8::Wtf8.
kani-compiler/​src/​kani_middle/​kani_functions.rs Registers the WTF-8 model marker.
docs/​src/​reference/​experimental/​autoharness.md Documents bounded WTF-8 support.

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

Comment thread kani-compiler/src/kani_middle/mod.rs Resolved
@feliperodri feliperodri removed their assignment Sep 30, 2026
@feliperodri

Copy link
Copy Markdown
Member

@srivatsansamraj needs a rebase

The `&Wtf8` model now keeps the longest well-formed WTF-8 prefix of its
storage. Before, it converted the output of the `&str` model, so no
surrogate code point was ever generated.

The check follows the UTF-8 byte table, with `ED` also accepting
`A0..=BF`, and ends the prefix at a trail surrogate that directly follows
a lead surrogate, since well-formed WTF-8 writes that pair as one
four-byte sequence. Continuation bytes are checked by index, which leaves
no inner loop for symbolic execution to unwind.
@srivatsansamraj

Copy link
Copy Markdown
Contributor Author

Rebased onto main now that #4809 is in.

@tautschnig
tautschnig added this pull request to the merge queue Sep 30, 2026
Merged via the queue into model-checking:main with commit 4be7087 Sep 30, 2026
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-Autoharness Issue related to autoharness subcommand 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.

Autoharness: generate &Wtf8 values with unpaired surrogates

4 participants