1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-24 00:35:43 +03:00
Commit Graph

1278 Commits

Author SHA1 Message Date
Jan Mas Rovira
13f64afbc1
upgrade to Ghc 9.8.1 (#2624)
This PR updates the stackage LTS resolver to `nightly-2024-02-06` which
uses GHC 9.8.1

## Upgrade notes

You will need to update your HLS to
[2.6.0.0](https://github.com/haskell/haskell-language-server/releases/tag/2.6.0.0),
this release contains support for GHC 9.8.1

## Fixes

### `haskeline` / `repline`

We have removed the custom haskeline / repline forks used in the build.
This is because we had trouble overriding haskeline as it is bundled
with GHC and the stackage resolver uses this bundled version. We were
using a custom fork of haskeline to implement
[mapInputT_](15c0685c91/app/Commands/Repl.hs (L409))
in the Juvix REPL, required to implement error handling. This requires
private API from the Haskeline library.

Instead of using a custom fork we use TemplateHaskell to obtain access
to the private API we need. See
[DarkArts.hs](15c0685c91/src/Juvix/Prelude/DarkArts.hs)
and
[HaskelineJB.hs](15c0685c91/app/HaskelineJH.hs).

To obtain access to the private API, we adapted a method from [a Tweag
blogpost](https://www.tweag.io/blog/2021-01-07-haskell-dark-arts-part-i/)
and [repo](https://github.com/tweag/th-jailbreak) - updating it for GHC
9.8.1.

### `aeson-better-errors`

The `aeson-better-errors` library has not been updated to work with
`mtl-2.3.0` so it cannot work with the new stackage resolver. We are
using a [fork](https://github.com/Vekhir/aeson-better-errors.git) which
has been updated.

We should consider replacing this library in future, see
https://github.com/anoma/juvix/issues/2621

###  `path`

The `path` library now includes API `splitDrive` and `dropDrive` so we
can remove our versions of those functions from the prelude.

### `with-utf8`

We no longer need to depend on `with-utf8`. We were using this package
for UTF-8 versions of `readFile` and `writeFile` APIs. These APIs are
now available in the `text` package.

### Compiler warnings

GHC 9.8.1 introduces several new compiler warnings. 

* We have suppressed `missing-role-annotations` and
`missing-poly-kind-signatures`
* We added our own versions of `head` and `tail` to work around the new
`partial-tx` warning introduced for those functions in `Data.List`.
* We fixed up the code to avoid the
[term-variable-capture](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/using-warnings.html#ghc-flag--Wterm-variable-capture)
warning.
2024-02-07 09:47:48 +00:00
Łukasz Czajka
795212b092
JuvixTree validation (#2616)
* Validation (type checking) of JuvixTree. Similar to JuvixAsm
validation, will help with debugging.
* Depends on #2608
2024-02-06 15:46:55 +01:00
Jan Mas Rovira
10e2a23239
Translation from Juvix Tree to Nockma (#2614)
This PR replaces the JuvixAsm -> Nockma translation with a JuvixTree ->
Nockma translation.

We can now enable some of the JuvixTree tests that did not work with
JuvixAsm->Nockma because they were too slow.


## Notes

We have changed [test031: temp stack with
branching](22ee87f0e7/tests/Tree/positive/test031.jvt)
to avoid using negative numbers (because negative integers are not
supported in Nockma).

Three tree tests trace/output lists. Lists are serialised differently by
the asm and nockma pretty printers so they cannot share a single test
output file. We have created separate nockma output files for these
tests (see eg.
[test028.nockma.out](22ee87f0e7/tests/Tree/positive/out/test028.nockma.out)).

* Closes https://github.com/anoma/juvix/issues/2606

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2024-02-06 08:33:14 +00:00
Olivier Benz
5a878827f2
Use images from Quay (#2620)
I now mirror the *GHC musl* images to both Docker Hub and Quay:

* https://hub.docker.com/r/benz0li/ghc-musl
* https://quay.io/repository/benz0li/ghc-musl

Docker Hub imposes a rate limit. Quay, on the other hand, does not.

This also ensures the long-term availability of these images.
2024-02-05 11:42:07 +00:00
Jan Mas Rovira
3005772f09
Replace egrep with grep -E (#2618)
Quoting the [release notes of gnu
`grep-3.8`](https://lists.gnu.org/archive/html/info-gnu/2022-09/msg00001.html)

>   The egrep and fgrep commands, which have been deprecated since
  release 2.5.3 (2007), now warn that they are obsolescent and should
  be replaced by grep -E and grep -F.

In order to fix the warning, I've replaced all instances of `egrep` with
`grep -E`
2024-02-05 10:27:46 +01:00
Paul Cadman
262966d745
Add a justfile to perform project install, test, clean, format tasks (#2615)
This PR adds a https://github.com/casey/just

```
$ just
Available recipes:
    build *opts  # Build the project. `build runtime` builds only the runtime.
    clean *opts  # Clean the project. `clean runtime` cleans only the runtime. `clean juvix-build` cleans only juvix-build dirs.
    format *opts # Formats all Haskell files in the project. `format changed` formats only changed files. `format FILES` formats individual files.
    install      # Install juvix
    test *filter # Run the tests in the project. Use the filter arg to set a Tasty pattern.
```

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2024-02-02 12:48:14 +01:00
Łukasz Czajka
9322e5d21f
JuvixTree REPL (#2608)
* JuvixTree REPL
* Depends on #2601
2024-02-01 17:50:09 +00:00
Łukasz Czajka
7b0a11d570
JuvixTree negative evaluation tests (#2601)
* Adds negative tests for the JuvixTree evaluator
* Depends on #2600 
* Depends on #2599 
* Depends on #2598 
* Depends on #2597 
* Depends on #2596 
* Depends on #2595 
* Depends on #2594 
* Depends on #2590
2024-02-01 12:58:38 +00:00
Łukasz Czajka
b433eb48cb
Location info in JuvixTree nodes (#2600) 2024-01-31 22:11:44 +00:00
Łukasz Czajka
8956e51b33
Options for juvix dev tree read (#2599)
* Adds the `--transforms`, `--eval` and `--no-print` options to the
`juvix dev tree read` command.
* Depends on #2598 
* Depends on #2597 
* Depends on #2596 
* Depends on #2595 
* Depends on #2594 
* Depends on #2590
2024-01-31 15:17:14 +01:00
Paul Cadman
ab887e3138
Store syntax aliases in serialized scoper infotable (#2605)
This PR fixes an issue with importing `syntax alias` and using them from
another module:

Say you have a module defining a syntax alias:

```
module SyntaxAlias;

import Stdlib.Prelude open;

syntax alias MyNat := Nat;
```

and another which imports / uses it:

```
module test073;

import SyntaxAlias open;

main : MyNat := 11;
```

The compiler crashed with the following error:

```
^?!): empty Fold
            CallStack (from HasCallStack):
              error, called at src/Lens/Micro.hs:711:28 in microlens-0.4.13.1-ARwI8t2x86cAxRs56XPcG1:Lens.Micro
              ^?!, called at src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs:565:29 in juvix-0.5.5-G7jC6MbkbsJGkMT9u4BkYQ:Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping
```

We fix this by adding the aliases to the store's [scoper info
table](6649209d26/src/Juvix/Compiler/Store/Scoped/Data/InfoTable.hs (L14))
and then use it to initialise the scoper state when scoping a module.
2024-01-31 11:56:09 +00:00
Jan Mas Rovira
84b0e5605f
Use writeFileEnsureLn in place of writeFile (#2604)
Now we guarantee that whenever we write a file there is a newline
character at the end, which is a [Unix
convention](https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_205).

The juvix prelude now exports `writeFileEnsureLn` and it no longer
exports `writeFile`. If at some point we need the behaviour of
`writeFile` I'd suggest that we export it renamed as `writeFileVerbatim`
or something similar.
2024-01-31 11:15:17 +01:00
Łukasz Czajka
dc54bbb2c2
JuvixTree smoke tests (#2598)
* Adds smoke tests for `juvix dev tree` CLI commands.
* Fixes a bug with printing JuvixAsm.
* Depends on #2597 
* Depends on #2596 
* Depends on #2595 
* Depends on #2594 
* Depends on #2590
2024-01-31 08:33:52 +00:00
Łukasz Czajka
15c223d0f1
Filter out unreachable functions in JuvixTree (#2597)
* Adds the `FilterUnreachable` transformation in JuvixTree.
* Depends on #2596 
* Depends on #2595 
* Depends on #2594 
* Depends on #2590 
* Depends on #2589 
* Depends on #2587
2024-01-30 20:01:07 +00:00
Łukasz Czajka
4651d1eafe
Compute temporary stack height in JuvixTree (#2596) 2024-01-30 18:34:36 +00:00
Łukasz Czajka
1153f6b338
JuvixTree "apply" transformation (#2595)
* Moves the "apply" transformation from JuivxAsm to JuvixTree. This
transformation removes the `CallClosures` nodes.
* Makes Nockma compilation tests use JuvixTree instead of JuvixAsm
files.
* Depends on #2594 
* Depends on #2590
* Depends on #2589 
* Depends on #2587
2024-01-30 15:46:10 +00:00
Jan Mas Rovira
4c5050ccae
Remove redundant QuasiQuotes pragmas (#2603)
We already have `QuasiQuotes` in the default extensions list.
2024-01-30 10:08:07 +01:00
Łukasz Czajka
a5bfba6c1c
JuvixTree recursors and transformation framework (#2594)
* Generalizes JuvixCore map and fold recursors to work also for
JuvixTree.
* Adds a transformation framework to JuvixTree.
* Adds identity trasformation tests for JuvixTree.
* Depends on #2590 
* Depends on #2589 
* Depends on #2587
2024-01-29 16:43:08 +00:00
Jan Mas Rovira
21a5568985
Add dev nockma format command (#2593)
Useful for formatting nockma code. 
Usage:
```
juvix dev nockma format input.nockma
```
The formatted code is printed to stdout.
2024-01-29 13:36:53 +01:00
Łukasz Czajka
6649209d26
Add the juvix dev tree compile command (#2590)
* Adds the `juvix dev tree compile` CLI command.
* Depends on #2589 
* Depends on #2587 
* Depends on #2583
2024-01-27 08:54:57 +01:00
Paul Cadman
df9b17d74f
Fix generation and evaluation of Nock isCell op (#2602)
This PR fixes the generation and evaluation of the Nock isCell op.

As we can see from its
[definition](https://developers.urbit.org/reference/nock/definition),
the isCell op (Nock 3) evaluates its argument:

```
*[a 3 b]            ?*[a b]
```

Previously we were not evaluating the argument before checking if it is
an atom/cell.

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2024-01-26 19:37:47 +00:00
Łukasz Czajka
0073d04f89
JuvixTree evaluator (#2589)
* Implements JuvixTree evaluator
* Adds JuvixTree evaluation tests
* Adds the `juvix dev tree eval` command
* Depends on #2587 
* Depends on #2583
2024-01-25 19:11:45 +00:00
Łukasz Czajka
c95fcb38c8
JuvixTree tests (#2587)
* Implements a translation from JuvixAsm to JuvixTree. It does not work
in general, but works for all code generated from Juvix and all JuvixAsm
tests.
* Adds the `juvix dev tree from-asm` command.
* Adds tests automatically converted from JuvixAsm tests.
* Depends on #2583
2024-01-25 18:02:06 +00:00
Paul Cadman
06d459695d
Use Anoma compatible Nockma serialization of Bools and List-like data structures (#2591)
This PR changes the Nockma representation of builtin Bool and list-like
types to make them compatible with Anoma.

True and False are now compiled to the Nockma atoms 0 and 1
respectively.

For inductive types that have exactly two constructors, one of arity
zero and one of arity two, we compile the arity zero constructor to
Nockma zero, and the arity two constructor to a Nockma cell. In
particular a Juvix stdlib List will be compiled to an Anoma/Nockma list.
This is necessary for compatibility with the layout of resource and
resource logic types in Anoma.

In tests we avoid using the StackRef memory reference because it will be
removed as part of the JuvixTree work.

---------

Co-authored-by: Łukasz Czajka <62751+lukaszcz@users.noreply.github.com>
2024-01-24 15:16:04 +00:00
Łukasz Czajka
e5ea085f1c
JuvixTree parser and pretty printer (#2583)
This PR implements:
* JuvixTree parser.
* JuvixTree pretty printer.
* `juvix dev tree read file.jvt` command which reads and pretty prints a
JuvixTree file.
* The `tree` target in the `compile` command.
* Removal of `StackRef` in JuvixAsm. This makes JuvixAsm more consistent
with JuvixTree and simplifies the data structures. `StackRef` is not
needed for compilation from Core.

Tests for the parser will appear in a separate PR, when I implement an
automatic translation of JuvixAsm to JuvixTree files.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2024-01-24 12:45:39 +01:00
Jan Mas Rovira
510490a5bf
Support MemRepTuple in the Nockma backend (#2586)
We can represent Anoma types like
[resource](e18e50e3c3/hoon/resource-machine.hoon (L7))
as Juvix records.

The Nockma encoding of types uses Nockma 'tuples' where each component
of the tuple holds a value of a field. So for Juvix->Anoma integration
it is convenient to compile values of record types as Nockma tuples.

We already have the concept of representing constructors of inductive
types that have only one non-zero-field constructor in the compiler, see
[`MemRepTuple`](1147e1fce1/src/Juvix/Compiler/Tree/Language/Rep.hs (L13)).

In this PR, as part of the Nockma step, we mark constructors that
satisfy the requirements of the `MemRepTuple` translation as such. Then
we use a tuple encoding for those constructors.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2024-01-23 14:36:19 +01:00
Jan Mas Rovira
8005089dc5
Improved errors for nockma eval (#2585)
This is needed if we want to debug nockma in a more sane manner.

Evaluation errors now include an evaluation trace (with source locations
when present). It looks like this:

![image](https://github.com/anoma/juvix/assets/5511599/4a553035-f56e-4f7c-bb69-9a2aeb41afcb)
2024-01-23 09:37:06 +00:00
Jan Mas Rovira
1147e1fce1
Unqualify language import in nockma parser (#2584) 2024-01-22 09:20:38 +00:00
Jan Mas Rovira
39d176e643
Fast nockma eval (#2580)
Adds annotations to cells to indicate that it is a call to the stdlib
and might be evaluated faster in the Haskell evaluator.

The syntax for stdlib calls is as follows:
```
[stdlib@add args@<args-term> <left-term> <right-term>]
```
where `add` is the name of the function being called, `<args-term>` is a
nockma term that points to the position of the arguments, and
`<left-term>` and `<right-term>` are the actual components of the cell.
2024-01-19 12:01:58 +01:00
Łukasz Czajka
91ba586336
Factor the JuvixCore -> JuvixAsm translation into JuvixCore -> JuvixTree -> JuvixAsm (#2581)
This PR:
* introduces the JuvixTree language which is like JuvixAsm except that
instead of the value stack there is an applicative structure,
* refactors the JuvixCore -> JuvixAsm translation into JuvixCore ->
JuvixTree -> JuvixAsm.

JuvixAsm is a bit too low level for efficient compilation to Nock.
Translating the value stack explicitly is a bad idea and it's
unnecessary, because the value stack just represents an applicative
structure which can be represented directly in Nock. It's possible, but
cumbersome and unnecessary, to recover the applicative structure from
JuvixAsm code. It's better to have a bit more high-level JuvixTree
language which still retains the explicit applicative structure.
2024-01-18 15:36:44 +01:00
Łukasz Czajka
3aaa8229cc
Merge stack and temporary variable groups in JuvixReg (#2579)
After this change there are only two types of variables in JuvixReg:
arguments and local variables. The previous distinction between stack
and temporary variables was spurious and complicated things
unnecessarily.
2024-01-17 19:11:40 +01:00
Jan Mas Rovira
73364f4887
Nockma compile (#2570)
This PR is a snapshot of the current work on the JuvixAsm -> Nockma
translation. The compilation of Juvix programs to Nockma now works so we
decided to raise this PR now to avoid it getting too large.

## Juvix -> Nockma compilation

You can compile a frontend Juvix file to Nockma as follows:

example.juvix
```
module example;

import Stdlib.Prelude open;

fib : Nat → Nat → Nat → Nat
  | zero x1 _ := x1
  | (suc n) x1 x2 := fib n x2 (x1 + x2);

fibonacci (n : Nat) : Nat := fib n 0 1;

sumList (xs : List Nat) : Nat :=
  for (acc := 0) (x in xs)
    acc + x;

main : Nat := fibonacci 9 + sumList [1; 2; 3; 4];
```

```
$ juvix compile -t nockma example.juvix
```

This will generate a file `example.nockma` which can be run using the
nockma evaluator:

```
$ juvix dev nockma eval example.nockma
```

Alternatively you can compile JuvixAsm to Nockma:

```
$ juvix dev asm compile -t nockma example.jva
```

## Tests

We compile an evaluate the JuvixAsm tests in
cb3659e08e/test/Nockma/Compile/Asm/Positive.hs

We currently skip some because either:
1. They are too slow to run in the current evaluator (due to arithmetic
operations using the unjetted nock code from the anoma nock stdlib).
2. They trace data types like lists and booleans which are represented
differently by the asm interpreter and the nock interpreter
3. They operate on raw negative numbers, nock only supports raw natural
numbers

## Next steps

On top of this PR we will work on improving the evaluator so that we can
enable the slow compilation tests.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2024-01-17 11:15:38 +01:00
Paul Cadman
517897930f
Nockma compile refactor (#2582)
This PR contains refactors split out from the Nockma compile PR
https://github.com/anoma/juvix/pull/2570. Each refactor is associated
with a separate commit in this PR.
2024-01-16 16:22:10 +00:00
Łukasz Czajka
fa2a731833
Cairo ASM language and interpreter (#2572)
* Closes #2561 
* Defines an extended subset of Cairo Assembly, following Section 5 of
[1].
* Adds the commands `juvix dev casm read file.casm` and `juvix dev casm
run file.casm` to print and run `*.casm` files.
* The tests cover CASM semantics. Some are "manual translations" of
corresponding JuvixAsm tests according to the JuvixAsm -> CASM
compilation concept.
2024-01-12 11:57:02 +00:00
Łukasz Czajka
3269c8f369
Filter out unreachable functions in JuvixAsm (#2575)
Adds a JuvixAsm transformation to filter out unreachable functions. This
will make the generated nock/cairo code smaller.
2024-01-12 10:48:32 +01:00
Paul Cadman
a9995b8e1c
Add nockma evaluator (#2564)
This PR adds an parser, pretty printer, evaluator, repl and quasi-quoter
for Nock terms.

## Parser / Pretty Printer

The parser and pretty printer handle both standard Nock terms and
'pretty' Nock terms (where op codes and paths can be named). Standard
and pretty Nock forms can be mixed in the same term.

For example instead of `[0 2]` you can write `[@ L]`.

See
a6028b0d92/src/Juvix/Compiler/Nockma/Language.hs (L79)
for the correspondence between pretty Nock and Nock operators.

In pretty Nock, paths are represented as strings of `L` (for head) and
`R` (for tail) instead of the number encoding in standard nock. The
character `S` is used to refer to the whole subject, i.e it is sugar for
`1` in standard Nock.

See
a6028b0d92/src/Juvix/Compiler/Nockma/Language.hs (L177)
for the correspondence between pretty Nock path and standard Nock
position.

## Quasi-quoter

A quasi-quoter is added so Nock terms can be included in the source, e.g
`[nock| [@ LL] |]`.

## REPL

Launch the repl with `juvix dev nockma repl`.

A Nock `[subject formula]` cell is input as `subject / formula` , e.g:

```
nockma>  [1 0] / [@ L]
1
```

The subject can be set using `:set-stack`.

```
nockma> :set-stack [1 0]
nockma> [@ L]
1
```

The subject can be viewed using `:get-stack`.

```
nockma> :set-stack [1 0]
nockma> :get-stack
[1 0]
```

You can assign a Nock term to a variable and use it in another
expression:

```
nockma> r := [@ L]
nockma> [1 0] / r
1
```

A list of assignments can be read from a file:

```
$ cat stack.nock
r := [@ L]
$ juvix dev nockma repl
nockma> :load stack.nock
nockma> [1 0] / r
1
```

* Closes https://github.com/anoma/juvix/issues/2557

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2024-01-11 12:04:38 +00:00
Łukasz Czajka
8e5f45f16f
Require semicolon to separate case/if branches in JuvixAsm syntax (#2574)
This makes the syntax more uniform. It was especially confusing with
nested branching, where some closing braces had to and others couldn't
be followed by a semicolon. Now all have to be followed by a semicolon
(except function ending braces).
2024-01-11 09:19:36 +00:00
Dimitris Apostolou
d6d21a22e3
Fix typos (#2573) 2024-01-08 13:27:18 +01:00
Łukasz Czajka
75bce8f665
Per-module compilation (#2468)
* Closes #2392 

Changes checklist
-----------------
* [X] Abstract out data types for stored module representation
(`ModuleInfo` in `Juvix.Compiler.Store.Language`)
* [X] Adapt the parser to operate per-module
* [X] Adapt the scoper to operate per-module
* [X] Adapt the arity checker to operate per-module
* [X] Adapt the type checker to operate per-module
* [x] Adapt Core transformations to operate per-module
* [X] Adapt the pipeline functions in `Juvix.Compiler.Pipeline`
* [X] Add `Juvix.Compiler.Pipeline.Driver` which drives the per-module
compilation process
* [x] Implement module saving / loading in `Pipeline.Driver`
* [x] Detect cyclic module dependencies in `Pipeline.Driver`
* [x] Cache visited modules in memory in `Pipeline.Driver` to avoid
excessive disk operations and repeated hash re-computations
* [x] Recompile a module if one of its dependencies needs recompilation
and contains functions that are always inlined.
* [x] Fix identifier dependencies for mutual block creation in
`Internal.fromConcrete`
- Fixed by making textually later definitions depend on earlier ones.
- Now instances are used for resolution only after the textual point of
their definition.
- Similarly, type synonyms will be unfolded only after the textual point
of their definition.
* [x] Fix CLI
* [x] Fix REPL
* [x] Fix highlighting
* [x] Fix HTML generation
* [x] Adapt test suite
2023-12-30 20:15:35 +01:00
Łukasz Czajka
758d1cd949
Implement the dynamic dispatch loop in JuvixAsm (#2556)
* Closes #2555 
* Depends on #2554
2023-12-15 19:08:40 +01:00
Łukasz Czajka
76548e464a
Structured temporary stack manipulation in JuvixAsm (#2554)
* Replaces the `pusht` and `popt` instructions with block-based `save`
and `tsave`. This encodes the structure of temporary stack manipulation
syntactically, making it impossible to manipulate it in unexpected ways.
Also simplifies compilation to Nock.
* Adds optional names for temporaries and function arguments.
2023-12-15 12:55:53 +00:00
Paul Cadman
170a4d39c0
Fix benchmarks test compilation (#2552)
The benchmarks build has been broken for some time because one of the
juvix programs was not compiling.
2023-12-10 12:13:56 +01:00
Jan Mas Rovira
d3e862fc51
Improve formatting of function definition arguments (#2551)
- Closes #2534
2023-12-07 11:26:48 +01:00
Jan Mas Rovira
4fa17359a6
Implement wildcard constructor (#2550)
- Closes #2549 

The implementation of wildcard constructors was previously done in the
arity checker. I did not realise I was missing it because there was not
tests for it that included typechecking (we were only checking
formatting).
2023-12-07 10:12:36 +01:00
Jan Mas Rovira
69594edc7b
Read Package on demand and cache it (#2548)
This patch dramatically increases the efficiency of `juvix dev root`,
which was unnecessarily parsing all dependencies included in the
`Package.juvix` file. Other commands that do not require the `Package`
will also be faster.

It also refactors some functions so that the `TaggedLock` effect is run
globally.

I've added `singletons-base` as a dependency so we can have `++` on the
type level. We've tried to define a type family ourselves but inference
was not working properly.
2023-12-06 18:24:59 +01:00
Jonathan Cubides
9f8c26dbb2
Bump up version to v0.5.5 (#2547)
This PR updates:

- [x] Package version
- [x] Smoke test
- [x] Changelog

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-12-01 20:48:35 +01:00
Jonathan Cubides
b8a016fc57
Add Makefile to hyperfine benchmarks (#2533)
This PR adds a target for our Makefile to run benchmarks using
hyperfine.
We run different commands which can be easily modified in
bench/hyperfine/Makefile.

```
make hyperfine-benchmarks
```

After running this on your terminal, checkout the generated file
bench/hyperfine/README.md for the results.

The results below are the runs using the following module.

```
module fibo;

import Stdlib.Prelude open;

fib : Nat → Nat → Nat → Nat
  | zero x1 _ := x1
  | (suc n) x1 x2 := fib n x2 (x1 + x2);

fibonacci (n : Nat) : Nat := fib n 0 1;

main : IO := printNatLn (fibonacci 50);
```

(For now, I got the following on my machine (ran in about 5min or less)
Darwin Jonathans-MacBook-Pro-2.local 22.6.0 Darwin Kernel Version
22.6.0: Fri Sep 15 13:41:28 PDT 2023;
root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6020 arm64 arm)

- The binary without the version below is the latest commit on main.

# Hyperfine Benchmarks

## dev parse

| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `juvix-v0.4.3 dev parse fibo.juvix` | 184.3 ± 5.4 | 178.5 | 193.2 |
1.06 ± 0.04 |
| `juvix-v0.5.0 dev parse fibo.juvix` | 184.7 ± 6.9 | 179.2 | 201.3 |
1.06 ± 0.05 |
| `juvix-v0.5.1 dev parse fibo.juvix` | 174.2 ± 5.4 | 167.9 | 181.0 |
1.00 |
| `juvix-v0.5.2 dev parse fibo.juvix` | 181.3 ± 1.6 | 179.5 | 184.1 |
1.04 ± 0.03 |
| `juvix-v0.5.3 dev parse fibo.juvix` | 1185.8 ± 5.7 | 1178.4 | 1197.3 |
6.81 ± 0.21 |
| `juvix-v0.5.4 dev parse fibo.juvix` | 1308.4 ± 6.9 | 1297.6 | 1319.3 |
7.51 ± 0.23 |
| `juvix dev parse fibo.juvix` | 1311.0 ± 5.5 | 1303.2 | 1318.5 | 7.53 ±
0.23 |

## dev highlight

| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `juvix-v0.4.3 dev highlight fibo.juvix` | 770.2 ± 67.5 | 742.9 | 961.6
| 1.01 ± 0.09 |
| `juvix-v0.5.0 dev highlight fibo.juvix` | 762.7 ± 11.8 | 749.9 | 787.2
| 1.00 |
| `juvix-v0.5.1 dev highlight fibo.juvix` | 849.3 ± 9.3 | 836.5 | 863.9
| 1.11 ± 0.02 |
| `juvix-v0.5.2 dev highlight fibo.juvix` | 873.5 ± 21.1 | 855.2 | 918.9
| 1.15 ± 0.03 |
| `juvix-v0.5.3 dev highlight fibo.juvix` | 2035.9 ± 69.5 | 1946.9 |
2125.4 | 2.67 ± 0.10 |
| `juvix-v0.5.4 dev highlight fibo.juvix` | 2218.0 ± 57.3 | 2169.5 |
2316.4 | 2.91 ± 0.09 |
| `juvix dev highlight fibo.juvix` | 2206.5 ± 55.9 | 2150.4 | 2296.6 |
2.89 ± 0.09 |

## typecheck

| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `juvix-v0.4.3 typecheck fibo.juvix` | 684.1 ± 5.1 | 674.1 | 691.0 |
1.00 |
| `juvix-v0.5.0 typecheck fibo.juvix` | 695.9 ± 14.2 | 679.0 | 720.6 |
1.02 ± 0.02 |
| `juvix-v0.5.1 typecheck fibo.juvix` | 808.5 ± 18.2 | 780.8 | 848.6 |
1.18 ± 0.03 |
| `juvix-v0.5.2 typecheck fibo.juvix` | 816.0 ± 13.9 | 802.3 | 846.3 |
1.19 ± 0.02 |
| `juvix-v0.5.3 typecheck fibo.juvix` | 1934.3 ± 29.0 | 1907.3 | 1992.1
| 2.83 ± 0.05 |
| `juvix-v0.5.4 typecheck fibo.juvix` | 2106.8 ± 19.6 | 2075.6 | 2138.9
| 3.08 ± 0.04 |
| `juvix typecheck fibo.juvix` | 2135.3 ± 29.9 | 2107.4 | 2183.2 | 3.12
± 0.05 |

## compile -o /dev/null

| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `juvix-v0.4.3 compile -o /dev/null fibo.juvix` | 754.3 ± 4.9 | 745.2 |
759.8 | 1.00 ± 0.01 |
| `juvix-v0.5.0 compile -o /dev/null fibo.juvix` | 752.6 ± 3.9 | 745.2 |
757.6 | 1.00 |
| `juvix-v0.5.1 compile -o /dev/null fibo.juvix` | 845.4 ± 5.7 | 837.6 |
857.0 | 1.12 ± 0.01 |
| `juvix-v0.5.2 compile -o /dev/null fibo.juvix` | 883.7 ± 15.7 | 864.5
| 918.3 | 1.17 ± 0.02 |
| `juvix-v0.5.3 compile -o /dev/null fibo.juvix` | 1990.8 ± 12.5 |
1975.0 | 2010.4 | 2.65 ± 0.02 |
| `juvix-v0.5.4 compile -o /dev/null fibo.juvix` | 2193.9 ± 5.6 | 2182.7
| 2200.5 | 2.91 ± 0.02 |
| `juvix compile -o /dev/null fibo.juvix` | 2197.4 ± 11.6 | 2185.0 |
2226.0 | 2.92 ± 0.02 |

## eval

| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `juvix-v0.4.3 eval fibo.juvix` | 680.9 ± 5.4 | 669.7 | 687.1 | 1.00 |
| `juvix-v0.5.0 eval fibo.juvix` | 681.7 ± 5.0 | 675.0 | 689.8 | 1.00 ±
0.01 |
| `juvix-v0.5.1 eval fibo.juvix` | 772.7 ± 2.7 | 769.0 | 777.9 | 1.13 ±
0.01 |
| `juvix-v0.5.2 eval fibo.juvix` | 796.1 ± 2.7 | 791.9 | 799.5 | 1.17 ±
0.01 |
| `juvix-v0.5.3 eval fibo.juvix` | 1902.2 ± 6.5 | 1889.6 | 1913.2 | 2.79
± 0.02 |
| `juvix-v0.5.4 eval fibo.juvix` | 2101.3 ± 5.9 | 2093.1 | 2112.1 | 3.09
± 0.03 |
| `juvix eval fibo.juvix` | 2111.1 ± 17.4 | 2085.5 | 2148.3 | 3.10 ±
0.04 |

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-12-01 18:39:39 +01:00
Jan Mas Rovira
c8e7ce8afd
Remove old typechecker (#2545) 2023-12-01 16:50:37 +01:00
Paul Cadman
77b29c6963
Update to the latest juvix-stdlib (#2546)
This PR updates the juvix-stdlib submodule ref to the current
juvix-stdlib/main.

NB: The Markdown test is not stable after changes to the stdlib - the
ids (deriving from internal name ids?) will change and so the expected
file must be regenerated.
2023-12-01 15:12:54 +01:00
Jan Mas Rovira
c237f292a7
Add dependent defaults for the new typechecker (#2541)
This pr adds support for default values that depend on previous
arguments. For instance, see
[test071](ca7d0fa06d/tests/Compilation/positive/test071.juvix).
- After #2540 is implemented, we'll be able to remove the old type
checker (including the aritychecker).
2023-11-30 19:17:00 +01:00