Checking¶
The Quivers Indexed Effect Core (QIEC) checker validates a module and infers the types and effects of its terms (indexed case analysis). A constructor match can refine an index, and later operations in the branch may use the resulting equality. Runtime providers give the implementations an accepted computation needs to run.
checking
¶
Validation and type/effect inference for the QIEC reference kernel.
HOLE_OBSERVER
module-attribute
¶
HOLE_OBSERVER: ContextVar[HoleObserver | None] = ContextVar('HOLE_OBSERVER', default=None)
The observer of typed holes for checks in the current context, if any.
A hole checks at its type without consulting the observer; the observer
only learns where each hole is and what is in scope there, which is how
hole_goals reports goals.
NEVER
module-attribute
¶
NEVER = ResumptionUse(minimum=0, maximum=0)
A computation that cannot invoke the continuation.
ONCE
module-attribute
¶
ONCE = ResumptionUse(minimum=1, maximum=1)
A computation that invokes the continuation exactly once.
HoleObserver
¶
HoleObserver = Callable[[HoleValue, CheckContext], None]
Receives each typed hole the checker meets, with the context it is in.
KernelError
¶
Bases: TypeError
A static QIEC kernel rejection.
Carries a stable diagnostic code alongside its message. The code is attached where the rejection is raised, because only that site knows which condition fired; classifying by message text afterwards is a guess that silently changes whenever the prose is reworded.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
What was rejected, in prose, for a human reader.
TYPE:
|
code
|
A member of the published code set. Defaults to
TYPE:
|
Source code in src/quivers/qiec/checking.py
StaticScope
didactic-model
¶
StaticScope(*, types: tuple[tuple[str, Kind], ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), indices: tuple[tuple[str, IndexSort], ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), effects: tuple[str, ...] = ())
Bases: QiecModel
The three disjoint namespaces visible in a declaration body.
| PARAMETER | DESCRIPTION |
|---|---|
types
|
Type binders in scope, each with its kind.
TYPE:
|
indices
|
Index binders in scope, each with its sort.
TYPE:
|
effects
|
Effect binder names in scope.
TYPE:
|
names
property
¶
Every static name bound here, across all three namespaces.
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
The union of the type, index, and effect binder names. The namespaces are disjoint by construction, so this is what shadowing is tested against. |
extend
¶
extend(telescope: Telescope, *, subject: str) -> StaticScope
Return this scope widened by a telescope's binders.
| PARAMETER | DESCRIPTION |
|---|---|
telescope
|
Binders to add. Each must be a type, index, or effect binder.
TYPE:
|
subject
|
What is being extended, named in any diagnostic so the error points at the declaration rather than at the scope.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StaticScope
|
A scope carrying the original binders and the new ones. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If a binder is of an unknown class, or if its name is already bound. Shadowing is rejected rather than resolved so a static name always denotes one thing within a declaration. |
Source code in src/quivers/qiec/checking.py
type_kind
¶
type_kind(name: str) -> Kind | None
The kind of a type binder in scope.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The binder name to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Kind or None
|
The binder's kind, or None when |
Source code in src/quivers/qiec/checking.py
index_sort
¶
index_sort(name: str) -> IndexSort | None
The sort of an index binder in scope.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The binder name to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IndexSort or None
|
The binder's sort, or None when |
Source code in src/quivers/qiec/checking.py
ComputationSignature
didactic-model
¶
ComputationSignature(*, id: ComputationId = field(opaque=True, extras=OPAQUE_BY_VALUE), name: str, telescope: Telescope = field(opaque=True, extras=OPAQUE_BY_VALUE), parameters: tuple[TypeExpr, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), result: TypeExpr = field(opaque=True, extras=OPAQUE_BY_VALUE), effects: EffectRow = field(opaque=True, extras=OPAQUE_BY_VALUE), predicates: tuple[RowPredicate, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
What a call needs to know about a computation it invokes.
A signature rather than a declaration, and deliberately so: a call resolves against this, not against the callee's body. That is what lets every signature be collected before any body is checked, which in turn makes a forward call and mutual recursion ordinary rather than requiring a forward declaration.
| PARAMETER | DESCRIPTION |
|---|---|
id
|
The declaration's stable identity, which the call carries.
TYPE:
|
name
|
The authored name, used in diagnostics.
TYPE:
|
telescope
|
Static binders the computation takes.
TYPE:
|
parameters
|
Value parameter types, in order, before instantiation.
TYPE:
|
result
|
The result type before instantiation.
TYPE:
|
effects
|
The row the computation performs, before instantiation.
TYPE:
|
predicates
class-attribute
instance-attribute
¶
predicates: tuple[RowPredicate, ...] = dx.field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)
The row predicates the computation assumes, over its row binders.
A call must entail each predicate at its static arguments.
KernelRegistry
didactic-model
¶
KernelRegistry(*, distribution_families: tuple[DistributionFamily, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), families: dict[FamilyId, FamilyDecl] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), constructors: dict[ConstructorId, ConstructorDecl] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), effects: dict[EffectId, EffectDef] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), operations: dict[OperationId, tuple[EffectDef, OperationDef]] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), handlers: dict[HandlerId, HandlerDef] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), type_constructors: dict[TypeId, TypeConstructorRef] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), computations: dict[ComputationId, ComputationSignature] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), computation_bodies: dict[ComputationId, Computation] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), instance_names: dict[EffectInstanceId, str] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), elaborated: dict[EffectInstanceId, EffectRow] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Resolved declarations used by the reference checker.
Every table is keyed by stable identity, so a lookup never depends on a display name.
| PARAMETER | DESCRIPTION |
|---|---|
distribution_families
|
Compilation-local distribution contracts, extending the builtin table.
TYPE:
|
families
|
Indexed data families by identity.
TYPE:
|
constructors
|
Family constructors by identity.
TYPE:
|
effects
|
Effect interfaces by identity.
TYPE:
|
operations
|
Each operation by identity, paired with the interface declaring it.
TYPE:
|
handlers
|
Handler declarations by identity.
TYPE:
|
type_constructors
|
Type constructors by identity, recording the telescope each is known with.
TYPE:
|
computations
|
Named computation signatures by identity.
TYPE:
|
computation_bodies
|
The resolved local definitions available for checked pure application.
TYPE:
|
instance_names
|
The source name of each lexical effect instance, for rendering rows in diagnostics.
TYPE:
|
elaborated
|
The instances whose higher-order requests elaboration replaces, each with the row its elaborator introduces: a request to one performs that row, which is what the request becomes.
TYPE:
|
distributions
property
¶
distributions: Mapping[str, DistributionFamily]
Builtin and explicitly retained custom distribution contracts.
| RETURNS | DESCRIPTION |
|---|---|
Mapping[str, DistributionFamily]
|
Read-only contract lookup for this checking context. |
validate_static
¶
validate_static(term: StaticArgument, scope: StaticScope | None = None) -> None
Validate a static term against every declaration known here.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The static term to check.
TYPE:
|
scope
|
Binders in scope at the term's position. None means the empty scope, so any variable reference is out of scope.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the term is ill-kinded, references an unbound static variable, or applies a known declaration wrongly. |
Source code in src/quivers/qiec/checking.py
validate_type
¶
validate_type(type_: TypeExpr, scope: StaticScope | None = None) -> None
Validate a value type against every declaration known here.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
The value type to check.
TYPE:
|
scope
|
Binders in scope at the type's position. None means the empty scope.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the type is ill-kinded or references an unbound variable. |
Source code in src/quivers/qiec/checking.py
validate_effect_row
¶
validate_effect_row(row: EffectRow) -> None
Validate all concrete interface applications in an effect row.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
The row whose entries to check. An open tail carries no application and so is not checked here.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If an entry applies its interface wrongly. |
Source code in src/quivers/qiec/checking.py
validate_computation_type
¶
validate_computation_type(type_: ComputationType) -> None
Validate both strata of a computation type.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
The computation type whose effect row and result type to check.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If either stratum is ill-formed. |
Source code in src/quivers/qiec/checking.py
register_family
¶
register_family(family: FamilyDecl) -> None
Record an indexed family declaration.
| PARAMETER | DESCRIPTION |
|---|---|
family
|
The family to register, with its uniform parameters and its refinable indices.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If a family with this identity is already registered, if two of its binders share a name, or if its type constructor disagrees with one already recorded. |
Source code in src/quivers/qiec/checking.py
register_constructor
¶
register_constructor(constructor: ConstructorDecl) -> None
Record a constructor against the family that declares it.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The constructor to register. Its family must already be registered and must list this constructor.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the constructor is already registered, if its family is unknown or does not declare it, if it returns the wrong number of result indices, if its telescope shadows a family binder, or if a field type or result index is ill-formed. |
Source code in src/quivers/qiec/checking.py
register_effect
¶
register_effect(effect: EffectDef) -> None
Record an effect interface and index its operations.
Each operation's signature is checked in a scope carrying the interface binders and then its own, and may mention the interface being declared.
| PARAMETER | DESCRIPTION |
|---|---|
effect
|
The interface to register.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the interface or one of its operations is already registered, if a binder is shadowed, or if an argument or result type is ill-formed. |
Source code in src/quivers/qiec/checking.py
register_handler
¶
register_handler(handler: HandlerDef) -> None
Record a handler against the interface it handles.
Coverage is checked here rather than at construction, because it is a claim about the interface's operations and only the registry knows those.
| PARAMETER | DESCRIPTION |
|---|---|
handler
|
The handler signature to register.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the handler is already registered, if its telescope shadows a binder, if its input, output, parameter types, or introduced row is ill-formed, if the interface it names is unknown or wrongly applied, if a clause covers an operation the interface does not declare, or if the handler claims totality while leaving an operation uncovered, or if an authored clause body fails to check, answers the wrong type, or resumes more often than its grade allows. |
Source code in src/quivers/qiec/checking.py
register_computation
¶
register_computation(signature: ComputationSignature) -> None
Record a computation's signature so calls can resolve to it.
Signatures are registered before any body is checked. A call therefore resolves whether the callee is declared above or below it, and mutual recursion needs no forward declaration.
| PARAMETER | DESCRIPTION |
|---|---|
signature
|
The signature to record.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If a computation with this identity is already registered, if its telescope shadows a binder, or if a parameter type, the result type, or the declared row is ill-formed. A duplicate identity is rejected rather than overwritten, since a call carrying that identity would otherwise resolve to whichever declaration happened to register last. |
Source code in src/quivers/qiec/checking.py
computation
¶
computation(computation: ComputationId) -> ComputationSignature
The registered signature with a given identity.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The identity to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComputationSignature
|
The registered signature. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If no computation is registered under that identity, which is how a call to an undeclared name is caught. |
Source code in src/quivers/qiec/checking.py
constructor
¶
constructor(constructor: ConstructorId) -> ConstructorDecl
The registered constructor with a given identity.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The identity to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ConstructorDecl
|
The registered declaration. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If no constructor is registered under that identity. The
underlying |
Source code in src/quivers/qiec/checking.py
handler
¶
handler(handler: HandlerId) -> HandlerDef
The registered handler with a given identity.
| PARAMETER | DESCRIPTION |
|---|---|
handler
|
The identity to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HandlerDef
|
The registered signature. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If no handler is registered under that identity. |
Source code in src/quivers/qiec/checking.py
operation
¶
operation(operation: OperationId) -> tuple[EffectDef, OperationDef]
The operation with a given identity, and its owning interface.
| PARAMETER | DESCRIPTION |
|---|---|
operation
|
The identity to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[EffectDef, OperationDef]
|
The interface that declares the operation, and the operation itself. The interface comes back too because checking a request needs both. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If no operation is registered under that identity. |
Source code in src/quivers/qiec/checking.py
family_for_type
¶
family_for_type(type_: TypeApplication) -> FamilyDecl
The indexed family a type application is an instance of.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
The applied type whose family to find.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FamilyDecl
|
The family whose type constructor the application names. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the application is ill-formed, or names a constructor no registered family declares, which is how a case analysis on a non-family type is rejected. |
Source code in src/quivers/qiec/checking.py
ResumptionType
didactic-model
¶
ResumptionType(*, result: TypeExpr = field(opaque=True, extras=OPAQUE_BY_VALUE), answer: TypeExpr = field(opaque=True, extras=OPAQUE_BY_VALUE), effects: EffectRow = field(opaque=True, extras=OPAQUE_BY_VALUE), parameters: tuple[Local, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
The continuation available inside one handler clause body.
A resumption is not a value and cannot be stored, so it is not a local binding. It is a capability of the position instead: available inside a clause body and nowhere else.
| PARAMETER | DESCRIPTION |
|---|---|
result
|
What the resumed operation supplies, so a
TYPE:
|
answer
|
What resuming produces, which is the clause's own answer type.
TYPE:
|
effects
|
The row resuming performs.
TYPE:
|
parameters
|
The handler's parameters, a value of each of which a resumption carries.
TYPE:
|
CheckContext
didactic-model
¶
CheckContext(*, locals: tuple[Local, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), givens: tuple[BranchGiven, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), static_scopes: tuple[StaticScopeId, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), static_variables: tuple[StaticVariableId, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), resumption: ResumptionType | None = field(default=None, opaque=True, extras=OPAQUE_BY_VALUE), rows: RowTheory = field(default=EMPTY_ROW_THEORY, opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
What is in scope at one point in a term being checked.
| PARAMETER | DESCRIPTION |
|---|---|
locals
|
Value bindings, innermost last.
TYPE:
|
givens
|
Equality evidence introduced by enclosing case branches, which is what makes an index refinement usable in the branch body.
TYPE:
|
static_scopes
|
Static scopes already entered. Tracked so a branch cannot reuse an enclosing scope's identity and silently capture its variables.
TYPE:
|
static_variables
|
Rigid variables currently active, tracked for the same reason.
TYPE:
|
resumption
class-attribute
instance-attribute
¶
resumption: ResumptionType | None = dx.field(default=None, opaque=True, extras=OPAQUE_BY_VALUE)
The continuation, when checking a handler clause body.
None everywhere else, which is what makes resume outside a
clause a checker error rather than a term with no meaning.
rows
class-attribute
instance-attribute
¶
rows: RowTheory = dx.field(default=EMPTY_ROW_THEORY, opaque=True, extras=OPAQUE_BY_VALUE)
The row predicates and absences the enclosing computation states.
with_rows
¶
with_rows(rows: RowTheory) -> CheckContext
Return this context under a theory of rows.
| PARAMETER | DESCRIPTION |
|---|---|
rows
|
The row predicates and absences in force.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CheckContext
|
The context, with its other bindings unchanged. |
Source code in src/quivers/qiec/checking.py
extend
¶
extend(local: Local) -> CheckContext
Return this context with one more value binding.
| PARAMETER | DESCRIPTION |
|---|---|
local
|
The binding to add.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CheckContext
|
A context carrying the new binding innermost. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the name is already bound. Rebinding is rejected rather than shadowed, so a name denotes one value throughout a body. |
Source code in src/quivers/qiec/checking.py
with_givens
¶
with_givens(givens: tuple[BranchGiven, ...]) -> CheckContext
Return this context with further equality evidence in scope.
| PARAMETER | DESCRIPTION |
|---|---|
givens
|
Evidence a case branch introduces by matching a constructor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CheckContext
|
A context in which that evidence may be appealed to. |
Source code in src/quivers/qiec/checking.py
with_static_scope
¶
with_static_scope(scope: StaticScopeId, variables: tuple[StaticVariableId, ...] = ()) -> CheckContext
Return this context inside a fresh static scope.
| PARAMETER | DESCRIPTION |
|---|---|
scope
|
Identity of the scope being entered.
TYPE:
|
variables
|
Rigid variables the scope introduces.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CheckContext
|
A context recording the scope and its variables as active. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the scope or one of its variables is already active. Reuse would let a branch's rigid variable be confused with an enclosing one, which is what keeps branch refinements from leaking out of the branch. |
Source code in src/quivers/qiec/checking.py
with_resumption
¶
with_resumption(resumption: ResumptionType) -> CheckContext
Return this context inside a handler clause body.
| PARAMETER | DESCRIPTION |
|---|---|
resumption
|
The continuation the clause body may invoke.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CheckContext
|
A context in which |
Source code in src/quivers/qiec/checking.py
local_type
¶
local_type(name: str) -> TypeExpr | None
The type of a value binding in scope.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The bound name to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeExpr or None
|
The binding's type, or None when the name is not bound here.
The innermost binding wins, though |
Source code in src/quivers/qiec/checking.py
given
¶
given(equality: EqualityId) -> BranchGiven | None
The equality evidence with a given identity, if in scope.
| PARAMETER | DESCRIPTION |
|---|---|
equality
|
The identity to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BranchGiven or None
|
The evidence, or None when it is not in scope, which is how an appeal to a refinement outside its branch is caught. |
Source code in src/quivers/qiec/checking.py
ResumptionUse
didactic-model
¶
Bases: Model
How many times a clause body may invoke its continuation.
An interval rather than a count, because a case splits the paths
through a body and different branches may resume different numbers of
times. minimum is what every path does at least, maximum what
some path does at most.
| PARAMETER | DESCRIPTION |
|---|---|
minimum
|
The fewest invocations on any path.
TYPE:
|
maximum
|
The most on any path, or None for unbounded. None is the top of the lattice and is used wherever the analysis cannot bound the count, so an unbounded use is never mistaken for a small one.
TYPE:
|
then
¶
then(other: ResumptionUse) -> ResumptionUse
Sequential composition: both run, so the counts add.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
What runs after this.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResumptionUse
|
The combined use. Unbounded on either side stays unbounded. |
Source code in src/quivers/qiec/checking.py
join
¶
join(other: ResumptionUse) -> ResumptionUse
Alternation: one path or the other, so the interval widens.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The alternative path's use.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResumptionUse
|
The interval covering both. The minimum drops to the smaller because some path now does that few, and the maximum rises to the larger for the same reason. |
Source code in src/quivers/qiec/checking.py
check_static
¶
check_static(term: StaticArgument, scope: StaticScope | None = None, *, registry: KernelRegistry | None = None) -> None
Check the intrinsic kind/sort structure of one static term.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The static term to check.
TYPE:
|
scope
|
Binders in scope. None checks the term's intrinsic structure alone and permits no variable reference, which is the right mode for a closed declaration.
TYPE:
|
registry
|
Registry to resolve interface applications against. None skips that check, leaving only the structural one.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the term is ill-kinded, references an unbound or wrongly kinded static variable, carries a scoped variable where a declaration is expected, or applies a known interface wrongly. |
Source code in src/quivers/qiec/checking.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 | |
check_type
¶
check_type(type_: TypeExpr, scope: StaticScope | None = None, *, registry: KernelRegistry | None = None) -> None
Check that a type expression is intrinsically well-kinded.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
The type expression to check.
TYPE:
|
scope
|
Binders in scope, or None for a closed type.
TYPE:
|
registry
|
Registry to resolve interface applications against, or None.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the expression is ill-kinded, or is a well-formed static term that is not a type, such as an index where a type is required. |
Source code in src/quivers/qiec/checking.py
check_evidence
¶
check_evidence(evidence: EqualityEvidence, context: CheckContext) -> EqualityType
Check an appeal to equality evidence and return what it proves.
| PARAMETER | DESCRIPTION |
|---|---|
evidence
|
The appeal being made, either reflexivity or an appeal to a branch given.
TYPE:
|
context
|
Scope the appeal is made in, which decides whether a branch given is still available.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EqualityType
|
The equality the evidence establishes. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the stated equality is ill-kinded, if reflexivity is claimed between unequal endpoints, if a branch given is appealed to outside its branch or with an equality other than the one it carries, or if the evidence is of an unknown class. |
Source code in src/quivers/qiec/checking.py
infer_value
¶
infer_value(value: Value, registry: KernelRegistry, context: CheckContext = CheckContext()) -> TypeExpr
Infer the type of a pure value term.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value to check.
TYPE:
|
registry
|
Declarations the value's types are resolved against.
TYPE:
|
context
|
Bindings and evidence in scope. The default empty context suits a closed value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeExpr
|
The inferred type. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If a local is unbound or carries a type other than the one the term claims, if a literal's value does not inhabit its type, if a constructor is applied wrongly, if a let binds a value of a type other than its binder's or rebinds a name in scope, if equality evidence is forged or out of scope, or if an inferred type mentions a rigid variable that escapes its branch. |
Source code in src/quivers/qiec/checking.py
2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 | |
check_request
¶
check_request(request: EffectRequest, registry: KernelRegistry, context: CheckContext) -> tuple[EffectRef, TypeExpr]
Check one effect request and report what performing it yields.
| PARAMETER | DESCRIPTION |
|---|---|
request
|
The request to check, naming an instance, an interface application, an operation, and the arguments it carries.
TYPE:
|
registry
|
Declarations the request is resolved against.
TYPE:
|
context
|
Scope the request is made in.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[EffectRef, TypeExpr]
|
The interface application the request performs, and the type resuming it supplies. The interface comes back because the caller needs it to build the row this request adds to. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the operation is unknown, if the named interface does not own it, if the static or value arguments do not match the operation's signature, if the declared result type disagrees with the instantiated one, or if any part mentions a rigid variable out of scope. |
Source code in src/quivers/qiec/checking.py
3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 | |
infer_computation
¶
infer_computation(computation: Computation, registry: KernelRegistry, context: CheckContext = CheckContext()) -> ComputationType
Infer the result type and effect row of a computation.
This is the kernel's entry point for checking effectful code. The
row it returns is what remains unhandled: a Handle discharges its
instance, so a fully handled computation comes back with the empty
row.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The term to check.
TYPE:
|
registry
|
Declarations the term is resolved against.
TYPE:
|
context
|
Bindings and evidence in scope. The default empty context suits a closed computation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComputationType
|
The result type paired with the effects still outstanding. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If two case branches share a static scope, if a request, value, or branch fails to check, if a handler's interface does not match the instance it discharges, if branch types or rows fail to unify, or if a rigid variable escapes the branch that introduced it. |
Source code in src/quivers/qiec/checking.py
resumption_use
¶
resumption_use(computation: Computation) -> ResumptionUse
Count the continuation invocations along the paths of a body.
A resume is lexical to the clause that encloses it, so a call
contributes nothing: the callee has no access to this clause's
continuation and cannot invoke it however it is written. That is what
keeps the analysis exact rather than conservative across recursion.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The clause body to analyse.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResumptionUse
|
The interval of invocation counts over the body's paths. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the term is of an unknown computation class. |
Source code in src/quivers/qiec/checking.py
4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 | |
check_resumption_grade
¶
check_resumption_grade(grade: ResumptionGrade | ResumptionInterval, use: ResumptionUse, *, subject: str) -> None
Hold a clause body to the grade its declaration promises.
| PARAMETER | DESCRIPTION |
|---|---|
grade
|
The declared grade.
TYPE:
|
use
|
What the body actually does, from
TYPE:
|
subject
|
What is being checked, named in any diagnostic.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the body can resume more often than the grade allows, or, for
a linear grade, if some path fails to resume at all. A grade is a
promise other code relies on: a handler declared |
Source code in src/quivers/qiec/checking.py
4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 | |