Skip to content

Latest commit

 

History

History
58 lines (50 loc) · 2.63 KB

HACKING.adoc

File metadata and controls

58 lines (50 loc) · 2.63 KB

The implementation of the OCaml typechecker is complex. Modifying it will need a good understanding of the OCaml type system and type inference. Here is a reading list to ease your discovery of the typechecker:

Using, Understanding, and Unraveling the OCaml Language by Didier Rémy

This book provides (among other things) a formal description of parts of the core OCaml language, starting with a simple Core ML.

Efficient and Insightful Generalization by Oleg Kiselyov

This article describes the basis of the type inference algorithm used by the OCaml type checker. It is a recommended read if you want to understand the type-checker codebase, in particular its handling of polymorphism/generalization.

After that, it is best to dive right in. There is no real "entry point", but an understanding of both the parsetree and the typedtree is necessary.

The datastructures

Types and Typedtree are the two main datastructures in the typechecker. They correspond to the source code annotated with all the information needed for type checking and type inference. Env contains all the environments that are used in the typechecker. Each node in the typedtree is annotated with the local environment in which it was type-checked.

Core utilities

Btype and Ctype contain the various low-level function needed for typing, in particular related to levels, unification and backtracking. Mtype contains utilities related to modules.

Inference and checking

The Type.. modules are related to inference and typechecking, each for a different part of the language: Typetexp for type expressions, Typecore for the core language, Typemod for modules, Typedecl for type declarations and finally Typeclass for the object system.

Inclusion/Module subtyping

Handling of inclusion relations are separated in the Include…​ modules: Includecore for the type and value declarations, Includemod for modules and finally Includeclass for the object system.

Dependencies between modules

Most of the modules presented above are inter-dependent. Since OCaml does not permit circular dependencies between files, the implementation uses forward declarations, implemented with references to functions that are filled later on. An example can be seen in Typecore.type_module, which is filled in Typemod.