Commit Graph

160 Commits

Author SHA1 Message Date
Louis Gesbert
4dc049f784
Mostly graphical improvements to the explain plugin (#733) 2024-10-31 14:39:33 +01:00
Louis Gesbert
57f85ffb9c Fix non-identchars appearing in backend idents 2024-10-30 14:15:56 +01:00
Louis Gesbert
b67758ec6a Explain plugin: more layout improvements 2024-10-29 14:17:40 +01:00
Louis Gesbert
5afe4ca340 Explain plugin: add theme option 2024-10-29 14:17:17 +01:00
Louis Gesbert
f0ab63ea54 Explain plugin: add an heuristic to display values as percent
if < 1.0 and on either side of a multiplication (don't display `foo + 10%` as
that could be misinterpreted)
2024-10-29 14:17:17 +01:00
Louis Gesbert
0f87f0ec8f Explain plugin: evaluate matches eagerly
They don't display well. Incidentally that seems to work around issue #721 on
our example.
2024-10-29 14:07:03 +01:00
Louis Gesbert
6373df08a9 Explain graphs: hack to keep inputs on top 2024-10-29 14:07:03 +01:00
Louis Gesbert
d45a7ff7b5 Explain output: some styling and colors 2024-10-29 14:07:03 +01:00
vbot
26875d24ad
Ast: add binders positions to EAbs 2024-10-28 17:45:18 +01:00
vbot
588d17de66
Lint: commit changes 2024-10-22 17:08:39 +02:00
vbot
c8c1fb490d
tweak svg to make it fit on browsers 2024-10-11 17:54:48 +02:00
vbot
ffbeab1871
Explain plugin: make the module usage inlining optional 2024-10-10 16:50:23 +02:00
vbot
06f76bd49c
Explain plugin: make links more customizable 2024-10-10 16:50:23 +02:00
vbot
359227ad65
Explain plugin: inline module usage 2024-10-10 16:50:22 +02:00
Louis Gesbert
38a161e23c Explain plugin: add an html output (thin wrapper around the svg)
(it breaks the tooltips though, I am not sure if there is a workaround for that)
2024-10-08 15:37:32 +02:00
Louis Gesbert
eac39d0ee8 Explain plugin: improve layout and formatting
Gather variable affectations, formulas and results in a single box
Update formatting by using the Graphviz HTML subset
And some styling improvements
2024-10-08 15:37:32 +02:00
Louis Gesbert
1800ef36ef Explain plugin: handle neutral elements
They are skipped from formulas, but the fact that they are indeed neutral is
re-added as condition.
2024-10-08 15:37:32 +02:00
Louis Gesbert
8a01395f53 Showing pos, which one is the right one ? 2024-10-08 15:37:32 +02:00
Louis Gesbert
6355c5a6f0 Explain plugin: tweak for analysing test scopes
it will scan the test scope for a call to an underlying scope, registering its
inputs as roots and displaying them on top of the graph.
2024-10-08 15:37:32 +02:00
Louis Gesbert
983212f29b Explain plugin: show pos of variable affectation rather than declaration 2024-10-08 15:37:32 +02:00
Louis Gesbert
c4eb521fe4 Explain plugin: customise default source URL for our example 2024-10-08 15:37:32 +02:00
Louis Gesbert
c805f41da4
Add --autotest option (#706) 2024-10-03 13:15:51 +02:00
Louis Gesbert
0407db1ad1 Dcalc: don't thunk context inputs anymore
With the exceptions backend gone, there is no reason to turn context variables
into functions of `unit` anymore: they can be handled directly
as (`EPureDefault` | `EEmpty`) in dcalc, and options in lcalc.

This provides a big simplification on some programs, in particular when closure
conversion is required.

Note that all complexity is not gone: it's now focused on the interesting case
of context _functions_, which are not of type `default` but instead functions
that _return_ a default type, allowing the possible exceptions to be delayed
until the arguments of the functions are known. The behaviour here is unchanged.

I had to tweak the invariant check on default types (@adelaett could you have a
look ?) :
- it now allows raw `default` types as fields of input structs

In the proof mode, unthunked `EPureDefault` had to be explicitely marked as safe
with being empty (this check could probably be simplified now that we already
get a lot of info by default typing; but I am not yet familiar with the code.
@rmonat would you like to have a look ?)
2024-10-02 18:42:03 +02:00
Louis Gesbert
69e0a002dd Restore fatal assertion failures during evaluation with --stop-on-error 2024-10-01 15:03:31 +02:00
Louis Gesbert
20c37495b5 Fix the date - duration operator to handle date rounding mode
it was only applied to the addition!
2024-09-10 18:26:34 +02:00
Louis Gesbert
634de675a2 Fix a few remaining renaming glitches 2024-09-04 10:50:25 +02:00
Louis Gesbert
f2ac1e39cc Move struct_or_enum type to generic TypeIdent.t
It used to be hidden away in Scopelang.Dependencies, but is useful throughout.
2024-09-02 13:52:34 +02:00
Louis Gesbert
671ada52e7 Forward visibility information of scopes/topdefs in the ctx
it will be needed for safe renaming, and probably more use-cases later on
2024-09-02 13:52:34 +02:00
Louis Gesbert
a971260cab Closure conversion: restore non-transformation of higher order ops under a flag
by reusing the `--keep-special-ops` flag
2024-08-30 15:36:25 +02:00
Louis Gesbert
7def9a20f4 Merge commit origin/master into crun 2024-08-30 15:27:01 +02:00
Louis Gesbert
081e07378a Renaming: move to its own module 2024-08-28 18:12:28 +02:00
Louis Gesbert
1230f787d6 Renaming: use in the scalc translation and in Python 2024-08-28 18:10:36 +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
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
Louis Gesbert
8405301632 Reformat 2024-08-09 12:24:34 +02:00
Louis Gesbert
edb8db9ada Implement expansion of equality tests
This adds an optional pass that recursively expands equality tests across
structures and enums, on lcalc.

NOTE: this is a temporary solution.

- all tests are completely inlined, which may be a bit bloated
- due to the lack of primitives (and expressive pattern-matching), checking
  equality on enums generates a 2-level pattern matching, quadratic in the
  number of constructors
- this is completely separate from the monomorphisation pass, which morally
  should take care of generating this code (as specific functions rather
  than inlined code)

So, while this should work as a place-holder for now, it actually seems more
reasonable mid-term (before we do it through monomorphisation) to do this
translation at the backend level, i.e. when generating the C code, when we have
full access to the representation of enums.
2024-08-09 11:54:34 +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
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
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
cee8e57d02 More precise positions for operators throughout 2024-04-30 16:35:08 +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
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
def10e7f98 Message: further simplification 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
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
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
dc6bfae75c Fixes for linking modules in the backends (in particular, Python) 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