polydat 0.8.2

Polydat — a variates construction engine
Documentation
---
type: specification
title: None Semantics
timestamp: 2026-09-27
description: How Value::None flows through the kernel and the language, including the conditional-shadow const rule.
tags: [runtime, language, types]
---

# None Semantics

This document specifies how `Value::None` flows through the kernel
and the language surface: the None rule at the language level, the
three rules that apply it at interpolation, default, and render sites,
and the conditional-shadow compilation rule for `const`. It gives the
mechanism behind three axiom-level statements: T1 (typed return) in
[composition_substrate.md](composition_substrate.md), where None is the
canonical "absent" sentinel of the `Value` enum; D1 in
[runtime_model.md](runtime_model.md), under which a typed return of
None never silently becomes a string; and G1 (auto-extern) in
[polydat_grammar.md §18](polydat_grammar.md#sec-gaxioms), through the
conditional-shadow `const` compilation rule below. This document is
normative for the implemented language and runtime surfaces.

**Related specifications.** [Scope Model](scope_model.md) (the scope
chain, visibility rules, and the two-tier lookup this document relies
on); [Wire Materialization](wire_materialization.md) (the cross-scope
read invariant, which conditional-shadow `const` extends).

## Motivation

`Value::None` is the canonical "absent" sentinel of the `Value` enum.
The kernel's name-resolution chokepoints (`get_constant`, `lookup` in
`kernel/state.rs`) treat a `Value::None` output as "not present in
this scope" and fall through to the next tier. The language surface
follows the same discipline: string-literal interpolation in source
code and bind-point substitution at op-template render time must not
coerce `None` into `Str("")` or into the literal text `"None"` (Debug
formatting). Either coercion conflates **absent** with
**present-but-empty**, a type error whose symptom is corrupted bytes at
a wire-protocol boundary, where an empty field is a real value that a
remote system stores and returns.

The contract is that ordinary nodes propagate `Value::None` unless
their metadata declares `accepts_none_inputs()`, and that rendering
boundaries never coerce absence silently. This is
**None-propagation**, the pattern SQL uses for NULL
(`NULL || 'foo'` → NULL) and Rust uses for `Option`'s `?` operator:
absence propagates, and interpolating it into a string yields no
string at all.

## Three orthogonal rules

The discipline consists of three rules, each applied at a different
site. Each rule is independently necessary, and together they give
the `set:` desugar (and any other "shadow if present" pattern) its
behavior.

### Rule 1 — String interpolation propagates None

A source-level string literal containing one or more `{X_i}`
placeholders desugars (via `parse_interpolated_string` in
`polydat-grammar/src/parser.rs`) to a `printf(fmt, X_1, ..., X_n)` call. The
`Printf` node's `eval` applies:

> If any input slot referenced by a `{}` placeholder holds
> `Value::None`, the output is `Value::None`. Otherwise the
> output is the formatted `Value::Str(...)`.

Inputs not referenced by any placeholder (unusual but permitted by the
variadic signature) do not trigger propagation.

The consequence through `const` is:

```
const X := "{Y}"            // Y is unbound (read as Value::None)
   ↓
   at initialization, __init_X = printf("{}", Y) → Value::None   // Rule 1
   ↓
   X's own value is None → initialization takes the fallback,
   the input slot X that the binder filled from the enclosing scope
   ↓
   __const_X holds that value (None when the enclosing scope has no X)
   ↓
   X reads __const_X
```

`printf` never renders `Value::None` through its debug
representation. Doing so would create the real string `"None"`, which
`get_constant` would return and which would incorrectly shadow an
outer binding for `X`.

Rule 1 applies to every node, not only `printf`, on the interpreter
(P1), the closure tier (P2), and native (P3). The interpreter's
`EngineCore::eval_node` checks each node before invoking it. The
closure tier and the hybrid kernel of P3 keep a None mask over the
slot buffer, and a step whose node does not accept None marks every
output None without running when any input is None. Native code never
accepts None. On P3 a step downstream of an unset extern is a closure
step, so a None arrives at a native segment only if a host clears an
extern after the build, and that is a panic. The interpreter's
native-cone extraction admits a None-tolerant node into a cone only
when every input is an intra-cone wire, where no None can arrive.
`Kernel::pull` returns `None` for a slot that holds None on the
interpreter, the closure tier, and native.

A comprehension applies the rule to the names its clause sources and
filter predicates read ([comprehension_forms.md](comprehension_forms.md)
§5 V3, §10.9.1). A name bound nowhere, outside `pragma strict`, and a
name bound to None both read None. A source that reads None yields
nothing, and a predicate that reads None for a tuple is None and keeps
no tuple, on every surface and every engine.

Pure native has no closures to hold a None, so it refuses a pull
whose output depends on an unset input, naming the extern, where the
other three engines would return `None` for that output
([engines.md](engines.md) §3.3). A pull of an output that reads no
unset input is served as on the other engines: after `mode` is
cleared, pulling an output that never reads `mode` returns its value,
and pulling one that reads `mode` is refused. The check exempts the
slots only initialization reads, a const's slot and the fallback
input a const reads, and exempts a `shared` register with a computed
start only until initialization seeds it; after that the register
counts like any other extern. Initialization on pure native refuses a
const whose value is None (`KernelError::Refused`).

### Rule 2 — Defaults are explicit expressions

`{X}` is the only interpolation bind-point form. If `X` is absent,
Rule 1 propagates `None`. The grammar does not define `{X?}` or
`{X ?? Y}`.

An author who requires a fallback uses an explicit None-aware node
such as `default_or(X, fallback)` in the expression graph and then
interpolates that binding. Empty-string substitution is therefore an
authored value, never an implicit rendering rule.

### Rule 3 — Op-template render refuses silent None

`Value::to_display_strict` lives in `polydat-core/src/ast.rs` and returns
`Option<String>`: `None` for `Value::None` and `Some(text)` otherwise.
Any host wire renderer must use this strict primitive and report an
explicit error naming the bind point when it returns `None`. Calling
`to_display_string`, which renders the literal text `"None"`, does not
satisfy the op-template rendering contract.

The render path is the wire-protocol boundary. Bytes rendered there
are sent to a remote system, where an empty field is a real value that
the system stores and returns, so absence must not render as an empty
field. `to_display_string` is the lossy form, for a log or a
diagnostic where empty is acceptable; a render site uses the strict
form.

Structural omission of an op-template segment is not a bind-point
operation. The host must construct or select the complete segment
explicitly before rendering.

## Interaction with `set:` and the grammar invariant

The workload-parser sugar `set: { X: "{Y}" }` desugars to:

```
const X := "{Y}"
```

This is canonical Polydat grammar, and the desugar produces no
special-case AST. The semantics are defined by **how Polydat compiles
and evaluates `const NAME := <expr>`**, not by the sugar layer.

Under Rule 1, `const X := "{Y}"` with `Y` unbound evaluates to
`Value::None` at initialization. Initialization then takes the value of
the input slot `X`, which holds nothing unless the compiler gave `X`
that slot. The conditional-shadow compiler rule below gives `X` that
slot.

## Conditional-shadow semantics for `const`

`assemble_parent` in `dsl/compile.rs` is the one lowering that every
entry point uses, for all four engines (the interpreter, the closure
tier, native, and pure native). It collects the names each binding's
RHS references (`dsl::validate::collect_references`) and gives every
referenced name not defined locally an input slot, so a const whose
RHS references at least one name gets an implicit input slot `NAME`
of its own name, in addition to its const slot `__const_NAME` and
the output `__init_NAME` that computes its expression. The binder
fills the input slot `NAME` from the enclosing scope's `NAME`
binding, if any, before the kernel is initialized. Initialization
then provides the fall-through:

1. It evaluates `__init_NAME`. A real value is the const's value.
2. A `Value::None` falls back to the input slot `NAME` (the
   `fallback` of the const's `ConstInit` record), and the const's
   value is whatever the binder wrote there, or `Value::None` when
   the enclosing scope has no `NAME`.

The value is written to `__const_NAME`, and the const `NAME` reads
it. As a result, `const NAME := <expr>` is a *conditional shadow*
when its RHS can evaluate to None. A real value shadows the outer
binding; a None leaves the outer binding visible. The `set:` sugar remains canonical
Polydat, and the semantics come from the compiler's handling of every
const, not from special-casing the sugar.

**Pure-literal exception:** a const whose RHS has zero name references
(e.g. `const x := 1`, the form a comprehension's per-iteration binding
takes) is NOT auto-externed. It always folds to a real value, never
takes the fall-through path, and must not appear as an input slot.
The presence of a name reference is the exact criterion.

**Wiring composition (`materialize_wiring_from_outer`):** the read
invariant of [wire_materialization.md](wire_materialization.md)
requires that reading `X` on the inner scope returns what
`outer.lookup(X)` returns. An outer const's value is fixed at the
outer kernel's initialization, and it is already the fall-through
value when the outer const's own expression yielded None, so step 2
of the materializer copies the value returned by `outer.lookup`
instead of attaching a cell. A const does not change during its
kernel's life, so a copy is exact. For a non-const computed output,
whose value changes when its inputs change, cell attachment is the
correct primitive, because consumers need the value broadcast live.
Conditional-shadow `const` thereby extends the read invariant: to its
consumers, a const whose output is None is structurally identical to
no const declared.

The rule produces four behaviors:

- a const whose interpolation resolves shadows the outer binding of
  the same name;
- a const whose interpolation is unbound falls through to the outer
  binding;
- a None in a middle scope is transparent to its descendants: the
  fall-through is transitive through any number of scope layers;
- a pure-literal const is not auto-externed.

When both the outer and the inner scope declare `const NAME := <lit>`
with non-None values, the inner const shadows the outer through the
normal `get_constant` path; the fall-through applies only when the
inner const evaluates to None.

## Implementation correspondence

- `EngineCore::eval_node` enforces Rule 1 on the interpreter for
  `Printf` and every node that does not declare `accepts_none_inputs`.
  The closure tier's step guard and the hybrid kernel's
  `run_hybrid_step` enforce it through the None mask on the closure
  tier and native, and native code never receives a None; pure native
  refuses a pull whose output depends on an unset extern
  (`Externs::unset_read` and the per-output input lists;
  [engines.md]engines.md §3.3).
- `default_or` is the explicit None-aware fallback primitive for
  Rule 2.
- The compiler's conditional-shadow auto-extern rule
  (`assemble_parent`), `materialize_wiring_from_outer`, and
  `Kernel::init`'s fallback implement scope fall-through. Strict mode
  (composition_substrate.md L2.f) detects a silent fall-through by
  reading `__init_NAME`, the const's own value before the fallback.
- `Value::to_display_strict` is the Polydat primitive required by
  Rule 3; the host renderer constructs the bind-point error.

## Why this is safe

- **The desugar invariant is preserved.** `set:` produces canonical
  Polydat; the semantics come from how the compiler handles `const`,
  not from special-casing the sugar.
- **Resolved bind points keep ordinary rendering semantics.** Rule 1
  adds one boolean check per placeholder slot on the hot path.
- **Absent bind points fail visibly.** A `Value::None` propagates and
  then arrives at one of three places: the fall-through path, Rule 3's
  render-time error, or, if the author wrote a `default_or`, the
  authored fallback.
- **`Value::None` semantics are unified.** Every operation that
  consumes a value either propagates None or refuses to coerce it
  silently. This holds on the interpreter, the closure tier, and
  native; pure native admits no None, because it refuses a pull whose
  output depends on an unset extern and serves every other pull.

## See also

- [Scope Model]scope_model.md — scope chain, visibility rules,
  two-tier lookup.
- [Wire Materialization]wire_materialization.md — cross-scope wire
  materialization invariants.