Skip to content

Decompose codegen.py into codegen/ mixin package#158

Merged
aallan merged 1 commit into
mainfrom
decompose-codegen
Mar 1, 2026
Merged

Decompose codegen.py into codegen/ mixin package#158
aallan merged 1 commit into
mainfrom
decompose-codegen

Conversation

@aallan

@aallan aallan commented Mar 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Split the 2,140-line codegen.py monolith into 11 focused modules using the mixin pattern established by checker/ and wasm/
  • Added 5 coverage gap tests reaching defensive error paths (E600, E601, E605, E606, unknown module calls)
  • Split the 4,834-line test_codegen.py into 6 focused test files mirroring the new module structure
  • Updated all documentation: vera/README.md module map, CLAUDE.md, AGENTS.md, project README.md

New codegen modules

Module Responsibility
codegen/api.py Public API, compile(), execute()
codegen/core.py Composed CodeGenerator class, shared helpers
codegen/modules.py Cross-module call detection (Pass 0)
codegen/registration.py Function/ADT registration (Pass 1)
codegen/monomorphize.py Generic instantiation (Pass 1.5)
codegen/functions.py Function body compilation (Pass 2)
codegen/closures.py Closure lifting
codegen/contracts.py Runtime contract insertion
codegen/assembly.py WAT module assembly
codegen/compilability.py Compilability checks

New test files

File Tests What it covers
test_codegen_contracts.py 32 Runtime pre/postconditions, contract fail messages
test_codegen_monomorphize.py 17 Generic instantiation, type inference
test_codegen_closures.py 17 Closure lifting, captured variables
test_codegen_modules.py 11 Cross-module guard rail and codegen
test_codegen_coverage.py 5 Defensive error paths via direct AST construction

Test plan

  • All 1,076 tests pass
  • mypy clean (40 source files)
  • All 14 examples compile + verify
  • Pre-commit hooks pass (mypy + pytest + examples + readme)

Closes #155

Split the 2,140-line codegen.py monolith into 11 focused modules
following the mixin pattern established by checker/ and wasm/:

  codegen/api.py          - Public API, compile(), execute()
  codegen/core.py         - Composed CodeGenerator class
  codegen/modules.py      - Cross-module call detection (Pass 0)
  codegen/registration.py - Function/ADT registration (Pass 1)
  codegen/monomorphize.py - Generic instantiation (Pass 1.5)
  codegen/functions.py    - Function body compilation (Pass 2)
  codegen/closures.py     - Closure lifting
  codegen/contracts.py    - Runtime contract insertion
  codegen/assembly.py     - WAT module assembly
  codegen/compilability.py - Compilability checks

Also adds 5 coverage gap tests (E600/E601/E605/E606, unknown module
calls) and splits the 4,834-line test_codegen.py into 6 focused files:
test_codegen_contracts.py, test_codegen_monomorphize.py,
test_codegen_closures.py, test_codegen_modules.py, and
test_codegen_coverage.py.

All 1,076 tests pass, mypy clean, all 14 examples validate.

Closes #155

Co-Authored-By: Claude <noreply@anthropic.invalid>
@aallan aallan merged commit 8d345ab into main Mar 1, 2026
10 checks passed
@aallan aallan deleted the decompose-codegen branch March 1, 2026 12:34
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.

Decompose codegen.py (~2,140 lines) into codegen/ submodules

1 participant