Commit Graph

3991 Commits

Author SHA1 Message Date
Louis Gesbert
5f289307a0 Runtime value printer: use <object> on non-printable entitites 2024-05-15 10:24:18 +02:00
Louis Gesbert
1cf34d9123 Fix formatting of syntax error messages 2024-05-08 12:36:56 +02:00
Louis Gesbert
1efdf4262d Clerk: fix finalisation on exit
We have temporary files to remove upon `ninja` completion so it's not a good
idea to `exec` without fork. This patch ensures `/tmp/clerk_*.ninja` files
aren't left in `/tmp`.
2024-05-08 12:27:10 +02:00
Louis Gesbert
affa45c115 Unify traces between interpreter and runtime
This is a first step into unifying trace handling. This patch only affects the
interpreter, by delegating trace recording to the already existing runtime
functions.

At end of interpretation, it recovers the registered trace from the runtime, and
prints it.

NOTE: there are some limitations due to this approach, as runtime values going
through this interface have to be converted to the "runtime embedded" type. In
particular, functions can no longer be printed (which makes full sense if we
want it to happen in the same way in compiled code) ; some information, like
types, is lost, but it didn't appear to be used.

Also, a specific printer had to be added for runtime values (but it's very
simple so that shouldn't be a problem).

@denismerigoux I'd like your input on how well this goes for your use-cases.

Further work should probably be cleanup and unification of the runtime logging
interfaces ; there is already code for re-structuring the traces, printing to
JSON, etc. which could be common to runtime and interpreter.
2024-05-06 22:16:54 +02:00
Louis Gesbert
59b0f21ff8
Fixes for 0.10.0 (#617) 2024-05-06 22:15:57 +02:00
Louis Gesbert
51ba370f06 Update opam file according to opam-repository reviews 2024-05-06 21:39:58 +02:00
Louis Gesbert
8ad3b68d5f Fix 'make testsuite' return value 2024-05-06 21:39:58 +02:00
Louis Gesbert
3d1e9a56bf Fix adjustment of format width to terminal 2024-05-06 21:39:58 +02:00
Louis Gesbert
0ee512b832 Bump version in package descriptions to 0.10.0 2024-05-06 13:51:05 +02:00
Louis Gesbert
8d659d0557
Cleaner message printing (#614) 2024-05-03 15:57:57 +02:00
Louis Gesbert
19672d2305 Messages: ensure disabled messages aren't computed 2024-05-03 15:27:06 +02:00
Louis Gesbert
396ea03ff9 Message formatting: some more space for results 2024-05-03 15:27:06 +02:00
Louis Gesbert
56b456d137 Message formatting: final touches 2024-05-03 15:14:51 +02:00
Denis Merigoux
da89411189
Restore formatting 2024-05-03 13:55:19 +02:00
Louis Gesbert
c864f658c8 Cleaner message printing
Aerates the printing of messages, removes extraneous noise, and more clearly
attaches the various information tied to a given message.
2024-05-03 12:21:34 +02:00
Denis Merigoux
0f425dc408
Unify runtime error handling (#611) 2024-05-03 10:11:36 +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
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