-
Notifications
You must be signed in to change notification settings - Fork 78
Do not unfold the AST on deep-copying #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
merkste
wants to merge
8
commits into
prismmodelchecker:master
Choose a base branch
from
merkste:DAG-aware-copying
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
dd1c63e to
84b0b5c
Compare
39c5bb2 to
acb294c
Compare
Contributor
Author
|
If required, we could easily implement a new method |
acb294c to
ef39b93
Compare
9255921 to
4008148
Compare
After certain replacements, e.g., formula substitution, the AST becomes a directed acyclic graph. Most often it is not required to visit a node of this DAG multiply times. The new class DAGVisitor keeps track of the nodes already seen and visits each node only once. The class DAGVisitor is inserted between ASTVisitor and ASTTraverse and ASTTraverseModify without changing the behavior of their subclasses.
94eb434 to
3b35763
Compare
Contributor
Author
|
I've rearranged and split some commits to make the PR more approachable. |
3b35763 to
6e4ea8c
Compare
Rename the method visit to visitNow in existing visitor classes. This makes them traverse the AST without visiting nodes multiple times.
6e4ea8c to
944aff4
Compare
Implement Object#clone to support shallow copies of ASTElements. Overrides should take care to also clone inner container types, such as lists and vectors.
After certain replacements, e.g., formula substitution, the AST becomes a directed acyclic graph. On copying wewant to preserve this structure. The identification of duplicates is non-local since duplicates may appear everywhere in the AST/DAG. The implementation introduces a new visitor to keep track of duplicate nodes and makes copying a two-step process: 1. Cloning a node and its internal container types via Object::clone 2. Deep-copying AST child nodes using the visitor
944aff4 to
802a5a6
Compare
ca12ca0 to
6bf73df
Compare
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.
After certain replacements, e.g., formula substitution, the AST becomes a directed acyclic graph. On copying we want to preserve this structure. The identification of duplicates is non-local since duplicates may appear everywhere in the AST/DAG.
Significance
Certain more complex models that feature nested formulas cannot be handled with reasonable time and memory bounds with the current traversal and copying implementation. In one case-study this makes the difference between building and model-checking in a few seconds and running out of time and 16g memory right after parsing the input file. Even syntax-highlighting does not work at all.
Structure
This PR consists of three logical parts.
Changes to ASTTraverse / ASTTraverseModify
Part 2 introduces a new root class for AST traversal,
DAGVisitorthat keeps track of visited nodes. The methodvisitnow visits only nodes never seen before. If a new node is seen, the newly introduced methodvisitNowis called. Subclasses have to override this method instead ofvisitto implement their behavior. If they decide to visit node, they should callvisit. There are no changes tovisitPreandvisitPostFor the complete ASTTraverse and ASTTraverseModify hierarchy this is already done. Hence adaption of visitors in existing branches is done by simply renaming their implementation ofvisittovisitNow. Furthermore, if needed, the duplicate identification can be turned off which leads to the old behavior of visiting nodes multiple times.For details, please see commits
Changes to deep copying
Part 3 splits deep-copying into two steps. First, creating a shallow copy of an AST node by calling
clone. Second, copying sub-nodes of the clone usingdeepCopywith the DeepCopy visitor.This is already implemented for all ASTElement classes. Newly created ASTElements are only required to provide an implementation of
cloneanddeepCopy(DeepCopy copier)instead of the old monolithicdeepCopy(). Nothing else changes.For details, please see commit