Module¶
Serializable whole-module containers.
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
dataclass
¶
NamedEffectInstance(name: str, entry: RowEntry, origin: SourceOrigin)
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:
|
__post_init__
¶
Reject an unnamed instance.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the source name is empty. The name is how a request resolves to this instance, so an empty one names nothing. |
Source code in src/quivers/qiec/module.py
NamedComputation
dataclass
¶
NamedComputation(id: ComputationId, name: str, telescope: Telescope, parameters: tuple[Local, ...], body: Computation, type: ComputationType, origin: SourceOrigin)
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 checked effect row and result type of
TYPE:
|
origin
|
Where the computation was declared.
TYPE:
|
__post_init__
¶
Reject a computation whose names collide or are absent.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the name is empty, the telescope is malformed, two parameters share a name, or a parameter shadows a static binder. Shadowing is rejected so a name inside the body denotes one thing. |
Source code in src/quivers/qiec/module.py
QiecModule
dataclass
¶
QiecModule(module: str, source_protocol: str, index_sorts: tuple[UserIndexSort, ...] = (), families: tuple[FamilyDecl, ...] = (), constructors: tuple[ConstructorDecl, ...] = (), effects: tuple[EffectDef, ...] = (), instances: tuple[NamedEffectInstance, ...] = (), handlers: tuple[HandlerDef, ...] = (), computations: tuple[NamedComputation, ...] = (), entries: tuple[ProgramEntry, ...] = (), gap: str = '', abi: str = QIEC_ABI)
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:
|
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:
|
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:
|
__post_init__
¶
Reject a module whose identity or ABI is missing or wrong.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the module name or source protocol is empty, or the ABI is not the one this kernel speaks. The ABI is checked here as well as at the wire envelope so a module built in process cannot claim a version it was not built for. |
Source code in src/quivers/qiec/module.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
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 |
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
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.
| 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
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
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
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. |