Skip to content

Commit 04ffee1

Browse files
authored
[mypyc] Update docstrings of IR builder classes (#18246)
Having the documentation in class docstrings makes it easier to find.
1 parent 5082a22 commit 04ffee1

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

mypyc/irbuild/builder.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
"""Builder class used to transform a mypy AST to the IR form.
1+
"""Builder class to transform a mypy AST to the IR form.
22
3-
The IRBuilder class maintains transformation state and provides access
4-
to various helpers used to implement the transform.
5-
6-
The top-level transform control logic is in mypyc.irbuild.main.
7-
8-
mypyc.irbuild.visitor.IRBuilderVisitor is used to dispatch based on mypy
9-
AST node type to code that actually does the bulk of the work. For
10-
example, expressions are transformed in mypyc.irbuild.expression and
11-
functions are transformed in mypyc.irbuild.function.
3+
See the docstring of class IRBuilder for more information.
124
"""
135

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

155147

156148
class IRBuilder:
149+
"""Builder class used to construct mypyc IR from a mypy AST.
150+
151+
The IRBuilder class maintains IR transformation state and provides access
152+
to various helpers used to implement the transform.
153+
154+
mypyc.irbuild.visitor.IRBuilderVisitor is used to dispatch based on mypy
155+
AST node type to code that actually does the bulk of the work. For
156+
example, expressions are transformed in mypyc.irbuild.expression and
157+
functions are transformed in mypyc.irbuild.function.
158+
159+
Use the "accept()" method to translate individual mypy AST nodes to IR.
160+
Other methods are used to generate IR for various lower-level operations.
161+
162+
This class wraps the lower-level LowLevelIRBuilder class, an instance
163+
of which is available through the "builder" attribute. The low-level
164+
builder class doesn't have any knowledge of the mypy AST. Wrappers for
165+
some LowLevelIRBuilder method are provided for convenience, but others
166+
can also be accessed via the "builder" attribute.
167+
168+
See also:
169+
* The mypyc IR is defined in the mypyc.ir package.
170+
* The top-level IR transform control logic is in mypyc.irbuild.main.
171+
"""
172+
157173
def __init__(
158174
self,
159175
current_module: str,

mypyc/irbuild/ll_builder.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
"""A "low-level" IR builder class.
22
3-
LowLevelIRBuilder provides core abstractions we use for constructing
4-
IR as well as a number of higher-level ones (accessing attributes,
5-
calling functions and methods, and coercing between types, for
6-
example). The core principle of the low-level IR builder is that all
7-
of its facilities operate solely on the IR level and not the AST
8-
level---it has *no knowledge* of mypy types or expressions.
3+
See the docstring of class LowLevelIRBuiler for more information.
4+
95
"""
106

117
from __future__ import annotations
@@ -224,6 +220,22 @@
224220

225221

226222
class LowLevelIRBuilder:
223+
"""A "low-level" IR builder class.
224+
225+
LowLevelIRBuilder provides core abstractions we use for constructing
226+
IR as well as a number of higher-level ones (accessing attributes,
227+
calling functions and methods, and coercing between types, for
228+
example).
229+
230+
The core principle of the low-level IR builder is that all of its
231+
facilities operate solely on the mypyc IR level and not the mypy AST
232+
level---it has *no knowledge* of mypy types or expressions.
233+
234+
The mypyc.irbuilder.builder.IRBuilder class wraps an instance of this
235+
class and provides additional functionality to transform mypy AST nodes
236+
to IR.
237+
"""
238+
227239
def __init__(self, errors: Errors | None, options: CompilerOptions) -> None:
228240
self.errors = errors
229241
self.options = options

0 commit comments

Comments
 (0)