Skip to content

Typed holes

Where a checked module's typed holes are, and the refusal every export path makes for a module that has one. The typing and evaluation rules are in Typed holes.

holes

Typed holes in checked QIEC: where they are and who refuses them.

A typed hole stands for a value or a type the author has not written yet. A value hole is the core term HoleValue, well typed at its goal type and at no other. A type hole is an opaque family with no constructors whose name is the hole's spelling, ?A: checking treats it as an unknown type distinct from every other type, so a body that checks with it checks for every type that could fill it. ? cannot begin a declared name, so only a type hole declares such a family.

A module with holes checks and runs on the reference machine, but it has no compiled or exported form. Every export path (the stable wire form, compilation to PyTorch, transpilation, fitting, and runs that produce experiment records) calls refuse_holes, which lists every hole of the module, not only the first.

HOLE_SIGIL module-attribute

HOLE_SIGIL = '?'

The character that begins a hole's spelling, ?name.

HoleSite didactic-model

HoleSite(*, name: str, kind: Literal['value', 'type'], goal: str, origin: SourceOrigin | None = field(default=None, opaque=True, extras=OPAQUE_BY_VALUE))

Bases: ValueModel

One typed hole of a module, as an export refusal lists it.

PARAMETER DESCRIPTION
name

The hole's name, without the sigil.

TYPE: str

kind

Whether the hole stands for a value or for a type.

TYPE: ('value', 'type') DEFAULT: "value"

goal

The rendered goal: the hole's type for a value hole, Type for a type hole.

TYPE: str

origin

Where a value hole was written; a type hole is reported by name.

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

render

render() -> str

Render the hole as one line of a refusal.

RETURNS DESCRIPTION
str

?name : goal, followed by at file:line:column when the hole's position is known.

Source code in src/quivers/qiec/holes.py
def render(self) -> str:
    """Render the hole as one line of a refusal.

    Returns
    -------
    str
        ``?name : goal``, followed by ``at file:line:column`` when the
        hole's position is known.
    """
    text = f"{HOLE_SIGIL}{self.name} : {self.goal}"
    origin = self.origin
    if origin is not None and origin.line is not None:
        where = origin.file or origin.module
        text += f" at {where}:{origin.line}:{origin.column or 0}"
    return text

HoleError

HoleError(action: str, holes: tuple[HoleSite, ...])

Bases: ValueError

An export path was given a module that contains typed holes.

PARAMETER DESCRIPTION
action

What was refused, as a noun phrase ("transpilation").

TYPE: str

holes

Every hole of the module.

TYPE: tuple[HoleSite, ...]

ATTRIBUTE DESCRIPTION
code

The diagnostic code, qiec-hole.

TYPE: str

Source code in src/quivers/qiec/holes.py
def __init__(self, action: str, holes: tuple[HoleSite, ...]) -> None:
    self.action = action
    self.holes = holes
    listed = "; ".join(hole.render() for hole in holes)
    count = len(holes)
    noun = "hole" if count == 1 else "holes"
    super().__init__(
        f"{action} needs a complete module, but it has {count} typed "
        f"{noun}: {listed}; fill every hole first"
    )

type_hole_name

type_hole_name(name: str) -> str

The name of the opaque family a type hole ?name declares.

PARAMETER DESCRIPTION
name

The hole's name as written, without the sigil.

TYPE: str

RETURNS DESCRIPTION
str

?name.

Source code in src/quivers/qiec/holes.py
def type_hole_name(name: str) -> str:
    """The name of the opaque family a type hole ``?name`` declares.

    Parameters
    ----------
    name : str
        The hole's name as written, without the sigil.

    Returns
    -------
    str
        ``?name``.
    """
    return HOLE_SIGIL + name

is_type_hole

is_type_hole(family: FamilyDecl) -> bool

Whether a family is the opaque family of a type hole.

PARAMETER DESCRIPTION
family

The family.

TYPE: FamilyDecl

RETURNS DESCRIPTION
bool

True when its local name begins with ?, which no declared name can.

Source code in src/quivers/qiec/holes.py
def is_type_hole(family: FamilyDecl) -> bool:
    """Whether a family is the opaque family of a type hole.

    Parameters
    ----------
    family : FamilyDecl
        The family.

    Returns
    -------
    bool
        True when its local name begins with ``?``, which no declared name
        can.
    """
    return split_module(family.name)[1].startswith(HOLE_SIGIL)

holes_in

holes_in(datum: HeldValue) -> tuple[HoleValue, ...]

Every value hole a QIEC datum contains, in traversal order.

PARAMETER DESCRIPTION
datum

A module, declaration, computation, value, or tuple of them.

TYPE: HeldValue

RETURNS DESCRIPTION
tuple[HoleValue, ...]

Each occurrence once, outermost and leftmost first.

Source code in src/quivers/qiec/holes.py
def holes_in(datum: HeldValue) -> tuple[HoleValue, ...]:
    """Every value hole a QIEC datum contains, in traversal order.

    Parameters
    ----------
    datum : HeldValue
        A module, declaration, computation, value, or tuple of them.

    Returns
    -------
    tuple[HoleValue, ...]
        Each occurrence once, outermost and leftmost first.
    """
    found: list[HoleValue] = []
    pending: list[HeldValue] = [datum]
    seen: set[int] = set()
    while pending:
        item = pending.pop()
        if isinstance(item, HoleValue):
            found.append(item)
            continue
        if isinstance(item, QiecModel | tuple):
            if id(item) in seen:
                continue
            seen.add(id(item))
            pending.extend(reversed(_children(item)))
    return tuple(found)

type_holes_in

type_holes_in(datum: HeldValue) -> tuple[FamilyDecl, ...]

Every type-hole family a QIEC datum declares.

PARAMETER DESCRIPTION
datum

A module or any datum holding family declarations.

TYPE: HeldValue

RETURNS DESCRIPTION
tuple[FamilyDecl, ...]

The opaque families of type holes, in traversal order.

Source code in src/quivers/qiec/holes.py
def type_holes_in(datum: HeldValue) -> tuple[FamilyDecl, ...]:
    """Every type-hole family a QIEC datum declares.

    Parameters
    ----------
    datum : HeldValue
        A module or any datum holding family declarations.

    Returns
    -------
    tuple[FamilyDecl, ...]
        The opaque families of type holes, in traversal order.
    """
    found: list[FamilyDecl] = []
    pending: list[HeldValue] = [datum]
    seen: set[int] = set()
    while pending:
        item = pending.pop()
        if isinstance(item, FamilyDecl):
            if is_type_hole(item) and item not in found:
                found.append(item)
            continue
        if isinstance(item, QiecModel | tuple):
            if id(item) in seen:
                continue
            seen.add(id(item))
            pending.extend(reversed(_children(item)))
    return tuple(found)

hole_sites

hole_sites(datum: HeldValue) -> tuple[HoleSite, ...]

Every typed hole of a QIEC datum, as refusals list them.

PARAMETER DESCRIPTION
datum

A module or any part of one.

TYPE: HeldValue

RETURNS DESCRIPTION
tuple[HoleSite, ...]

The type holes by name, then each value hole occurrence by position; an occurrence reached through two paths is listed once.

Source code in src/quivers/qiec/holes.py
def hole_sites(datum: HeldValue) -> tuple[HoleSite, ...]:
    """Every typed hole of a QIEC datum, as refusals list them.

    Parameters
    ----------
    datum : HeldValue
        A module or any part of one.

    Returns
    -------
    tuple[HoleSite, ...]
        The type holes by name, then each value hole occurrence by
        position; an occurrence reached through two paths is listed once.
    """
    sites: list[HoleSite] = [
        HoleSite(
            name=split_module(family.name)[1].removeprefix(HOLE_SIGIL),
            kind="type",
            goal="Type",
        )
        for family in type_holes_in(datum)
    ]
    seen: set[tuple[str, SourceOrigin]] = set()
    for hole in holes_in(datum):
        key = (hole.name, hole.origin)
        if key in seen:
            continue
        seen.add(key)
        sites.append(
            HoleSite(
                name=hole.name,
                kind="value",
                goal=render_static(hole.type),
                origin=hole.origin,
            )
        )
    return tuple(sites)

has_holes

has_holes(datum: HeldValue) -> bool

Whether a QIEC datum contains a typed hole of either kind.

PARAMETER DESCRIPTION
datum

A module or any part of one.

TYPE: HeldValue

RETURNS DESCRIPTION
bool

True when a value hole occurs in it or it declares a type hole.

Source code in src/quivers/qiec/holes.py
def has_holes(datum: HeldValue) -> bool:
    """Whether a QIEC datum contains a typed hole of either kind.

    Parameters
    ----------
    datum : HeldValue
        A module or any part of one.

    Returns
    -------
    bool
        True when a value hole occurs in it or it declares a type hole.
    """
    return bool(holes_in(datum) or type_holes_in(datum))

refuse_holes

refuse_holes(datum: HeldValue, *, action: str) -> None

Refuse a module, or any part of one, that contains a typed hole.

Every path that leaves the reference machine calls this first: a hole has no compiled, transpiled, serialized, or fitted form, and a run that feeds an experiment record must not depend on one.

PARAMETER DESCRIPTION
datum

The module, or the declaration or term about to be exported.

TYPE: HeldValue

action

What is being refused, as a noun phrase that names the path.

TYPE: str

RAISES DESCRIPTION
HoleError

If the datum contains a hole; the message lists every hole with its goal and position.

Source code in src/quivers/qiec/holes.py
def refuse_holes(datum: HeldValue, *, action: str) -> None:
    """Refuse a module, or any part of one, that contains a typed hole.

    Every path that leaves the reference machine calls this first: a hole
    has no compiled, transpiled, serialized, or fitted form, and a run that
    feeds an experiment record must not depend on one.

    Parameters
    ----------
    datum : HeldValue
        The module, or the declaration or term about to be exported.
    action : str
        What is being refused, as a noun phrase that names the path.

    Raises
    ------
    HoleError
        If the datum contains a hole; the message lists every hole with its
        goal and position.
    """
    holes = hole_sites(datum)
    if holes:
        raise HoleError(action, holes)