Commit Graph

4125 Commits

Author SHA1 Message Date
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
a8635f0e61 Simplify unthunking function ; cleanup warnings in 'make testuite' 2024-04-30 17:56:06 +02:00
Louis Gesbert
c01d4ac512 Fix exception positions being lost during translation/optimisations
Positions within the Default terms are specially important since they can come
from separate definitions in the source (before this, we would be falling back
to the single declaration).
2024-04-30 17:56:06 +02:00
Louis Gesbert
59740bd560 QoL: guess the scope and make suggestions on 'interpret' command
when no scope was specified
2024-04-30 17:55:55 +02:00
Louis Gesbert
cee8e57d02 More precise positions for operators throughout 2024-04-30 16:35:08 +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
959bcb9ccd Remove obsolete "except" type from the interpreter 2024-04-29 13:42:40 +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
791ae3229b Messages: adjust to terminal width 2024-04-26 15:40:55 +02:00
Louis Gesbert
97d007f1e7 Rename EmptyError to Empty
It's not an error! It happens in the normal control flow :)

This is to distinguish from the other runtime exceptions which are actually
fatal errors.
2024-04-25 14:39:15 +02:00
Louis Gesbert
fe2a562730 Cheat-sheets fixes and improvements 2024-04-25 14:20:22 +02:00
Louis Gesbert
3e2aa54b81
Fix some statement orderings in scalc (#608) 2024-04-23 16:40:31 +02:00
Louis Gesbert
1412e76938 Clerk: fix OCaml linking options to allow inlining
Fixes occurences of `Warning 58 [no-cmx-file]: no cmx file was found in path for
module` during builds.
2024-04-23 16:01:23 +02:00
Louis Gesbert
090faf8c9f Fix statement ordering in scalc 2024-04-23 16:01:23 +02:00
Louis Gesbert
d72141653a Allow trace w/ avoid-exceptions, fix options in api_web
--trace and --avoid-exceptions is a warning, but we want to be able to test with
the combination (in particular, api_web as forcing --trace, so we couldn't
detect its issues with exceptions).
2024-04-23 16:01:23 +02:00
Louis Gesbert
36ca23eb89 Cheat-sheet: minor adjustments 2024-04-23 16:01:23 +02:00
Louis Gesbert
62c9500b63
Add env variables to set flags -O, --avoid-exceptions, --trace (#607) 2024-04-23 16:00:00 +02:00
Louis Gesbert
96ea034839 Clerk: clean up CATALA_* variables on tests 2024-04-19 16:50:36 +02:00
Louis Gesbert
623d2ef03d Add env variables to set flags -O, --avoid-exceptions, --trace
It makes it easier to batch-set them when testing a given repo with different
sets of options. Direct flags should still be preferred in general, of course.
2024-04-19 15:30:51 +02:00
Louis Gesbert
e8820d79b8
Update syntax highlighting rules and cheat-sheets (#606) 2024-04-17 17:24:10 +02:00
Louis Gesbert
aa38d1b2ca Update the syntax cheat-sheet, add a consistency tests
Should now have all latest syntax updates and additions, along with some
reformatting to make it fit.
2024-04-16 23:20:37 +02:00
Louis Gesbert
86e5775a91 Update syntax highlighting for the "but replace" keyword
(and fix highlighting of date rounding keywords in French)
2024-04-16 23:18:57 +02:00
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