catala/compiler/verification
Louis Gesbert e925ec1795 Swap boxing and annotations in expressions
This was the only reasonable solution I found to the issue raised
[here](https://github.com/CatalaLang/catala/pull/334#discussion_r987175884).

This was a pretty tedious rewrite, but it should now ensure we are doing things
correctly. As a bonus, the "smart" expression constructors are now used
everywhere to build expressions (so another refactoring like this one should be
much easier) and this makes the code overall feel more
straightforward (`Bindlib.box_apply` or `let+` no longer need to be visible!)

---

Basically, we were using values of type `gexpr box = naked_gexpr marked box`
throughout when (re-)building expressions. This was done 99% of the time by
using `Bindlib.box_apply add_mark naked_e` right after building `naked_e`. In
lots of places, we needed to recover the annotation of this expression later on,
typically to build its parent term (to inherit the position, or build the type).

Since it wasn't always possible to wrap these uses within `box_apply` (esp. as
bindlib boxes aren't a monad), here and there we had to call `Bindlib.unbox`,
just to recover the position or type. This had the very unpleasant effect of
forcing the resolution of the whole box (including applying any stored closures)
to reach the top-level annotation which isn't even dependant on specific
variable bindings. Then, generally, throwing away the result.

Therefore, the change proposed here transforms
- `naked_gexpr marked Bindlib.box` into
- `naked_gexpr Bindlib.box marked` (aliased to `boxed_gexpr` or `gexpr boxed` for
convenience)

This means only
1. not fitting the mark into the box right away when building, and
2. accessing the top-level mark directly without unboxing

The functions for building terms from module `Shared_ast.Expr` could be changed
easily. But then they needed to be consistently used throughout, without
manually building terms through `Bindlib.apply_box` -- which covers most of the
changes in this patch.

`Expr.Box.inj` is provided to swap back to a box, before binding for example.

Additionally, this gives a 40% speedup on `make -C examples pass_all_tests`,
which hints at the amount of unnecessary work we were doing --'
2022-10-07 18:00:23 +02:00
..
conditions.ml Swap boxing and annotations in expressions 2022-10-07 18:00:23 +02:00
conditions.mli Make all supertypes use ('a, 't) gexpr as parameter instead of naked_gexpr 2022-08-29 10:57:21 +02:00
dune Merge branch 'master' into dates_calc_lib 2022-08-06 17:26:55 +02:00
io.ml Correct test output for proof mode 2022-09-06 14:10:32 +02:00
io.mli Correct test output for proof mode 2022-09-06 14:10:32 +02:00
solver.ml Correct test output for proof mode 2022-09-06 14:10:32 +02:00
solver.mli Leverage the shared AST: big cleanup (part I) 2022-08-22 19:28:21 +02:00
verification.mld Documentation pass 2022-01-19 10:54:16 +01:00
z3backend.dummy.ml Make Z3 an optional dependency 2022-03-08 18:38:42 +01:00
z3backend.mli Big reformatting 2022-03-08 15:03:14 +01:00
z3backend.real.ml Swap boxing and annotations in expressions 2022-10-07 18:00:23 +02:00