Commit Graph

1579 Commits

Author SHA1 Message Date
Louis Gesbert
35c862f906 Cleanup a bit the generation of the HandleExceptions operator
this behaviour in part duplicates the work of `-O`, but it's lighter-weight, and
it's often more convenient to debug code without `-O` (which still has impact on
traces generation) ; and this removes one or two levels of obfuscation when you
read the intermediate code.
2024-08-29 10:55:12 +02:00
Louis Gesbert
3cbfa5f258 Generalise optimisation of nested matches 2024-08-29 10:54:47 +02:00
Louis Gesbert
8e91dcb281 Apply suggestions from code review
Thanks @vincent-botbol

Co-authored-by: vbot <vincent.botbol@inria.fr>
2024-08-28 18:12:33 +02:00
Louis Gesbert
9fa5f91e3a Python printer: add some parens to be safe
I can't find where the line cut triggering the error at
https://github.com/CatalaLang/catala/actions/runs/10304111306/job/28522272547?pr=666
came from:
```
/home/ocaml/french-law/_python_venv/lib/python3.12/site-packages/french_law/Aides_logement.py:27785:
error: invalid syntax  [syntax]
```

the file at this point contains:
```
    def traitement_aide_finale_montee_en_charge_saint_pierre_miquelon1(
        aide_finale4:Money):
→       traitement_aide_finale_montee_en_charge_saint_pierre_miquelon4 =
            handle_exceptions(
                [],
                []
            )
```

This workaround adds parens after `=`, which ensures the syntax will be correct.
2024-08-28 18:12:33 +02:00
Louis Gesbert
5d61963a93 Reformat 2024-08-28 18:12:32 +02:00
Louis Gesbert
e9abbf9bd8 Scalc change: switch only on variables
matches can bind, but switches cannot, so we can assume the switch argument
should always be bound to a name ; this allow the intermediate variable to be
better renamed.
2024-08-28 18:12:32 +02:00
Louis Gesbert
14a378a33d Translation to scalc: fix renaming in blocks
Statements are often flattened, in which case their idents need to be
conflict-free. We pass along the renaming context to handle this.
2024-08-28 18:12:32 +02:00
Louis Gesbert
f565e84dae Restore special handling of the option enum in scalc backends
it's not very satisfying, but we make it pass through renaming for now. A better
approach could be to make this special handling structural, or to have something
more specific than an id to hold onto.
2024-08-28 18:12:32 +02:00
Louis Gesbert
081e07378a Renaming: move to its own module 2024-08-28 18:12:28 +02:00
Louis Gesbert
1b6da0b572 reformat (renaming in scalc) 2024-08-28 18:10:41 +02:00
Louis Gesbert
1230f787d6 Renaming: use in the scalc translation and in Python 2024-08-28 18:10:36 +02:00
Louis Gesbert
d23544de39 Apply suggestions from code review
Fix typos following review

Thanks @vincent-botbol

Co-authored-by: vbot <vincent.botbol@inria.fr>
2024-08-28 17:18:26 +02:00
Louis Gesbert
8b06511915 Renaming: more customisation
in particular, this avoids regression with reused struct fields getting renamed
with indices, which would have required changes in e.g.
`french_law/ocaml/bench.ml`
2024-08-28 17:18:26 +02:00
Louis Gesbert
acc13867bf Fix: return module items in file order
This affects their UIDs, and the order in which they later get traversed.

In particular, it was affecting the struct names renaming.
2024-08-28 17:18:26 +02:00
Louis Gesbert
dbfd05155b Fix: Expr.map was missing types in logs 2024-08-28 17:18:26 +02:00
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
7f4824bed6
adapt existing errors to changes 2024-07-31 14:01:55 +02:00
vbot
c83e247d5d
add lsp error notification mechanism 2024-07-31 12:13:49 +02:00
vbot
2b8d6676d5
Scopelang: add list of definitions's positions to scope var def 2024-07-17 18:03:23 +02:00
vbot
d78f004848
Scopelang: fix scope definition incorrect position 2024-07-17 15:34:47 +02:00
Louis Gesbert
98a460e1b3 Remove the R backend
There are no users at the moment, so we won't be actively maintaining it.

If and when the need arises again, we can revert this commit and resurrect it.
2024-07-08 14:52:41 +02:00
Louis Gesbert
0b19130c1d Fix the Python printer 2024-07-08 14:52:41 +02:00
Louis Gesbert
7e97c19901 Cleanup leftover commented code bits 2024-07-08 10:12:42 +02:00
Louis Gesbert
ec6b50988b Fix bug in closure conversion 2024-07-05 18:03:01 +02:00
Louis Gesbert
961a93ae83 Small printer fix 2024-07-05 18:03:01 +02:00
Louis Gesbert
a5278244ec Debugging monomorphisation 2024-07-04 15:08:13 +02:00
Louis Gesbert
03e74b505d Cleanup 2024-07-04 15:08:13 +02:00
Louis Gesbert
561788cbaf Fix formatting of debug timing markers 2024-07-04 15:08:13 +02:00
Louis Gesbert
88f5e932c8 Remove RaiseEmpty and CatchEmpty from the AST 2024-07-04 15:08:13 +02:00
Louis Gesbert
e331c5b37c Interpreter: handle conversion to runtime of defaults//options
This case is really acrobatic, because we are interfacing code compiled to
OCaml (from lcalc) with code from dcalc, and the two have a different
representation for default terms. It... seems to work though.

A more reasonable solution, if there are problems with this or it reveals too
fragile, would be to enforce interpreting at the lcalc level as soon as you want
to link compiled modules.
2024-07-04 15:08:13 +02:00
Louis Gesbert
293bcd3817 Replace HandleDefault* internal operators by HandleExceptions
HandleExceptions only takes an array of exceptions, and returns Some if only one
of them is Some, None if they are all None, or raises a conflict error
otherwise.

The compilation of default terms then wraps this in a match (for the result of
HandleExceptions), and an if-then-else (for the justification-consequence in the
None case).

This avoids the complexity of having to handle thunked functions as arguments.
2024-07-04 15:08:13 +02:00
Louis Gesbert
b005652a85 Fix program printer flushing the ppf unnecessarily 2024-07-04 15:08:13 +02:00
Louis Gesbert
c3b978bef8 Remove the now unused HandleDefault operator
(we now only need HandleDefaultOpt)
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
d073103578 Typecheck operator args bottom-up after monomorphisation
(?)
2024-07-04 15:08:13 +02:00
Louis Gesbert
c0ad0e8820 Closure conversion: recursive hoisting 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
69d8f433e7
Update opam dependencies (#626) 2024-06-27 14:24:21 +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
2471c60beb Update some dependencies
- more recent sedlex fixes a bug that needed a workaround in our code
- we need recent dates_calc to avoid extra runtime dependency on `Str` that our
  build system won't handle
2024-06-26 12:37:57 +02:00
Louis Gesbert
647ab22c04 Literate output: adjust catala-metadata margins
to make sure that 80 characters fit in the line
2024-06-26 12:09:15 +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
dc1b725e9b Reformat 2024-06-21 12:23:01 +02:00
Louis Gesbert
7d7dd47216 Closure conversion: add missing Map2 to matched functional operators 2024-06-21 12:23:01 +02:00
Louis Gesbert
0e05c75028 Internal typing: print the faulty program when debug is enabled
Since the typing error happened on generated code, it's hard to debug without
printing it.
2024-06-21 12:23:01 +02:00
Louis Gesbert
70c01749b2 Fix regression on internal typing errors reported as user errors 2024-06-21 12:23:01 +02:00
Louis Gesbert
712fc1e279 Support closure calls across modules
First I was disappointed that we couldn't convert closure environment properly
because of their opaque nature (native/interpreted conversion is based on the
Catala types) ; but after more thought it's actually unnecessary to convert them
at all since we are guaranteed that they can't be consumed outside of their
realm.
2024-06-21 12:23:01 +02:00