Commit Graph

1269 Commits

Author SHA1 Message Date
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
Denis Merigoux
a3087ee163 Adding typing for closure env 2023-06-15 11:11:56 +02:00
Denis Merigoux
385e19b9e1 Formatting 2023-06-15 10:51:31 +02:00
Denis Merigoux
571c7c5d89
Correctly count number of var occurences 2023-06-14 11:39:27 +02:00
Denis Merigoux
42aaa1017d
Created minimal not working example and tame down beta-reduction 2023-06-14 11:18:39 +02:00
Denis Merigoux
2c9b56fb70
More agressive re-typing 2023-06-13 20:37:23 +02:00
Denis Merigoux
27bbe78438
Understanding a limitation 2023-06-13 20:10:42 +02:00
Aminata-Dev
10d147a8b1 Messages renamed to Message (lighter syntax) 2023-06-13 11:50:56 +02:00
Denis Merigoux
7072369b2d
Starting to work 2023-06-13 11:43:13 +02:00
Denis Merigoux
926c9436e3
Fix some bugs 2023-06-13 11:15:32 +02:00
Denis Merigoux
0e99d1598b
Continue closure conversion 2023-06-13 10:49:46 +02:00
Denis Merigoux
30eb3c0bdb
Better printing for types in typing error message 2023-06-13 09:55:48 +02:00