Commit Graph

4000 Commits

Author SHA1 Message Date
Louis Gesbert
78200953f3
Improvements around external modules and error handling (#605) 2024-04-16 23:13:46 +02:00
Denis Merigoux
ce7bed1314
Support for direct tuple member access (#604) 2024-04-16 17:20:54 +02:00
Louis Gesbert
1de18f0e04 Preserve the capitalisation of module filenames
Module names must be capitalised (start with a capital letter), and the name of
the file on disk must match ; however, matching up to capitalisation is allowed,
i.e. the file on disk can start with a lowercase letter.

A mismatch between Clerk assuming generated module artifacts would match the
capitalised module name, and `catala depends` matching the names of files on
disk (because it would otherwise mean treating dependencies differently
depending on if they originate from modules or not) was causing "file not found"
errors later on in the compilation chain.

This patch enforces that the capitalisation of the original file name on
disk (which is always known) takes precedence in Clerk, matching the behaviour
of `catala depends` and fixing the issue. It's also actually a small
simplification in Clerk code.
2024-04-15 23:00:56 +02:00
Louis Gesbert
20288bcb26 Protect the interpreter against exceptions from custom code 2024-04-15 14:13:33 +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
c8e529dd9f Fix: allow external modules to access the OCaml stdlib
This would deserve a further look into it, but for now it's impeding development
without providing any meaningful security.
2024-04-13 12:01:47 +02:00
Louis Gesbert
eded54d2b5 Support for direct tuple member access
As discussed in #549

NOTE: This implements only the direct tuple member access (syntax `foo.N` with N a
number)

- It seems more efficient to wait for the general pattern-matching rewrite to
  handle pattern-matching on tuples
- Until then we keep the (now obsolete) `let (x, y) = pair in x` syntax, to
  leave time for updates, but we won't be documenting it
2024-04-13 09:37:03 +02:00
Louis Gesbert
87b2c4ded2
Support for structure updates (#603) 2024-04-13 09:36:13 +02:00
Louis Gesbert
a61ae7979f
Support for structure updates
Closes #592

A new node is added in `desugared`, and translated into an exploded structure
literal during translation to `scopelang`. The main reason to put it there is
that it needs to be after disambiguation, since that is used to discover the
type of the structure that is being updated.
2024-04-12 17:17:48 +02:00
Louis Gesbert
68b78e7a81
Fix broken links in README
Fixes #600. Thanks to @BapMel for reporting!
2024-04-12 17:17:42 +02:00
Denis Merigoux
55cec0c7f0
Improve message formatting throughout (#602) 2024-04-12 17:16:56 +02:00
Louis Gesbert
b78cd9c29a
Improve message formatting throughout
Ensuring messages don't print overlong lines still requires some manual work:
- if they don't contain any `Format` directives (`%` or `@`), use `"%a"
  Format.pp_print_text` to turn word-wrapping on.
- otherwise replace spaces with `@ ` to mark possible cutting points, as soon
  that it's possible the line will get over 80 chars (most often, this means
  starting before the first `%a`)
2024-04-12 17:07:36 +02:00
Denis Merigoux
ff683f3ea0
Rework the Message module interface (#601) 2024-04-12 17:07:14 +02:00
Denis Merigoux
1e76366f51
Fix extra_pos/pos 2024-04-12 17:06:44 +02:00
Louis Gesbert
241f55a71a Fix formatting of messages
This preserves the existing
2024-04-10 19:26:23 +02:00
Louis Gesbert
def10e7f98 Message: further simplification 2024-04-10 19:26:23 +02:00
Louis Gesbert
9524e5d3f8 Message: remove the now obsolete interface 2024-04-10 19:26:23 +02:00
Louis Gesbert
98fc97a241 Rewriting message calls to use the new intf 2024-04-10 19:26:23 +02:00
Louis Gesbert
454667a47b Messages: add a more concise interface with optional args 2024-04-10 19:26:23 +02:00
Louis Gesbert
f3164051cc
Allow "output subscopes" ; unify the internal representation of subscopes (#597) 2024-04-10 19:25:34 +02:00
Louis Gesbert
e19332522e Output subscope: improvements following review
Thanks @denismerigoux

This renames the "ScopeDef" variant from `SubScope` to `SubScopeInput`, which is
much clearer and avoids confusion with the `SubScope` elements in the surface
AST (which are really subscopes and not variables at this point).

And improves some error message by specialising depending on whether we are
dealing with a subscope or an explicit structure.
2024-04-10 18:38:50 +02:00
Louis Gesbert
8ae9701a4f Fix python name clash printing again, for non-ascii 2024-04-05 15:25:46 +02:00
Louis Gesbert
f71db385d5 Python backend: workaround func/var name clash 2024-04-05 14:45:17 +02:00
Louis Gesbert
75bf768264 Reformat 2024-04-04 10:56:56 +02:00
Louis Gesbert
0ec04c4925 Branch cleanup and test outputs update
Lots of tests have a new warning because they were calling subscopes without
using their outputs. A better solution could be to mark these subscopes as
`output`, now that it's possible !
2024-04-04 10:55:21 +02:00
Louis Gesbert
cde9a66295 Output scopes and subscope variable rework done 2024-04-04 10:24:18 +02:00
Louis Gesbert
852bebd357 Completely remove subscope input vars (use local vars) 2024-04-04 10:24:18 +02:00
Louis Gesbert
f151a9a794 Wip: handling subscope calls as normal definitions
- for the moment we still have specific vars for subscope inputs (in scopelang)
- this causes trouble with default-embedding of scope calls
2024-04-04 10:24:18 +02:00
Louis Gesbert
4eeb8221f4 Fix var bindings in desugared->scopelang 2024-04-04 10:24:18 +02:00
Louis Gesbert
7951661981 Turn subscope-vars into scope vars
They are to become citizens of the same class if we want to allow
output-subscopes (without unnecessary complications like deconstructing and
reconstructing the same structure). And it's reasonable to assume that they
share the same namespace.

With this we should shortly collapse the (internal) ambiguity between

- `subscope.subvar`: access to a variable within a subscope
- `subscope.subfield`: access to a field of the output structure contained in a
  subscope variable

With the subscope a variable, these should now become strictly equivalent, so
the plan is that the first could be removed.
2024-04-04 10:24:18 +02:00
Louis Gesbert
eeaadef27c Output subscopes: implement syntax
required a little generalisation and explicit parsing errors to avoid conflicts,
but it remains reasonable
2024-04-04 10:24:18 +02:00
Louis Gesbert
36eca9bf29
Temporary: switch to unreleased version of dates_calc to avoid str dep (#595) 2024-03-27 15:00:39 +01:00
Louis Gesbert
6ce9a6542e CI: disable attempting to build the rescript bindings
Temporarily until we can find how to fix it on Github. At the moment the error
is impossible to reproduce locally...

All the rest from french-law is still tested (wrappers and benches in OCaml, js
and python)
2024-03-27 14:22:14 +01:00
Louis Gesbert
391ecb679c Temporary: switch to unreleased version of dates_calc to avoid str dep 2024-03-26 15:54:29 +01:00
Louis Gesbert
60b2e6f205
Some tweaks helping with separate compilation of the examples (#586) 2024-03-25 16:54:10 +01:00
Louis Gesbert
c85e665650 CI: adjust script for new make rules & artifacts 2024-03-20 16:40:04 +01:00
Louis Gesbert
c9dca1fc6d Fix multi-repo compilation and the 'make alltest' target 2024-03-20 14:41:10 +01:00
Louis Gesbert
adaaf735e6 'catala depends': allow multiple extensions 2024-03-20 14:41:10 +01:00
Louis Gesbert
619cafebb8 Reformat 2024-03-20 14:41:06 +01:00
Louis Gesbert
1a17098297 Move file functions that were in Cli to File
it's now possible because Globals where moved away
2024-03-19 15:26:32 +01:00
Louis Gesbert
0908ed85c3 Clerk: generate all .mli files as well 2024-03-19 15:26:32 +01:00
Louis Gesbert
36c8a7effc Sort strings in natural order when they contain numbers
Seeing results sorted as 1 10 11 2 doesn't look nice.
2024-03-19 15:26:32 +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
77ba1b8b38 Clerk: split OCaml compiler & link rules
and fix call to `catala depends` for OCaml linking
2024-03-14 14:04:52 +01:00
Louis Gesbert
3c03da4a50 file.ml: add a function to cleanup relative paths 2024-03-14 14:04:52 +01:00
Louis Gesbert
99004ab1d9 catala depends fixes
- automatically include the directories of listed files
- work for files that don't define modules
2024-03-13 18:15:50 +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
9bf441ae31 'catala depends': allow specifying multiple files
The return is a topological order over their joint dependencies.
NOTE: the specified files are now included in the returns
2024-03-12 16:04:59 +01:00
Louis Gesbert
dc6bfae75c Fixes for linking modules in the backends (in particular, Python) 2024-03-08 17:36:00 +01:00