Skip to content

[mypyc] Update docstrings of IR builder classes #18246

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 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading