Commit Graph

127 Commits

Author SHA1 Message Date
Louis Gesbert
291a8e05e4 Specify latest gmpy2 dependency 2024-06-26 12:40:29 +02:00
Louis Gesbert
d871b95447 Basic support for closure conversion in the OCaml backend 2024-06-21 12:23:01 +02:00
Louis Gesbert
4acf321309 C backend: make error raising more concise 2024-05-30 16:59:55 +02:00
Louis Gesbert
081605d04d tests: check the generated C code
(and update for new errors)
2024-05-30 16:19:55 +02:00
Louis Gesbert
403156b36e Computation and checking of module hashes
This includes a few separate changes:

- pass visibility information of declarations (depending on wether the
  declaration was in a ```catala-metadata block or not)

- add reasonable hash computation functions to discriminate the interfaces. In
  particular:
  * Uids have a `hash` function that depends on their string, but not on their
    actual uid (which is not stable between runs of the compiler) ; the existing
    `hash` function and its uses have been renamed to `id`.
  * The `Hash` module provides the tools to properly combine hashes, etc. While
    we rely on `Hashtbl.hash` for the atoms, we take care not to use it on any
    recursive structure (it relies on a bounded traversal).

- insert the hashes in the artefacts, and properly check and report those (for
  OCaml)

**Remains to do**:

- Record and check the hashes in the other backends

- Provide a way to get stable inline-test outputs in the presence of module
  hashes

- Provide a way to write external modules that don't break at every Catala
  update.
2024-05-28 11:43:50 +02:00
Raphaël Monat
e78c225437 Another fix to Python runtime 2024-05-15 09:08:53 +02:00
Raphaël Monat
3426ca3617 Python backend: fix money multiplication, round 2024-05-10 15:36:40 +02:00
Raphaël Monat
a076dc70b6 Python runtime: remove quoted type annotations 2024-05-10 12:19:53 +02:00
Raphaël Monat
43218e31ce Python runtime: fix rounding 2024-05-10 12:19:53 +02:00
Louis Gesbert
0ee512b832 Bump version in package descriptions to 0.10.0 2024-05-06 13:51:05 +02:00
Denis Merigoux
8288754de2
JSOO runtime fix 2024-05-03 09:35:20 +02:00
Louis Gesbert
facce68b25 Make refactored runtime error messages clearer
mostly reverting to the ones the interpreter was printing ; for the case of
divisions, we choose to point to the denominator instead of the operator as it's
where the only possible error (division by zero) comes from.
2024-05-02 16:30:47 +02:00
Louis Gesbert
4d412027d0 Remove direct dependency towards dates_calc from the compiler
The dependency should only go through the `Runtime` module
2024-05-02 16:30:46 +02:00
Louis Gesbert
50d686f089 Pass exception positions to the HandleDefault operators
This puts runtime exception info on par with what we had in the interpreter, and
repairs the regression on the interpreter which no longer had them.
2024-04-29 16:09:38 +02:00
Louis Gesbert
4f6769c7f2 Adjust exception handling in the Python backend
in order to match the exceptions in OCaml
2024-04-29 11:47:41 +02:00
Louis Gesbert
9d07015864 Unify runtime error handling
- Clearly distinguish Exceptions from Errors. The only catchable exception
  available in our AST is `EmptyError`, so the corresponding nodes are made less
  generic, and a node `FatalError` is added

- Runtime errors are defined as a specific type in the OCaml runtime, with a
  carrier exception and printing functions. These are used throughout, and
  consistently by the interpreter. They always carry a position, that can be
  converted to be printed with the fancy compiler location printer, or in a
  simpler way from the backends.

- All operators that might be subject to an error take a position as argument,
  in order to print an informative message without relying on backtraces from
  the backend
2024-04-26 18:31:26 +02:00
Louis Gesbert
5d432d6bb9 OCaml runtime: register fallback exception printers
This was a pending TODO: now the Catala program compiled into OCaml should
return better messages and a little more information about uncaught exceptions.

Note that this also concerns, at the moment, compiled modules called from the
Catala interpreter: in this case, it's already better than nothing, but what we
need is proper interoperation between the runtime exceptions and the interpreter
handling (`EmptyError` should already be handled properly since it is critical
to the computation flow, but "error" exceptions are left uncaught and will kill
the interpreter).

This may be part of a bigger task on unifying the output of the runtime and
toplevel, which also concerns computation traces.

Note 2: All runtime exceptions don't have a position available, which is quite
unfortunate when your program hits an error. With `OCAMLRUNPARAM=b` and if
compiled with `-g` (which should normally be the case), you can get an OCaml
backtrace but that's not very friendly. Ideas for improvement:
- The runtime could force-enable backtrace recording (`Printexc.record_backtrace
  true`) to supersede the need for `OCAMLRUNPARAM`. We can also record our own
  handler to print the file position and/or backtrace in the way we see fit
- The printer of OCaml code in Catala could insert line directives so that the
  positions in the backtrace actually trace automatically back to the Catala
  code
- If we don't want to leverage any OCaml machinery in this way, the compiler
  should add position information to any operator that might fail (e.g.
  divisions, date comparisons, etc.).
Note that running in trace mode might already help pinpoint the location of the
error ?
2024-04-15 14:13:33 +02:00
Louis Gesbert
c9dca1fc6d Fix multi-repo compilation and the 'make alltest' target 2024-03-20 14:41:10 +01:00
Louis Gesbert
4cec981f62 Move global options of Cli to their own module
This resolves a dependency cycle that would forbid `Cli` from using the modue
`File`, which was annoying.
2024-03-19 15:18:35 +01:00
Louis Gesbert
21a429bfcf Jsoo runtime: fix over-wrapping of event manager callbacks 2024-03-12 16:05:38 +01:00
Louis Gesbert
959a49ee92 Jsoo runtime: expose the event manager to JS 2024-03-12 16:04:59 +01:00
Louis Gesbert
ff06ddf40c Fixing linking across modules for backends
- This adds a `catala depends` command that recursively tracks module dependency.
It can then be used by Clerk for linking.

- Generation of cmo object files are added for OCaml (we only built native
objects, but jsoo requires bytecode).

- Some fixes to the generation of value embed/deembed shims (related to types
coming from different modules ; add support for options ; etc.)
2024-03-08 17:36:00 +01:00
Louis Gesbert
c5b09d55b4 OCaml runtime: expose the dates_rounding type for direct access from the backend 2024-03-08 17:36:00 +01:00
Louis Gesbert
e0928677b1 Small ocaml/js output rehaul
Print to json directly rather than depend on yojson and a ppx.

Note: this should be tested with the website in order to validate that the Json
output is 1-to-1.
(a second step could be to simplify this output, now that it's manual)
2024-02-21 11:28:56 +01:00
Louis Gesbert
7b43f393c5 Add some optimisations to nested maps 2024-02-05 11:01:55 +01:00
Louis Gesbert
d60b521a4e Fix Python backend and CI 2024-02-01 01:01:04 +01:00
Denis Merigoux
b48fb0e223
Array compilation to C is OK 2024-01-26 20:15:32 +01:00
Denis Merigoux
a39b67bf12
Merge branch 'master' into c_backend 2024-01-26 17:43:07 +01:00
Louis Gesbert
371f9554b8 Support for list recombinations
The primary use-case for this was to be able to run computations on a list of
structures, then return an updated list with some fields in the structures
modified : that is what we need for distribution of tax amounts among household
members, for example.

This patch has a few components:

- Addition of a test as an example for tax distributions

- Added a transformation, performed during desugaring, that -- where lists are
  syntactically expected, i.e. after the `among` keyword -- turns a (syntactic)
  tuple of lists into a list of tuples ("zipping" the lists)

- Arg-extremum transformation was also fixed to use an intermediate list instead
  of computing the predicate twice

- For convenience, allow to bind multiple variables in most* list
  operations (previously only `let in` and functions allowed it)

- Fixed the printer for tuples to differentiate them from lists

*Note: tuples are not yet allowed on the left-hand side of filters and
arg-extremums for annoying syntax conflict reasons.
2024-01-26 11:29:33 +01:00
Louis Gesbert
bc90a7b890 Add (internally) a map2 operator 2024-01-26 11:22:12 +01:00
Denis Merigoux
8a139f6a3c
Work on arrays 2024-01-22 16:49:58 +01:00
Louis Gesbert
db6c8c6c16 Add missing python package file 2024-01-19 13:39:22 +01:00
Denis Merigoux
349da741d4
Merge branch 'master' into c_backend 2024-01-16 16:23:35 +01:00
Louis Gesbert
e0c2c58687 Makefile: remove references to the examples 2024-01-16 11:54:28 +01:00
Louis Gesbert
538e97dfd3 Install Python and R runtimes
Runtimes for the various backends are expected to be made available from their
own ecosystem. However, for convenience and to help with development
settings (where the runtime might change), as part of installing catala they are
put, in source form, into `<prefix>/lib/catala/runtime_LANG`.

When using a dev version of Catala, and using Python, one would then just have
to do `pip install <prefix>/lib/catala/runtime_python` within their venv to be
able to run their python programs.
2024-01-16 11:54:28 +01:00
Pierre Goutagny
6a39d066f2
Unify rounding operations in OCaml runtime 2024-01-10 13:43:19 +01:00
Denis Merigoux
fe5b842a03
Simple example compiles and runs fine 2023-12-13 16:58:02 +01:00
Denis Merigoux
d88f67bb2c
Progress 2023-12-12 16:08:40 +01:00
Louis Gesbert
cf89204a4b Reformat 2023-11-27 11:17:38 +01:00
adelaett
a734413d39 typing default: fix ocaml runtime when using eoption 2023-11-27 11:17:38 +01:00
adelaett
ae4956c40f Typing defaults: update ocaml & python runtimes. 2023-11-27 11:17:38 +01:00
Denis Merigoux
fc242a5d1f
Fix Python compilation and runtime 2023-11-22 18:08:44 +01:00
Louis Gesbert
4910158aea Reformat 2023-09-01 16:24:27 +02:00
Denis Merigoux
6d7b1f2585
Last fixes 2023-08-07 17:55:04 +02:00
Denis Merigoux
8743b73459
Debugging the R backend 2023-08-07 16:19:13 +02:00
Denis Merigoux
4d419ac167
Switch to S4 classes and package runtime 2023-08-07 15:58:55 +02:00
Denis Merigoux
695faebefb Cleaning up 2023-08-05 16:23:29 +02:00
Denis Merigoux
e2f8e56e7d Backend seems to work, needs more debugging 2023-08-05 14:28:18 +02:00
Denis Merigoux
62ea40a40d Fix tryWith compilation 2023-08-05 13:05:31 +02:00
Denis Merigoux
d0483d681a
First test passing 2023-08-04 19:30:43 +02:00