QIEC lowering¶
lower_qvr_to_qiec translates a parsed module into the
Quivers Indexed Effect Core (QIEC), the typed core
language that checking, execution, and transpilation share. It rewrites source syntax into
explicit operations, checks the result, and
raises a diagnostic naming any construct it cannot represent.
qiec_lowering
¶
Exact QVR to QIEC lowering.
Quivers owns this adapter. Didactic orders and negotiates its stages and checks the first-order indexed-family projection. Name resolution, stable identity, effect elaboration, runtime checking, and the QIEC ABI remain source-language responsibilities.
QVR_SOURCE_VERSION
module-attribute
¶
The source protocol a QvrQiecLowerer route accepts.
lower_qvr_to_qiec checks its source_version argument against this
identifier, which names the QVR surface the elaboration reads.
QIEC_STATEMENT_TYPES
module-attribute
¶
QIEC_STATEMENT_TYPES = (surface.QiecIndexDecl, surface.QiecIndexMapDecl, surface.QiecFamilyDecl, surface.QiecPatternSynonymDecl, surface.QiecEffectDecl, surface.QiecEffectInstanceDecl, surface.QiecEffectLawDecl, surface.QiecBernoulliCompletionDecl, surface.QiecCheckpointDerivativeDecl, surface.QiecImplicitDerivativeDecl, surface.QiecRationalDerivativeDecl, surface.QiecSiteEstimatorsDecl, surface.QiecScopedOperationDecl, surface.QiecHandlerInterchangeDecl, surface.QiecHandlerDecl, surface.QiecComputationDecl, QiecRecordDecl, surface.QiecInterpretationDecl, surface.QiecRelationDecl, surface.QiecRelationComposeDecl, surface.QiecRelationTransformDecl, surface.QiecRelationScoreDecl, surface.QiecStringGraphDecl, surface.QiecStringGraphScoreDecl, *surface.META_STATEMENT_TYPES, *surface.NOTATION_STATEMENT_TYPES)
The declaration classes that make up the QIEC surface of a module.
qiec_projection keeps these statements and non_qiec_projection
drops them, so the tuple fixes where the two routes divide a module.
RESUME
module-attribute
¶
The name a traversal's lambda invokes a clause's continuation by.
QvrQiecSource
didactic-model
¶
QvrQiecSource(*, syntax: Module, module_name: str, file_path: str = '<source>', elaborate_programs: bool = True, distribution_families: tuple[DistributionFamily, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), prechecked: QiecModule | None = field(default=None, opaque=True, extras=OPAQUE_BY_VALUE), structures: tuple[StructureDecl, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), spellings: tuple[NameSpelling, ...] = ())
Bases: ValueModel
A parsed QVR projection plus the identity absent from the AST root.
| PARAMETER | DESCRIPTION |
|---|---|
syntax
|
The projected module.
TYPE:
|
module_name
|
The name every stable identity derives from.
TYPE:
|
file_path
|
The path recorded on diagnostics.
TYPE:
|
elaborate_programs
|
Whether
TYPE:
|
prechecked
|
A module already checked from declarations of this syntax under the same module name, such as a library shared by many modules and checked from its own file. A computation declaration whose name and origin, apart from the file, match one of its computations is not lowered again: that computation is reused, with the families its lowering generated. The module's independent recheck still checks it.
TYPE:
|
structures
|
The module's structure declarations, which the checked module records beside its computations.
TYPE:
|
spellings
|
How the program's root module writes the names other modules declare, which generated printers write them as.
TYPE:
|
CheckedQvrQiec
didactic-model
¶
CheckedQvrQiec(*, module: QiecModule = field(opaque=True, extras=OPAQUE_BY_VALUE), closed_interpretations: tuple[ClosedInterpretationBinding, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), packed_interpretations: tuple[PackedBooleanInterpretationBinding, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), generated_declarations: tuple[GeneratedDeclaration, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
The checked result passed between Didactic's ordered stages.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The kernel module the stages produced.
TYPE:
|
closed_interpretations
|
Source companions retained through checked model schema extraction.
TYPE:
|
packed_interpretations
|
Each verified invocation of a closed interpretation's packed form.
TYPE:
|
generated_declarations
|
Source declarations and their provenance from the checked meta expansion.
TYPE:
|
QvrQiecLowerer
¶
Quivers-owned implementation of Didactic's extension-lowering protocol.
check
¶
check(source: QvrQiecSource) -> CheckedQvrQiec
Elaborate a source module and recheck the result.
The recheck is deliberate rather than redundant: it rebuilds a registry from the lowered module alone, so a bug in elaboration surfaces here instead of reaching a backend.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The QIEC projection, its module name, and its file path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CheckedQvrQiec
|
The checked module. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If elaboration rejects the source, carrying a stable code and a source position. |
KernelError
|
If the lowered module fails its independent recheck. |
Source code in src/quivers/dsl/qiec_lowering.py
lower
¶
lower(checked: CheckedQvrQiec) -> QiecModule
Return the checked module.
Checking and lowering are one step here, because the elaborator produces the kernel module directly, so this unwraps rather than transforms.
| PARAMETER | DESCRIPTION |
|---|---|
checked
|
The result of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecModule
|
The lowered module. |
Source code in src/quivers/dsl/qiec_lowering.py
validate
¶
validate(target: QiecModule) -> None
Recheck a module and confirm it survives serialization.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
The module to validate.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the module fails its recheck, or if a dump and load round trip does not return an equal module. The second is checked because identities downstream are content addressed: a module that changed under serialization would hash differently on the other side of the boundary. |
Source code in src/quivers/dsl/qiec_lowering.py
DeclaredFamilies
didactic-model
¶
DeclaredFamilies(*, families: tuple[FamilyDecl, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), constructors: tuple[ConstructorDecl, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), deduction_items: Mapping[str, str] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_VALUE), computations: tuple[str, ...] = ())
Bases: QiecModel
The families a module declares and generates, before any body is read.
| PARAMETER | DESCRIPTION |
|---|---|
families
|
Every family: declared in source, or generated by a declaration.
TYPE:
|
constructors
|
Every constructor of those families.
TYPE:
|
deduction_items
|
Each deduction's name mapped to the name of the item family it generates.
TYPE:
|
computations
|
The computations the declarations generate, such as a signature
sort's
TYPE:
|
has_qiec_surface
¶
has_qiec_surface(module: Module) -> bool
Return whether a parsed module has anything to elaborate through QIEC.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module to inspect.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when at least one statement belongs to the QIEC surface or is a program or deduction the elaboration turns into computations. Callers use this to decide whether the QIEC route runs at all, so a module of other declarations pays nothing for it. |
Source code in src/quivers/dsl/qiec_lowering.py
qiec_projection
¶
Project QIEC declarations from a module with multiple neighborhoods.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module to project.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Module
|
A module of the QIEC statements alone, in source order. The
complement is |
Source code in src/quivers/dsl/qiec_lowering.py
non_qiec_projection
¶
Project declarations consumed by the categorical/probabilistic compiler.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module to project.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Module
|
A module of everything outside the QIEC surface, in source order. |
Source code in src/quivers/dsl/qiec_lowering.py
lower_qvr_to_qiec
¶
lower_qvr_to_qiec(module: Module, *, module_name: str | None = None, file_path: str = '<source>', source_version: str = QVR_SOURCE_VERSION, target_version: str = QIEC_ABI, elaborate_programs: bool = True, families: FamilyCatalog | None = None) -> QiecModule
Check and lower the QIEC projection of one parsed QVR module.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module, which may mix QIEC and ordinary declarations.
TYPE:
|
module_name
|
Name the stable identities derive from. None takes it from
TYPE:
|
file_path
|
Path recorded on diagnostics.
TYPE:
|
source_version
|
The source protocol the module is written against.
TYPE:
|
target_version
|
The kernel ABI to lower to.
TYPE:
|
elaborate_programs
|
Whether
TYPE:
|
families
|
Compilation-local custom distribution contracts and native bindings. Only the semantic contracts are retained in the checked module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecModule
|
The checked, lowered module. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If the source is rejected, with a stable code and a position. The
code |
KernelError
|
If the lowered module fails its independent recheck. |
Source code in src/quivers/dsl/qiec_lowering.py
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | |
declared_families
¶
declared_families(module: Module, *, module_name: str | None = None, file_path: str = '<source>') -> DeclaredFamilies
Declare a module's families without checking any computation body.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module.
TYPE:
|
module_name
|
The name identities derive from; None takes it from
TYPE:
|
file_path
|
The path recorded on diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DeclaredFamilies
|
The declared and generated families and their constructors. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If a declaration is rejected, or with code |