Skip to content

Commit

Permalink
[mypyc] Update docstrings of IR builder classes (#18246)
Browse files Browse the repository at this point in the history
Having the documentation in class docstrings makes it easier to find.
  • Loading branch information
JukkaL authored Dec 5, 2024
1 parent 5082a22 commit 04ffee1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
36 changes: 26 additions & 10 deletions mypyc/irbuild/builder.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
"""Builder class used to transform a mypy AST to the IR form.
"""Builder class to transform a mypy AST to the IR form.
The IRBuilder class maintains transformation state and provides access
to various helpers used to implement the transform.
The top-level transform control logic is in mypyc.irbuild.main.
mypyc.irbuild.visitor.IRBuilderVisitor is used to dispatch based on mypy
AST node type to code that actually does the bulk of the work. For
example, expressions are transformed in mypyc.irbuild.expression and
functions are transformed in mypyc.irbuild.function.
See the docstring of class IRBuilder for more information.
"""

from __future__ import annotations
Expand Down Expand Up @@ -154,6 +146,30 @@ class UnsupportedException(Exception):


class IRBuilder:
"""Builder class used to construct mypyc IR from a mypy AST.
The IRBuilder class maintains IR transformation state and provides access
to various helpers used to implement the transform.
mypyc.irbuild.visitor.IRBuilderVisitor is used to dispatch based on mypy
AST node type to code that actually does the bulk of the work. For
example, expressions are transformed in mypyc.irbuild.expression and
functions are transformed in mypyc.irbuild.function.
Use the "accept()" method to translate individual mypy AST nodes to IR.
Other methods are used to generate IR for various lower-level operations.
This class wraps the lower-level LowLevelIRBuilder class, an instance
of which is available through the "builder" attribute. The low-level
builder class doesn't have any knowledge of the mypy AST. Wrappers for
some LowLevelIRBuilder method are provided for convenience, but others
can also be accessed via the "builder" attribute.
See also:
* The mypyc IR is defined in the mypyc.ir package.
* The top-level IR transform control logic is in mypyc.irbuild.main.
"""

def __init__(
self,
current_module: str,
Expand Down
24 changes: 18 additions & 6 deletions mypyc/irbuild/ll_builder.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
"""A "low-level" IR builder class.
LowLevelIRBuilder provides core abstractions we use for constructing
IR as well as a number of higher-level ones (accessing attributes,
calling functions and methods, and coercing between types, for
example). The core principle of the low-level IR builder is that all
of its facilities operate solely on the IR level and not the AST
level---it has *no knowledge* of mypy types or expressions.
See the docstring of class LowLevelIRBuiler for more information.
"""

from __future__ import annotations
Expand Down Expand Up @@ -224,6 +220,22 @@


class LowLevelIRBuilder:
"""A "low-level" IR builder class.
LowLevelIRBuilder provides core abstractions we use for constructing
IR as well as a number of higher-level ones (accessing attributes,
calling functions and methods, and coercing between types, for
example).
The core principle of the low-level IR builder is that all of its
facilities operate solely on the mypyc IR level and not the mypy AST
level---it has *no knowledge* of mypy types or expressions.
The mypyc.irbuilder.builder.IRBuilder class wraps an instance of this
class and provides additional functionality to transform mypy AST nodes
to IR.
"""

def __init__(self, errors: Errors | None, options: CompilerOptions) -> None:
self.errors = errors
self.options = options
Expand Down

0 comments on commit 04ffee1

Please sign in to comment.