Skip to content

Add optional narrowing and payload access #28

Description

@itsfuad

Goal

Make builtin nullable ?T usable through full-CFG narrowing and ownership-safe payload access.

Settled source semantics

  • T promotes directly to ?T; none represents absence.
  • value != none proves presence on true edge; value == none proves presence on false edge. Reversed operands behave identically.
  • Proven ordinary value use unwraps one optional layer. Nested optionals need one proof per layer.
  • Inferred bindings use effective per-use type: let payload = value infers T under proof and ?T outside proof.
  • Explicit optional destinations and whole-carrier assignments preserve carrier type.
  • Terminating guards preserve surviving facts; joins intersect them; loops run to fixed point.
  • && and || remain eager. RHS receives no short-circuit proof, while outgoing edges may use facts implied by completed boolean result.
  • Presence checks inspect without consuming.

Stable places

  • Narrow variables, fields, nested projections, constant-foldable indexes, and direct resolved integral binding indexes.
  • Direct binding indexes carry dependency identity. Assignment to index binding invalidates dependent facts.
  • Computed indexes such as items[i + 1] are unstable unless existing const evaluation reduces them.
  • Assignment to carrier or ancestor invalidates; payload-descendant mutation preserves outer presence.
  • Overlapping alias mutation invalidates affected facts.
  • Mutable-reference and known raw-pointer calls invalidate overlapping facts after argument evaluation.
  • Unknown raw-pointer effects invalidate all potentially reachable facts. Calls invalidate mutable module-global facts.
  • Scope exit removes facts rooted in exited bindings.

Ownership boundary

  • Copyable payload and shared-reference payload reads preserve carrier.
  • Moving move-only payload from direct named local/parameter optional consumes whole carrier; reinitialization restores it.
  • Field/index/pointee payloads may be narrowed and borrowed, but move-only partial extraction is rejected.
  • Mutable-reference payload transfer follows existing transfer and borrow-conflict rules.

Compiler work

  • Insert explicit FlowTyped phase: Typechecked -> CFG -> FlowTyped -> DefiniteInit -> Ownership -> Usage -> HIR.
  • Store per-function site facts, refined expression types, payload evidence, carrier/value origins, and index dependencies in module-owned flow result.
  • Reuse canonical typechecker expression logic through refinement injection; do not add a second AST typing switch.
  • Reuse and extend internal/semantics/place origin/overlap logic; do not add a second alias walker.
  • Add T0041 for unproven payload use and T0042 for unstable narrowing subjects.
  • Ownership consumes flow evidence while preserving cleanup planning.
  • Add explicit optional-presence and optional-payload HIR/MIR operations.
  • LLVM lowers through named present and value layout fields.

Representation and explicit non-scope

  • Keep tagged {i1, payload} representation for every optional in this issue.
  • Niche layout remains Add optional niche layouts #30 and cannot affect source semantics.
  • No Some, unwrap operator, optional pattern, fallback operator, extraction operator, optional chaining, optional-to-optional equality, or new syntax.

Dependencies

Validation

  • Presence polarity, reversed operands, guards, joins, loops, eager boolean results, unreachable paths, and nested optionals.
  • Inference, explicit carrier contexts, shadowing, fields, nested fields, constant indexes, binding indexes, and computed-index rejection.
  • Exact/ancestor/descendant assignment, alias, call, global, index-dependency, and scope-exit invalidation.
  • Copy/borrow/move ownership, direct owner consumption/reinitialization, use-after-consume, conditional cleanup, and rejected partial moves.
  • Explicit HIR/MIR operations, tagged 32-bit/64-bit LLVM layout, payload projection, presence checks, and drops.
  • Positive runtime plus applicable negative x_test fixtures with bundled compiler.
  • LSP refined hover, diagnostics, incremental reset, and snapshot reuse.

Activity

  1. added
    enhancementNew feature or request
    runtime-loweringHIR/MIR/backend runtime lowering work
    language-modelPeeper language model, ownership, pointer, optional, array/slice work
    on Jun 27, 2026
  2. changed the title [-]Add optional inspect and unwrap operations[/-] [+]Add optional narrowing and payload access[/+] on Aug 21, 2026
  3. moved this from Todo to In Progress in Peeper Roadmapon Aug 21, 2026
  4. moved this from In Progress to Done in Peeper Roadmapon Aug 25, 2026
  5. moved this from Done to In Progress in Peeper Roadmapon Aug 25, 2026
  6. moved this from In Progress to Done in Peeper Roadmapon Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestlanguage-modelPeeper language model, ownership, pointer, optional, array/slice workruntime-loweringHIR/MIR/backend runtime lowering work

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions