Skip to content

Refactor: split CompilationModel.lean (5,404 lines) into separate modules #1157

@Th0rgal

Description

@Th0rgal

Why

CompilationModel.lean is the single largest file in the codebase at 5,404 lines. It contains:

  • Type definitions (Expr, Stmt, CompilationModel, etc.)
  • The entire compiler logic (compileExpr, compileStmt, compile)
  • Validation walkers
  • ABI encoding
  • 201 error messages

This is the #1 obstacle for:

  • LLM comprehension: models struggle with 5k+ line files and lose context
  • Build times: changes to any part of the file trigger full recompilation of everything downstream
  • Code review: PRs touching this file are hard to review

Solution

Split into separate modules:

Compiler/
  CompilationModel/
    Types.lean          -- Expr, Stmt, CompilationModel, Field, StorageSlot, etc.
    ExprCompiler.lean   -- compileExpr and expression-level compilation
    StmtCompiler.lean   -- compileStmt and statement-level compilation
    Compile.lean        -- top-level compile function, contract assembly
    Validation.lean     -- validation walkers, field checks
    AbiEncoding.lean    -- ABI JSON generation, selector computation
    Errors.lean         -- error message constants and formatting (optional)
  CompilationModel.lean -- re-exports all submodules for backwards compatibility

Effort

1 week

Acceptance

  • All content from the monolith distributed across well-named submodules
  • A single CompilationModel.lean re-export file for backwards compatibility
  • No regressions in build or proofs
  • Incremental build time improvement measurable on the compiler target

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions