Skip to content

Fiber backend: converge onto minicoro semantics — hand-port with port map, behind the permanent backend interface #676

Open

Description

@ehartford

⛔ Blocked on #675 — minicoro lands as a MigrationSpec manifest entry, not a hand-rolled build module. Blocks #369 — the Windows async stack-overflow fix rides on minicoro's Windows backend; do not attempt #369's fix against the current Darwin-only backend.

Goal

Execute docs/feature_plans/async-proposal.md: migrate minicoro (~1800 lines of public-domain C, battle-tested in Nelua) with with migrate, and replace the platform-specific fiber backend (rt/fiber_core_darwin.w + fiber_asm_darwin.s, aarch64-only) with a minicoro-backed one behind a permanent backend interface (rt/fiber_backend.w: fiber_create/resume/yield/destroy/running).

The scheduler, scope tracking, cancellation, channels, completion sequencing, and all async language semantics stay owned by With — minicoro provides only the context-switch substrate (proposal §2.2/§2.3 tables are the contract for what changes vs what must not).

Why

Current backend: Darwin/aarch64 only, hand-written asm, fixed mmap stacks, 1024-fiber cap, no sanitizer support. minicoro: x86_64/ARM/ARM64/RISC-V + ucontext + Windows fiber backends, WASM paths, vmem growable stacks, Valgrind/ASan/TSan compatibility. This is the cross-platform unlock for the async runtime — and the prerequisite for #369.

Sequencing (from the proposal)

  1. Prerequisites first (proposal §3): fix the five known async-review bugs so migration regressions are distinguishable from pre-existing issues.
  2. Introduce rt/fiber_backend.w while the CURRENT backend still works — verify the interface against known-good behavior (proposal §"introduce the abstraction first").
  3. Migrate minicoro via the Build: manifest-driven C-library migrations — one generic pipeline engine, per-library specs as data #675 manifest pipeline; wire as the second backend.
  4. Cut over per-platform; keep the interface as permanent insurance (WASM/debug/sanitizer backends).

Policy (same as #673/#674)

Deliverables

References

docs/feature_plans/async-proposal.md (canonical plan), §14 (async semantics that must not change), #675 (build pipeline), #369 (blocked Windows fix), #489/#637 runtime invariants.

Activity

  1. added this to the post-v0.16.0 milestone on Jul 16, 2026
  2. added a commit that references this issue on Jul 16, 2026
  3. changed the title [-]Migrate minicoro: cross-platform fiber backend behind a permanent backend interface (docs/feature_plans/async-proposal.md)[/-] [+]Fiber backend: converge onto minicoro semantics — hand-port with port map, behind the permanent backend interface[/+] on Aug 31, 2026
  4. ehartford commented on Aug 31, 2026

    @ehartford
    ContributorAuthor

    Re-scoped 2026-08-31 after the strategic review with Eric; docs/feature_plans/async-proposal.md is rewritten to match and is the canonical plan.

    The rationale is trust, stated properly: the fiber substrate is too critical to home-grow, and minicoro's value is that its failure modes are documented — including four open upstream defects (issues #11, #27, #31; PRs #29, #30 unmerged) and four README caveats a language runtime must convert from disclaimers into guarantees (thread-safety, TLS-across-threads, overflow-UB, unwind-on-cancel).

    Mechanism changed: hand-port/convergence, not with migrate. The trust-critical parts (switch sequences, TEB machine-code bytes, inline asm) can't go through the migrator anyway, and at ~2K lines a comprehension port transfers more trust than mechanical translation. The existing multi-platform backend (correct register sets, guard pages with per-fiber overflow attribution, stack pooling) is converged function-by-function onto minicoro semantics rather than replaced.

    Key findings folded in:

    • Our Windows x64 switch misses minicoro's four-field TEB swap (StackBase/StackLimit/DeallocationStack/FiberData) — a live correctness hole (__chkstk, SEH, OS callbacks see the wrong stack). Immediate slice: transcribe it now, ahead of the campaign.
    • Upstream issue Comparing f32 values with unsuffixed float literals emits invalid LLVM IR #27 (OpenBSD MAP_STACK) is the same bug class — generalized as a "stack registration" obligation in the backend interface.
    • On Windows, minicoro's own MSVC default is the Win32 Fiber API (OS owns TEB); the port decides raw-asm-vs-OS-fibers per Windows arch, recorded in the port map. windows-aarch64 has no upstream raw-asm precedent, which argues for OS fibers there.

    Deliverables: docs/fiber-minicoro-port.md (function map + named deviations with fixtures), transcribed switch sequences with offset provenance, minicoro's testsuite ported, the C original as an external differential oracle, dual-backend test matrix (--fiber-backend=current|ported), then flip + one A/B release + cleanup.

    Prerequisite audit already done: the old §3.1 scope-track UAF and §3.5 await_first bugs are verified fixed in today's tree; §3.2–3.4 need verification and the §3.6 panic/defer matrix is still owed (it doubles as the dual-backend acceptance suite).

  5. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): still open, and no longer blocked on #675 (the corpus registry exists). No minicoro corpus or backend exists in build/ or lib/std; async-proposal.md is the canonical plan per the 2026-08-31 re-scope.

    post-release: replacing the fiber substrate is a campaign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions