Add "Heap reference monotone" post condition for procedures that modify the Heap#1099
Add "Heap reference monotone" post condition for procedures that modify the Heap#1099thanhnguyen-aws wants to merge 8 commits intostrata-org:mainfrom
Conversation
|
@keyboardDrummer-bot Please rewrite and add more details to the PR description. |
|
I've rewritten the PR description. Key improvements:
|
|
|
||
| procedure modifyContainerWithoutPermission1(c: Container, d: Container) | ||
| // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: modifies clause does not hold | ||
| // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: modifies clause could not be proved |
There was a problem hiding this comment.
This error message changed from "modifies clause does not hold" to "modifies clause could not be proved". The former means the SMT solver found a counterexample; the latter means it timed out or returned unknown.
This is a diagnostic quality regression caused by the additional monotonicity postcondition making the VC harder for the solver. The same regression occurs at lines 130 and 155.
Please investigate whether the solver timeout can be avoided — e.g., by increasing the timeout for these VCs, or by structuring the postcondition differently so it doesn't interfere with the solver's ability to find counterexamples for unrelated assertions.
| @@ -0,0 +1,7 @@ | |||
| unknown location: ✅ pass - Heap reference counter monotone | |||
There was a problem hiding this comment.
The unknown location prefix confirms that the synthesized postcondition has no source location. This will be confusing for users when the monotonicity check fails — they won't know which procedure it relates to.
Also: this test has two Heap reference counter monotone results (one for ClassA@__init__ and one for __main__). In a program with many classes, this could produce a lot of noise. Consider whether the monotonicity postcondition should be suppressed from user-facing output (e.g., by marking it as an internal/infrastructure check).
Co-authored-by: Michael Tautschnig <mt@debian.org>
Issue #, if available: #1098
Problem
When two distinct class instances are allocated on the heap, the analyzer cannot prove that their heap references are different. For example:
Root cause
During the heap-parameterization pass (
HeapParameterization.lean), every procedure that writes to the heap is rewritten to accept an input heap ($heap_in) and produce an output heap ($heap). However, there was no postcondition constraining the relationship between the two heaps' internal reference counters. Without such a constraint, the verifier cannot determine that references returned by separate allocations are distinct —a1anda2could be assigned the same heap reference, makinga1.val != a2.valunprovable.Solution
This PR injects a "heap reference counter monotone" postcondition into every heap-writing procedure during the
heapTransformProcedurepass inHeapParameterization.lean.How it works
Three new expressions are constructed before the body match:
inHeapRefHeap..nextReference!($heap_in)outHeapRefHeap..nextReference!($heap)monoCondoutHeapRef >= inHeapRefConditionasserting the counter never decreases, with summary"Heap reference counter monotone"This
monoCondis prepended to the postcondition list of bothOpaqueandAbstractbody variants. The other body kinds are unaffected:Transparent— exposes its full implementation to the verifier, which can derive the monotonicity property directly from the body.External— has no heap parameters, so the postcondition does not apply.The postcondition tells the verifier that each heap-writing call advances (or at least preserves) the heap's reference counter. Since each allocation increments this counter, references obtained from different calls are guaranteed to be distinct.
Changes
Strata/Languages/Laurel/HeapParameterization.leanmonoCondand prepend it toOpaqueandAbstractpostcondition listsStrataTest/Languages/Python/tests/test_heap_reference_monotone.pyClassAinstances with different values, assertinga1.val != a2.valStrataTest/Languages/Python/run_py_analyze_sarif.pyStrataTest/Languages/Python/expected_laurel/test_heap_reference_monotone.expectedStrataTest/Languages/Python/expected_interpret/test_heap_reference_monotone.expectedexpected_laurel/*.expectedfilesTesting
test_heap_reference_monotone.py): The motivating example from Python Class objects does not have unique Heap reference #1098. TwoClassAinstances are allocated with different values, andassert a1.val != a2.valis verified successfully — the assertion now passes thanks to the monotonicity postcondition establishing thata1anda2have distinct heap references.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.