Skip to content


Rémi requested to merge nanopasses into dev

Motivation and Context

Put an end to the monolithic compilers we had, namely the "abstractors".


Generated code

  • folds/unfolds are written using the generated (see recursion schemes )
  • there is no printers (very annoying to maintain). We use deriving.sexp


Ast_unified (produced by unification)

  • written in a style suitable for generated fold
  • some node can't be emited by unification and only be emited by a nanopass. Those are tagged with [@is_initial]

New flow

When compiling, things happen in this way:

  1. Unification (CST_<syntax> --> AST_unified) @ src/passes/03-unification/
  2. Nanopasses (AST_unified --> AST_unified) @ src/passes/04-nanopasses/
  3. Trivial (Ast_unified --> AST_core) @ src/passes/04-nanopasses/

A pass is define here, should be able to compile/decompile an expression/pattern/program

Each nanopass have a run-time check (reduction_check) making sure that node that are considered reduced are not present in the AST anymore (we could remove those from LIGO release binary?)


  • it is not yet due to annoying CST differences, but (1) should be trivial. Sometimes, some constructs in one syntax use a slightly different type from another syntax. To not create a dummy nanopasses just for that, I do the translation directly in unification (see module TODO_in_parsing / TODO_unifiy_in_cst)
  • the last transformation (3) is trivial already. The only things being done there is handling the warnings on attributes (TODO?)


Unit test

unit testing is made possible. A small example here.
But this needs to be improved


  • generated recursion schemes [trivial]
  • generated sexp_of to_sexp [trivial]
  • using anomorphism for pass 3 unification [trivial but long]
  • define new type for each nanopasses, [complex: require ppx to generate new type (see existing ocaml nanopass framework)]
  • if CSTs would share more types, write a ppx to generated unification [complex / need work]


  • compiler
  • website
  • webide
  • vscode-plugin
  • debugger

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)


frontend: syntax unification and nanopasses (replacing old abstraction)


  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Start titles under ## Changelog section with #### (if appropriate).
  • There is no image or uploaded file in changelog
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Laurent Canis

Merge request reports