Skip to content

feat: implementation plans + finish match-exhaustiveness & cooperative fiber yield#147

Merged
MelbourneDeveloper merged 2 commits into
mainfrom
newstuff
Jun 23, 2026
Merged

feat: implementation plans + finish match-exhaustiveness & cooperative fiber yield#147
MelbourneDeveloper merged 2 commits into
mainfrom
newstuff

Conversation

@MelbourneDeveloper

Copy link
Copy Markdown
Collaborator

TLDR

Adds implementation plans for the compiler's seven remaining partial features, and fully implements two of them — match exhaustiveness with catch-alls, and cooperative yield.

Details

Planning docsdocs/plans/ gains an index (README.md) plus seven actionable plans (0001, 0002, 0004, 0005, 0007, 0008, 0009), each ending in a TODO checklist, covering the compiler features that currently bail or no-op.

Match exhaustivenesscrates/osprey-types/src/pattern.rs:

  • is_catch_all is tightened so a capitalised bare binding is treated as a (possibly mis-spelled) constructor rather than a catch-all. Previously any such binding silently disabled the whole exhaustiveness check; now a misspelled variant (e.g. Bleu over Red | Green | Blue) is reported instead of absorbing the missing variants.
  • New check_redundant_arms reports dead arms: any arm following an irrefutable catch-all, and duplicate constructor/variant arms.
  • A new is_irrefutable (wildcard / lower-case variable only) is used for reachability, distinct from is_catch_all — so a refutable typed-binding arm (n: Int =>) does not wrongly mark a following _ unreachable.
  • pattern_ctor_name now counts bare built-in Result variant bindings (Success/Error) toward Result exhaustiveness.

Cooperative yieldcrates/osprey-codegen/src/fiber.rs + compiler/runtime/fiber_runtime.c:

  • gen_yield previously lowered yield e to plain identity, leaving the C fiber_yield as dead code. It now emits a real call to fiber_yield, forwarding the operand (value and type preserved); the fiber_yield(x) function form shares the same lowering.
  • fiber_yield replaces its no-op stub with a real cooperative hand-off: sched_yield() in concurrent (thread-backed) mode, and a deliberate no-op under deterministic mode — which both avoids deadlocking on the runtime_mutex held by fiber_await during deterministic execution and keeps the differential harness byte-for-byte reproducible. (True cross-fiber interleaving under deterministic mode needs stackful context switching; noted as out of scope in spec 0011.)

The 0003 and 0006 plan docs are removed now that they are implemented; spec 0011's status note for yield is updated.

How Do The Automated Tests Prove It Works?

  • New osprey-types unit tests (pattern.rs): misspelled_uppercase_variant_is_not_a_catch_all (the Bleu typo is reported), arm_after_a_catch_all_is_unreachable, duplicate_variant_arm_is_unreachable, and lowercase_binding_is_a_legal_catch_all (a genuine variable catch-all still suppresses the missing-variant error). All 100 osprey-types tests pass.
  • New must-reject cases: match_misspelled_variant.ospo and match_unreachable_after_catch_all.ospo are rejected by the compiler — the differential harness reports FC_REJECT=56 … FC_OK (ratchet of 12 held; the two new cases are not in the escape list).
  • yield codegen is exercised by the existing fibers_channels_yield_select_and_done and yield_without_value_and_let_bound_lambda_materialize codegen tests (covering both the with-value and no-operand paths), and end-to-end by compiler/examples/tested/fiber/fiber_showcase.osp (yield 25, fiber_yield(200), yield streamProcessor(...)), which still matches its .expectedoutput.
  • Differential harness: PASS=47 FAIL=0 NOEXP=0, FC_OK — no existing example regressed under the tightened exhaustiveness rules or the new yield lowering.
  • Coverage thresholds all hold, including the two changed crates: osprey-codegen 95.6% ≥ 95% and osprey-types 99.1% ≥ 98%. Full-workspace cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, and cargo test --workspace are clean.

Match exhaustiveness (osprey-types/pattern.rs):
- Tighten is_catch_all: a capitalised bare binding is a (possibly
  mis-spelled) constructor, not a catch-all, so exhaustiveness checking
  fires instead of being silently disabled by the bare binding.
- Add unreachable-arm detection: any arm after an irrefutable catch-all,
  and duplicate constructor/variant arms, are reported.
- Count bare Result variant bindings (Success/Error) toward Result
  exhaustiveness via pattern_ctor_name.
- Add 4 unit tests + 2 failscompilation reject-cases.

Cooperative yield (osprey-codegen/fiber.rs, runtime/fiber_runtime.c):
- gen_yield now emits a real call to the runtime fiber_yield (previously
  dead identity); fiber_yield(x) as a function shares the same lowering
  and the operand's value/type are preserved.
- fiber_yield performs a real cooperative hand-off: sched_yield() in
  concurrent mode, a no-op under deterministic mode (avoids deadlocking
  on the runtime mutex held by fiber_await and keeps the differential
  harness reproducible).

Removes docs/plans/0003 and 0006 (now implemented); updates the
spec 0011 status note for yield.
@MelbourneDeveloper MelbourneDeveloper merged commit c0b3c32 into main Jun 23, 2026
5 checks passed
@MelbourneDeveloper MelbourneDeveloper deleted the newstuff branch June 23, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant