Skip to content

Instantly share code, notes, and snippets.

@DamianReeves
Created January 17, 2026 11:27
Show Gist options
  • Select an option

  • Save DamianReeves/0d1ac9cc464cb3a849337552ed12f78e to your computer and use it in GitHub Desktop.

Select an option

Save DamianReeves/0d1ac9cc464cb3a849337552ed12f78e to your computer and use it in GitHub Desktop.
Morphir & WebAssembly

AGENTS.md

Morphir x WebAssembly Component Model Interactive Guide (Working Agreement)

Date: 2026-01-17

Audience: Damian (Morphir maintainer), engineer

Style: concise, creative, progressive, interactive

Goal

Build an interactive, self-guided tutorial that explains the WebAssembly Component Model ABI (with emphasis on canonical ABI, lifting/lowering) while being extremely aware of Morphir IR.

We will use the learning to evaluate:

  1. Mapping Morphir IR programs and types to WebAssembly (core Wasm level).
  2. Whether Morphir IR could serve as a practical replacement for WIT to achieve similar interaction patterns with core Wasm (imports/exports, type-safe boundaries), using Morphir IR concepts instead of WIT.
  3. Where gaps prevent this substitution (semantic/ABI/tooling mismatches).
  4. How Morphir could be enhanced to support this use case (IR extensions, conventions, tooling, validation).

Scope of Concepts to Cover (Progressively)

We will proceed module-by-module, and only advance when Damian explicitly says to move on or we both feel confident the current module is understood.

Modules will progressively cover:

  • Core Wasm boundary constraints (i32/i64/f32/f64, linear memory)
  • Canonical ABI: lifting and lowering
  • Scalars (bool/int/float)
  • Strings and byte sequences (ptr/len, encoding)
  • Lists, records/structs, tuples
  • Variants/enums, option/result
  • Functions, multi-arg/multi-return, flattening rules
  • Resources/handles (ownership, borrowing patterns)
  • Error handling and traps vs typed errors
  • Versioning and evolution patterns
  • Performance considerations (copies, allocations, alignment)

Morphir IR Awareness (Always On)

Every module must include:

  • A parallel view in Morphir IR terms (types, values, modules, functions).
  • Concrete examples that include Morphir IR representation, not just WIT.
  • A mapping discussion: Morphir IR -> canonical ABI representation -> core Wasm signature
    • memory layout.
  • A “WIT replacement check” section:
    • Which WIT feature is being approximated
    • What Morphir IR already supports
    • What is missing (gaps)
    • Candidate enhancements to Morphir IR and/or Morphir toolchain

Deliverables per Module

Each module should include:

  • A short conceptual explanation (no rushing).
  • Visual diagrams (ASCII is fine) showing lifting/lowering paths.
  • Code snippets in:
    • F#
    • Scala
    • Go
  • A Morphir IR example (types + a small function/value).
  • A boundary-level view:
    • core Wasm function signature
    • memory layout (ptr/len, field layout, tags)
  • A “confidence check” with questions Damian answers before proceeding.

Key Questions We Are Trying to Answer

  • Can Morphir IR act as an IDL/interface definition layer analogous to WIT?
  • Can we systematically derive canonical ABI lowering/lifting rules from Morphir IR types?
  • What semantics does WIT/component model have that Morphir IR lacks (e.g. resources, ownership/borrowing, explicit world/import/export structure, stability/versioning rules)?
  • What additions would make Morphir IR more suitable (annotations, effect/IO boundaries, representation/ABI metadata, canonicalization rules, package/interface boundaries)?

Interaction Rules

  • The guide is interactive and self-paced.
  • Do not advance to the next module until Damian says:
    • “Move on”, or equivalent explicit permission.
  • If a concept is unclear, we pause and refine with more examples.
  • Use precise language; avoid hand-wavy leaps.

Constraints & Formatting

  • No HTML formatting.
  • Use Markdown code fences with language identifiers for code.
  • Prefer immutable-first modeling and typed domain modeling (product/sum types).
  • When presenting mappings, be explicit about:
    • numeric sizes, signedness, endianness assumptions
    • alignment/padding expectations
    • ownership and who frees memory

First Steps (Planned)

Module 1: Establish a shared baseline:

  • Minimal core Wasm ABI constraints
  • What “canonical ABI” means operationally
  • Lifting/lowering for scalar types
  • Morphir IR scalar type mapping and any mismatches

(Then proceed to strings/lists/etc.)

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