-
Notifications
You must be signed in to change notification settings - Fork 7
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
implementation of an AST -> SCFG transformer #114
Merged
Merged
Commits on Apr 19, 2024
-
implementation of an AST -> SCFG tranformer
AST: Python Abstract Synatx Tree (S)CFG: (Structured) Control Flow Graph Items to note for reviewers: * Most of changes are in the `ast_transforms.py` module which contains the meat of the implementation. * Temporary data structures are created for a pure AST based CFG (`ASTCFG`) with blocks that are writable. This made it much easier to implement the builder pattern. They can easily be converted to a SCFG using the `ASTCFG.to_SCFG()` function. * The `AST2SCFGTranformer` is stateful and is populated with housekeeping data structures post transform. * The tests are all in `test_ast_transforms.py`. They are of the usual format: Python function as input and serialized graph to compare to. * The tests also check the values of the unreachable and empty nodes that have been pruned from the CFG. * The for-loop decomposition is a bit involved, hence there is an extensive docstring to describe what it does. * Some minor changes had to be made to the `scfg.py` module to support displaying "broken" SCFGs during development. This makes it easier to visually debug the graph upon making programming mistakes. * The modules `basic_block.py` and `rendering.py` were modified to support construction and visualization of the `PythonASTBlock`, which is a new block type for the SCFG that contains a block derived from Python AST. * The central entrypoint is: `AST2CFG(function) -> SCFG `. This will turn a Python function into an SCFG. * A stub has been added for the invserse, SCFG -> AST transformer. Example: ```python from numba_rvsdg import AST2SCFG def fun(): ... scfg = AST2SCFG(fun) scfg.render() scfg.restructure() scfg.render() ```
Configuration menu - View commit details
-
Copy full SHA for d9a33f1 - Browse repository at this point
Copy the full SHA d9a33f1View commit details -
Configuration menu - View commit details
-
Copy full SHA for c1ec0cc - Browse repository at this point
Copy the full SHA c1ec0ccView commit details -
Configuration menu - View commit details
-
Copy full SHA for 7ae7668 - Browse repository at this point
Copy the full SHA 7ae7668View commit details -
Configuration menu - View commit details
-
Copy full SHA for 377d161 - Browse repository at this point
Copy the full SHA 377d161View commit details -
Configuration menu - View commit details
-
Copy full SHA for a84bdd8 - Browse repository at this point
Copy the full SHA a84bdd8View commit details -
remove break and continue nodes
This reduces the graph even more, since blocks with a single break or continue become empty blocks and are pruned
Configuration menu - View commit details
-
Copy full SHA for caa5ea2 - Browse repository at this point
Copy the full SHA caa5ea2View commit details
Commits on Apr 20, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 80ae78e - Browse repository at this point
Copy the full SHA 80ae78eView commit details -
bugfix: set jump targets after recursion
The jump_targets for the else-branch of the for-loop must be set after recursion, not before. Otherwise nested flow-control constructs in the else-branch will fail to codegen correctly, leading to a broken CFG with blocks that point to non-existing blocks. The test exposes this and demonstrates the fix is valid.
Configuration menu - View commit details
-
Copy full SHA for ca8fdca - Browse repository at this point
Copy the full SHA ca8fdcaView commit details
Commits on Apr 24, 2024
-
bugfix: continue from nested else
This test exposes a bug in a missing seal for using continue in the nested for-else clause. Specifically, one needs to have an else-clause with a series of linear statements and a continue to hit this. If you try to break, the break index will be the same as the exit index for the seal_inside_of_loop as the default_index is also the exit_index. So you can only hit this with exit_index. In that case the block with the continue does not point to the loop header but to the incorrect exit instead. The test has been constructed such that a potential reconstruction would also fail execution with an incorrect return value.
Configuration menu - View commit details
-
Copy full SHA for a497881 - Browse repository at this point
Copy the full SHA a497881View commit details -
Configuration menu - View commit details
-
Copy full SHA for dc64724 - Browse repository at this point
Copy the full SHA dc64724View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8d78bd3 - Browse repository at this point
Copy the full SHA 8d78bd3View commit details
Commits on Apr 25, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 8a119a4 - Browse repository at this point
Copy the full SHA 8a119a4View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4ab1cea - Browse repository at this point
Copy the full SHA 4ab1ceaView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6579173 - Browse repository at this point
Copy the full SHA 6579173View commit details -
Configuration menu - View commit details
-
Copy full SHA for b7908e5 - Browse repository at this point
Copy the full SHA b7908e5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3563570 - Browse repository at this point
Copy the full SHA 3563570View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7bb82cf - Browse repository at this point
Copy the full SHA 7bb82cfView commit details -
Configuration menu - View commit details
-
Copy full SHA for 040af33 - Browse repository at this point
Copy the full SHA 040af33View commit details -
Configuration menu - View commit details
-
Copy full SHA for adfbc51 - Browse repository at this point
Copy the full SHA adfbc51View commit details -
Configuration menu - View commit details
-
Copy full SHA for d3137c5 - Browse repository at this point
Copy the full SHA d3137c5View commit details
Commits on Apr 29, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 4b7d46b - Browse repository at this point
Copy the full SHA 4b7d46bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 41cc5e3 - Browse repository at this point
Copy the full SHA 41cc5e3View commit details
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.