Skip to content

[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

Merged
merged 3 commits into from
Nov 4, 2021
Merged

Conversation

jhance
Copy link
Collaborator

@jhance jhance commented Oct 6, 2021

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.

jhance added 2 commits October 6, 2021 10:16
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.
Copy link
Collaborator

@JukkaL JukkaL left a 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.


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).
Copy link
Collaborator

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

pass


def check_funcdef_and_crash(fn: FuncIR) -> None:
Copy link
Collaborator

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
Copy link
Collaborator

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.

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 7, 2021

Also flake8 is failing.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@JukkaL JukkaL merged commit ad7e353 into python:master Nov 4, 2021
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants