314 karma · joined April 29, 2016
In the GADTs case, the type system is only used to remove the failure branch. For instance,
type 'a t = A: int t | B: float t
let always_a (x:int t) = match x with
| A -> ()
| _ -> .
is translated to (let (always_a/270 = (function x/272[int] : int 0))
because the typechecker can prove that the `B` case is impossible.
In other words, GADTs are yet another instance where the type system can be used to eliminate dead code in the untyped IR.For instance
let f x = match x with
| [] -> ()
is translated into (is_empty/267 =
(function x/269 : int
(if x/269
(raise (makeblock 0 (global Match_failure/18!) [0: "r.ml" 1 17]))
1)))
where you can see the exception being build and raised in the `then` branch of the test.
Contrarily, the total function let is_empty x = match x with
| [] -> true
| _ :: _ -> false
becomes (let (is_empty/267 = (function x/269 : int (if x/269 0 1)))
And since the function doesn't need to handle the failure case, it doesn't have that `(raise ...)` case.Another important point is that type system information is only needed to check the exhautiveness of pattern matching in presence of GADTs. Otherwise the exhautiveness of pattern matching can be checked using syntatic criteria on the pattern matching and type definitions.
However, such matches are considered valid code: "non-exhaustive match" is a warning by default, even if most people advise to turn that warning into an error.
In other words, the `Match_failure` exception is part of OCaml non-typed semantics and there is no soundness issue involved here.
It is hard or even counter-productive to try to fit them on a roadmap.
The multicore project is(was?) a bit unusual from the point of view of OCaml development since it is a massive engineering effort with a focused team.
Nevertheless, I hope that we continue and extend the "OCaml compiler bimonthly" news to give more information about the ongoing work on the compiler.
In other words, I am keen to not reproduce the announcement that "multicore might be in 4.03" from 5 years ago.
So this is an example of carefully constrained conditions where equality between all total functions on an infinite set is decidable.
To add some data to the discussion, I have been recently measuring the compilation profile of some OCaml libraries, and the average time spent in the typechecker is around 40% (https://www.polychoron.fr/ocaml/2021/08/19/measuring_compila...).
Thus the complexity of the OCaml type system can only have a limited effect on OCaml compilation time.
And this measure does include interface files, where the compilation pipeline is reduced to just parsing, typechecking, and dumping the computed file to the disk.
Darklang is being rewritten to .Net because they were unsatisfied with the OCaml ecosystem.
Horrible performance is generally more a question of algorithms and software architecture than a problem with a language, which only account for a flat percentage of performance.
I have hoped to have eliminated all of them in 4.08.