Skip to content
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

Closed
iritkatriel opened this issue Jun 6, 2022 · 5 comments
Closed

direct unit tests for compiler optimisations #405

iritkatriel opened this issue Jun 6, 2022 · 5 comments
Assignees

Comments

@iritkatriel
Copy link
Collaborator

iritkatriel commented Jun 6, 2022

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).

@iritkatriel iritkatriel self-assigned this Jun 6, 2022
@iritkatriel iritkatriel moved this to In Progress in Fancy CPython Board Jun 6, 2022
@ericsnowcurrently
Copy link
Collaborator

@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.

@iritkatriel
Copy link
Collaborator Author

@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).

@gvanrossum
Copy link
Collaborator

@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.

Hm, I don't recall doing that. :-( But I do find this an interesting idea.

@iritkatriel
Copy link
Collaborator Author

Issue for exposing the virtual opcodes in python: python/cpython#94216

@iritkatriel iritkatriel moved this from In Progress to In Review in Fancy CPython Board Aug 30, 2022
@iritkatriel iritkatriel moved this from In Review to In Progress in Fancy CPython Board Aug 31, 2022
@iritkatriel iritkatriel moved this from In Progress to Done in Fancy CPython Board Sep 1, 2022
@iritkatriel
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

3 participants