Translate literal bytes to Coma - #2198
Conversation
Creusot failed to analyze Rust programs using literal bytes as they were not translated in the generated Coma files. Introduce a new Coma function `of_seq` in `Slice` modules to enable crafting a pure WhyML term with the contents of the literal bytes. Fixes: creusot-rs#2161 Fixes: df21379 ("Partially fix translation of non-trivial format strings")
Use the new Coma function `Slice.of_seq` to translate arrays. This removes all uses of `Any` statements in the generated Coma code.
|
I asked Claude Code (model Sonnet 4.6) to take a look and it emitted a very reasonable diagnostic:
At first, I had trouble with this explanation, as I was believing that
Therefore Why3 generates a type-invariant axiom I am therefore now looking into ways to define a pure function ( Btw, it would be much simpler if Coma/WhyML had a way to instantiate record types with invariant, as the condition here is very simple to prove (it is "some length constant is below the |
That is wrong. Why3 generates once and for all an axiom Instead, I think the problem is that sequenc literals in Why3 are translated with a combination of The core of the problem is that support of sequences in Why3 is not very good. At some point I thought it was because Why3 is not using native SMTLib support of sequences, but then I tried to port Why3 sequences to SMTLib, and a whole lot of proofs broke in the test suite of Why3... What should we do ? Perhaps we could find a better encoding of sequence literals in Why3, based on axioms like those we were adding before this PR??? |
Essentially, such a syntax would be encoded just like |
Creusot failed to analyze Rust programs using literal bytes as they were not translated in the generated Coma files. Introduce a new Coma function
of_seqinSlicemodules to enable crafting a pure WhyML term with the contents of the literal bytes.Use this new Coma function
Slice.of_seqto translate arrays as well.This Pull Request follows a discussion in issue #2161 where several approaches were suggested. It adds a function and an axiom (which is hopefully sound) to the prelue:
There is observable drawback: some tests now fail with timeouts. On my host, I observed that
should_succeed/slices/03_stdtimes out after the first commit (which only introducesof_seqand the translation of literal bytes, not modifying anything else). More precisely, using only the prelude changes from the latest commit in branchmasterfails:With
prelude-of_seq.patchcontaining:... The test fails:
Adding
--time 5(to thecargo testcommand) fixes the test, andtests/should_succeed/slices/03_std/proof.jsonshows that Z3 takes 10 times more time to achieve a proof:{ "tactic": "split_vc", - "children": [ { "prover": "z3", "time": 0.38 } ] + "children": [ { "prover": "z3", "time": 3.8 } ] },This happens in the test
check_iterincreusot/tests/should_succeed/slices/03_std.rs
Lines 17 to 18 in b51999c
So there is currently a strong performance regression caused by the introduction of function
of_seqand axiomof_seq_elts, even when not using the function. This regression becomes all the more visible with the second commit of this Pull Request, which modifies how Rust arrays are translated: this makes more tests time out.Fixes: #2161