Add generics monomorphization — compile forall<T> to WASM (C6i)#42
Merged
Conversation
…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>
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.
Summary
codegen.py: collection pass finds concrete call sites offorall<T>functions, infers type variable bindings, creates specializedFnDeclcopies with type variables replaced, and name-mangles (e.g.identity$Int,const$Int_Bool)wasm.py: generic function calls resolve to mangled names at WASM translation time, with type inference for chained calls and if-branchesTestMonomorphizationcovering identity/const/is_some instantiation, two-instantiation exports, ADT match, chained calls (identity(identity(99))), if-branches, let bindings, arithmetic args, and example file compilationCloses #29.
Test plan
pytest tests/ -v— 660 tests passmypy vera/— cleanpython scripts/check_examples.py— all 14 examples pass check + verify🤖 Generated with Claude Code