GitHub

aot_compiler

API reference for aot_compiler.

Schema decoders written ahead of time as a Python module (Effect's SchemaAOTCompiler).

compile(targets) gives the source of a module exporting install(asts). Save it, import it, and call install with the targets' ASTs in the same order before parsing: it installs the generated operations in the registry pyfect.schema.compiler shares with the JIT compiler, each initialized on first use. The module imports only pyfect.schema.compiler.runtime: no code generation and no exec at run time.

Only the requested operation families and their static dependencies are emitted; repeated ASTs and shared dependencies are installed once, by identity, and identical factories are written once. Unrequested or unsupported operations keep the interpreter. Constants, functions and checks are read from the ASTs given to install, never serialized, so regenerate the module whenever a schema or pyfect changes. Target the type side (ast.to_type()) with "make" or "is", and the flipped AST (ast.flip()) with "decode" to prepare encoding.

Types

TypeDefinitionDescription
Operationtype Operation = Literal['decode', 'is', 'make']

A parser operation prepared by compile.

Classes

Functions

compile

compile(targets) -> str

The source of a module exporting install(asts) for targets (see the module). Generation installs nothing and runs no check or transformation; an empty list gives a module whose install does nothing.

ParameterTypeDescription
targetsSequence[Target]

Returns str

def compile(targets: Sequence[Target], /) -> str:
    """The source of a module exporting ``install(asts)`` for ``targets``
    (see the module). Generation installs nothing and runs no check or
    transformation; an empty list gives a module whose ``install`` does
    nothing."""
    seen: dict[int, tuple[AST, _Plan]] = {}
    for index, target in enumerate(targets):
        for operation in _OPERATION_ORDER:
            if operation in target.operations:
                _visit(seen, target.ast, f"asts[{index}]", operation)
    return _module([plan for _, plan in seen.values()])

Modules