-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Add a simple irchecking analysis system #11283
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
Conversation
Adds a new module for performing analysis checks on ir as several bugs in mypy had underlying issues in which the ir produced by mypy was invalid and guaranteed to have issues at runtime. For now the checks are relatively simple - the only two supported are some validity on basic blocks: that they terminate and that control ops reference a basic block within the same function. Error reporting is non-existent and instead we are just testing that the resulting error datatypes are what we expect. In the future we will need to incorporate the errors into the pretty-printer so that we can produce an ir dump that references where the error actually is. In addition it would be useful if we had an ir parser so we could have a test framework similar to other parts of mypyc in which we simply write the IR in text format instead of constructing the IR ast from within python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few nits.
mypyc/analysis/ircheck.py
Outdated
|
||
def check_funcdef(fn: FuncIR) -> List[FnError]: | ||
"""Check a list of basic blocks (e.g. from a function definition) in surrounding | ||
context (e.g. args). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring seems out of date.
For consistency, maybe name check_func_ir
(funcdef usually means the corresponding mypy AST node).
mypyc/analysis/ircheck.py
Outdated
pass | ||
|
||
|
||
def check_funcdef_and_crash(fn: FuncIR) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits: The implies that this crashes unconditionally, and funcdef sounds like mypy ast terminology. Maybe something like check_ir_and_raise_on_error
?
@@ -0,0 +1,164 @@ | |||
from typing import List, Union |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a short module-level docstring.
Also flake8 is failing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
* Introduce basic ir analysis checks Adds a new module for performing analysis checks on ir as several bugs in mypy had underlying issues in which the ir produced by mypy was invalid and guaranteed to have issues at runtime. For now the checks are relatively simple - the only two supported are some validity on basic blocks: that they terminate and that control ops reference a basic block within the same function. Error reporting is non-existent and instead we are just testing that the resulting error datatypes are what we expect. In the future we will need to incorporate the errors into the pretty-printer so that we can produce an ir dump that references where the error actually is. In addition it would be useful if we had an ir parser so we could have a test framework similar to other parts of mypyc in which we simply write the IR in text format instead of constructing the IR ast from within python. * Integrate ircheck analysis into ir tests
Adds a new module for performing analysis checks on ir as several bugs
in mypy had underlying issues in which the ir produced by mypy was
invalid and guaranteed to have issues at runtime.
For now the checks are relatively simple - the only two supported are
some validity on basic blocks: that they terminate and that control
ops reference a basic block within the same function.
In addition it would be useful if we had an ir parser so we could have a
test framework similar to other parts of mypyc in which we simply write
the IR in text format instead of constructing the IR ast from within
python.
The first commit here implements the checking but not the presentation;
the second implements basic presentation and integrates it into the test framework.