summaryrefslogtreecommitdiff
path: root/typing/HACKING.adoc
blob: 8633ef52ed6e6aa607c8bbb98069b333daf0e95c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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:

http://caml.inria.fr/pub/docs/u3-ocaml/index.html[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.

http://okmij.org/ftp/ML/generalization.html[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 ::
link:types.mli[Types] and link:typedtree.mli[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. link:env.mli[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 ::
link:btype.mli[Btype] and link:ctype.mli[Ctype] contain
the various low-level function needed for typing, in particular
related to levels, unification and
backtracking. link:mtype.mli[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:
link:typetexp.mli[Typetexp] for type expressions,
link:typecore.mli[Typecore] for the core language,
link:typemod.mli[Typemod] for modules,
link:typedecl.mli[Typedecl] for type declarations and finally
link:typeclass.mli[Typeclass] for the object system.

Inclusion/Module subtyping::
Handling of inclusion relations are separated in the `Include...`
modules: link:includecore.ml[Includecore] for the type and
value declarations, link:includemod.mli[Includemod] for modules
and finally link:includeclass.mli[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
link:typecore.ml[Typecore.type_module], which is filled in
link:typemod.ml[Typemod].