Risks and alternatives
Risks (semantic, build, supply chain, performance, ergonomic), explicit alternatives considered (LLVM IR, WASM, Rust, JIT, C++, Zig), kill switches that demote the transpiler back to optional, comparable industrial precedent.
16 notes
Risks (semantic, build, supply chain, performance, ergonomic), explicit alternatives considered (LLVM IR, WASM, Rust, JIT, C++, Zig), kill switches that demote the transpiler back to optional, comparable industrial precedent.
Testing strategy: differential testing against vm3, BG corpus, fuzzing, sanitiser matrix (ASan/UBSan/TSan/MSan/LeakSan), property tests, reproducibility check, 16 phased CI gates.
Build pipeline: `mochi build` command surface, output layout, amalgamated runtime, cross-compilation via bundled zig cc, APE via cosmocc, WASM via wasi-sdk, content-addressed caching, reproducibility.
Lowering Mochi `stream<T>`, stream definitions, `on`-handlers, agent records, and `intent` methods, plus the M:N work-stealing scheduler over minicoro fibers that runs them.
Lowering the Mochi query DSL (LINQ-style from/where/select/join/group by/order/limit/union/intersect/except) to C with arena allocation, operator fusion, and load/save adapters.
The C target itself: C23 features used, compiler matrix (clang, gcc, msvc, zig cc, cosmocc, tcc), tier-1/2/3 architectures and OSes, ABI per arch, libc matrix, sanitisers, reproducibility, hardening, style guide for emitted C.
Type-system lowering details: generics/monomorphisation, records, sum types with niche optimisation, closures with fat pointer, strings with SSO, lists, maps with Swiss-table, sets, time/duration, error values with built-in code table.
Codegen pipeline, why a C IR, name mangling rules, type-lowering table, value representation with `mochi_value` boxed type, expression lowering, statement lowering, for-loop lowering, try/catch via setjmp, Maranget pattern matching, modules, amalgamation.
Inventory of the third-party and home-grown components the C runtime can stand on: GC (BDWGC, MMTk, Perceus), allocator (mimalloc, scudo), coroutines (minicoro), I/O (libuv, libxev), strings, hash tables, JSON/YAML/CSV, HTTP, LLM, FFI.
Survey of transpilers and AOT compilers that emit C or behave like a C-target system: Nim, Crystal, Vala, OCaml, Roc, Koka, MLton, Cosmopolitan, zig cc, Cython, ATS, Soufflé. Twelve distilled lessons.
The five guiding principles behind the Mochi-to-C transpiler (spec-first, boring C, no ABI surprises, portability over performance, verifiable output), plus the runtime shape and a sample C output.
Every Mochi construct the MEP-45 codegen must lower: value core, function core, collection core, ADT core, query DSL, stream/agent core, logic, AI/FFI, tests, modules, error model, concurrency semantics.
Deep research notes that back specific design documents. Each subsection is the substrate for one MEP (Mochi Enhancement Proposal) or comparable design brief.
Research substrate for Mochi MEP-45 (May 2026). A 12-file deep dive into ahead-of-time transpilation from Mochi to ISO C23: language surface, design philosophy, prior-art transpilers, runtime building blocks, codegen design, type-system lowering, C-target portability, dataset pipeline, streams and agents, build system, testing gates, and risks.
Research substrate for Mochi MEP-41 (May 2026). A 57-file deep dive into memory-safety advances from 2023 to mid-2026: capability hardware, generational references, ownership systems, runtime techniques, formal verification, and industry policy (CISA / NSA / ONCD).
Research substrate for Mochi MEP-42 (May 2026). A 73-file deep dive into how managed-language runtimes lower typed IR to native machine code: code generation backends, AOT case studies, naive emission techniques, target ISAs and ABIs, object formats, linkers, runtime and libc, debug info, and recent PLDI/POPL papers.