Goal
Make builtin nullable ?T usable through control-flow narrowing and safe payload access.
Settled source semantics
T promotes directly to ?T.
none represents absence.
value != none narrows a stable optional binding to T in the true branch.
value == none narrows that binding in the false branch.
- A terminating guard preserves the surviving branch proof after the guard.
- Assignment to the checked binding invalidates its proof.
- Presence checks inspect without consuming the optional value.
Explicit non-scope
- No
Some, some(...), unwrap operator, optional pattern form, fallback operator, extraction operator, or optional chaining syntax.
- No source behavior may depend on tagged versus niche backend layout.
- V1 narrowing applies to stable named bindings. Field and indexed-place narrowing require separate stability evidence.
Compiler work
- Key branch-local narrowing facts by canonical resolved symbol identity.
- Record payload-access evidence during semantic checking; HIR and later phases must consume it without re-resolving source expressions.
- Invalidate facts on assignment and merge facts conservatively across branches and loops.
- Preserve move, borrow, cleanup, and single-owner rules when payload type is move-only.
- Lower presence checks and payload extraction through canonical optional layout APIs for tagged and niche representations.
Dependencies
Validation
- Typechecker tests for true branch, false branch, reversed comparisons, terminating guards, merge behavior, shadowing, assignment invalidation, and unstable places.
- Ownership tests for copy, borrow, and move-only payloads.
- HIR, MIR, and LLVM tests for explicit presence and payload operations.
- Positive and negative
x_test fixtures using bundled compiler.
- Tagged and niche optional coverage on 32-bit and 64-bit targets.
Goal
Make builtin nullable
?Tusable through control-flow narrowing and safe payload access.Settled source semantics
Tpromotes directly to?T.nonerepresents absence.value != nonenarrows a stable optional binding toTin the true branch.value == nonenarrows that binding in the false branch.Explicit non-scope
Some,some(...), unwrap operator, optional pattern form, fallback operator, extraction operator, or optional chaining syntax.Compiler work
Dependencies
nextreturns?T.Validation
x_testfixtures using bundled compiler.