|
| 1 | +/- |
| 2 | + Copyright Strata Contributors |
| 3 | +
|
| 4 | + SPDX-License-Identifier: Apache-2.0 OR MIT |
| 5 | +-/ |
| 6 | + |
| 7 | +/- |
| 8 | +Perf / regression: the array-theory frame is not merely faster, it is more |
| 9 | +complete on heap-heavy code. |
| 10 | +
|
| 11 | +`stress` makes a deep chain of opaque heap-modifying calls on freshly allocated |
| 12 | +objects, then asserts that an object allocated *before* the chain is untouched. |
| 13 | +
|
| 14 | + - Under the `∀` frame (array theory off) the solver cannot instantiate the |
| 15 | + quantified frame across the whole chain: the assertion "could not be proved". |
| 16 | + This is a definite verdict in ~2s, not a wall-clock timeout. |
| 17 | + - Under the quantifier-free frame (`--use-array-theory`) the same assertion |
| 18 | + verifies: each step is a `store` on a single row, so the read of the |
| 19 | + untouched object is a pure array rewrite with nothing to instantiate. |
| 20 | +
|
| 21 | +The two blocks are identical apart from `useArrayTheory`. |
| 22 | +
|
| 23 | +Note: the `∀` outcome depends on the SMT solver's quantifier heuristics. If a |
| 24 | +future solver discharges it, the annotation below must be updated. |
| 25 | +-/ |
| 26 | + |
| 27 | +import StrataTest.Util.TestLaurel |
| 28 | + |
| 29 | +open StrataTest.Util |
| 30 | +open Strata |
| 31 | + |
| 32 | +-- ∀ frame (array theory off): the chain defeats quantifier instantiation. |
| 33 | +#eval testLaurel |
| 34 | + (options := { defaultLaurelTestOptions with |
| 35 | + translateOptions := { defaultLaurelTestOptions.translateOptions with useArrayTheory := false }, |
| 36 | + verifyOptions := { defaultLaurelTestOptions.verifyOptions with useArrayTheory := false } }) <| |
| 37 | +#strata |
| 38 | +program Laurel; |
| 39 | +composite Container { |
| 40 | + var value: int |
| 41 | +} |
| 42 | + |
| 43 | +procedure modifyOne(c: Container) |
| 44 | + opaque |
| 45 | + modifies c; |
| 46 | + |
| 47 | +procedure stress() |
| 48 | + opaque |
| 49 | + modifies * |
| 50 | +{ |
| 51 | + var target: Container := new Container; |
| 52 | + var x: int := target#value; |
| 53 | + var c0: Container := new Container; modifyOne(c0); |
| 54 | + var c1: Container := new Container; modifyOne(c1); |
| 55 | + var c2: Container := new Container; modifyOne(c2); |
| 56 | + var c3: Container := new Container; modifyOne(c3); |
| 57 | + var c4: Container := new Container; modifyOne(c4); |
| 58 | + var c5: Container := new Container; modifyOne(c5); |
| 59 | + var c6: Container := new Container; modifyOne(c6); |
| 60 | + var c7: Container := new Container; modifyOne(c7); |
| 61 | + var c8: Container := new Container; modifyOne(c8); |
| 62 | + var c9: Container := new Container; modifyOne(c9); |
| 63 | + var c10: Container := new Container; modifyOne(c10); |
| 64 | + var c11: Container := new Container; modifyOne(c11); |
| 65 | + var c12: Container := new Container; modifyOne(c12); |
| 66 | + var c13: Container := new Container; modifyOne(c13); |
| 67 | + var c14: Container := new Container; modifyOne(c14); |
| 68 | + var c15: Container := new Container; modifyOne(c15); |
| 69 | + var c16: Container := new Container; modifyOne(c16); |
| 70 | + var c17: Container := new Container; modifyOne(c17); |
| 71 | + var c18: Container := new Container; modifyOne(c18); |
| 72 | + var c19: Container := new Container; modifyOne(c19); |
| 73 | + assert x == target#value |
| 74 | +//^^^^^^^^^^^^^^^^^^^^^^^^ error: assertion could not be proved |
| 75 | +}; |
| 76 | +#end |
| 77 | + |
| 78 | +-- Quantifier-free frame (--use-array-theory): the same program verifies. |
| 79 | +#eval testLaurel |
| 80 | + (options := { defaultLaurelTestOptions with |
| 81 | + translateOptions := { defaultLaurelTestOptions.translateOptions with useArrayTheory := true }, |
| 82 | + verifyOptions := { defaultLaurelTestOptions.verifyOptions with useArrayTheory := true } }) <| |
| 83 | +#strata |
| 84 | +program Laurel; |
| 85 | +composite Container { |
| 86 | + var value: int |
| 87 | +} |
| 88 | + |
| 89 | +procedure modifyOne(c: Container) |
| 90 | + opaque |
| 91 | + modifies c; |
| 92 | + |
| 93 | +procedure stress() |
| 94 | + opaque |
| 95 | + modifies * |
| 96 | +{ |
| 97 | + var target: Container := new Container; |
| 98 | + var x: int := target#value; |
| 99 | + var c0: Container := new Container; modifyOne(c0); |
| 100 | + var c1: Container := new Container; modifyOne(c1); |
| 101 | + var c2: Container := new Container; modifyOne(c2); |
| 102 | + var c3: Container := new Container; modifyOne(c3); |
| 103 | + var c4: Container := new Container; modifyOne(c4); |
| 104 | + var c5: Container := new Container; modifyOne(c5); |
| 105 | + var c6: Container := new Container; modifyOne(c6); |
| 106 | + var c7: Container := new Container; modifyOne(c7); |
| 107 | + var c8: Container := new Container; modifyOne(c8); |
| 108 | + var c9: Container := new Container; modifyOne(c9); |
| 109 | + var c10: Container := new Container; modifyOne(c10); |
| 110 | + var c11: Container := new Container; modifyOne(c11); |
| 111 | + var c12: Container := new Container; modifyOne(c12); |
| 112 | + var c13: Container := new Container; modifyOne(c13); |
| 113 | + var c14: Container := new Container; modifyOne(c14); |
| 114 | + var c15: Container := new Container; modifyOne(c15); |
| 115 | + var c16: Container := new Container; modifyOne(c16); |
| 116 | + var c17: Container := new Container; modifyOne(c17); |
| 117 | + var c18: Container := new Container; modifyOne(c18); |
| 118 | + var c19: Container := new Container; modifyOne(c19); |
| 119 | + assert x == target#value |
| 120 | +}; |
| 121 | +#end |
0 commit comments