Skip to content

Module

A QiecModule holds a module's declarations, definitions, and entry points as one serializable value. A module is checked before its computations run, and a run needs the runtime services that the chosen entry requires.

module

Serializable, whole-module containers for the QIEC kernel.

The small records in this module are the boundary returned by source-language extension lowerers. They contain declarations and checked computation graphs, but never parser nodes, compiler objects, callbacks, or backend-specific data.

NamedEffectInstance didactic-model

NamedEffectInstance(*, name: str, entry: RowEntry = field(opaque=True, extras=OPAQUE_BY_VALUE), origin: SourceOrigin = field(opaque=True, extras=OPAQUE_BY_VALUE))

Bases: QiecModel

A source name for one deterministically allocated lexical instance.

PARAMETER DESCRIPTION
name

The name requests resolve through; must be non-empty.

TYPE: str

entry

The allocated instance and its interface application.

TYPE: RowEntry DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

origin

Where the instance was declared.

TYPE: SourceOrigin DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

NamedComputation didactic-model

NamedComputation(*, id: ComputationId = field(opaque=True, extras=OPAQUE_BY_VALUE), name: str, telescope: Telescope = field(opaque=True, extras=OPAQUE_BY_VALUE), parameters: tuple[Local, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), body: Computation = field(opaque=True, extras=OPAQUE_BY_VALUE), type: ComputationType = field(opaque=True, extras=OPAQUE_BY_VALUE), origin: SourceOrigin = field(opaque=True, extras=OPAQUE_BY_VALUE), predicates: tuple[RowPredicate, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))

Bases: QiecModel

One named QVR computation and its checked QIEC type.

PARAMETER DESCRIPTION
id

The computation's stable identity, which calls refer to.

TYPE: ComputationId DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

name

The display name; must be non-empty and unique within the module.

TYPE: str

telescope

The static parameters the computation abstracts over, in order.

TYPE: Telescope DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

parameters

The value parameters, in order; their names must be distinct and must not reuse a telescope binder's name.

TYPE: tuple[Local, ...] DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

body

The computation's body, with the parameters in scope.

TYPE: Computation DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

type

The result type and effect row at the named calling boundary.

TYPE: ComputationType DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

origin

Where the computation was declared.

TYPE: SourceOrigin DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

predicates

The row predicates the computation assumes over its row binders: its body may rely on them, and each call must entail them.

TYPE: tuple[RowPredicate, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

QiecModule didactic-model

QiecModule(*, module: str, source_protocol: str, distribution_families: tuple[DistributionFamily, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), index_sorts: tuple[UserIndexSort, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), families: tuple[FamilyDecl, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), constructors: tuple[ConstructorDecl, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), effects: tuple[EffectDef, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), instances: tuple[NamedEffectInstance, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), handlers: tuple[HandlerDef, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), computations: tuple[NamedComputation, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), entries: tuple[ProgramEntry, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), structures: tuple[StructureDecl, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), gap: str = '', abi: str = QIEC_ABI)

Bases: QiecModel

A complete, serializable QIEC compilation unit.

source_protocol records the exact source route that produced the module. The wire envelope separately records :data:QIEC_ABI, so neither endpoint can be guessed during deserialization or compiler integration.

PARAMETER DESCRIPTION
module

The module's name, from which every stable identity in it derives.

TYPE: str

source_protocol

The source route that produced the module.

TYPE: str

distribution_families

Custom distribution contracts, excluding executable implementations.

TYPE: tuple[DistributionFamily, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

index_sorts

The user-defined closed index sorts.

TYPE: tuple[UserIndexSort, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

families

The indexed data families.

TYPE: tuple[FamilyDecl, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

constructors

The family constructors.

TYPE: tuple[ConstructorDecl, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

effects

The effect interfaces.

TYPE: tuple[EffectDef, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

instances

The module-scoped named effect instances.

TYPE: tuple[NamedEffectInstance, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

handlers

The handler declarations.

TYPE: tuple[HandlerDef, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

computations

The named computations.

TYPE: tuple[NamedComputation, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

entries

The program entry points, each naming one of the computations.

TYPE: tuple[ProgramEntry, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

structures

The structure declarations: objects, the headers and bodies of programs and deductions, relations, losses, encoders, decoders, and every other declaration the compiled runtime reads beside the computations, in source order.

TYPE: tuple[StructureDecl, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

gap

The diagnostic of a program the module lowered without, because it uses a construct whose elaboration is not yet defined; empty when every program elaborated.

TYPE: str DEFAULT: ''

abi

The kernel ABI the module is expressed against; must equal :data:QIEC_ABI.

TYPE: str DEFAULT: QIEC_ABI

called_computations

called_computations(body: Computation) -> frozenset[ComputationId]

The computations a body calls, directly.

PARAMETER DESCRIPTION
body

The body to walk.

TYPE: Computation

RETURNS DESCRIPTION
frozenset[ComputationId]

The callee of every call and pure application in the body, at any depth.

Source code in src/quivers/qiec/module.py
def called_computations(body: Computation) -> frozenset[ComputationId]:
    """The computations a body calls, directly.

    Parameters
    ----------
    body : Computation
        The body to walk.

    Returns
    -------
    frozenset[ComputationId]
        The callee of every call and pure application in the body, at any depth.
    """
    found: set[ComputationId] = set()
    pending: list[Computation] = [body]
    while pending:
        term = pending.pop()
        if isinstance(term, Call | ApplyPure):
            found.add(term.callee)
        pending.extend(_structural_children(term))
    return frozenset(found)

installed_handlers

installed_handlers(body: Computation) -> frozenset[HandlerId]

The handlers a body installs, directly.

PARAMETER DESCRIPTION
body

The body to walk.

TYPE: Computation

RETURNS DESCRIPTION
frozenset[HandlerId]

The handler of every Handle in the body, at any depth.

Source code in src/quivers/qiec/module.py
def installed_handlers(body: Computation) -> frozenset[HandlerId]:
    """The handlers a body installs, directly.

    Parameters
    ----------
    body : Computation
        The body to walk.

    Returns
    -------
    frozenset[HandlerId]
        The handler of every ``Handle`` in the body, at any depth.
    """
    found: set[HandlerId] = set()
    pending: list[Computation] = [body]
    while pending:
        term = pending.pop()
        if isinstance(term, Handle):
            found.add(term.handler)
        pending.extend(_structural_children(term))
    return frozenset(found)

reached_handlers

reached_handlers(module: QiecModule, root: ComputationId) -> frozenset[HandlerId]

The handlers a run of one computation may install.

Every computation the root reaches through calls is walked, and so is every clause of an authored handler one of them installs, since a clause body may call and install further.

PARAMETER DESCRIPTION
module

The module.

TYPE: QiecModule

root

The computation run.

TYPE: ComputationId

RETURNS DESCRIPTION
frozenset[HandlerId]

The identity of every handler installed along the way.

Source code in src/quivers/qiec/module.py
def reached_handlers(module: QiecModule, root: ComputationId) -> frozenset[HandlerId]:
    """The handlers a run of one computation may install.

    Every computation the root reaches through calls is walked, and so is
    every clause of an authored handler one of them installs, since a
    clause body may call and install further.

    Parameters
    ----------
    module : QiecModule
        The module.
    root : ComputationId
        The computation run.

    Returns
    -------
    frozenset[HandlerId]
        The identity of every handler installed along the way.
    """
    _, handlers = _execution_reachability(module, root)
    return frozenset(handlers)

program_computations

program_computations(module: QiecModule) -> frozenset[ComputationId]

The computations that hold programs and their own helpers.

PARAMETER DESCRIPTION
module

The module.

TYPE: QiecModule

RETURNS DESCRIPTION
frozenset[ComputationId]

The identity of every entry point's computation and of every computation the elaboration made for a program, such as a marginalization helper or a scan's recurrence: what a target renders from the program's plan rather than as a computation of its own.

Source code in src/quivers/qiec/module.py
def program_computations(module: QiecModule) -> frozenset[ComputationId]:
    """The computations that hold programs and their own helpers.

    Parameters
    ----------
    module : QiecModule
        The module.

    Returns
    -------
    frozenset[ComputationId]
        The identity of every entry point's computation and of every
        computation the elaboration made for a program, such as a
        marginalization helper or a scan's recurrence: what a target
        renders from the program's plan rather than as a computation
        of its own.
    """
    entries = {entry.computation for entry in module.entries}
    return frozenset(
        computation.id
        for computation in module.computations
        if computation.id in entries
        or computation.origin.structural_path[:1] == ("programs",)
    )

reachable_computations

reachable_computations(module: QiecModule) -> frozenset[ComputationId]

The computations a program reaches.

PARAMETER DESCRIPTION
module

The module.

TYPE: QiecModule

RETURNS DESCRIPTION
frozenset[ComputationId]

The identity of every entry point's computation and of every computation it calls, transitively.

Source code in src/quivers/qiec/module.py
def reachable_computations(module: QiecModule) -> frozenset[ComputationId]:
    """The computations a program reaches.

    Parameters
    ----------
    module : QiecModule
        The module.

    Returns
    -------
    frozenset[ComputationId]
        The identity of every entry point's computation and of every
        computation it calls, transitively.
    """
    by_id = {computation.id: computation for computation in module.computations}
    found: set[ComputationId] = set()
    pending = [entry.computation for entry in module.entries]
    while pending:
        identity = pending.pop()
        if identity in found or identity not in by_id:
            continue
        found.add(identity)
        pending.extend(called_computations(by_id[identity].body))
    return frozenset(found)

declaration_registry

declaration_registry(module: QiecModule) -> KernelRegistry

Resolve a module's declarations and signatures without its bodies.

PARAMETER DESCRIPTION
module

The module.

TYPE: QiecModule

RETURNS DESCRIPTION
KernelRegistry

Its families, constructors, effects, instance names, computation signatures, and handlers, against which a body can be checked.

RAISES DESCRIPTION
KernelError

If a declaration is ill-formed or an instance's interface is unknown.

Source code in src/quivers/qiec/module.py
def declaration_registry(module: QiecModule) -> KernelRegistry:
    """Resolve a module's declarations and signatures without its bodies.

    Parameters
    ----------
    module : QiecModule
        The module.

    Returns
    -------
    KernelRegistry
        Its families, constructors, effects, instance names, computation
        signatures, and handlers, against which a body can be checked.

    Raises
    ------
    KernelError
        If a declaration is ill-formed or an instance's interface is
        unknown.
    """
    registry = KernelRegistry(
        distribution_families=module.distribution_families,
        computation_bodies={item.id: item.body for item in module.computations},
    )
    for family in module.families:
        registry.register_family(family)
    # A field indexing a tensor by a finite family is checked against that
    # family's constructors, so they are registered first.
    try:
        constructors = registration_order(module.families, module.constructors)
    except FiniteAxisError as error:
        raise KernelError(error.message, error.code) from error
    for constructor in constructors:
        registry.register_constructor(constructor)
    for effect in module.effects:
        registry.register_effect(effect)
    for instance in module.instances:
        _validate_closed_effect_instance(instance)
        registry.validate_static(instance.entry.effect)
        declared = registry.effects.get(instance.entry.effect.id)
        if declared is None or not declared.matches(instance.entry.effect):
            raise KernelError(
                f"unknown effect interface for instance {instance.name!r}"
            )
        registry.instance_names[instance.entry.instance] = instance.name
    # Every computation signature is registered before any body is
    # rechecked, for the same reason the lowerer collects them first: a
    # body may call a computation declared after it, and two may call
    # each other.
    for computation in module.computations:
        registry.register_computation(
            ComputationSignature(
                id=computation.id,
                name=computation.name,
                telescope=computation.telescope,
                parameters=tuple(
                    parameter.type for parameter in computation.parameters
                ),
                result=computation.type.result,
                effects=computation.type.effects,
                predicates=computation.predicates,
            )
        )
    for handler in module.handlers:
        registry.register_handler(handler)
    return registry

validate_module

validate_module(module: QiecModule) -> KernelRegistry

Recheck a whole lowered module and return its resolved registry.

This is deliberately independent of the lowerer. It rebuilds the registry from the module's own declarations and rechecks every body against it, so a module that arrived from elsewhere, or from a lowerer with a bug, is held to the same standard as one just built.

A module is immutable and the recheck reads nothing else, so the bodies of one instance are rechecked once. Every call resolves a registry of its own, which the caller may extend.

PARAMETER DESCRIPTION
module

The lowered module to recheck.

TYPE: QiecModule

RETURNS DESCRIPTION
KernelRegistry

The registry resolved from the module's declarations, for a caller that wants to check further terms against it.

RAISES DESCRIPTION
KernelError

If the ABI does not match, a declaration is ill-formed, an instance or index sort is undeclared, a body fails to check, or an inferred type does not conform to the declared one.

Source code in src/quivers/qiec/module.py
def validate_module(module: QiecModule) -> KernelRegistry:
    """Recheck a whole lowered module and return its resolved registry.

    This is deliberately independent of the lowerer. It rebuilds the
    registry from the module's own declarations and rechecks every body
    against it, so a module that arrived from elsewhere, or from a
    lowerer with a bug, is held to the same standard as one just built.

    A module is immutable and the recheck reads nothing else, so the bodies
    of one instance are rechecked once. Every call resolves a registry of
    its own, which the caller may extend.

    Parameters
    ----------
    module : QiecModule
        The lowered module to recheck.

    Returns
    -------
    KernelRegistry
        The registry resolved from the module's declarations, for a
        caller that wants to check further terms against it.

    Raises
    ------
    KernelError
        If the ABI does not match, a declaration is ill-formed, an
        instance or index sort is undeclared, a body fails to check, or
        an inferred type does not conform to the declared one.
    """

    if module.abi != QIEC_ABI:
        raise KernelError(f"unsupported QIEC ABI {module.abi!r}")
    rechecked = _RECHECKED in module.__dict__
    if not rechecked:
        _validate_index_sorts(module)
    names = [item.name for item in module.distribution_families]
    if len(set(names)) != len(names) or any(name in FAMILIES for name in names):
        raise KernelError(
            "custom distribution contracts must have distinct nonbuiltin names"
        )
    registry = declaration_registry(module)
    if not rechecked:
        guard_bodies: dict[ComputationId, NamedComputation] | None = None
        for handler in module.handlers:
            if isinstance(handler.foreign, DeductionLinearGoal):
                from quivers.qiec.linear_deduction import validate_linear_goal

                validate_linear_goal(handler, handler.foreign, registry, module.module)
            elif isinstance(
                handler.foreign,
                DeductionOutcomes | DeductionProofs | DeductionBooleanOutcomes,
            ):
                from quivers.qiec.deduction_outcomes import validate_outcome_adapter

                validate_outcome_adapter(handler, handler.foreign, registry)
                if isinstance(handler.foreign, DeductionOutcomes):
                    from quivers.qiec.rules import RulePresentation

                    presentation = handler.foreign.presentation
                    assert isinstance(presentation, RulePresentation)
                    if presentation.conditions:
                        if guard_bodies is None:
                            guard_bodies = {
                                body.id: body for body in module.computations
                            }
                        from quivers.qiec._deduction_guards import (
                            _TermGuard,
                            _guard_in_scope,
                            _term_guard_in_scope,
                        )

                        for guard in presentation.conditions:
                            outer = guard_bodies.get(guard.id)
                            scoped = None
                            if outer is not None:
                                if isinstance(guard, _TermGuard):
                                    owner = FamilyId.derive(
                                        module.module,
                                        "family",
                                        member_name(presentation.name, "Item"),
                                    )
                                    family = registry.families.get(guard.item_family.id)
                                    if (
                                        guard.item_family.id != owner
                                        or family != guard.item_family
                                        or any(
                                            registry.constructors.get(item.id) != item
                                            for item in guard.item_constructors
                                        )
                                    ):
                                        raise KernelError(
                                            f"deduction term guard {guard.name!r} must "
                                            "capture its exact outer item declarations"
                                        )
                                    scoped = _term_guard_in_scope(
                                        outer,
                                        presentation.name,
                                        guard.item_family,
                                        guard.item_constructors,
                                    )
                                else:
                                    scoped = _guard_in_scope(outer, presentation.name)
                            if scoped != guard:
                                raise KernelError(
                                    f"deduction rule guard {guard.name!r} must match "
                                    "the outer module's checked computation"
                                )
            elif isinstance(handler.foreign, DeductionOutcomeGrouping):
                from quivers.qiec.deduction_outcomes import validate_outcome_grouping

                validate_outcome_grouping(handler, handler.foreign, registry)
            elif isinstance(handler.foreign, DeductionOutcomeLaw):
                from quivers.qiec.deduction_outcomes import validate_outcome_law

                validate_outcome_law(handler, handler.foreign, registry)
        _recheck_bodies(module, registry)
        require_control_flow_linearity(module)
        from quivers.qiec._resumption_intervals import _check_interval_installations

        _check_interval_installations(module)
        module.__dict__[_RECHECKED] = True
    return registry

module_linearity

module_linearity(module: QiecModule) -> tuple[LinearityViolation, ...]

Every multi-shot installation whose shots can each resume one token.

PARAMETER DESCRIPTION
module

The checked module.

TYPE: QiecModule

RETURNS DESCRIPTION
tuple[LinearityViolation, ...]

The violations control_flow_violations finds.

Source code in src/quivers/qiec/module.py
def module_linearity(module: QiecModule) -> tuple[LinearityViolation, ...]:
    """Every multi-shot installation whose shots can each resume one token.

    Parameters
    ----------
    module : QiecModule
        The checked module.

    Returns
    -------
    tuple[LinearityViolation, ...]
        The violations `control_flow_violations` finds.
    """
    return control_flow_violations(
        {item.id: (item.name, item.body) for item in module.computations},
        {item.id: item for item in module.handlers},
        {
            operation.id: operation.name
            for effect in module.effects
            for operation in effect.operations
        },
    )

require_control_flow_linearity

require_control_flow_linearity(module: QiecModule) -> None

Refuse a module in which a multi-shot handler can copy a one-shot token.

PARAMETER DESCRIPTION
module

The checked module.

TYPE: QiecModule

RAISES DESCRIPTION
KernelError

With code qiec-linearity, naming the first violation.

Source code in src/quivers/qiec/module.py
def require_control_flow_linearity(module: QiecModule) -> None:
    """Refuse a module in which a multi-shot handler can copy a one-shot token.

    Parameters
    ----------
    module : QiecModule
        The checked module.

    Raises
    ------
    KernelError
        With code ``qiec-linearity``, naming the first violation.
    """
    violations = module_linearity(module)
    if violations:
        raise KernelError(violations[0].message(), "qiec-linearity")

render_computation_type

render_computation_type(type_: ComputationType, names: Mapping[EffectInstanceId, str] | None = None) -> str

Render a computation type as its result and row.

PARAMETER DESCRIPTION
type_

The type.

TYPE: ComputationType

names

The source name of each lexical instance, for the row.

TYPE: Mapping[EffectInstanceId, str] | None DEFAULT: None

RETURNS DESCRIPTION
str

Result !{row}.

Source code in src/quivers/qiec/module.py
def render_computation_type(
    type_: ComputationType, names: Mapping[EffectInstanceId, str] | None = None
) -> str:
    """Render a computation type as its result and row.

    Parameters
    ----------
    type_ : ComputationType
        The type.
    names : Mapping[EffectInstanceId, str] | None
        The source name of each lexical instance, for the row.

    Returns
    -------
    str
        ``Result !{row}``.
    """
    return f"{render_static(type_.result)} {render_row(type_.effects, names)}"

inferred_computation_type

inferred_computation_type(module: QiecModule, registry: KernelRegistry, name: str) -> ComputationType

The type a named computation's body has, as the checker infers it.

PARAMETER DESCRIPTION
module

The module, already validated.

TYPE: QiecModule

registry

The registry validate_module resolved for it.

TYPE: KernelRegistry

name

The computation's name.

TYPE: str

RETURNS DESCRIPTION
ComputationType

The inferred result type and the row the body performs, which the declared row may widen.

RAISES DESCRIPTION
KeyError

If the module has no computation of that name.

Source code in src/quivers/qiec/module.py
def inferred_computation_type(
    module: QiecModule, registry: KernelRegistry, name: str
) -> ComputationType:
    """The type a named computation's body has, as the checker infers it.

    Parameters
    ----------
    module : QiecModule
        The module, already validated.
    registry : KernelRegistry
        The registry `validate_module` resolved for it.
    name : str
        The computation's name.

    Returns
    -------
    ComputationType
        The inferred result type and the row the body performs, which the
        declared row may widen.

    Raises
    ------
    KeyError
        If the module has no computation of that name.
    """
    computation = next(
        (item for item in module.computations if item.name == name), None
    )
    if computation is None:
        raise KeyError(f"module {module.module!r} has no computation {name!r}")
    return _infer_named_body(computation, registry)

row_theory

row_theory(types: tuple[TypeExpr, ...], predicates: tuple[RowPredicate, ...]) -> RowTheory

The row theory a signature's types and predicates give a body.

PARAMETER DESCRIPTION
types

The parameter types and the result type.

TYPE: tuple[TypeExpr, ...]

predicates

The stated predicates.

TYPE: tuple[RowPredicate, ...]

RETURNS DESCRIPTION
RowTheory

The predicates, and the absences the types prove: a parameter of type {a : T | r} proves that r lacks a.

Source code in src/quivers/qiec/module.py
def row_theory(
    types: tuple[TypeExpr, ...], predicates: tuple[RowPredicate, ...]
) -> RowTheory:
    """The row theory a signature's types and predicates give a body.

    Parameters
    ----------
    types : tuple[TypeExpr, ...]
        The parameter types and the result type.
    predicates : tuple[RowPredicate, ...]
        The stated predicates.

    Returns
    -------
    RowTheory
        The predicates, and the absences the types prove: a parameter of
        type ``{a : T | r}`` proves that ``r`` lacks ``a``.
    """
    rows = [row for type_ in types for row in _rows_in(type_)]
    return RowTheory().extended(predicates, rows)

signature_row_theory

signature_row_theory(computation: NamedComputation) -> RowTheory

The row theory a computation's body is checked under.

PARAMETER DESCRIPTION
computation

The computation.

TYPE: NamedComputation

RETURNS DESCRIPTION
RowTheory

Its stated predicates, and the absences its parameter and result types prove.

Source code in src/quivers/qiec/module.py
def signature_row_theory(computation: NamedComputation) -> RowTheory:
    """The row theory a computation's body is checked under.

    Parameters
    ----------
    computation : NamedComputation
        The computation.

    Returns
    -------
    RowTheory
        Its stated predicates, and the absences its parameter and result
        types prove.
    """
    return row_theory(
        (
            *(parameter.type for parameter in computation.parameters),
            computation.type.result,
        ),
        computation.predicates,
    )

computation_type_conforms

computation_type_conforms(actual: ComputationType, declared: ComputationType) -> bool

Check exact rows or sound weakening into an explicitly open row.

An inferred open tail can inhabit a declared open row only when it proves every absence guaranteed by the declaration. Row-variable names and IDs are lexical identities, so conformance compares their constraints rather than treating unrelated tails as identical.

PARAMETER DESCRIPTION
actual

The type inferred from the body.

TYPE: ComputationType

declared

The type the declaration states.

TYPE: ComputationType

RETURNS DESCRIPTION
bool

True when the body's type inhabits the declaration. The result types must be equal; the rows may differ only by the inferred row being weakened into a declared open one that it proves every absence of.

Source code in src/quivers/qiec/module.py
def computation_type_conforms(
    actual: ComputationType,
    declared: ComputationType,
) -> bool:
    """Check exact rows or sound weakening into an explicitly open row.

    An inferred open tail can inhabit a declared open row only when it proves
    every absence guaranteed by the declaration. Row-variable names and IDs
    are lexical identities, so conformance compares their constraints rather
    than treating unrelated tails as identical.

    Parameters
    ----------
    actual : ComputationType
        The type inferred from the body.
    declared : ComputationType
        The type the declaration states.

    Returns
    -------
    bool
        True when the body's type inhabits the declaration. The result
        types must be equal; the rows may differ only by the inferred row
        being weakened into a declared open one that it proves every
        absence of.
    """

    if actual.result != declared.result:
        return False
    if declared.effects.tail is None:
        return actual.effects == declared.effects
    actual_entries = {entry.instance: entry.effect for entry in actual.effects.entries}
    declared_entries = {
        entry.instance: entry.effect for entry in declared.effects.entries
    }
    for instance, effect in actual_entries.items():
        expected = declared_entries.get(instance)
        if expected is not None:
            if expected != effect:
                return False
            continue
        if declared.effects.tail.proves_lacks(instance):
            return False
    if actual.effects.tail is None:
        return True
    forbidden = set(declared.effects.tail.lacks) - set(declared_entries)
    if any(instance in actual_entries for instance in forbidden):
        return False
    if any(not actual.effects.tail.proves_lacks(instance) for instance in forbidden):
        return False
    return True