Skip to content

Add generics monomorphization — compile forall<T> to WASM (C6i)#42

Merged
aallan merged 1 commit into
mainfrom
c6i-generics-monomorphization
Feb 24, 2026
Merged

Add generics monomorphization — compile forall<T> to WASM (C6i)#42
aallan merged 1 commit into
mainfrom
c6i-generics-monomorphization

Conversation

@aallan

@aallan aallan commented Feb 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Monomorphization pipeline in codegen.py: collection pass finds concrete call sites of forall<T> functions, infers type variable bindings, creates specialized FnDecl copies with type variables replaced, and name-mangles (e.g. identity$Int, const$Int_Bool)
  • Call rewriting in wasm.py: generic function calls resolve to mangled names at WASM translation time, with type inference for chained calls and if-branches
  • 17 new tests in TestMonomorphization covering identity/const/is_some instantiation, two-instantiation exports, ADT match, chained calls (identity(identity(99))), if-branches, let bindings, arithmetic args, and example file compilation
  • Version bump to v0.0.17 (660 tests, up from 643)

Closes #29.

Test plan

  • pytest tests/ -v — 660 tests pass
  • mypy vera/ — clean
  • python scripts/check_examples.py — all 14 examples pass check + verify
  • Pre-commit hooks pass (mypy, pytest, examples, readme)

🤖 Generated with Claude Code

…C6i)

Monomorphize generic functions by collecting concrete call sites,
creating specialized FnDecl copies with type variables replaced,
and rewriting calls to mangled names at WASM translation time.

Supports literal args, slot refs, constructors, chained generic calls,
arithmetic expressions, ADT match patterns, and multiple type params.

17 new tests (660 total). Closes #29.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aallan aallan merged commit 9d5d265 into main Feb 24, 2026
10 checks passed
@aallan aallan deleted the c6i-generics-monomorphization branch February 24, 2026 23:09
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.

Generic function codegen (monomorphization)

1 participant