Refactoring: Move heap handling to separate HeapSupporter and merge lots of resource-type specific code into general code#930
Merged
Conversation
…o separate heap interface
…r, adapted pred produce in fold
…orPerm evaluation
There was a problem hiding this comment.
Pull Request Overview
Refactors all direct heap interactions into a new HeapSupporter, centralizing heap initialization and chunk operations, and generalizes resource-specific handling into unified helper calls.
- Adds a
heapSupporterinstance to theVerifiertrait and replacesHeap()withheapSupporter.getEmptyHeap(...) - Introduces state utility methods (
isUsedAsTrigger,isQuantifiedResource,getFormalArgVars,getFormalArgDecls) inState.scala - Replaces resource-specific code in Producer, Consumer, PredicateSupporter, MagicWandSupporter, HavocSupporter, and Executor with generic
heapSupportercalls
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/scala/verifier/Verifier.scala | Added heapSupporter field and defaultHeapSupporter import |
| src/main/scala/supporters/functions/FunctionVerificationUnit.scala | Replaced Heap() with heapSupporter.getEmptyHeap |
| src/main/scala/supporters/PredicateVerificationUnit.scala | Ditto for predicate setup |
| src/main/scala/supporters/MethodSupporter.scala | Ditto for method verification unit |
| src/main/scala/supporters/CfgSupporter.scala | Ditto for CFG unit |
| src/main/scala/state/State.scala | Added trigger and quantified-resource utilities |
| src/main/scala/rules/QuantifiedChunkSupport.scala | Switched trigger checks to new isUsedAsTrigger |
| src/main/scala/rules/Producer.scala | Unified access predicate handling via heapSupporter |
| src/main/scala/rules/PredicateSupporter.scala | Delegated single/quantified produce to heapSupporter |
| src/main/scala/rules/MagicWandSupporter.scala | Updated heap initializations and chunk logic use heapSupporter |
| src/main/scala/rules/HavocSupporter.scala | Replaced raw heap updates with havocResource |
| src/main/scala/rules/Executor.scala | Replaced direct Heap() and chunk code with heapSupporter |
| src/main/scala/rules/Consumer.scala | Unified consume logic via heapSupporter |
| silver | Updated submodule commit |
Comments suppressed due to low confidence (4)
src/main/scala/state/State.scala:121
- Hardcoding "r" in getFormalArgDecls may drift out of sync with the
?rterm identifier. Consider using?r.id.namefor the LocalVarDecl name to ensure consistency between the AST variable and the internal term.
case _: ast.Field => Seq(ast.LocalVarDecl("r", ast.Ref)())
src/main/scala/rules/MagicWandSupporter.scala:368
- [nitpick] Calls to
getEmptyHeapare scattered (e.g. lines 242, 368, and 412). Consider computing it once and reusing theemptyHeapvariable in each block to avoid repeated invocations.
val emptyHeap = v.heapSupporter.getEmptyHeap(sLhs.program)
src/main/scala/rules/HavocSupporter.scala:46
- With the new
havocResourcepath, add unit tests covering both quantified and non-quantified resource havoc scenarios to ensure the refactored behavior matches the previous implementation.
evals(s0, havoc.exp.args(s0.program), _ => pve, v0)((s1, tRcvrs, _, v1) => {
src/main/scala/rules/MagicWandSupporter.scala:304
- [nitpick] The parameter name
sshadows the state variables used throughout this method, which can be confusing. Rename it (e.g.initialState) to avoid shadowing and improve readability.
def createWandChunkAndRecordResults(s: State,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactoring with two major goals:
HeapSupporter. TheProducer,Evaluator,Consumeretc. perform all the work they currently do and then hand it off to theHeapSupporterthe moment any interaction with heap chunks is needed. As a result, quantified resource case splits now happen only in saidHeapSupporter. Therefore it will be much simpler to change the heap representation (e.g. to SE-TR/Silicarbon) in the future without having to add new cases all over the place.ProducerandConsumerhave three separate cases for handling QPs for fields, predicates, and wands, even though the code in those cases is largely the same. Another example is the translation of resource triggers, for which there is currently a function for field triggers, one for predicate triggers, and one for wand triggers, which largely do the same thing. Additionally, there is lots of code all over the place that, for example, checks whether a resource is quantified, or extracts arguments from a resource access, or computes the parameters of a resource. This PR creates utility methods for such common functionality, and merges a lot of code that is currently specific to a resource type into more general code that works with any resource type.In the process, this PR also fixes a small issue with trigger translation where predicate and field triggers were treated differently for no good reason.