-
Notifications
You must be signed in to change notification settings - Fork 49
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
direct unit tests for compiler optimisations #405
Comments
@gvanrossum, didn't you have a tool or proof-of-concept branch from a while back (a year ago?) that did something like rebuilding basic blocks from instructions? IIRC, it was part of one of your early experiments. |
@ericsnowcurrently I think this step may be easier now than it used to be, because the compiler detects end-of-basicblock automatically (it used to be defined explicitly in the compiler_* functions). |
Hm, I don't recall doing that. :-( But I do find this an interesting idea. |
Issue for exposing the virtual opcodes in python: python/cpython#94216 |
This is done now, we have the plumbing to write such tests in Lib/test/support/bytecode_helper.py (CodegenTestCase, CfgOptimizationTestCase) and a few tests of each type. We will be adding more tests, but I consider this issue as resolved. |
The compiler's optimisation steps are unit tested only indirectly, because we don't have a way to call them from python. So things like test_peepholer input some python code, and check for evidence of the optimisation in the bytecode that it is compiled to. As the compiler changes, the intention of the test may no longer be fulfilled (the input to the optimiser is no longer what we intended it to be), but we wouldn't know. And when we want to write a test to cover an input that we don't know how to make the compiler generate, we can't do it.
The idea here is to create a python API that allows us to input a sequence of bytecode instructions from a unit test, and get the instructions after the optimisations. The test harness would need to construct basicblocks from the instruction sequence (because that's what the optimiser wants) and to convert the blocks in the output back to an instruction sequence.
We can construct similar test for the AST optimiser (currently I believe it just does const folding, but it could do more).
The text was updated successfully, but these errors were encountered: