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:
|
entry
|
The allocated instance and its interface application.
TYPE:
|
origin
|
Where the instance was declared.
TYPE:
|
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:
|
name
|
The display name; must be non-empty and unique within the module.
TYPE:
|
telescope
|
The static parameters the computation abstracts over, in order.
TYPE:
|
parameters
|
The value parameters, in order; their names must be distinct and must not reuse a telescope binder's name.
TYPE:
|
body
|
The computation's body, with the parameters in scope.
TYPE:
|
type
|
The result type and effect row at the named calling boundary.
TYPE:
|
origin
|
Where the computation was declared.
TYPE:
|
predicates
|
The row predicates the computation assumes over its row binders: its body may rely on them, and each call must entail them.
TYPE:
|
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:
|
source_protocol
|
The source route that produced the module.
TYPE:
|
distribution_families
|
Custom distribution contracts, excluding executable implementations.
TYPE:
|
index_sorts
|
The user-defined closed index sorts.
TYPE:
|
families
|
The indexed data families.
TYPE:
|
constructors
|
The family constructors.
TYPE:
|
effects
|
The effect interfaces.
TYPE:
|
instances
|
The module-scoped named effect instances.
TYPE:
|
handlers
|
The handler declarations.
TYPE:
|
computations
|
The named computations.
TYPE:
|
entries
|
The program entry points, each naming one of the computations.
TYPE:
|
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:
|
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:
|
abi
|
The kernel ABI the module is expressed against; must equal
:data:
TYPE:
|
called_computations
¶
called_computations(body: Computation) -> frozenset[ComputationId]
The computations a body calls, directly.
| PARAMETER | DESCRIPTION |
|---|---|
body
|
The body to walk.
TYPE:
|
| 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
installed_handlers
¶
installed_handlers(body: Computation) -> frozenset[HandlerId]
The handlers a body installs, directly.
| PARAMETER | DESCRIPTION |
|---|---|
body
|
The body to walk.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[HandlerId]
|
The handler of every |
Source code in src/quivers/qiec/module.py
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:
|
root
|
The computation run.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[HandlerId]
|
The identity of every handler installed along the way. |
Source code in src/quivers/qiec/module.py
program_computations
¶
program_computations(module: QiecModule) -> frozenset[ComputationId]
The computations that hold programs and their own helpers.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
| 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
reachable_computations
¶
reachable_computations(module: QiecModule) -> frozenset[ComputationId]
The computations a program reaches.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
| 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
declaration_registry
¶
declaration_registry(module: QiecModule) -> KernelRegistry
Resolve a module's declarations and signatures without its bodies.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
| 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
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:
|
| 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
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 | |
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:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[LinearityViolation, ...]
|
The violations |
Source code in src/quivers/qiec/module.py
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:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
With code |
Source code in src/quivers/qiec/module.py
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:
|
names
|
The source name of each lexical instance, for the row.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/qiec/module.py
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:
|
registry
|
The registry
TYPE:
|
name
|
The computation's name.
TYPE:
|
| 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
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:
|
predicates
|
The stated predicates.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RowTheory
|
The predicates, and the absences the types prove: a parameter of
type |
Source code in src/quivers/qiec/module.py
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:
|
| RETURNS | DESCRIPTION |
|---|---|
RowTheory
|
Its stated predicates, and the absences its parameter and result types prove. |
Source code in src/quivers/qiec/module.py
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:
|
declared
|
The type the declaration states.
TYPE:
|
| 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. |