Compiler utilities

Unique identifiers

In the desugared representation or in the the scope language, a number of things are named using global identifiers. These identifiers use OCaml's type system to statically distinguish e.g. a scope identifier from a struct identifier.

The Catala_utils.Uid module provides a generative functor whose output is a fresh sort of global identifiers.

Related modules:

Source code positions and attributes

This module is used throughout the compiler to annotate the abstract syntax trees with information about the position of the element in the original source code. These annotations are critical to produce readable error messages.

The positions also include attribute information, as an extensible variant defined in the same module.

Related modules:

Error messages

Error handling is critical in a compiler. The Catala compiler uses an architecture of error messages inspired by the Rust compiler, where error messages all correspond to the same exception. This exception carries messages and positions that are displayed in the end in a nicely-formatted error message.

Hence, all error thrown by the compiler should use Catala_utils.Message

Related modules:

AST marks

Throughout we use values with a "mark", which most often contains position information, or more in the case of AST nodes. Such values are simply pairs payload, mark, but the following module provides some helper to work with them (e.g. to do mark-agnostic comparisons).

Related modules:

Globals

For some global flags, like the debug option, having a global reference is more convenient than passing the information everywhere. This is all gathered in the single global value Global.options (and forbidden in other modules).

Related modules:

Maps

The Map module is an overlay on the OCaml stdlib Map that provides some extensions and convenience functions.

Note of warning: the Not_found exception is specialised for every instance of the functor. This is useful to automatically report what element was not found, but be careful with catching Stdlib.Not_found, which won't work.

Related modules:

Other utilies

Related modules: