1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-04 05:33:27 +03:00
Commit Graph

1575 Commits

Author SHA1 Message Date
Łukasz Czajka
a3bfaca7bb
Avoid duplication in Nockma code generation (#3070)
* Closes #3013 
* Removes all remaining problems with evaluation duplication that could
potentially lead to an exponential blow-up in the running time.
* Adds the capacity to generate saves of temporary values in the Nock
code generation backend.
* Removes the `TempHeight` transformation on JuvixTree. It is no longer
needed.
* Removes the `ComputeCaseANF` transformation on JuvixCore from the
Anoma pipeline. It is no longer necessary.
2024-10-08 10:05:20 +02:00
Łukasz Czajka
4014030305
Add coding style guidelines (#3059)
Juvix coding style guidelines for the standard library and Anoma apps.
Compiled from discussions with @janmasrovira @paulcadman @heueristik

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2024-10-07 16:49:02 +02:00
Łukasz Czajka
40b71b95de
Nockma backend: translate trace to %puts hints (#3053)
* Closes #3022 
* Requires https://github.com/anoma/anoma/pull/861
2024-10-07 14:01:01 +02:00
Jan Mas Rovira
358551995e
Fix named application bug (#3075)
- Fixes #3074

- Merge after #3076

---------

Co-authored-by: Łukasz Czajka <62751+lukaszcz@users.noreply.github.com>
2024-10-03 16:26:59 +01:00
Jan Mas Rovira
8c37d9b439
Merge typechecker negative tests (#3076) 2024-10-03 10:02:45 +02:00
Jan Mas Rovira
137b6d83eb
Fix termination crash due to empty permutation (#3081)
- Fixes #3064
2024-10-02 18:59:30 +02:00
Jan Mas Rovira
a1926547a2
Reimplement positivity checker (#3057)
- Fixes #3048
- Fixes #3058

Due to #3071 I had to change the order of two lines in
tests/Compilation/positive/test079.juvix.
2024-10-01 13:39:28 +02:00
Jan Mas Rovira
eaec932df1
Remove unused field from ScoperState (#3073) 2024-09-30 19:28:44 +02:00
Jan Mas Rovira
deca981fa3
Ignore files that start with a . (#3072)
- Closes #3068
2024-09-30 12:17:18 +02:00
Paul Cadman
6e58aad8e7
Include the juvix version in the build directory path (#3069)
For example, by default the build directory would now be:

```
.juvix-build/0.6.6
```

It is necessary to separate the build files by compiler version because
the structure of jvo files may be incompatible between compiler
releases.

* Closes https://github.com/anoma/juvix/issues/3019
2024-09-30 08:57:47 +01:00
Paul Cadman
625d5e0b67
Parse stdlibPlaceholder in Nockma parser (#3065)
In the nockma parser (e.g used when running `juvix dev nockma run`), the
strings "nil", "functionsPlaceholder", and "stdlibPlaceholder" all parse
to Nockma nil.

We added `stdlibPlaceholder` in:

* https://github.com/anoma/juvix/pull/3005

but we forgot to add it to the parser.
2024-09-26 14:38:25 +02:00
Łukasz Czajka
038931ac6c
Fix RISC0 on the CI (#3061)
It seems that whenever a new major version of `cargo-risczero` becomes
available, the CI needs to be updated to install this version.
2024-09-26 13:30:04 +02:00
Jan Mas Rovira
7ae42a1d43
Group tables related to typechecking (#3056)
I've grouped tables related to typechecking:
```
data TypeCheckingTables = TypeCheckingTables
  { _typeCheckingTablesTypesTable :: TypesTable,
    _typeCheckingTablesFunctionsTable :: FunctionsTable,
    _typeCheckingTablesInstanceTable :: InstanceTable,
    _typeCheckingTablesCoercionTable :: CoercionTable
  }
```
2024-09-25 18:28:41 +02:00
Paul Cadman
49e8c9dd13
Fix linux static build: Remove -j argument from C runtime make invocation (#3055)
This PR removes the `-j` (concurrent jobs) argument from the C runtime
make invocation.

`-j` cannot be used in the juvix_c make invocation because it causes an
error in the 'Build Linux static binary workflow'

```
cd runtime && make
make[1]: Entering directory '/__w/juvix/juvix/runtime'
cd c && make -j 4 -s
make[3]: *** No rule to make target '_build.wasm32-wasi/src/juvix/arch/wasi.o', needed by 'all'.  Stop.
make[3]: *** No rule to make target '_build.wasm32-wasi-debug/src/juvix/arch/wasi.o', needed by 'all'.  Stop.
make[2]: *** [Makefile:20: wasm32-wasi] Error 2
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [Makefile:35: wasm32-wasi-debug] Error 2
_build.native64/src/juvix/opts.d:1: *** recipe commences before first target.  Stop.
make[2]: *** [Makefile:26: native64] Error 2
_build.native64-debug/src/juvix/opts.d:1: *** recipe commences before first target.  Stop.
make[2]: *** [Makefile:41: native64-debug] Error 2
make[1]: *** [Makefile:9: juvix_c] Error 2
make[1]: Leaving directory '/__w/juvix/juvix/runtime'
make: *** [Makefile:206: runtime] Error 2
```
2024-09-23 10:42:45 +02:00
Jan Mas Rovira
c09d10db02
Improve parsing error for missing @ in named application (#3012)
- Closes #2796 

Example:
```
module NamedApplicationMissingAt;

type T := t;

fun (a : T)
 : T := t;

main : T := fun {a := t};
```

The error displays as:

![image](https://github.com/user-attachments/assets/e36232cb-9ec3-462c-8ee4-8332924b4b07)
2024-09-20 18:00:38 +01:00
Paul Cadman
0d18294fce
Revert GHC 9.10.1 update (#3052)
We cannot build linux static binaries with GHC 9.10.1:

* https://github.com/anoma/juvix/issues/3037

This PR reverts the GHC update to unblock Juvix releases / nightly
releases. We can try the update again when stackage nightly updates to
GHC 9.10.1.
2024-09-19 21:02:43 +01:00
Łukasz Czajka
66427cdbc9
Precompute debug operations info in linear time (#3038)
After

* https://github.com/anoma/juvix/pull/2973

let-folding stopped being linear in the size of the input program. All
transformations should be linear whenever possible. This PR makes
let-folding linear again.
2024-09-14 08:53:36 +02:00
Paul Cadman
a63314d475
Update cabal.project.freeze for GHC 9.10.1 update (#3035)
This PR updates the cabal freeze file to reflect the changes to
dependencies after the GHC 9.10.1 stack.yaml update.

@janmasrovira can you check this? The last time I think you updated this
and the freeze file was much smaller for you.

I downloaded the stack2cabal binary from
https://github.com/hasufell/stack2cabal/releases/latest and ran
`stack2cabal` in the root of our repo.

* Fixes https://github.com/anoma/juvix/issues/3036
2024-09-13 19:50:06 +01:00
Łukasz Czajka
b609e1f6a5
Don't fold lets if the let-bound variable occurs under a lambda-abstraction (#3029)
* Closes #3002
2024-09-13 19:29:39 +02:00
Paul Cadman
ef0bc6efb8
Update linux static binary workflow for GHC 9.10.1 (#3034)
This PR updates the GHC version and the stack version in the linux
static binary GitHub workflow. This is used to make Juvix linux binary
releases.

NB: The linux binary releases of stack no longer have the `-static`
suffix in the tar filename.
2024-09-13 17:52:51 +02:00
Łukasz Czajka
87adaf4512
Update to GHC 9.10.1 (#2991)
Since GHC 9.8.2 has a bug which blocks our development (see
https://github.com/anoma/juvix/pull/2977#issuecomment-2325866056), I
made a PR to update to GHC 9.10.1. Because stackage doesn't yet support
GHC 9.10.1, I had to add some explicit dependencies and use
`allow-newer-deps` in `stack.yaml`.

I think we should merge this not to get blocked by the bug, and later
clean up `stack.yaml` when GHC 9.10.1 becomes supported on stackage.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2024-09-13 15:26:43 +02:00
Jan Mas Rovira
9d9591617d
Remove old named application syntax (#3026)
- Closes #2948
2024-09-12 19:27:29 +02:00
Łukasz Czajka
56e2db7336
Fix JuvixTree parsing and pretty printing (#3024)
Recent changes to the compiler left JuvixTree parsing and pretty
printing not in sync with each other.
2024-09-12 14:37:51 +02:00
Łukasz Czajka
c1774ffb76
Fix RISC0 in the CI (#3025) 2024-09-12 12:29:23 +02:00
Łukasz Czajka
26ea94b977
The assert builtin (#3014)
* Requires #3015
2024-09-12 09:29:57 +02:00
Jan Mas Rovira
8e204634b8
Fix the location in the parser for .juvix.md (#3020)
This pr makes it possible to properly hihglight .juvix.md files
2024-09-11 14:07:16 +02:00
Jan Mas Rovira
799d85034f
Store the DocTable in the .jvo file (#3021)
This allows the ide to display documentation for identifiers defined in
other modules.
2024-09-11 13:14:34 +02:00
Łukasz Czajka
5d3550b760
Fix bug in symbol dependency graph generation in Core (#3018)
The graph was missing some edges, which led to too many symbols being
filtered out by the `filter-unreachable` transformation.
2024-09-11 09:30:40 +02:00
Łukasz Czajka
5d0aa6ea54
Fix RISC0 compilation on the CI (#3015) 2024-09-10 17:17:00 +02:00
Jan Mas Rovira
d8919087dd
Fix location of scoped modulePathName (#3011)
Closes #2737.

This issues caused the formatter to sometimes insert unwanted line
breaks.
2024-09-09 15:50:29 +02:00
Łukasz Czajka
7167cb319a
Lift non-immediate expressions out of case values for the Nockma backend (#3010)
Implements a transformation `compute-case-anf` which lifts out
non-immediate values matched on in case expressions by introducing
let-bindings for them. In essence, this is a partial ANF transformation
for case expressions only.

For example, transforms
```
case f x of { c y := y + x; d y := y }
```
to
```
let z := f x in case z of { c y := y + x; d y := y }
```
This transformation is needed to avoid duplication of values matched on
in case-expressions in the Nockma backend.
2024-09-09 14:56:36 +02:00
Jan Mas Rovira
f47b9b0034
Do not duplicate nockma stdlib in the nockma backend (#3005) 2024-09-09 14:02:47 +02:00
Jan Mas Rovira
372375ef4d
Only output .debug.nockma file with the --debug flag (#3006) 2024-09-09 13:16:32 +02:00
Łukasz Czajka
ab2d31a313
Compilation of side conditions in pattern matches (#2984)
* Closes #2804 
* Requires #3003
* Front-end syntax for side conditions was implemented in #2852. This PR
implements compilation of side conditions.
* Adds side-conditions to `Match` nodes in Core. Updates Core parsing,
printing and the evaluator.
* Only side-conditions without an `else` branch are allowed in Core. If
there is an `else` branch, the side conditions are translated in
`fromInternal` into nested ifs. Because with `else` the conditions are
exhaustive, there are no implications for pattern exhaustiveness
checking.
* Adjusts the "wildcard row" case in the pattern matching compilation
algorithm to take into account the side conditions.
2024-09-09 12:25:15 +02:00
Jan Mas Rovira
453afffd15
Do not inline the functions library everywhere in the Nockma backend (#3004) 2024-09-08 22:39:55 +02:00
Łukasz Czajka
5675b4f480
Remove legacy naive match-to-case compiler (#3003)
Removes the naive match-to-case transformation.
2024-09-08 11:59:45 +02:00
Jan Mas Rovira
4ae4e4e4d9
Fix a bug that prevented use of name signature defined after the point (#3001)
- Fixes #2999
2024-09-06 14:32:03 +02:00
Jan Mas Rovira
e45503a63e
Fix typechecking of default arguments in signatures with trait arguments (#2998)
- Fixes #2994
2024-09-05 19:43:04 +02:00
Łukasz Czajka
d7c69db126
Fix locations in Internal hole substitution (only for the case of substituting identifiers) (#2995)
Type checking messes up the locations by substituting the holes
(instance holes and ordinary holes) without adjusting the location of
the expression substituted into the hole. Instead, the location of the
expression substituted into the hole is preserved. This messes up
locations in type-checked Internal, because the substituted expressions
can come from anywhere. Later on, the error locations are wrong in Core,
and get wrongly displayed e.g. for pattern matching coverage errors.

This PR implements a partial solution for the (most common) case when
the substituted expression is an identifier. In the future, we should
have a general solution to preserve the hole locations.
2024-09-05 10:57:30 +02:00
Paul Cadman
e4559bbc87
Release 0.6.6 (#2993)
This PR updates:

- [x] Package version
- [x] Smoke test
- [x] Changelog
2024-09-03 18:10:01 +01:00
Łukasz Czajka
b9d864123a
Isabelle/HOL translation: comments (#2974)
* Closes #2962 
* Depends on #2963 
* In Isabelle/HOL comments cannot appear in internal syntax. All
comments inside a Juvix definition are moved outside: to before the
definition or before the earliest function clause.

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2024-09-02 15:56:58 +02:00
Jan Mas Rovira
9d2a2b5638
Add IsInstanceCoercion to Internal (#2981)
We now use a sum type:
```
data IsInstanceCoercion
  = IsInstanceCoercionInstance
  | IsInstanceCoercionCoercion
```
instead of two mutually exclusive Bools.

Moreover, we properly print the keyword in the internal prettyprinter.
2024-09-02 13:46:53 +02:00
Paul Cadman
87c5f0af44
Improve performance of anomaEncode / anomaDecode in the Core evaluator (#2975)
This PR:

* Adds a new implementation of {decode, encode}ByteString functions,
used by anomaEncode and anomaDecode in the Core evaluator
* Adds property tests for roundtripping and benchmarks for the new
functions.

The old implementation used
[bitvec](https://hackage.haskell.org/package/bitvec) to manipulate the
ByteString. This was far too slow. The new implementation uses bit
operations directly on the input integer and ByteArray.

It's now possible to run
[anoma-app-patterns:`Tests/Swap.juvix`](https://github.com/anoma/anoma-app-patterns/blob/feature/tests/Tests/Swap.juvix)
to completion.

For encoding, if the size of the output integer exceeds 64 bits (and
therefore a BigInt must be used) then the new implementation has
quadratic time complexity in the number of input bytes if an
implementation of `ByteString -> Integer` is used as follows:

```
byteStringToIntegerLE :: ByteString -> Integer
byteStringToIntegerLE = BS.foldr (\b acc -> acc `shiftL` 8 .|. fromIntegral b) 0
```

```
byteStringToInteger' :: ByteString -> Integer
byteStringToInteger' = BS.foldl' (\acc b -> acc `shiftL` 8 .|. fromIntegral b) 0

```

I think this is because `shiftL` is expensive for large Integers. To
mitigate this I'm splitting the input ByteString into 1024 byte chunks
and processing each separately. Using this we get 100x speed up at
~0.25Mb input over the non-chunked approach and linear time-complexity
thereafter.

## Benchmarks

The benchmarks for encoding and decoding 250000 bytes:

```
 ByteString Encoding to/from integer
      encode bytes to integer:   OK
        59.1 ms ± 5.3 ms
      decode bytes from integer: OK
        338  ms ±  16 ms
```

The previous implementation would never complete for this input.

Benchmarks for encoding and decoding 2 * 250000 bytes:

```
    ByteString Encoding to/from integer
      encode bytes to integer:   OK
        121  ms ± 8.3 ms
      decode bytes from integer: OK
        651  ms ±  27 ms
```

Benchmarks for encoding and decoding 4 * 250000 bytes:

```
    ByteString Encoding to/from integer
      encode bytes to integer:   OK
        249  ms ±  17 ms
      decode bytes from integer: OK
        1.317 s ±  16 ms
```

---------

Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2024-08-30 18:20:18 +01:00
Jan Mas Rovira
7119d3929b
Add PartialDo effect (#2978)
This effect is a different name for [Effectful's
`Fail`](https://hackage.haskell.org/package/effectful-core-2.3.1.0/docs/Effectful-Fail.html).
It gives an instance of
[`MonadFail`](https://hackage.haskell.org/package/base-4.18.1.0/docs/Control-Monad-Fail.html#t:MonadFail)
to `Sem`
2024-08-30 16:27:08 +02:00
Paul Cadman
3d21ab4325
Monad and Applicative traits in juvix stdlib (#2979)
This PR updates the stdlib submodule to juvix-stdlib main branch.

It contains Monad and Applicative traits.
2024-08-30 15:07:29 +02:00
Jan Mas Rovira
eb00fa48ba
Improve compilation progress log (#2969)
- Closes #2797 

Changes:

1. The global flag `--dev-show-thread-ids` is now properly being passed.
Before it was ignored.
3. The progress log has been refactored out of the `ParallelTemplate`
into the `Pipeline.Driver`. With the extra information available, I've
improved how we display the progress log:
1. We show `Compiling`, `Recompiling`, `Loading` to tell if the module
is compiled for the first time (the jvo is missing), or it needs to be
recompiled (with the reason displayed in parentheses), or is loaded from
a jvo file. In the latter case, the message is only showed with
`--log-level verbose|debug`.
2. The modules in other packages are displayed as dependencies with
their own progress counter.
2. When using `-N 1` and compiling a whole project we also get progress
log.

Example screencast:


https://github.com/user-attachments/assets/7cc43cd4-9b23-4ad5-a863-832abacc1b6c
2024-08-30 00:10:13 +02:00
Łukasz Czajka
a4f3704f4e
Isabelle/HOL translation: records and named patterns (#2963)
* Closes #2894 
* Closes #2895
* The translation of pattern matching on records is a bit tricky because
one cannot pattern match on records in Isabelle, except in top patterns
of function clauses. We thus need to translate into nested pattern
matching and record projections. Named patterns can be translated with a
similar technique and are also handled in this PR.

Checklist
---------
- [x] record creation
- [x] record projections
- [x] record update
- [x] top-level record patterns
- [x] nested record patterns
- [x] named patterns
- [x] remove redundant pattern matching clauses
- [x] remove redundant single-branch pattern matches
2024-08-29 16:15:58 +02:00
Jan Mas Rovira
e0bbac2d11
Improve output of juvix dev import-tree print (#2976)
Example:

Old:
```
Import Tree:
============

* Package at /home/jan/.config/juvix/0.6.5/package-base/
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Bool.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/List.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Maybe.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Nat.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/String.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Trait/Natural.juvix
Juvix/Builtin/V1/List.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/Nat.juvix imports Juvix/Builtin/V1/Nat/Base.juvix
Juvix/Builtin/V1/Nat.juvix imports Juvix/Builtin/V1/Trait/FromNatural.juvix
Juvix/Builtin/V1/Nat.juvix imports Juvix/Builtin/V1/Trait/Natural.juvix
Juvix/Builtin/V1/Nat/Base.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/String.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/Trait/FromNatural.juvix imports Juvix/Builtin/V1/Nat/Base.juvix
Juvix/Builtin/V1/Trait/Natural.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/Trait/Natural.juvix imports Juvix/Builtin/V1/Nat/Base.juvix
Juvix/Builtin/V1/Trait/Natural.juvix imports Juvix/Builtin/V1/Trait/FromNatural.juvix
```

New:
```
Import Tree:
============

* Package at /home/jan/.config/juvix/0.6.5/package-base/
Nodes (10)
Juvix/Builtin/V1/Nat.juvix
Juvix/Builtin/V1/Nat/Base.juvix
Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/Trait/Natural.juvix
Juvix/Builtin/V1/Bool.juvix
Juvix/Builtin/V1.juvix
Juvix/Builtin/V1/List.juvix
Juvix/Builtin/V1/String.juvix
Juvix/Builtin/V1/Trait/FromNatural.juvix
Juvix/Builtin/V1/Maybe.juvix

Edges (17)
Juvix/Builtin/V1.juvix imports (7):
  • Juvix/Builtin/V1/Bool.juvix
  • Juvix/Builtin/V1/Fixity.juvix
  • Juvix/Builtin/V1/List.juvix
  • Juvix/Builtin/V1/Maybe.juvix
  • Juvix/Builtin/V1/Nat.juvix
  • Juvix/Builtin/V1/String.juvix
  • Juvix/Builtin/V1/Trait/Natural.juvix

Juvix/Builtin/V1/Bool.juvix imports (0):

Juvix/Builtin/V1/Fixity.juvix imports (0):

Juvix/Builtin/V1/List.juvix imports (1):
  • Juvix/Builtin/V1/Fixity.juvix

Juvix/Builtin/V1/Maybe.juvix imports (0):

Juvix/Builtin/V1/Nat.juvix imports (3):
  • Juvix/Builtin/V1/Nat/Base.juvix
  • Juvix/Builtin/V1/Trait/FromNatural.juvix
  • Juvix/Builtin/V1/Trait/Natural.juvix

Juvix/Builtin/V1/Nat/Base.juvix imports (1):
  • Juvix/Builtin/V1/Fixity.juvix

Juvix/Builtin/V1/String.juvix imports (1):
  • Juvix/Builtin/V1/Fixity.juvix

Juvix/Builtin/V1/Trait/FromNatural.juvix imports (1):
  • Juvix/Builtin/V1/Nat/Base.juvix

Juvix/Builtin/V1/Trait/Natural.juvix imports (3):
  • Juvix/Builtin/V1/Fixity.juvix
  • Juvix/Builtin/V1/Nat/Base.juvix
  • Juvix/Builtin/V1/Trait/FromNatural.juvix
```
2024-08-28 12:26:45 +02:00
Łukasz Czajka
7c8ac153e6
Don't fold lets with fail, trace or >-> in the body (#2973)
This is to avoid optimizing e.g.
```
let x := A in
trace "after A" >-> x
```
into 
```
trace "after A" >-> A
```
which is annoying when debugging.
2024-08-27 15:52:08 +02:00
Łukasz Czajka
eb5b2e4595
Fix JuvixTree type unification (#2972)
* Closes #2954 
* The problem was that the type validation algorithm was too strict for
higher-order functions with a dynamic (unknown) target.
2024-08-27 10:31:14 +02:00