Skip to content

Typed holes

A typed hole stands for part of a program that has not been written yet. A module with holes still checks: each hole is well typed at its goal, and qvr check reports every goal together with the bindings in scope where the hole stands. The reference machine runs such a module around its holes. Nothing that leaves the reference machine accepts one: compilation, transpilation, serialization, fitting, and program runs refuse the module and list every hole (Export). The typing and evaluation rules are in Typed holes.

Forms

Form Position Meaning
?x value a value whose goal the position fixes
?x : T value a value with goal T
?A type an unknown type, distinct from every other type
?f[..](..) : T !{e} declaration a computation whose body is the hole ?f

A hole's name is one identifier; ?a.b is refused. Two occurrences of one name are two holes that a filling fills together. ? begins nothing else in the language.

Value holes

A value hole may stand wherever a value may. Its goal is the type written after it or, when nothing is written, the type its position expects: a return expects the computation's result type, an argument the parameter's type, a field its declared type.

family Light : Type
    constructor Red : Light
    constructor Green : Light

define pick(b : Bool, x : Int) : Int !{} =
    if b then
        return x
    else
        return ?fallback

define scaled(x : Real) : Real !{} =
    let y = ?factor : Real
    return x * y

define light() : Light !{} =
    return ?colour

Here ?fallback has goal Int and sees b : Bool and x : Int; ?factor has the written goal Real; ?colour has goal Light. A hole is well typed at its goal and at no other type, so the body around it checks exactly as it would with a value of that type in its place.

A position that fixes no type, such as the right side of let y = ?h, needs the annotation: qvr check refuses ?h with qiec-hole-goal and asks for ?h : T. An annotation that contradicts the position (return ?h : Bool in a computation returning Int) is refused with the same code.

Type holes

?A in a type position is an unknown type. Every occurrence of one name in a module is the same unknown, and it is distinct from every other type:

define keep(x : ?A) : ?A !{} =
    return x

keep checks because its body uses x only as a value of the unknown type. A body that needs the unknown to be a particular type, such as return x + 1 with x : ?A, is refused, naming ?A: a body that checks with a type hole checks for every type that fills it.

Declaration holes

A declaration hole is the header of a define with ? in place of define and no body. The row may be omitted, in which case it is empty. Calls of the computation check against the header:

?helper(n : Int) : Int

define use(n : Int) : Int !{} =
    let m <- helper(n)
    return m + 1

helper is the computation whose body returns the value hole ?helper, whose goal is the result type and whose bindings are the parameters.

Checking and goals

qvr check reports each hole as a note with code qiec-hole and exits with status 0, since a note is not an error:

holed.qvr:7:15: note[qiec-hole]: type hole ?P : Type
holed.qvr:9:15: note[qiec-hole]: goal ?fallback : Int  [b : Bool, x : Int] in pick

hole_goals returns the same goals for a checked module, each a HoleGoal with its type, the bindings in scope, the declaration that holds it, and its position. The goals come from the kernel checker itself, so a goal states exactly the context the hole is checked in.

The language server publishes each goal as an information diagnostic, shows the goal and the bindings when the pointer is on a hole, and offers fills as quick fixes: each binding in scope whose type is the goal, each constructor of the goal's family (with a fresh hole per field, as in Pair(?colour_1, ?colour_2)), and a literal of a builtin goal type. Filling a declaration hole writes the declaration's define with the fill as its body.

Running around holes

qvr run --holes FILE ENTRY ARGS runs a computation of a module with holes on the reference machine; without --holes, qvr run refuses the module. A run that never inspects a hole's value finishes as usual. A run that does is indeterminate:

pick = indeterminate, holding ?fallback : Int
use = indeterminate, stopped where ?helper is needed : Int

In the first, the run finished but its value is the hole. In the second, the step m + 1 had to inspect the value of ?helper, so the run stopped there. --json reports the same as {"indeterminate": {"holes": [...], "needed": ..., "value": ...}}. --cache is refused with --holes, since a run around holes is not a reproducible run.

From Python, run_named returns an ExecutionResult whose indeterminate is true and whose value is an Indeterminate. resume_run fills holes and continues the run where it stopped, without running again what ran before:

from quivers.dsl import parse
from quivers.dsl.qiec_lowering import lower_qvr_to_qiec
from quivers.qiec import resume_run, run_named
from quivers.qiec.terms import LiteralValue
from quivers.qiec.types import INT

with open("holed.qvr") as file:
    module = lower_qvr_to_qiec(parse(file.read()))
stopped = run_named(module, "use", (4,))
assert stopped.indeterminate
done = resume_run(stopped, {"helper": LiteralValue(value=10, type=INT)})
assert int(done.value) == 11

A filling is a core value checked against the goal of every hole of its name; it may mention the bindings the hole sees and may contain holes of its own, which a later resumption fills. A filling of another type, one that mentions a binding the hole cannot see, or one that names no hole is refused with qiec-hole-fill. A stopped run resumes once.

Export

Every path that leaves the reference machine refuses a module with holes and lists every hole, each with its goal and position:

Path Refusal
loads, load, Compiler.compile CompileError
transpile, every target UnsupportedConstruct with one hole:<name> kind per hole
dumps and the stable wire form SerializationError
Model.fit HoleError
a program run (invoke_entry, qvr run) ExecutionFailure with code qiec-hole
qvr run without --holes code qiec-hole

A further path calls refuse_holes on the checked module before it does anything else.

Content identity

A declaration with holes has a content hash of its own. A hole's name is a name, not content, so renaming a hole leaves the hash unchanged, while filling it changes it (Content identity).