Commit Graph

177 Commits

Author SHA1 Message Date
Louis Gesbert
b9156bb60e Implement safe renaming of idents for backend printing
Previously we had some heuristics in the backends trying to achieve this with a
lot of holes ; this should be much more solid, relying on `Bindlib` to do the
correct renamings.

**Note1**: it's not plugged into the backends other than OCaml at the moment.

**Note2**: the related, obsolete heuristics haven't been cleaned out yet

**Note3**: we conservatively suppose a single namespace at the moment. This is
required for e.g. Python, but it forces vars named like struct fields to be
renamed, which is more verbose in e.g. OCaml. The renaming engine could be
improved to support different namespaces, with a way to select how to route the
different kinds of identifiers into them.

Similarly, customisation for what needs to be uppercase or lowercase is not
available yet.

**Note4**: besides excluding keywords, we should also be careful to exclude (or
namespace):
- the idents used in the runtime (e.g. `o_add_int_int`)
- the dynamically generated idents (e.g. `embed_*`)

**Note5**: module names themselves aren't handled yet. The reason is that they
must be discoverable by the user, and even need to match the filenames, etc. In
other words, imagine that `Mod` is a keyword in the target language. You can't
rename a module called `Mod` to `Mod1` without knowing the whole module context,
because that would destroy the mapping for a module already called `Mod1`.

A reliable solution would be to translate all module names to e.g.
`CatalaModule_*`, which we can assume will never conflict with any built-in, and
forbid idents starting with that prefix. We may also want to restrict their
names to ASCII ? Currently we use a projection, but what if I have two modules
called `Là` and `La` ?
2024-08-28 17:18:26 +02:00
vbot
e062124e47
fix typing error missing position 2024-08-06 16:17:43 +02:00
vbot
f5b9e5df2d
fix position invalid test 2024-07-31 14:01:56 +02:00
vbot
c83e247d5d
add lsp error notification mechanism 2024-07-31 12:13:49 +02:00
Louis Gesbert
561788cbaf Fix formatting of debug timing markers 2024-07-04 15:08:13 +02:00
Louis Gesbert
583e80993a Remove the with-exceptions backend
*Disclaimer*: This is intended for discussion

My impression is that the with-exceptions backend is to be superseded by the
without-exception backend, which is more general and more efficient. Therefore,
seeing the added complexity of maintaining the two in parallel, I see no good
reason to keep the with-exceptions version now that the equivalence of their
semantics have been proved.

It will also be nice to reduce divergences between the different backends ; and
this should make further simplifications possible (e.g. some thunkings may no
longer be needed)

Of course I am ready to hear arguments in favor of keeping it, be it in the mid-
or long-term.

This patch removes the `--avoid-exceptions` flag, making it the only option, and
the corresponding `with_exceptions` variant of the dcalc->lcalc translation. It
doesn't do further simplifications.
2024-07-04 15:08:13 +02:00
Louis Gesbert
cdb31ffd57
Support for basic clerk.toml configuration files (#639) 2024-07-01 15:40:06 +02:00
Louis Gesbert
81e2d18100 Don't try to read screen columns without a tty 2024-06-27 13:59:25 +02:00
Louis Gesbert
05752988e6 Clerk: add support for basic configuration files
Not much there at the moment, but being able to specify the include directories
is already pretty useful to run clerk directly e.g. on `catala-examples`.

(you had to explicitely specify variable `CATALA_INCLUDE`, the `-I` flags or to
go through `make` without that)
2024-06-26 10:41:12 +02:00
Louis Gesbert
38a93424a8 Clerk reports: postprocess diff output
This relies less on specific color flags of GNU diff, and reformats and
colorises the output.
(it may still depend on the specific layout of GNU diff with the `-y` flag
though)
2024-06-21 18:19:09 +02:00
Louis Gesbert
8881fee37f Allow catala ocaml --closure-conversion
it's probably not useful per se, but will be handy for debugging
2024-06-21 12:23:01 +02:00
vbot
c26d3fdf4a
Refactor and improve suggestions' pretty-printing 2024-06-21 11:11:53 +02:00
vbot
441dd54ec3
Refactor suggestions 2024-06-20 15:59:54 +02:00
vbot
435794d70a
Add error messages numbering (#634) 2024-06-20 15:41:55 +02:00
Louis Gesbert
ad15984d0b More space between multiple errors, no numbers if just one 2024-06-20 11:15:53 +02:00
vbot
a7094fe52d
Add messages numbering 2024-06-19 18:06:03 +02:00
Louis Gesbert
80400d838a
Messages: improve string padding processing 2024-06-19 16:10:26 +02:00
Louis Gesbert
45b0feaf20
Generate tests reports from 'clerk test'
This is a proper replacement for the previous shell-based placeholder hack.

Here is a summary:

- `clerk runtest` (normally run by ninja) is much extended:
  * besides generating the test@out file, it checks individual tests for success
    and can write a report file containing their status, and the positions for
    their (expected/current) outputs (this uses `Marshal`)
  * it now handles out-tests directly in addition to inline-tests, for which
    it generates the separate output file ; they are included in the report

- ninja is now tasked with building all the test reports (which shouldn't fail);
  for directories, individual reports are concatenated (as before).
  Removing intermediate report rules, and out-test rules means that the ninja
  file is much simplified.

- then, clerk takes back control, reads the final reports and formats them in a
  user-friendly way. Printing the reports may imply running `diff` internally.
  In particular, the commands to easily reproduce each test are provided.
  Resetting the test results if required is also done directly by clerk, at this
  stage.

A few switches are available to customise the output, but I am waiting for some
feedback before deciding what to make available from the CLI.

The `clerk report` command is available to manually explore test reports, but
normally the processing is done directly at the end of `clerk test` (i.e. ninja
will no longer call that command)
2024-06-19 16:10:26 +02:00
vbot
9622ac4172
Add an option to stop on the first delayed error encountered 2024-06-19 14:52:32 +02:00
vbot
62470d0db8
Replace failwith by internal errors 2024-06-18 16:28:20 +02:00
vbot
421d281fc1
Add delayed errors in Message 2024-06-17 15:36:38 +02:00
Louis Gesbert
db87409125 Replace module hashes for external modules
NOTE: This is a temporary solution

A future approach could be to have Catala generate a module loader (with the
proper hash), relieving the user implementation from having to do the
registration.
2024-05-28 11:43:50 +02:00
Louis Gesbert
709b51beb6 Fix hashing of submodule references 2024-05-28 11:43:50 +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
Louis Gesbert
3d1e9a56bf Fix adjustment of format width to terminal 2024-05-06 21:39:58 +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
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
791ae3229b Messages: adjust to terminal width 2024-04-26 15:40:55 +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
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
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
cde9a66295 Output scopes and subscope variable rework done 2024-04-04 10:24:18 +02: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
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
3c03da4a50 file.ml: add a function to cleanup relative paths 2024-03-14 14:04:52 +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
95e3c4bedd Ensure we create the necessary target directories before opening output files 2024-03-08 17:36:00 +01:00
Louis Gesbert
e68e1244a5 Fix complexity of some string functions 2024-03-08 17:36:00 +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