feat: implementation plans + finish match-exhaustiveness & cooperative fiber yield#147
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 docs —
docs/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 exhaustiveness —
crates/osprey-types/src/pattern.rs:is_catch_allis 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.BleuoverRed | Green | Blue) is reported instead of absorbing the missing variants.check_redundant_armsreports dead arms: any arm following an irrefutable catch-all, and duplicate constructor/variant arms.is_irrefutable(wildcard / lower-case variable only) is used for reachability, distinct fromis_catch_all— so a refutable typed-binding arm (n: Int =>) does not wrongly mark a following_unreachable.pattern_ctor_namenow counts bare built-inResultvariant bindings (Success/Error) toward Result exhaustiveness.Cooperative
yield—crates/osprey-codegen/src/fiber.rs+compiler/runtime/fiber_runtime.c:gen_yieldpreviously loweredyield eto plain identity, leaving the Cfiber_yieldas dead code. It now emits a real call tofiber_yield, forwarding the operand (value and type preserved); thefiber_yield(x)function form shares the same lowering.fiber_yieldreplaces 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 theruntime_mutexheld byfiber_awaitduring 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
0003and0006plan docs are removed now that they are implemented; spec0011's status note foryieldis updated.How Do The Automated Tests Prove It Works?
osprey-typesunit tests (pattern.rs):misspelled_uppercase_variant_is_not_a_catch_all(theBleutypo is reported),arm_after_a_catch_all_is_unreachable,duplicate_variant_arm_is_unreachable, andlowercase_binding_is_a_legal_catch_all(a genuine variable catch-all still suppresses the missing-variant error). All 100osprey-typestests pass.match_misspelled_variant.ospoandmatch_unreachable_after_catch_all.ospoare rejected by the compiler — the differential harness reportsFC_REJECT=56 … FC_OK(ratchet of 12 held; the two new cases are not in the escape list).yieldcodegen is exercised by the existingfibers_channels_yield_select_and_doneandyield_without_value_and_let_bound_lambda_materializecodegen tests (covering both the with-value and no-operand paths), and end-to-end bycompiler/examples/tested/fiber/fiber_showcase.osp(yield 25,fiber_yield(200),yield streamProcessor(...)), which still matches its.expectedoutput.PASS=47 FAIL=0 NOEXP=0,FC_OK— no existing example regressed under the tightened exhaustiveness rules or the newyieldlowering.osprey-codegen 95.6% ≥ 95%andosprey-types 99.1% ≥ 98%. Full-workspacecargo fmt --check,cargo clippy --workspace --all-targets -D warnings, andcargo test --workspaceare clean.