Commit 5fe1929
Add array_read snapshot regression
The suspected missing PAL feature was support for relating a value read from a C array back to the logical `array_value_of` snapshot of that array. The motivating shape is code like `entry_t entry = entries[i]` or `uint32_t x = entries[i].x`, followed by ghost code that proves a property of the concrete local from a precondition quantified over `array_value_of entries`.
The new `array_read_snapshot.c` test captures that requirement directly. It defines `entries_ok` only over `array_value_of entries`, then checks two source patterns: copying a whole struct out of an `_array`, and copying a field out of an `_array` element. The post-read ghost assertions intentionally mention only the concrete locals, not the `Seq.index` expression. This makes the test a focused regression for whether PAL's generated Pulse preserves the connection between the C local and the array snapshot.
After reducing the example, no emitter extension was needed. PAL's ordinary assignment translation emits the direct form `var_entry := array_read entries i` (and, for fields, projection from that direct read). Pulse can use the `array_read` postcondition through that assignment: the read result rewrites to `Some?.v (Seq.index (array_value_of entries) i)`, and the mutable local receives exactly that value. Therefore the quantified `entries_ok (array_value_of entries) count` precondition instantiates at the loop index and proves the assertions about the concrete locals.
This commit keeps that behavior covered by a regression test and documents the lesson in the test source: do not add extra generated pure assertions or a second temporary binding for this case. The important restriction remains that this works for direct `_array` reads; `_arrayptr` reads do not expose the same parent-array snapshot relation and are not covered by this test.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 3f11c61 commit 5fe1929
1 file changed
Lines changed: 101 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
0 commit comments