1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-02 10:47:32 +03:00
Commit Graph

1602 Commits

Author SHA1 Message Date
Jan Mas Rovira
fe07c053d2
Improve css themes (#2921)
This pr:
- Removes the light `ayu` theme.
- Adds the light `latte` theme (this now becomes the default theme).
- Adds the dark `frappe` theme.
- Adds the dark `moccha` theme.
- Refactor all source themes to use css variables instead of inlined
color definitions. This makes it much easier to maintain.
2024-08-01 18:32:03 +02:00
Paul Cadman
d859a033c0
Add FromNatural trait in package-base (#2926)
This PR adds `FromNatural` to package-base. The change is backwards
compatible for existing Juvix code so we don't need to make a new
version of package-base. The new trait is unused, it will be integrated
in subsequent PRs.

### `FromNatural` trait

The `FromNatural` trait has the following definition.

```
trait
type FromNatural A :=
  mkFromNatural {
    builtin from-nat
    fromNat : Nat -> A
};
```

### `Natural` trait changes

The `Natural` trait is changed to remove its `fromNat` field and add a
new instance field for `FromNatural A`.

### juvix-stdlib changes

`FromNatural` instances are added for `Int` and `Field` in the standard
library.

## Rationale

The `FromNatural` trait will be used for the Bytes type.

We want the following properties for Byte:

1. Values of the Bytes type should be assignable from a non-negative
numeric literal.
2. We don't want to implement + and * for Bytes.

Currently, in order for a type to have property 1. it must have an
instance of `Natural` so property 2. can't be satisfied.

To solve this we split the `from-nat` builtin from the `Natural` trait
into a new trait `FromNatural`.
2024-08-01 08:26:52 +01:00
Jan Mas Rovira
0e27e9a49e
Fix html rendering of fixities (#2930)
Before:

![image](https://github.com/user-attachments/assets/656b3458-e994-4357-9ed2-cd3152cdb3be)

After:

![image](https://github.com/user-attachments/assets/5f65e81d-815a-45a1-8ea1-8f5f5fd82366)
2024-07-31 19:08:47 +02:00
Paul Cadman
0edbcfdaa0
Update juvix-stdlib to include Foldable and Functor traits (#2932)
This updates the juvix-stdlib to contain:

* https://github.com/anoma/juvix-stdlib/pull/111
* https://github.com/anoma/juvix-stdlib/pull/114

Much work needs to be done in the test suite to integrate these changes.
2024-07-31 15:13:27 +02:00
Jan Mas Rovira
3a9eb20f4a
Fix scanning of names with import prefix (#2929)
1. When the flatparse scanner fails and we fallback to megaparsec, a
warning is issued.
2. The flatparse scanner has been fixed so it is not confused when a
name starts with `import`.
2024-07-31 10:02:38 +02:00
Jonathan Cubides
2416f78a3e
Fix #2924. Use MegaParsec scanner for Markdown files (#2925)
This PR addresses a bug/missing case present since v0.6.2, introduced
specifically by

- PR #2779, 

That PR involves detecting imports in Juvix files before type checking,
and that's the issue.
Detecting/scanning imports is done by running a flat parser (which
ignores the Juvix Markdown structure) and when it fails, it runs a
Megaparser parse. So, for simplicity,
we could just continue using the same Megaparser as before for Juvix
Markdown files.

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2024-07-30 23:51:55 +02:00
Jan Mas Rovira
2524606757
Do not show progress log for juvix html (#2920)
We already print the html files that we write to disk, there is not need
to also show the progress log.
2024-07-30 18:57:58 +02:00
Jan Mas Rovira
178bc5324f
Fix name signature bug and extend test for instance fields (#2928)
- Closes #2923 

This pr fixes a bug where all fields were assigned to be explicit
arguments in the NameSignature Builder. A single line change was enough
to fix it.
```diff
-           RecordStatementField RecordField {..} -> addSymbol @s Explicit Nothing _fieldName _fieldType
+           RecordStatementField RecordField {..} -> addSymbol @s (fromIsImplicitField _fieldIsImplicit) Nothing _fieldName _fieldType
```

I've also added a compilation test for instance fields.
2024-07-30 17:56:42 +02:00
Jan Mas Rovira
1e9850c8f5
Allow instance field declarations (#2916)
- Closes #2897

---------

Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2024-07-29 18:44:16 +02:00
Jan Mas Rovira
a5479d0718
Properly handle confluent imports (#2915)
- Fixes #2914
2024-07-23 19:56:30 +02:00
Jan Mas Rovira
11425aa8e5
Allow record fields to be iterators (#2909)
- Closes #2904
2024-07-22 18:16:06 +02:00
Jan Mas Rovira
138d9e545d
Logger (#2908)
1. Adds the `--log-level LOG_LEVEL` flag to the CLI. This flag can be
given `error`, `warn`, `info`, `progress`, `debug` as argument to filter
the logged messages.
2. Removes the `--only-errors` flag.
3. Adds the `--ide-end-error-char CHAR`, which receives a character as
an argument, which is appended to the end of error messages. This is
handy to facilitate parsing of errors messages from the ide. This
functionality was previously embeded in the old `--only-errors` flag.
2024-07-22 17:14:37 +02:00
Paul Cadman
42a0b4a852
Release 0.6.4 (#2910)
This PR updates:

- [x] Package version
- [x] Smoke test
- [x] Changelog
2024-07-19 11:54:06 +01:00
Paul Cadman
32f7bd2500
Update juvix-stdlib to point to main ref of the juvix-stdlib repo (#2911)
This PR updates the juvix-stdlib submodule to the main ref of the
juvix-stdlib repo.
2024-07-19 10:58:54 +01:00
Jan Mas Rovira
3609b213f6
Use ormolu from stackage in the CI (#2900)
1. Adds the command `just format check`, which checks that all Haskell
files are formatted.
2. In CI, we use install ormolu from stackage and run it. This will
facilitate consistency between CI and local setups.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2024-07-19 09:38:39 +01:00
Łukasz Czajka
83837b9c5f
Translate function bodies to Isabelle/HOL (#2868)
* Closes #2813 

Implements a translation from Juvix functions to Isabelle/HOL functions.
This extends the previous Juvix -> Isabelle translation which could
handle only type signatures.

Checklist
---------

- [x] Basic translation
- [x] Polymorphism
- [x] Arithmetic operators
- [x] Numeric literals
- [x] List literals
- [x] Comparison operators
- [x] Boolean operators
- [x] `if` translated to Isabelle `if`
- [x] `true` and `false` translated to Isabelle `True` and `False`
- [x] `zero` and `suc` translated to Isabelle `0` and `Suc`
- [x] `Maybe` translated to Isabelle `option`
- [x] Pairs translated to Isabelle tuples
- [x] Quote Isabelle identifier names (e.g. cannot begin with `_`)
- [x] Rename variables to avoid clashes (in Isabelle/HOL pattern
variables don't shadow function identifiers)
- [x] Common stdlib functions (`map`, `filter`, etc) translated to
corresponding Isabelle functions
- [x] Multiple assignments in a single `let`
- [x] CLI
- [x] Test
- The test is very fragile, similar to the markdown test. It just
compares the result of translation to Isabelle against a predefined
expected output file.

Limitations
-----------

The translation is not designed to be completely correct under all
circumstances. There are aspects of the Juvix language that cannot be
straightforwardly translated to Isabelle/HOL, and these are not planned
to ever be properly handled. There are other aspects that are difficult
but not impossible to translate, and these are left for future work.
Occasionally, the generated code may need manual adjustments to
type-check in Isabelle/HOL.

In particular:
* Higher-rank polymorphism or functions on types cannot be translated as
these features are not supported by Isabelle/HOL. Juvix programs using
these features will not be correctly translated (the generated output
may need manual adjustment).
* In cases where Juvix termination checking diverges from Isabelle/HOL
termination checking, providing a termination proof manually may be
necessary. Non-terminating Juvix functions cannot be automatically
translated and need to be manually modelled in Isabelle/HOL in a
different way (e.g. as relations).
* Comments (including judoc) are ignored. This is left for future work.
* Traits are not translated to Isabelle/HOL type classes / locales. This
is left for future work.
* Mutually recursive functions are not correctly translated. This is
left for future work.
* Record creation, update, field access and pattern matching are not
correctly translated. This is left for future work.
* Named patterns are not correctly translated. This is left for future
work.
* Side conditions in patterns are not supported. This is left for future
work.
* If a Juvix function in the translated module has the same name as some
function from the Isabelle/HOL standard library, there will be a name
clash in the generated code.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2024-07-19 08:40:07 +01:00
Jan Mas Rovira
2793514325
Puns for named application (#2890)
Since it is common to want to assign a named argument a variable of the
same name, we add special syntax for it. E.g.
```
f (fieldA : A) (fieldB : B) : S :=
  mkS@{
    fieldC := fieldA; -- normal named argument
    fieldA;  -- pun
    fieldB   -- pun
  };
```
2024-07-16 12:23:22 +02:00
Łukasz Czajka
5a76e5d9dc
Bugfix: compiler looping with the specialize pragma (#2899)
* Closes #2884
2024-07-15 15:08:31 +02:00
Jan Mas Rovira
7d2a59cc9f
Add precondition to run tests (#2887)
Some tests require external dependencies, such as `rustc`, `wasmer`,
`run_cairo_vm.sh`, etc. If one does not have some of these available on
their computer, then the test suite will have a lot of failed tests with
the same fail message `X is not on $PATH`. This can be a bit ditracting
and it slows running the test suite.
I've introduced some preconditions that are checked before the actual
test suite so that if some of these commands are not on path then the
tests that need them are not run. Instead, you get a single failed test
(for each of the subtrees that failed the precondition).
2024-07-15 10:02:48 +02:00
Jan Mas Rovira
3736ed1c2d
Migrate old named application syntax (#2876)
- Closes #2668

This pr migrates the old named application syntax to the new one. In
order to migrate a juvix file to the new syntax it suffices to run the
formatter.
After the next release, we should completely remove the support for the
old syntax.

## Other changes
I've improved Scope negative tests. Previously, when a negative test
failed, you could only see the title of the test and the message
"Incorrect Error", as well as the Haskell file and line where the test
is defined.
This is extremely incovenient because you have to go to the haskell test
file, go to the line where the error is defined, look at the name of the
file and then visit that file. Moreover, you need to manually run the
scoper on that file to see the error that was returned.
I've fixed that and it now shows all relevant information. Example:

![image](https://github.com/anoma/juvix/assets/5511599/f0b7ec60-55dc-4f38-9b51-1fbedbda63f4)
I've implemented this only using the `Generic` instance for the
`ScoperError` type, so doing something similar for the rest of negative
tests should be straightforward.
2024-07-12 18:31:09 +02:00
Jan Mas Rovira
2a7303d003
juvix typecheck with no file argument typechecks the whole project (#2889) 2024-07-12 17:48:29 +02:00
Łukasz Czajka
1777251fde
Fix CI for RISC0 version 1.0.2 (#2888)
This PR updates the version of `cargo-risczero` in the CI. Ultimately,
we should figure out how to properly pin a fixed version, but apparently
that's not easy - it seems some dependencies need to be pinned and it's
not clear which ones, how, and to which versions. The problem is that to
execute the Rust code generated for RISC0 we need to compile it, and the
generated code depends on some RISC0-related libraries. Having the
correct version of the RISC0 Rust toolchain installed locally doesn't
fully solve the problem (doesn't seem to automatically select the right
versions of dependencies).
2024-07-12 13:36:48 +02:00
Paul Cadman
40f5be4d7f
Remove Geb backend (#2886)
* Closes https://github.com/anoma/juvix/issues/2840
2024-07-11 15:45:52 +01:00
Paul Cadman
ea359adba4
Update juvix-stdlib submodule reference to add Result (#2885)
This update adds the stdlib Result type and a `find` function to `List`.

See https://github.com/anoma/juvix-stdlib/pull/106
2024-07-10 19:06:21 +01:00
Paul Cadman
4e227436ce
Make juvix format line width 100 with ribbon width 100 (#2883)
This PR increases the ribbon width of `juvix format` from 60 to 100
characters.

Reasons for the compromise to a fixed 100 chars ribbon width:

* It is clear that the ribbon width of 60 characters was too small.
* A ribbon width of 100 is an acceptable compromise between formatting
code for display and editing code in multiple buffers on the same
screen.
* We would like to avoid making the formatter configurable so that Juvix
code has a consistent look and to save future Juvix users from
discussions about formatting. Maxim: "juvix format's style is no one's
favourite, yet juvix format is everyone's favourite" (thanks go fmt).

## Definition of ribbon width from the
[docs](https://hackage.haskell.org/package/prettyprinter-1.7.1/docs/Prettyprinter.html)

> The page has a certain maximum width, which the layouter tries to not
exceed, by inserting line breaks where possible. The functions given in
this module make it fairly straightforward to specify where, and under
what circumstances, such a line break may be inserted by the layouter,
for example via the
[sep](https://hackage.haskell.org/package/prettyprinter-1.7.1/docs/Prettyprinter.html#v:sep)
function.
> 
> There is also the concept of ribbon width. The ribbon is the part of a
line that is printed, i.e. the line length without the leading
indentation. The layouters take a ribbon fraction argument, which
specifies how much of a line should be filled before trying to break it
up. A ribbon width of 0.5 in a document of width 80 will result in the
layouter to try to not exceed 0.5*80 = 40 (ignoring current indentation
depth).

Examples from
[`anoma-app-patterns:/Token/Transaction.juvix`](8d7e892de3/Token/Transaction.juvix).
NB: The file in the repo is unformatted so will not match the layout in
the left column below.

| Current (line width 150, ribbon width 60) | This PR (line width 100,
ribbon width 100) |
| --- | --- |
| <img width="1000" alt="Screenshot 2024-07-10 at 12 22 46"
src="https://github.com/anoma/juvix/assets/92877/108b59bc-4b3d-4b83-a148-bb7069d7bc13">
| <img width="1000" alt="Screenshot 2024-07-10 at 14 41 33"
src="https://github.com/anoma/juvix/assets/92877/c3cc2c11-bd45-4a07-84ba-3de3d960e542">
|
| <img width="1000" alt="Screenshot 2024-07-10 at 12 23 10"
src="https://github.com/anoma/juvix/assets/92877/9f3e2d47-bcac-409a-8b09-12dde5079ec5">
| <img width="1000" alt="Screenshot 2024-07-10 at 14 42 01"
src="https://github.com/anoma/juvix/assets/92877/3e20db90-5f62-48e0-ac38-ec357d5baec0">
|
| <img width="1000" alt="Screenshot 2024-07-10 at 12 23 21"
src="https://github.com/anoma/juvix/assets/92877/995d01a9-d19d-429e-aee4-114a4a40c899">
| <img width="1075" alt="Screenshot 2024-07-10 at 14 42 14"
src="https://github.com/anoma/juvix/assets/92877/3cfd1663-75d2-48a3-9e93-c7938cc62a47">
|
| <img width="1000" alt="Screenshot 2024-07-10 at 12 23 34"
src="https://github.com/anoma/juvix/assets/92877/1623afe4-89a6-4633-86e0-8d4d39e49e93">
| <img width="1000" alt="Screenshot 2024-07-10 at 14 42 29"
src="https://github.com/anoma/juvix/assets/92877/813f602f-04b4-4ed5-a21e-4435a58d8515">
|
| <img width="1086" alt="Screenshot 2024-07-10 at 12 23 50"
src="https://github.com/anoma/juvix/assets/92877/a04d0664-b9d4-46f3-8ea0-72e5ae0660e1">
| <img width="1093" alt="Screenshot 2024-07-10 at 14 42 40"
src="https://github.com/anoma/juvix/assets/92877/5cf2328d-b911-4ad9-bcc8-3611f4f89465">
|
| <img width="1000" alt="Screenshot 2024-07-10 at 12 24 13"
src="https://github.com/anoma/juvix/assets/92877/53053e7a-32e1-440e-9060-1ab15133a934">
| <img width="1058" alt="Screenshot 2024-07-10 at 14 42 57"
src="https://github.com/anoma/juvix/assets/92877/7263732e-a2cf-43f3-9d49-0599175a160d">
|
2024-07-10 18:21:09 +01:00
Jan Mas Rovira
597824e89d
Add ExceptT, MonadError, MonadTrans as a test (#2880)
This pr explores the option to implement error handling in Juvix à la
mtl. It adds the following as a test:
1. `MonadError` trait.
2. `MonadTrans` trait.
3. `ExceptT` monad transformer and its `Functor`, `Monad`, `MonadTrans`,
`MonadError` instances.
2024-07-10 18:21:01 +02:00
Jan Mas Rovira
424ad6e194
Print pipe for else branch in multi if expression (#2881)
- Fixes #2879
2024-07-10 10:39:06 +01:00
Jan Mas Rovira
840b7e95a6
Reduce Internal boilerplate (#2874)
This pr modifies the `HasExpressions` class to allow traversing direct
subexpressions rather than only leaf expressions. I've added the `lens`
library as a dependency to have access to generic traversals defined in
[Control.Lens.Plated](https://hackage.haskell.org/package/lens-5.3.2/docs/Control-Lens-Plated.html).
2024-07-09 23:39:19 +02:00
Jan Mas Rovira
d08bf942b6
Add front-end support for case expressions boolean side conditions (#2852)
- Syntax for #2804.
- ⚠️ Depends on #2869.

This pr introduces:
1. front-end support (parsing, printing, typechecking) for boolean side
conditions for branches of case expressions.
2. Now `if` is a reserved keyword.
3. Multiway `if` is allowed to have only the `else` branch. I've also
refactored the parser to be simpler.

Example:
```
 multiCaseBr : Nat :=
    case 1 of
      | zero
        | if 0 < 0 := 3
        | else := 4
      | suc (suc n)
        | if 0 < 0 := 3
        | else := n
      | suc n if 0 < 0 := 3;
```
The side if branches must satisfy the following.
1. There must be at least one `if` branch.
4. The `else` branch is optional. If present, it must be the last.

Future work:
1. Translate side if conditions to Core and extend the exhaustiveness
algorithm.
5. Add side if conditions to function clauses.
2024-07-04 01:16:30 +02:00
Łukasz Czajka
7c8016dbca
Pragmas for record fields (#2875)
* Closes #2872
2024-07-03 19:15:35 +02:00
Paul Cadman
379e76b708
Release 0.6.3 (#2870)
This PR updates:

- [x] Package version
- [x] Smoke test
- [x] Changelog
2024-07-02 12:37:45 +01:00
Paul Cadman
e3c35077b0
Update juvix-stdlib to main ref (#2871)
This PR updates the juvix-stdlib submodule ref to point to the current
main ref of the juvix-stdlib repository.

Previously it was pointing to the ref of a branch.
2024-07-02 11:23:41 +01:00
Jan Mas Rovira
82e6b5f5d2
Merge if -> ite renaming from stdlib (#2869) 2024-07-02 10:03:06 +02:00
Paul Cadman
93b76ce7f0
Adapt Anoma builtins to new Anoma Node API (#2861) 2024-07-01 18:44:02 +01:00
Jan Mas Rovira
6fcc9f21d2
Improve performance of formatting a project (#2863)
Currently formatting a project is equivalent to running `juvix format`
on each individual file. Hence, the performance is quadratic wrt the
number of modules in the project. This pr fixes that and we now we only
process each module once.

# Benchmark (1236% faster 🚀)
Checking the standard library
```
hyperfine --warmup 1 'juvix format --check' 'juvix-main format --check'
Benchmark 1: juvix format --check
  Time (mean ± σ):     450.6 ms ±  33.7 ms    [User: 707.2 ms, System: 178.7 ms]
  Range (min … max):   396.0 ms … 497.0 ms    10 runs

Benchmark 2: juvix-main format --check
  Time (mean ± σ):      6.019 s ±  0.267 s    [User: 9.333 s, System: 1.512 s]
  Range (min … max):    5.598 s …  6.524 s    10 runs

Summary
  juvix format --check ran
   13.36 ± 1.16 times faster than juvix-main format --check
```

# Other changes:
1. The `EntryPoint` field `entryPointModulePath` is now optional.
2. I've introduced a new type `TopModulePathKey` which is analogous to
`TopModulePath` but wihout location information. It is used in hashmap
keys where the location in the key is never used. This is useful as we
can now get a `TopModulePathKey` from a `Path Rel File`.
3. I've refactored the `_formatInput` field in `FormatOptions` so that
it doesn't need to be a special case anymore.
4. I've introduced a new effect `Forcing` that allows to individually
force fields of a record type with a convenient syntax.
5. I've refactored some of the constraints in scoping so that they only
require `Reader Package` instead of `Reader EntryPoint`.
6. I've introduced a new type family so that local modules are no longer
required to have `ModuleId` from their type. Before, they were assigned
one, but it was never used.


# Future work:
1. For project-wise formatting, the compilation is done in parallel, but
the formatting is still done sequentially. That should be improved.
2024-07-01 18:05:24 +02:00
Łukasz Czajka
fef37a86ee
Optimize letFunctionDefs in Juvix.Compiler.Internal.Data.InfoTable (#2867)
* Closes #2394 
* Removes the use of Uniplate in `letFunctionDefs` altogether, in favour
of handwritten traversal accumulating let definitions (implemented via
the new `HasLetDefs` typeclass).

Benchmark results
------------------

Using Uniplate:
```
heliax@imac bench % hyperfine --prepare 'juvix clean --global' -w 1 'juvix typecheck bench.juvix -N 1'
Benchmark 1: juvix typecheck bench.juvix -N 1
  Time (mean ± σ):      1.399 s ±  0.023 s    [User: 1.346 s, System: 0.041 s]
  Range (min … max):    1.374 s …  1.452 s    10 runs
```

Using `HasLetDefs`:
```
heliax@imac bench % hyperfine --prepare 'juvix clean --global' -w 1 'juvix typecheck bench.juvix -N 1'
Benchmark 1: juvix typecheck bench.juvix -N 1
  Time (mean ± σ):      1.098 s ±  0.015 s    [User: 1.047 s, System: 0.040 s]
  Range (min … max):    1.074 s …  1.120 s    10 runs
```

So it's roughly 1.1s vs. 1.4s, faster by 0.2s. About 14% improvement.

The benchmark file just imports the standard library:
```
module bench;

import Stdlib.Prelude open;

main : Nat := 0;
```

Both `juvix` binaries were compiled with optimizations, using `just
install`.
2024-06-28 18:23:27 +02:00
Łukasz Czajka
69a12d0c2f
Refactor pipeline functions for tests (#2864)
* Closes #2859
2024-06-28 12:15:51 +02:00
Łukasz Czajka
802d82f22e
Peephole optimization of Cairo assembly (#2858)
* Closes #2703 
* Adds [peephole
optimization](https://en.wikipedia.org/wiki/Peephole_optimization) of
Cairo assembly.
* Adds a transformation framework for the CASM IR.
* Adds `--transforms`, `--run` and `--no-print` options to the `dev casm
read` command.
2024-06-27 12:41:27 +02:00
Łukasz Czajka
4dcbb002fe
Add an if instruction to JuvixReg (#2855)
* Closes #2829
* Adds a transformation which converts `br` to `if` when the variable
branched on was assigned in the previous instruction. The transformation
itself doesn't check liveness and doesn't remove the assignment. Dead
code elimination should be run afterwards to remove the assignment.
* For Cairo, it only makes sense to convert `br` to `if` for equality
comparisons against zero. The assignment before `br` will always become
dead after converting `br` to `if`, because we convert to SSA before.
2024-06-26 19:08:33 +02:00
Paul Cadman
7cfddcf915
Make Maybe a builtin inductive type (#2860)
This is required as the return type of the builtin
`anomaVerifyWithMessage` axiom.

Part of:
* https://github.com/anoma/juvix/issues/2850
2024-06-26 17:12:29 +01:00
Paul Cadman
5538aee7fe
Support Anoma representation of Maybe (#2856) 2024-06-26 12:39:36 +01:00
Paul Cadman
b8cd84170b
Update juvix-stdlib to remove non-ASCII indentifiers (#2857)
This PR updates the juvix-stdlib to the current main commit which
includes:

* https://github.com/anoma/juvix-stdlib/issues/59
* https://github.com/anoma/juvix-stdlib/issues/101

All the Juvix test suite files and examples in this repo have been
updated to be compatible with the new stdlib.
2024-06-26 10:23:35 +02:00
Paul Cadman
6d24d7186d
Add support for anoma specific functions to the Core evaluator (#2851)
This PR adds support for the `anoma{encode, decode, sign, verify,
signDetached, verifyDetached}` functions to the Core evaluator.

## Encoding / Decoding

The serialization of values to `ByteString` for `anomaEncode` reuses the
Stored Core serialization. The Stored Core `Node` is extended to include
closures.

Anoma expects encoding of bytes as little-endian integers. In general
`ByteString -> Integer` is ambiguous because two `ByteString`s that
differ only by zero padding will map to the same integer. So we must
encode the length of the ByteString in the encoded integer alongside the
ByteString data so when it is decoded we can pad appropriately. We use
the same length encoding scheme that is used by Nockma jam.

## Verify

The Core evaluator implementation of `anomaVerify` crashes if the
verification fails. This matches the behaviour of Anoma node.

### `jvc` Support

You can now use `anoma-*` functions within `.jvc` core files.

* Closes https://github.com/anoma/juvix/issues/2808
2024-06-25 20:02:44 +02:00
Jan Mas Rovira
694d46fb4f
Add error message for ill-scoped variables (#2566)
- This PR adds a temporary compiler error for when the bug #2247
happens. We do not have plans to fix this bug until we move the
typechecker to Core, so it makes sense to add a better error message.
2024-06-25 16:56:36 +02:00
Łukasz Czajka
c963df7f5f
Cairo: untagged record representation (#2853)
* Closes #2722 
* Omits the header (tag) field from in-memory record representation in
Cairo
* Requires updating
[juvix-cairo-vm](https://github.com/anoma/juvix-cairo-vm): depends on
https://github.com/anoma/juvix-cairo-vm/pull/8
2024-06-25 10:29:39 +02:00
Łukasz Czajka
7bb663c308
Dead code elimination in JuvixReg (#2835)
* Closes #2827 
* Adds an optimization phase to the JuvixReg -> Casm pipeline, which
consists of repeated copy & constant propagation and dead code
elimination.
2024-06-24 13:56:50 +02:00
Jan Mas Rovira
e43797f0a0
Generalize import syntax (#2819)
- Closes #2429 

This pr introduces two enchancements to import statements:
1. They can have `using/hiding` list of symbols, with a behaviour
analogous to the open statement.
2. They can be public. When an import is marked as public, a local
module (or a series of nested local modules) is generated like this:
   ```
    import A public;
    -- equivalent to
    import A;
    module A;
      open A public;
    end;
   ```
    It is easier to understand when there is an alias.
    ```
    import A as X.Y public;
    -- equivalent to
    import A;
    module X;
      module Y;
        open A public;
      end;
    end;
   ```
Public imports are allowed to be combined with `using/hiding` modifier
and open statements with the expected behaviour.
2024-06-21 15:02:30 +02:00
Łukasz Czajka
1410b6354a
Constant propagation in JuvixReg (#2833)
* Closes #2702 
* For this to give any improvement, we need to run dead code elimination
afterwards (#2827).

Depends on:
* #2828
2024-06-21 12:35:12 +02:00
Łukasz Czajka
af758cc8ad
Inline immediate values (#2842)
* Closes #2745 
* Adds inlining of immediate values, i.e., values that don't require
computation or memory allocation.
* Non-immediate zero-argument functions / values should not be inlined,
because when not inlined they can be computed only once.
2024-06-20 21:23:08 +02:00
Paul Cadman
a5cd3c9aa9
Add lcomposition fixity to support (>>) in the stdlib (#2847)
The stdlib composition function `∘` has fixity `composition` which means
it is right associative.

We will rename `∘` to `<<` in the stdlib and add a new function:

```
>> {a b c} : (a -> b) -> (b -> c) -> a -> c
```

for consistency with `<<` this should be left associative.

This is not a breaking change to package-base so we don't need to
increment the version number.
2024-06-20 12:34:24 +01:00