2018-10-24 10:48:40 -07:00
|
|
|
TODO for the OCaml typechecker implementation
|
|
|
|
=============================================
|
|
|
|
|
|
|
|
There is a consensus that the current implementation of the OCaml
|
|
|
|
typechecker is overly complex and fragile. A big rewriting "from
|
|
|
|
scratch" might be possible or desirable at some point, or not, but
|
|
|
|
incremental cleanup steps are certainly accessible and could bring the
|
|
|
|
current implementation in a better shape at a relatively small cost
|
Fixing typos in various files (#2246)
Note: Typos found with https://github.com/codespell-project/codespell
Here is the (semi-manual) command used to get (and correct) the typos:
$ codespell -i 3 -w --skip=".png,.gif,./ocaml/boot,./ocaml/.git,./ocaml/manual/styles,./ocaml/manual/manual/htmlman" -L minimise,instal,contructor,"o'caml",cristal,pres,clos,cmo,uint,iff,te,objext,nto,nd,mut,upto,larg,exten,leage,mthod,delte,tim,atleast,langage,hten,iwth,mke,contant,succint,methids,eles,valu,clas,modul,que,classe,missings,froms,defaut,correspondance,differents,configury,reachs,cas,approche,normale,dur,millon,amin,oje,transfert
2019-02-13 05:04:56 -08:00
|
|
|
and in a reasonably distant future.
|
2018-10-24 10:48:40 -07:00
|
|
|
|
2018-10-25 00:25:20 -07:00
|
|
|
Goals of the cleanup:
|
|
|
|
|
|
|
|
- Make the implementation more maintainable and less fragile.
|
|
|
|
|
|
|
|
- Allow new contributors, or people involved in bigger rewriting
|
|
|
|
projects, to get familiar with the code base more easily.
|
|
|
|
|
|
|
|
- Pave the way for future extensions or bigger structural changes to
|
|
|
|
the implementation.
|
|
|
|
|
2018-10-24 10:48:40 -07:00
|
|
|
This file collects specific cleanup ideas which have been discussed
|
|
|
|
amongst maintainers. Having the list committed in the repo allows for
|
|
|
|
everyone to get an idea of planned tasks, refine them through Pull
|
|
|
|
Requests, suggest more cleanups, or even start working on specific
|
|
|
|
tasks (ideally after discussing it first with maintainers).
|
|
|
|
|
2019-10-08 10:15:33 -07:00
|
|
|
# Code smells
|
|
|
|
|
|
|
|
- global mutable state
|
|
|
|
- poor data representation
|
|
|
|
- avoid constructing a parsetree locally
|
|
|
|
(methods build a piece of AST with a self argument
|
|
|
|
with a *-using name to avoid conflicts; #row, etc.)
|
|
|
|
- avoid magic string literals
|
|
|
|
|
|
|
|
# TODO List
|
|
|
|
|
2018-10-25 00:26:15 -07:00
|
|
|
Not all ideas have been thoroughly discussed, and there might not be a
|
2018-10-25 00:25:20 -07:00
|
|
|
consensus for all of them.
|
|
|
|
|
2018-10-24 10:48:40 -07:00
|
|
|
- Make the level generator be part of `Env.t` instead of being global.
|
|
|
|
|
|
|
|
- Introduce an abstraction boundary between "the type algebra" and
|
|
|
|
"the type checker" (at first between Ctype and Typecore) so that the
|
2018-10-25 00:19:25 -07:00
|
|
|
type checker is forced to go through a proper API to access/mutate
|
2018-10-24 10:48:40 -07:00
|
|
|
type nodes. This would make it impossible to "forget" a call
|
|
|
|
to `repr` and will allow further changes on the internal representation.
|
|
|
|
|
|
|
|
- Tidy up Typeclass (use records instead of 14-tuples, avoid
|
|
|
|
"#"-encoding, etc).
|
|
|
|
|
|
|
|
- Collect all global state of the type checker in a single place,
|
|
|
|
possibly a single reference to a persistent data structure
|
|
|
|
(e.g. maps instead of hashtables).
|
|
|
|
|
|
|
|
- Get rid of Tsubst. With the unique ids on each type node, copying
|
|
|
|
can be implemented rather efficiently with a map.
|
|
|
|
|
|
|
|
- Document row_desc, get rid of row_bound.
|
|
|
|
|
2018-10-25 00:19:25 -07:00
|
|
|
- Implement union-find with a more abstract/persistent datastructure
|
2018-10-24 10:48:40 -07:00
|
|
|
(be careful about memory leaks with the naive approach of representing
|
|
|
|
links with a persistent heap).
|
|
|
|
|
2019-10-08 10:15:33 -07:00
|
|
|
Modest version of the proposal: have an explicit indirection layer
|
|
|
|
(type_expr Unode.t)
|
|
|
|
for nodes in the union-find structure. Efficiency cost?
|
|
|
|
|
2018-10-24 10:48:40 -07:00
|
|
|
- Make the logic for record/constructor disambiguation more readable.
|
|
|
|
|
2019-10-08 10:15:33 -07:00
|
|
|
(Jacques should write a specification, and then we could try
|
|
|
|
to make the implementation easier for others to understand.)
|
|
|
|
|
2018-10-24 10:48:40 -07:00
|
|
|
- Tidy up destructive substitution.
|
|
|
|
|
|
|
|
- Get rid of syntactic encodings (generating Parsetree fragments
|
|
|
|
during type-checking, cf optional arguments or classes).
|
|
|
|
|
2018-10-25 00:19:25 -07:00
|
|
|
- Track "string literals" in the type-checker, which often act as
|
2018-10-24 10:48:40 -07:00
|
|
|
magic "internal" names which should be avoided.
|
|
|
|
|
2018-10-25 00:19:25 -07:00
|
|
|
- Consider storing warning settings (+other context) as part of `Env.t`?
|
2018-10-24 10:48:40 -07:00
|
|
|
|
|
|
|
- Parse attributes understood (e.g. the deprecated attribute) by the
|
|
|
|
compiler into a structured representation during type-checking.
|
|
|
|
|
|
|
|
- Introduce a notion of syntactic "path-like location" to point to
|
|
|
|
allow pointing to AST fragments, and use that to implement "unused"
|
|
|
|
warnings in a less invasive and less imperative way.
|
2019-10-08 10:15:33 -07:00
|
|
|
(See Thomas' PR)
|
2018-10-24 10:48:40 -07:00
|
|
|
|
2018-10-25 00:19:25 -07:00
|
|
|
- Deprecate -nolabels, or even get rid of it?
|
2019-10-08 10:15:33 -07:00
|
|
|
(We could even stop supporting unlabeled full applications.
|
|
|
|
First turn on the warning by default.)
|
2018-10-24 12:40:40 -07:00
|
|
|
|
|
|
|
- Using e.g. bisect_ppx, monitor coverage of the typechecker
|
|
|
|
implementation while running the testsuite, and expand the testsuite
|
|
|
|
and/or kill dead code in the typechecker to increase coverage ratio.
|
2019-10-08 10:15:33 -07:00
|
|
|
(Partially done by Oxana's Outreachy internship.
|
|
|
|
See PR#8874.
|
2019-10-15 05:21:04 -07:00
|
|
|
Ask Florian Angeletti and Sebastien Hinderer about the current state.)
|