Commit Graph

1580 Commits

Author SHA1 Message Date
Louis Gesbert
bc90a7b890 Add (internally) a map2 operator 2024-01-26 11:22:12 +01:00
Louis Gesbert
a9f8fa36b8 Reduce default verbosity of invariant checks
they break the tests too often for no good reason
2024-01-25 18:18:43 +01:00
Louis Gesbert
7b25a42970 Better version handling
Always generate the version through git when possible, and encode that within
the binaries so that `catala --version` does'nt give misleading information.

Previously we used dune's builtin functionality, but that resorts to a hack at
install time which is unpleasant and doesn't work with our use of `opam
install`.

The cost is a re-linking of catala_utils and the binaries upon git commit, which
is hardly noticeable.
2024-01-24 11:41:34 +01:00
Denis Merigoux
34c62a73c1
Improve missing field error message 2024-01-23 12:05:18 +01:00
Denis Merigoux
8a139f6a3c
Work on arrays 2024-01-22 16:49:58 +01:00
Louis Gesbert
7636a6e8d5 CI: cleanup the exposed artifacts 2024-01-22 13:58:32 +01:00
Louis Gesbert
81eb7bf6d2 CI: Fix artifact source dir 2024-01-20 11:51:01 +01:00
Louis Gesbert
c336a7bb62
[WIP] Rehaul CI to run examples and generate artifacts again (#562) 2024-01-19 18:34:24 +01:00
Louis Gesbert
1c2c41b2ff Allow literal scope output structures 2024-01-19 15:43:35 +01:00
Louis Gesbert
c006c3343e Rehaul CI to run examples and generate artifacts again
this requires to fetch catala-examples and french-law from their own repos

Restrict static builds and publication to master
2024-01-18 16:14:27 +01:00
Louis Gesbert
d9a17db4c0 Fix running inline tests
Warning: one of them is broken and was disabled
2024-01-18 16:14:27 +01:00
Denis Merigoux
50d3164f36
Restore C compilation 2024-01-17 17:26:41 +01:00
Denis Merigoux
5310e47e5b
Fix monomorphization problems with [TAny] left 2024-01-17 16:03:20 +01:00
Denis Merigoux
0a8fdde7de
Fix monomorphization 2024-01-17 14:02:32 +01:00
Denis Merigoux
ca8e4989ea
Type Scalc flow to avoid unresolved typing
With the new EAppOp node, the typing of operator application has changed and this causes some problems
with the example in test_scope/good/nothing.catala_en when retyping the LCalc to go to Scalc. This
commit changes the weird thing that for generating Scalc, the "typed" parameter was set to "untyped".
2024-01-17 13:08:20 +01:00
Denis Merigoux
a1ab58478c
Remove useless field 2024-01-17 11:29:39 +01:00
Denis Merigoux
349da741d4
Merge branch 'master' into c_backend 2024-01-16 16:23:35 +01:00
Louis Gesbert
8ed45c2762
Fixes missing minus sign printing for small negative amounts of money (#560) 2024-01-16 12:21:29 +01:00
Denis Merigoux
15c7691c09
Fixes #555 2024-01-16 11:40:10 +01:00
Denis Merigoux
b616e60c79
Fixes #558 2024-01-16 11:29:45 +01:00
Denis Merigoux
9f03b6b931
Merge branch 'master' into c_backend
Some tests still failing...
2024-01-15 17:19:17 +01:00
Louis Gesbert
12f208b3fc Adding tuples: fixes following review 2024-01-08 12:16:07 +01:00
Denis Merigoux
919dd2b812 Monomorphization properly done 2023-12-20 17:45:39 +01:00
Denis Merigoux
dcd883e53c
Uppercase constructors 2023-12-19 17:40:38 +01:00
Denis Merigoux
a9764d607e
Merge branch 'master' into c_backend 2023-12-19 17:39:02 +01:00
Louis Gesbert
d3e7c565a9 Closure conversion: use multiple let-in 2023-12-19 17:30:32 +01:00
Louis Gesbert
5384394a72 Fix typing upon detuplification 2023-12-19 17:30:32 +01:00
Louis Gesbert
a2efc94fd2 Register the option type in ctx when used in lcalc 2023-12-19 17:30:28 +01:00
Louis Gesbert
a1c1a7756f Update invariant tests outputs 2023-12-19 17:27:44 +01:00
Louis Gesbert
2823795f9f AST change: more specific application
As part of making tuples first-class citizens, expliciting the arity upon
function application was needed (so that a function of two args can
transparently -- in the surface language -- be applied to either two arguments
or a pair).

It was decided to actually explicit the whole type of arguments because the cost
is the same, and this is consistent with lambda definitions.

A related change done here is the replacement of the `EOp` node for operators by
an "operator application" `EAppOp` node, enforcing a pervasive invariant that
operators are always directly applied. This makes matches terser, and highlights
the fact that the treatment of operator application is almost always different
from function application in practice.
2023-12-19 17:27:40 +01:00
Denis Merigoux
af16be501a
Remove useless optimizations caught just after 2023-12-19 17:26:36 +01:00
Denis Merigoux
9d9a2c4496
Start to implement proper monomorphization 2023-12-19 17:26:17 +01:00
Louis Gesbert
94ebc1b65e Allow deconstruction of tuples using let in 2023-12-19 17:25:44 +01:00
Louis Gesbert
df3ab64fe9 Add tuples to the surface language
No helpers to destruct them at the moment
2023-12-19 17:25:44 +01:00
Louis Gesbert
fb51f58261 Optimise away trivially-true errors-on-empty 2023-12-19 16:10:11 +01:00
Louis Gesbert
ea4e191f27 Add optimisation to skip variable aliasings
This particularly of effect to the code introduced by closure conversion.
2023-12-19 16:07:22 +01:00
Louis Gesbert
7233ec403a Printer: add parens after constructors 2023-12-19 16:07:22 +01:00
Louis Gesbert
ad0afa2f64 Small interpreter optimisation
This is unholy, but we're manually bringing a typing proof so it may be
acceptable...
2023-12-19 16:07:22 +01:00
Louis Gesbert
e123d7eb95 Change type syntax of collection into list of 2023-12-19 15:26:44 +01:00
Louis Gesbert
3779a249db Unify all CLI arguments to use - rather than _
it's more common on UNIXes and the mix was unpleasant.
2023-12-19 15:25:37 +01:00
Denis Merigoux
85bbb7be1c
Add monomorphizing option 2023-12-19 15:01:06 +01:00
Denis Merigoux
9358ad945e
Better type translation in closure conversion 2023-12-19 14:31:57 +01:00
Denis Merigoux
e6a35f31b6
Fixes #551 2023-12-19 13:39:24 +01:00
Denis Merigoux
366c351930
Correctly compiles let bindings in expressions 2023-12-19 12:03:23 +01:00
Denis Merigoux
0323e71edb
Default types should be eliminated in compile_with_exceptions 2023-12-18 15:23:08 +01:00
Denis Merigoux
4eead4850b
There are no more defaults in type after compile_with_exceptions... 2023-12-18 15:14:28 +01:00
Denis Merigoux
91f8451899
Better beta-reduction 2023-12-18 14:49:43 +01:00
Denis Merigoux
35f829cd65
Fix default optimisation 2023-12-18 14:42:58 +01:00
Denis Merigoux
1f91c16e43
Fix little bug 2023-12-13 16:40:22 +01:00
Denis Merigoux
5c49581207
Compiling simple program correctly to C 2023-12-13 11:07:08 +01:00
Denis Merigoux
827fcef469
More progress but enums also require no struct literals 2023-12-12 18:21:20 +01:00
Denis Merigoux
adfb9297d3
Progress on compiling 2023-12-12 16:25:02 +01:00
Denis Merigoux
d88f67bb2c
Progress 2023-12-12 16:08:40 +01:00
Denis Merigoux
7e221b29eb
Gets C89 struct initialization right 2023-12-11 17:28:32 +01:00
Denis Merigoux
37ab4187bd
Almost there with structs 2023-12-11 17:08:32 +01:00
Denis Merigoux
aca1d0e712
Fields in AST nodes 2023-12-11 15:59:47 +01:00
Denis Merigoux
3711026a4f
Beginning to compile 2023-12-11 14:47:09 +01:00
Denis Merigoux
5b7470fd0d
Compile HandleDefaultOpt specially 2023-12-11 14:34:31 +01:00
Denis Merigoux
f072694e50
Trying to progress 2023-12-11 13:56:13 +01:00
Denis Merigoux
79a261bb47
Restore CI 2023-12-11 11:44:25 +01:00
Denis Merigoux
c61bdbc5d7
Setting up special compilation 2023-12-11 11:31:51 +01:00
Denis Merigoux
4e8d2ef219
Beginning to compile specially HandleDefaultOp, Map, Fold, etc. for C 2023-12-11 11:31:51 +01:00
Denis Merigoux
4f7b678cd7
Making progress and fixing bugs 2023-12-11 11:31:51 +01:00
Denis Merigoux
192e50540b
Correctly compile function pointer types 2023-12-11 11:31:51 +01:00
Denis Merigoux
4d969e13c5
Enum type 2023-12-11 11:31:51 +01:00
Denis Merigoux
2eaac39bb1
Some progress 2023-12-11 11:31:51 +01:00
Denis Merigoux
ad3e140e88
Progress on C backend 2023-12-11 11:31:51 +01:00
Denis Merigoux
5f045110b9
Add tuples to Scalc 2023-12-11 11:31:51 +01:00
Denis Merigoux
6652dc8df2
Add C backend command 2023-12-11 11:31:45 +01:00
Louis Gesbert
5b1462d529 Clerk: allow to include non-yet-existing directories
Useful when you have wide `-I` options that not all targets may depend on.
2023-12-08 13:56:31 +01:00
Louis Gesbert
a988ad473b Fix handling of embedded context through modules
Exceptions raised by the interpreter from within the native modules were not
handled correctly.
2023-12-08 13:56:18 +01:00
Louis Gesbert
509ce9788a
Document and first test for externals (#538) 2023-12-07 16:06:25 +01:00
adelaett
b5e7b297aa
typo fixing 2023-12-07 13:48:46 +01:00
adelaett
9f4a238a4a
Fix error messages for unexpected types.
do not retype the terms in the cases where checking invariant is not mandatory.
2023-12-07 13:45:50 +01:00
adelaett
934ab328ec
invariant checking is now available without printing the ast using the typecheck subprogram 2023-12-07 11:27:14 +01:00
adelaett
e1bda33e07
fmt 2023-12-07 11:27:14 +01:00
adelaett
030705eacd
Make the typing invariant more precise. 2023-12-07 11:27:14 +01:00
adelaett
67e36dcf42
Adding Typing Invariant for TDefault
Added a new type safety invariant to ensure that the type `TDefault` can only appear in certain positions,

* On the left-hand side of an arrow with arity 1, as the type of a scope (for scope calls).
* At the root of the type tree (outside a default).
* On the right-hand side of the arrow at the root of the type (occurs for rentrant variables).

This is crucial to maintain the safety of the type system, as demonstrated in the formal development.

The invariant was checked on all tests cases and on family and housing benefits.

Adjusted inversion invariant about app to handle external objects as well.
2023-12-07 11:27:14 +01:00
Denis Merigoux
2486fbcfb5
Fix LaTeX weaving failing with code blocks (#544) 2023-12-07 11:08:04 +01:00
Denis Merigoux
628cbc4fec
Fix #543 2023-12-06 16:58:38 +01:00
Louis Gesbert
7160093682 Allow scope execution in compiled ocaml executables 2023-12-06 11:06:54 +01:00
Louis Gesbert
54d956823b Some module fixes 2023-12-06 11:06:54 +01:00
Louis Gesbert
9a255522be Document and first test for externals
Also some fixes for Clerk to properly support them
2023-12-06 11:06:54 +01:00
Louis Gesbert
0d5759d99c Allow pre-declarations without an expression for topdefs
it allows for better splitting between metadata and code (even if the type has
to be repeated at the moment)
2023-12-05 16:21:04 +01:00
Louis Gesbert
e689f0c47b Small cleanup and doc on the module handling refactor 2023-12-05 16:01:56 +01:00
Louis Gesbert
1ae955b504 Reformat 2023-11-30 23:53:38 +01:00
Louis Gesbert
8df49dcea2 More tests and some fixes 2023-11-30 23:49:19 +01:00
Louis Gesbert
3649f92975 Rework resolution of module elements
This changes the `decl_ctx` to be toplevel only, with flattened references to
uids for most elements. The module hierarchy, which is still useful in a few
places, is kept separately.

Module names are also changed to UIDs early on, and support for module aliases
has been added (needs testing).

This resolves some issues with lookup, and should be much more robust, as well
as more convenient for most lookups.

The `decl_ctx` was also extended for string ident lookups, which avoids having
to keep the desugared resolution structure available throughout the compilation
chain.
2023-11-30 21:14:12 +01:00
Louis Gesbert
86b7f80e90 Clerk improvements
- Add a `-I` option that allows defined modules to be available from other
  directories

- Add reporting of the number of successful / failed tests

- Locate the project root, and always run the commands from there
2023-11-30 21:14:12 +01:00
Louis Gesbert
c019d1568f Clerk: fix handling of dependency on the catala exec 2023-11-30 17:46:38 +01:00
Louis Gesbert
326ee07f5d Interpreter: handle lcalc with exceptions 2023-11-28 15:02:11 +01:00
Louis Gesbert
4e465d2b48 Printer: some small improvements 2023-11-28 13:37:46 +01:00
Louis Gesbert
447f6d41f1 Interpreter: fix execution with closure_conversion
and context variables
2023-11-28 13:37:46 +01:00
Louis Gesbert
645c263ccc Fix closure-conversion
Joint debugging with @denismerigoux :)
2023-11-28 11:18:41 +01:00
Louis Gesbert
80475ad5ef Printer: show toplevel uids in debug mode
otherwise we had an inconsistency between what's defined at toplevel and what
appears in expressions.
2023-11-28 11:15:01 +01:00
Louis Gesbert
f0d930688e Support closure conversion with disabled typing or optims
This is very useful for debugging
2023-11-28 11:14:48 +01:00
Louis Gesbert
cf89204a4b Reformat 2023-11-27 11:17:38 +01:00
adelaett
a734413d39 typing default: fix ocaml runtime when using eoption 2023-11-27 11:17:38 +01:00
adelaett
324ca74053 typed defaults: fixed interpreter value initialization in lcalc mode
when having the avoid_exceptions flag enabled.
2023-11-27 11:12:35 +01:00
adelaett
576da177c5 Typed defaults: translate types in scope lets as well in the new
compile without exception passe
2023-11-27 11:12:35 +01:00
adelaett
cb29fdeefe fixing the handle_opt in the interpreter. 2023-11-27 11:09:08 +01:00
adelaett
1d72a57da4 Typed default: fix an issue to the error_on_empty constructor 2023-11-27 11:09:08 +01:00
adelaett
4a5335162e Typed default: implementing the type for handle defaults, as well as the
compile without exceptions compilation pass, using the newly found
invariant
2023-11-27 11:09:08 +01:00
adelaett
b0b83b14b9 Typed default: Implemented typing translating to the without exception compilation path. 2023-11-27 11:09:08 +01:00
adelaett
2c9f8ad8b1 Typed default: import the code from compile with exceptions to
re-implement without exceptions with the new typing of defaults terms.
2023-11-27 11:09:08 +01:00
Louis Gesbert
cc4e5339dd Typed defaults: small simplification and fixes 2023-11-27 11:09:08 +01:00
Louis Gesbert
3a149bc86e Fix compilation of plugins 2023-11-27 11:09:08 +01:00
Louis Gesbert
1efda5ca22 Typing defaults: support nested priorities
The way nested priorities are encoded use `< < excs | true :- nested > :- x >`,
which imply that `nested` can actually be ∅ ; to cope with this, the typing of
default terms is made more generic (the return type is now the same as the
`cons` type `'a`, rather than `<'a>`). For the general case, we add an explicit
`EPureDefault` node which just encapsulates its argument (a `return`, in monad
terminology).
2023-11-27 11:09:08 +01:00
Louis Gesbert
4ececf9960 Fix api_web plugin 2023-11-27 11:09:08 +01:00
Louis Gesbert
c4715ea86e Reformat 2023-11-27 11:09:08 +01:00
Louis Gesbert
bcf285913e Typing the HandleDefault operator 2023-11-27 11:06:33 +01:00
Louis Gesbert
fd50e6186f Fix default typing across modules 2023-11-27 11:06:33 +01:00
Louis Gesbert
9203e4f7bb Verification: support unboxed defaults 2023-11-27 11:06:33 +01:00
Louis Gesbert
dc3ffa0dcd Fix some error handling on scope calls
(and add suggestions)
2023-11-27 11:06:33 +01:00
Louis Gesbert
958aaebac3 Typing defaults fixes: keep in and out type in scope sigs 2023-11-27 11:06:16 +01:00
Louis Gesbert
ab6bec390d Adjust plugins and warnings 2023-11-27 11:06:16 +01:00
Louis Gesbert
0be2636e65 Typing defaults: making the compiler adhere to the new type discipline 2023-11-27 11:06:01 +01:00
Louis Gesbert
52486af6ac Correct typing of context subscope variables 2023-11-27 11:06:01 +01:00
Louis Gesbert
b98bad8c33 Add a --no-typing option
it is useful e.g. to be able to print intermediate ASTs when they don't type, to
debug the typing errors. This is better than commenting the typing line each
time.

Note that the option is not available on all targets (esp. not for ocaml and
python outputs ; it's allowed on the interpreters for debugging purposes but I'm
not sure if that's a good idea)
2023-11-27 11:06:01 +01:00
Louis Gesbert
9425753eca Typer: add built-in "'a default" type 2023-11-27 11:06:01 +01:00
Louis Gesbert
e2730c0b44 Avoid redundant position in type error 2023-11-27 11:05:58 +01:00
Louis Gesbert
4fa9326618 Typer: on error, print the expression being typed in debug mode
useful when typing fails on internally generated expressions
2023-11-27 11:03:47 +01:00
Denis Merigoux
fc242a5d1f
Fix Python compilation and runtime 2023-11-22 18:08:44 +01:00
Denis Merigoux
c46f5d568d
Don't put a box in list printing but do indent (#524)
Don't put a box in list printing but do indent
2023-11-02 11:56:57 +01:00
Louis Gesbert
1d8e3748ea Improving the printer on arrays 2023-11-02 11:12:51 +01:00
Louis Gesbert
73df41eb6f
More complete tests on module calls and a bunch of fixes (#525) 2023-10-17 09:42:48 +02:00
Louis Gesbert
bd90555e96 The interpreter might return custom terms
since scope outputs may contain functions this shouldn't be excluded; functions
from the interpreter now reflect this
2023-10-13 16:16:45 +02:00
Louis Gesbert
3b0e576a24 Fix module name propagation 2023-10-13 16:13:02 +02:00
Louis Gesbert
2d062a4ad0 Fix bug in dependency analysis around scope call arguments 2023-10-13 16:12:15 +02:00
Louis Gesbert
d09113163d Fix bug in dependency analysis around scope call arguments 2023-10-13 15:09:36 +02:00
Louis Gesbert
61ec34e3d9 Fix handling of context vars with all call cases 2023-10-12 14:47:43 +02:00
Louis Gesbert
af8ff472a5 Fix handing of context variables in modules
The call convention imposes a translation of their types within the scope input
structs definitions in dcalc.
2023-10-12 14:42:57 +02:00
Louis Gesbert
f8b6e60e16 Fix handling of context variables in the interpreter 2023-10-12 14:42:57 +02:00
Denis Merigoux
9024cf1222
Don't put a box in list printing but do indent 2023-10-12 12:01:28 +02:00
Denis Merigoux
fce192be20
Improve trace printing 2023-10-11 09:37:36 +02:00
Louis Gesbert
2708fa53b2 Reformat 2023-10-03 18:50:18 +02:00
Louis Gesbert
263cf3a9f7 Fix line-lexer on french syntax
"Usage de" being two words was tripping it
2023-10-03 18:49:16 +02:00
Louis Gesbert
2c6e6bf0b5 Disambiguate constructors and fields across modules 2023-10-03 18:49:00 +02:00
Louis Gesbert
8194abaf93 Operator mismatch fix
wow this remained unspotted for some time...
2023-10-03 18:44:12 +02:00
Louis Gesbert
22045a2f06 Tests and fixes on structures across modules 2023-10-03 18:43:14 +02:00
Louis Gesbert
cc7c3fc18c Clerk: add more tests, and small fixes 2023-10-02 17:51:16 +02:00
Louis Gesbert
a79acd1fa8 Reformat 2023-09-27 13:19:04 +02:00
Louis Gesbert
ce17d8e563 Fix plugins compilation 2023-09-27 13:18:28 +02:00
Louis Gesbert
ade51234e8 Discard catala option --build-dir that is not useful in the end 2023-09-27 13:18:28 +02:00
Louis Gesbert
50fad76df3 Clerk: copy files to _build and run catala there
this is more consistent, avoids empty stamp files and should make things simpler
overall.

The slightly tricky `-C` option is added to Catala so that it can be run from
_build while paths to source and destination files are still specified relative
to CWD (Ninja doesn't provide string manipulation, so otherwise we would have to
explicit both the `_build/dir/` and `dir/` versions of each path).
2023-09-27 13:18:28 +02:00
Louis Gesbert
5efa61a0ce Clerk: rewrite 'clerk runtest' to use the new lightweight lexer
* Obsolete code for included tests has been removed

* The engine uses a proper lexer and is much simplified

* An inline test in the middle of the file now only "sees" the file up to that
  point. This fixes an issue where we had spurious errors when a type error was
  added at the end of a file, and it would pop up in tests before it. This makes
  files including many tests much more practical.

* diffing and resetting the tests has been reintroduced (done at the moment in
  Ninja, but for more control (count number of failed tests, etc.) we could put it
  back into Clerk at some point

* The Catala CLI can now take an input from stdin (with the possibility to link
  a (possibly fake) on-disk file for error reporting and file locations ; this
  is useful for running tests)
2023-09-27 13:18:18 +02:00
Louis Gesbert
cc7066e9a8 Clerk: better handling of transitive dependencies
We need a concrete intermediate target for e.g. transitive uses of `> Include`
for Ninja to correctly handle them.

Of course we could also unroll all transitive dependencies, but meh.

Note also that now tests now just generate the outputs but facilities for
diffing and resetting are temporarily absent.
2023-09-27 13:14:40 +02:00
Louis Gesbert
dbe0990163 Rework module includes CLI in Catala
Rather than require all files to be listed on the command-line (and having to
check consistency with `> Using` directives), the main catala CLI is now a bit
more clever.

⇒ There is a new assumption that a module name definition must match the file
name (up to case and extension) — with appropriate error handling to enforce it.

In exchange, `> Using` directives are now used to more transparently lookup the
appropriate `.catala_*` interfaces and the compiled artifacts for the used modules (handling transitive dependencies), with just standard `-I` flags for when they need to be looked up in different places.
2023-09-27 13:14:40 +02:00
Louis Gesbert
4bce4e6322 Reformat 2023-09-27 13:14:38 +02:00
Louis Gesbert
f162f6e9bd Improve handling of module name definitions
and add some sanity-checks for consistency of used modules w.r.t. actually
loaded modules.
2023-09-27 13:14:03 +02:00
Louis Gesbert
22c69938b6 Fix handling of "output" tests
I.e. our legacy tests with a separate output tests, to distinguish from inline
tests.
2023-09-27 13:08:15 +02:00
Louis Gesbert
63773e48b5 Update tests outputs 2023-09-27 13:08:15 +02:00
Louis Gesbert
f8e3774662 Fix lookup of built modules in Catala 2023-09-27 13:08:15 +02:00
Louis Gesbert
494be673a8 Rehaul the Clerk build system to fully handle modules and linking 2023-09-27 13:08:15 +02:00
Louis Gesbert
cf8f365cf7 Extract Catala version from dune
(avoids multiple, possibly inconsistent, definitions ; also syncs up Clerk
versions with Catala)
2023-09-27 13:08:15 +02:00
Louis Gesbert
94ec864890 Scan file tree: proceed in sequence 2023-09-27 13:08:15 +02:00
Louis Gesbert
bf048f0a74 Add a lightweight lexer for dependency extraction in Clerk
The base is there but not fully used yet in Clerk
2023-09-27 13:08:15 +02:00
Louis Gesbert
9aed2c7479 support for parsing Module directives 2023-09-27 13:08:11 +02:00
Denis Merigoux
ec18ac10bb
Fix missing implem 2023-09-22 18:06:44 +02:00
Denis Merigoux
1f4805caad
Print interpreter error messages with localized expression printer 2023-09-22 18:06:43 +02:00
Denis Merigoux
9cecf5587a
Register surface syntax languge in program troughout the compilation chain 2023-09-22 18:05:26 +02:00
Denis Merigoux
ea838ed6af
Comment 2023-09-22 18:05:26 +02:00
Denis Merigoux
7bad9aa20e
Improve assertion failure message 2023-09-22 18:05:26 +02:00
Denis Merigoux
38782fa546
Correct fix 2023-09-22 18:02:44 +02:00
Denis Merigoux
5eba0b6562
Trying 2023-09-21 13:57:54 +02:00
Denis Merigoux
7971cb7651
Break lines in code Latex output 2023-09-21 13:30:30 +02:00
Louis Gesbert
c63d74647d Optim: avoid extra translations in the interpreter
A recent patch introduced custom terms in expressions manipulated by the
interpreter. For typing reasons, a traversal is done to extend the supplied
expression with these custom terms — it's functionally the identity, but, due to
the fact that the type-checker can't infer covariance of our AST terms on their
phantom parameter, playing by the rules imposes a full traversal + rebuild.

Without resorting to a (constrained) `Obj.magic`, this patch avoids extra
intermediate conversions, which is enough to cut out the huge extra cost we were
incurring.

Closes #516
2023-09-19 18:22:43 +02:00
Denis Merigoux
af1fbe884c
Encapsulate by default all Web API calls with execute_or_throw_error 2023-09-15 10:29:31 +02:00
Louis Gesbert
3cc77f4601
Improvements to the Polish translation (#499) 2023-09-13 16:19:06 +02:00
Denis Merigoux
c1d4592998 Correct MR_* fields for characters with accents 2023-09-13 14:14:47 +02:00
zapashcanon
97e5b15531
replace let _ by let () or add type annotation 2023-09-09 22:02:39 +02:00
Louis Gesbert
9a596a48f7 Improvements to searching for libs at runtime (plugins, runtime, etc.) 2023-09-04 09:57:49 +02:00
Louis Gesbert
4910158aea Reformat 2023-09-01 16:24:27 +02:00
Louis Gesbert
fe2c66af12 Select colors for Uids upon instanciation
This way different Uid kinds will have a consistent color across error messages,
AST dumps, etc.
2023-09-01 14:41:56 +02:00
Louis Gesbert
dcb057bc6f
Module support: handle structs, enums and scope calls across modules (#497) 2023-09-01 14:35:58 +02:00
Louis Gesbert
544e18e110 Fixes related to environments and lookups 2023-08-31 18:31:48 +02:00
Louis Gesbert
8278bb8c5d Make the passes appear more clearly in the driver debug 2023-08-31 18:31:48 +02:00
Louis Gesbert
ff60aee5ef Improve module error messages 2023-08-31 18:31:48 +02:00
Louis Gesbert
e75ea3da07 Cleanup tmp debug code 2023-08-31 18:31:48 +02:00
Louis Gesbert
8e33355ead Reformat 2023-08-31 18:31:48 +02:00
Louis Gesbert
6bccd89482 Fix OCaml backend for cross-module refs 2023-08-31 18:31:48 +02:00
Louis Gesbert
7db63e5f78 Simplification: store paths in Uids
rather than scattered in structures

The context is still hierarchical for defs though, so one needs to retrieve the
path to lookup in the correct context for info. Exceptions are enums and struct
defs, which are re-exposed at toplevel.
2023-08-31 18:31:48 +02:00
Louis Gesbert
a71b4e7f73 Some fixes to relative file lookups in modules and tests
This makes sure `catala module` finds the local runtime when run from the catala
source tree; and fixes lookup of the catala exec on custom uses of `clerk runtest`.
2023-08-31 17:55:36 +02:00
Louis Gesbert
17172cf47d Some fixes & cleanup after early review 2023-08-31 17:55:36 +02:00
Louis Gesbert
72882f82df Reformat 2023-08-31 17:55:36 +02:00
Louis Gesbert
c58e76f4e5 Gather the maps for subscope vars to the top level
(they use UIDs so this doesn't jeopardize proper name resolution ; and it allows
resolution of subscope calls without further code modifications)
2023-08-31 17:55:36 +02:00
Louis Gesbert
bcde10242f Specialise the Map.Not_found exception raised by Map.find
... and add a custom printer

Since this is a very common bug, this patch should gain us a lot of time when
debugging uncaught Not_found errors, because the element not found can now be
printed straight away without the need for further debugging.

The small cost is that one should remember to catch the correct specialised
`Foo.Map.Not_found _` exception rather than the standard `Not_found` (which
would type-check but not catch the exception). Using `find_opt` should be
preferred anyway.

Note that the other functions from the module `Map` that raise `Not_found` are
not affected ; these functions are `choose`, `min/max_binding`,
`find_first/last` which either take a predicate or fail on the empty map, so it
wouldn't make sense for them (and we probably don't use them much).
2023-08-31 17:55:36 +02:00
Louis Gesbert
9bac045d03 Implement module lookups for scopes, structs, and enums 2023-08-31 17:54:39 +02:00
Artur Cygan
c33cccd7c1 Improvements to the Polish translation 2023-08-17 12:15:25 +02:00
Adam Olech
8382492816 Fix typos for error triggered when no input variables were provided 2023-08-17 00:47:48 +02:00
Denis Merigoux
13654bde3a
R backend for Catala (#496) 2023-08-07 18:10:44 +02:00
Denis Merigoux
6d7b1f2585
Last fixes 2023-08-07 17:55:04 +02:00
Denis Merigoux
8743b73459
Debugging the R backend 2023-08-07 16:19:13 +02:00
Denis Merigoux
4d419ac167
Switch to S4 classes and package runtime 2023-08-07 15:58:55 +02:00
Denis Merigoux
695faebefb Cleaning up 2023-08-05 16:23:29 +02:00
Denis Merigoux
e2f8e56e7d Backend seems to work, needs more debugging 2023-08-05 14:28:18 +02:00
Denis Merigoux
62ea40a40d Fix tryWith compilation 2023-08-05 13:05:31 +02:00
Denis Merigoux
d0483d681a
First test passing 2023-08-04 19:30:43 +02:00
Denis Merigoux
1df2ebda13
Correct compilation of tryCatch 2023-08-04 19:03:10 +02:00
Denis Merigoux
84d37d8720
Print algebraic data types as R classes 2023-08-04 18:07:49 +02:00
Denis Merigoux
fd89562c8b
Starting to implement R backend 2023-08-04 17:25:12 +02:00
Louis Gesbert
4a06faa881 modules plugin: fix target directory of dlls 2023-08-04 12:08:18 +02:00
Louis Gesbert
300d993733 Simplify visitors ppx annotations
the small downside is that we lose a little bit of granularity by making
defining all the types at once (with `type ... and`) ; but one well-placed
annotation seems to be enough.

also discarded the `iter` visitor that was unused.
2023-08-04 11:43:16 +02:00
Aminata-Dev
94f8eac858 Better indications for the user :
- We're able to say from the parser what the user could have written. It may not be complete due to the acceptable function of Menhir : it is only an indication given to the user (and not intended to be an adaptive documentation)
- .mli file added : module interface for suggestions
- Add a test that provides a typographical or a logical error.
- Documentation and type / name changes for suggestions
2023-07-12 16:32:55 +02:00
Louis Gesbert
c96c6e187f Re-implement the GNU message output format 2023-07-12 13:57:58 +02:00
Aminata-Dev
af9c708960 Better help for the user
- Clearer (more detailed) error messages (see parser.messages, parser_driver.ml ->)
	--> Parser_driver.ml : we're more precise and show all possible instructions to the user.
- Suggestions.ml : unimportant display changes + renaming
2023-07-12 11:55:11 +02:00
Aminata-Dev
6123ebd004 get re(c)t 2023-07-12 11:55:11 +02:00
Aminata-Dev
17469565ec Improve the implementation of suggestions
- suggestions.ml : improve details + algorithm implementation (see @Altgr reviews) + comments
- suggestions implementation : since we want to keep the same structure to display suggestion messages, Suggestion is no longer a formatted string but a string list. The goal is to have a similar formatted string for each suggestion, no matter what the error message is.
--> This involves changes to suggestions.mli, compiler/desugared/from_surface.ml (most important one) and compiler/surface/parser_driver.ml
2023-07-12 11:55:11 +02:00
Aminata-Dev
b087ca4f47 Improve suggestions
- Improved implementation of suggestions (suggestion_minimum_levenshtein_distance_association > suggestions.ml)
- Magnifying glass emoji added for suggestions
- Improve display by...
	- Fixing "Pos.ml" (pretty-printing box not closed)
	- Remove unnecessary spaces
- compiler/surface/parserdriver.ml
	- Optionnal suggestions added when raising a parser error
	- Function "levenshtein_distance" removed and replaced by "Suggestions.levenshtein_distance"
- Tests updated (mostly line breaks and spacing changes)
- Variable names renamed for greater clarity
- (Based on commit 0813f5c36e)
2023-07-12 11:55:11 +02:00
Aminata-Dev
75b6251b43 Match the compiler code to the new type of error message content 2023-07-12 11:55:11 +02:00
Denis Merigoux
50113586e3 With @aminata-dev update Messages.Content 2023-07-12 11:55:11 +02:00
Denis Merigoux
4cdd2fce0f With @aminata-dev, implemented first error message improvement! 2023-07-12 11:55:11 +02:00
Denis Merigoux
67f69561c2 Renaming and correct autorship 2023-07-12 11:55:11 +02:00
Aminata-Dev
0360568e8e actual changes 2023-07-12 11:55:11 +02:00
Aminata-Dev
c55fa0a665 start implementing suggestions 2023-07-12 11:55:11 +02:00
Louis Gesbert
f2fc79f640 Add some helper functions in a wrapper Map module
and use them throughout. No more `List.map fst (Map.bindings m)` !

Also adds some facilities for direct formatting without going through a list.
2023-07-12 11:51:15 +02:00
Louis Gesbert
e0abb9aa24 Silence warning on duplicate plugin load
a debug is enough, it may happen on normal use
2023-07-11 18:57:05 +02:00
Louis Gesbert
db34c9a848 Generalise the expression printer
This patch functorises the generic expression printer, in order to be able to
re-use it for end-user printing.

It makes it possible to have an end-user, localised printer that shares the code
for e.g. priority and automatic parens handling.

A generic AST rewriting that disambiguates variables (very simple to write with
bindlib) is also added and used in the OCaml backend for something safer than
just appending `_user` (-- this also handles clashing variables that could be
introduced during compilation which would have generated wrong code before this)

Finally, the `explain` plugin is adapted to use the new printer.

Ah, and `String.format_t` was tweaked to correctly print strings that might
contain unicode without breaking alignment, and should be used instead of
`format_string` or `%s` whenever unicode can be expected.
2023-07-11 17:33:56 +02:00
Louis Gesbert
f9e3964621 Add an explain plugin
Based on the lazy_interp plugin, this new plugin generates a `dot` graph
retracing a given computation from source definitions to the results.
2023-07-11 17:33:56 +02:00
Louis Gesbert
71e3ca21c0 Remove generated files from git
and add proper pointers to the online artifacts
2023-07-10 15:48:11 +02:00
Louis Gesbert
3cb8fc1499 Tweak printing of if/then/else 2023-07-10 15:48:11 +02:00
Louis Gesbert
4ae949f7f8 Fix formatting of exception trees 2023-07-07 14:56:54 +02:00
Louis Gesbert
a3c0c366e6 Some code simplification
We now have all the functions to factorise this code
2023-07-04 18:31:52 +02:00
Louis Gesbert
fcb2d08983 Remove unconditional optimisation on exceptions compilation
This should be handled at a different level
2023-07-04 17:16:09 +02:00
Louis Gesbert
8920564f9e Fix some documentation comments formatting 2023-07-04 10:01:51 +02:00
Louis Gesbert
98f712365e Restore full expression printing when --debug is set 2023-07-03 17:30:17 +02:00
Louis Gesbert
89e90271c1 Implement an additional localised, user-facing value printer 2023-07-03 16:42:54 +02:00
Louis Gesbert
c799968934 Add a 'modules' plugin with helpers to compile modules
This will be done by Clerk at some point, but the plugin is useful for the time being.
2023-07-03 16:42:54 +02:00
Louis Gesbert
0f9ee2c72e Refacter the main Driver module
- Use separate functions for successive passes in module `Driver.Passes`
- Use other functions for end results printing in module `Driver.Commands`

As a consequence, it is much more flexible to use by plugins or libs and we no
longer need the complex polymorphic variant parameter.

This patch leverages previous changes to use Cmdliner subcommands and
effectively specialises the flags of each Catala subcommand.

Other changes include:

- an attempt to normalise the generic options and reduce the number of global
  references. Some are ok, like `debug` ; some would better be further cleaned up,
  e.g. the ones used by Proof backend were moved to a `Proof.globals` module and
  need discussion. The printer no longer relies on the global languages and prints
  money amounts in an agnostic way.
- the plugin directory is automatically guessed and loaded even in dev setups.
  Plugins are shown by the main `catala` command and listed in `catala --help`
- exception catching at the toplevel has been refactored a bit as well; return
  codes are normalised to follow the manpage and avoid codes >= 128 that are
  generally reserved for shells.

Update tests
2023-07-03 16:42:54 +02:00
Denis Merigoux
5f48e5dac1
Merge branch 'master' into closure_conversion 2023-06-20 11:02:13 +02:00
Denis Merigoux
9007eb4204
Apply suggestions by @altgr 2023-06-19 17:29:51 +02:00
Louis Gesbert
237dca2e75 Some commented code cleanup and clarifications 2023-06-19 16:36:09 +02:00
Denis Merigoux
420348beda Added a last TODO and put big example under CI 2023-06-18 21:38:00 +02:00
Denis Merigoux
b55d8c823b Closure conversion & hoisting working 2023-06-18 21:30:55 +02:00
Denis Merigoux
2ddbe93126 Bug identified 2023-06-18 18:15:29 +02:00
Denis Merigoux
a20adc0055 Closure hoisting (missing a bug on hardest case) 2023-06-18 18:08:18 +02:00
Denis Merigoux
2c45ca1599 More doc 2023-06-18 16:08:16 +02:00
Denis Merigoux
9cf55b0edd Closure env is unit if no extra variable captured 2023-06-18 15:49:02 +02:00
Louis Gesbert
52b1c25d50 Refactor CLI to use sub-commands
The upside of this is that each command can define specific flags ; there is a
small loss of backwards-compatibility in that the command needs to be the first
argument.

`catala --help` will now only show a summary of commands, with more specific
manpages shown on `catala CMD --help`.

Another point is that the plugin interface is extended to allow plugins to be
registered as subcommands and have their own flags (this will be very useful for
adding flags to the lazy/dot/explanation plugin that has many options).

Note that no efforts has yet been made to specialise the options, the previous
type was just made global for all subcommands.
2023-06-15 18:00:10 +02:00
Louis Gesbert
da59076223 Add a command-line option ('--use') for module linking 2023-06-15 17:58:46 +02:00
Louis Gesbert
ec97c386c3 Reformat + regen 2023-06-15 17:57:01 +02:00
Louis Gesbert
26c75af2ae Allow declaration of toplevel values without definition 2023-06-15 17:57:01 +02:00
Louis Gesbert
e224e87f71 Wip support for modules
(first working dynload test with compilation done by manual calls to ocaml)

A few pieces of the puzzle:

* Loading of interfaces only from Catala files
* Registration of toplevel values in modules compiled to OCaml, to allow access
  using dynlink
* Shady conversion from OCaml runtime values to/from Catala expressions, to
  allow interop (ffi) of compiled modules and the interpreter
2023-06-15 17:56:57 +02:00
Denis Merigoux
6962761774
Merge branch 'master' into closure_conversion 2023-06-15 17:56:41 +02:00
Louis Gesbert
2f2614c508 Use the AST mapper for scopelang-> dcalc 2023-06-15 17:55:52 +02:00
Louis Gesbert
2b7beeefb2 Rename 'IdentName' to 'Ident' 2023-06-15 17:55:49 +02:00
Denis Merigoux
3d3e735402
Nicer error message 2023-06-15 17:47:58 +02:00
Denis Merigoux
ed2891c761
Closure conversion should work now 2023-06-15 17:32:00 +02:00
Denis Merigoux
d850ac688a
Added operators for closure environment handling 2023-06-15 16:52:36 +02:00
Denis Merigoux
57abfbf2c7
Other pattern matching 2023-06-15 16:33:14 +02:00