1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00
Commit Graph

1049 Commits

Author SHA1 Message Date
Łukasz Czajka
5b44b2e654
Use specialization pragmas in the standard library (#2230)
* Adds `specialize` pragmas for folds, maps, etc.
* Fixes two bugs in `specializeArgs`
2023-06-27 15:37:11 +02:00
Łukasz Czajka
2fff65030b
Case folding (#2229)
Fold constant cases, i.e., convert
```
case C a b
| A := ..
| B x := ..
| C x y := M
```
to
```
let x := a;
     y := b;
in
M
```
2023-06-27 12:29:26 +02:00
Łukasz Czajka
7c039d687b
Specialization optimisation (#2164)
* Closes #2147 

Adds a `specialize` pragma which allows to specify (explicit) arguments
considered for specialization. Whenever a function is applied to a
constant known value for the specialized argument, a new version of the
function will be created with the argument pasted in. For example, the
code

```juvix
{-# specialize: [1] #-}
mymap : {A B : Type} -> (A -> B) -> List A -> List B;
mymap f nil := nil;
mymap f (x :: xs) := f x :: mymap f xs;

main : Nat;
main := length (mymap λ{x := x + 3} (1 :: 2 :: 3 :: 4 :: nil));
```

will be transformed into code equivalent to

```juvix
mymap' : (Nat -> Nat) -> List Nat -> List Nat;
mymap' f nil := nil;
mymap' f (x :: xs) := λ{x := x + 3} x :: mymap' xs;

main : Nat;
main := length (mymap' (1 :: 2 :: 3 :: 4 :: nil));
```
2023-06-26 16:49:19 +02:00
Łukasz Czajka
82a86ace45
Fix de Bruijn indices in LetRecs (#2227)
* Closes #2226 

For the program
```juvix
module letrec;

import Stdlib.Prelude open;

myfun : {A : Type} -> (A -> A) -> A -> A;
myfun {A} f a :=
      let
        go : Nat -> A -> A;
        go' : Nat -> A -> A;

        go zero a := a;
        go (suc n) a := f (go' n a);

        go' zero a := a;
        go' (suc n) a := f (go n a);
      in
      go 5 a;

main : Nat;
main := myfun ((+) 1) 7;
```
after translating to Core and lambda-lifting we got the incorrect
indices in types of the let-bindings.
```
def myfun : Π A : Type, (A$0 → A$1) → A$1 → A$2 :=
  λ(A : Type)
    λ(f : A$0 → A$1)
      λ(a : A$1)
        let go' : Int → a$1 → a$2 := go'_9 A$2 f$1 in
        let go : Int → a$2 → a$3 := go_10 A$3 f$2 in
        go$0 5 a$2;
```
The indices have been corrected in this PR.
2023-06-26 12:05:51 +02:00
Paul Cadman
4ab201f1ac
Bump version to 0.4.1 and update CHANGELOG (#2225)
This PR prepares the 0.4.1 release.

* Bump version in package.yaml
* Update version smoke test
* Updates CHANGELOG

NB: The links in the changelog will not work until we create the release
tag.
2023-06-23 12:39:27 +01:00
Veronika Romashkina
9840878413
Remove Subtree sections, all collapse all button (#2213)
- Resolves #2198

<img width="700" alt="Screenshot 2023-06-20 at 14 09 21"
src="https://github.com/anoma/juvix/assets/8126674/f5ebb89e-5f2a-41fe-8495-13b1ec4aea02">
2023-06-23 11:31:59 +01:00
Łukasz Czajka
f77e05513f
Lifting calls out of cases for the VampIR backend (#2218)
* Closes #2200 

For example,

```
def power' : Int → Int → Int → Int :=
  λ(acc : Int)
    λ(a : Int)
      λ(b : Int)
        if = b 0 then acc else if = (% b 2) 0 then power' acc (* a a) (/ b 2) else power' (* acc a) (* a a) (/ b 2);
```

is transformed into

```
def power' : Int → Int → Int → Int :=
  λ(acc : Int)
    λ(a : Int)
      λ(b : Int)
        if = b 0 then acc else let _X : Bool := = (% b 2) 0 in
        power' (if _X then acc else * acc a) (* a a) (/ b 2);
```
2023-06-23 10:55:19 +01:00
Łukasz Czajka
8201cb828c
The public pragma (#2223)
* Closes #2217
2023-06-22 18:31:53 +02:00
Łukasz Czajka
f7118d485c
Local pragmas (#2222)
* Closes #2196
2023-06-22 16:23:36 +02:00
Paul Cadman
1b30c75657
Build and cache smoke binary keyed using icu4c version (#2221)
This PR replaces fetching a precompiled binary of smoke with a
build/cache for macOS smoke tests on CI.

smoke dynamically links to icu4c, so a cached binary of smoke will break
when brew bumps the icu4c version. In this PR we use the icu4c version
in the cache key of the smoke build to avoid this issue.

NB: The smoke build cannot be done as a separate job because the smoke
binary must be built using exactly the same version of the macos-12
runner image as the smoke testing step to make sure that the icu4c
versions match.

Motivation for doing this is this failure:
https://github.com/anoma/juvix/actions/runs/5325094406/jobs/9645334642

which uses this release of the runner image
https://github.com/actions/runner-images/releases/tag/macOS-12%2F20230618.1

which contains the updated brew version of icu4c.

20230618.1 is currently a prerelease, but will start to run on more jobs
shortly.

```
2023-06-20T17:10:13.2222310Z Copied executables to /Users/runner/.local/bin:
2023-06-20T17:10:13.2223440Z - juvix
2023-06-20T17:10:13.5312790Z dyld[90256]: Library not loaded: '/usr/local/opt/icu4c/lib/libicuuc.72.dylib'
2023-06-20T17:10:13.5331930Z   Referenced from: '/Users/runner/hostedtoolcache/jonaprieto/smoke/latest/darwin-x64/smoke'
2023-06-20T17:10:13.5333610Z   Reason: tried: '/usr/local/opt/icu4c/lib/libicuuc.72.dylib' (no such file), '/usr/local/lib/libicuuc.72.dylib' (no such file), '/usr/lib/libicuuc.72.dylib' (no such file), '/usr/local/Cellar/icu4c/73.2/lib/libicuuc.72.dylib' (no such file), '/usr/local/lib/libicuuc.72.dylib' (no such file), '/usr/lib/libicuuc.72.dylib' (no such file)
2023-06-20T17:10:13.5334690Z make[1]: *** [smoke-only] Abort trap: 6
2023-06-20T17:10:13.5335310Z make: *** [smoke] Error 2
2023-06-20T17:10:13.5363170Z ##[error]Process completed with exit code 2.
```
2023-06-22 10:10:31 +02:00
Łukasz Czajka
5f35178575
Switch to Halo2 for VampIR backend tests (#2216)
* Closes #2214
2023-06-21 13:08:19 +02:00
Łukasz Czajka
c47320bb13
Use equality instead of less-equal when translating matching on Nats (#2215)
* Closes #2211
2023-06-20 15:39:53 +01:00
Łukasz Czajka
afbee7f14d
Fix isNegative in the VampIR runtime (#2212)
* Closes #2206
2023-06-20 15:34:50 +02:00
Veronika Romashkina
02e2f9f2dd
Use juvix-installer in CodeSpaces, install vamp-ir (#2210)
- Closes #2113
- Install `vamp-ir`.

---------

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2023-06-20 14:19:27 +02:00
Łukasz Czajka
50553758c2
Improve iterator formatting and syntax (#2204)
* Closes #2202
2023-06-20 13:21:46 +02:00
Jan Mas Rovira
6fb7bbff2d
Move termination checker to Internal (#2209)
- Closes #2203
2023-06-20 11:02:37 +02:00
Paul Cadman
5f3fdb9c08
Support juvix format with no argument to format a project (#2208)
When `juvix format` is invoked from some directory within a juvix
project then the formatter is run on all the files contained in the
project.

If `juvix format` is run from some directory outside of a Juvix project
then an error is reported. The user gets the same error as they would
get if
`juvix format` was run with a directory argument that is not within a
Juvix project.

* Closes https://github.com/anoma/juvix/issues/2087
2023-06-20 06:32:17 +01:00
Paul Cadman
fa4c92c7a5
Propogate formatter results when traversing subdirs (#2207)
Previously if a project looked like (where `Unformatted.juvix` contains
unformatted code, and `Formatted.juvix` is fully formatted):

```
Dir
|- juvix.yaml
|- Unformatted.juvix
|- Subdir
   |- Formatted.juvix
```

and the user ran `juvix format Dir/` then the command would return exit
code 0 instead of exit code 1. This is because only the result from
formatting files within `Subdir` was used, the result from `Dir` was
discarded.

This PR fixes this, the results of formatting all subdirectories in a
project are combined appropriately.
2023-06-19 18:42:28 +01:00
Paul Cadman
7840f9fa79
Always print source of formatted file unless --check is specified (#2205)
This PR was already merged in https://github.com/anoma/juvix/pull/2173,
but main was subsequently forced pushed as part of the 0.4.0 release and
these changes were erased by mistake.

This PR changes the behaviour of the formatter when run on files that
are already formatted. Previously the source of a file that was already
formatted was not output by the formatter.

After this PR, the formatter always outputs the contents of a formatted
file (when used on a single file, and if the --check option is not
specified).

If the `format: false` pragma is set then the source is echoed verbatim,
without highlighting (because it's not possible to get the highlighting
without the formatting).

This probably helps implementing the formatter in the vscode extension,
see https://github.com/anoma/vscode-juvix/issues/98
2023-06-19 15:14:59 +01:00
Łukasz Czajka
dd16274a24
Restrict permutative conversions on cases to non-booleans (#2201)
* Restricts permutative conversions for case-expressions to
non-booleans. This reduces the blow-up a bit.

  Permutative conversions rewrite
  ```
  case (case M | C1 -> A1 | C2 -> A2)
  | D1 -> B1
  | D2 -> B2
  ```
  to
  ```
  case M
  | C1 -> case A1
              | D1 -> B1
              | D2 -> B2
  | C2 -> case A2
              | D1 -> B1
              | D2 -> B2
  ```

It is necessary to perform them for non-boolean A1/A2 to obtain the
right kind of normal forms.

* Adds a test demonstrating the necessity of permutative conversions for
non-booleans.
2023-06-19 11:57:12 +02:00
Łukasz Czajka
f421e87963
Update to the new version of VampIR (#2138)
* Closes #2131 

It remains to update the VampIR version in the CI.
2023-06-16 16:34:58 +01:00
Jonathan Cubides
812edea6a8
Update vamp-ir CI installation (#2199)
- Leveraging https://github.com/anoma/vamp-ir/pull/108
2023-06-16 14:29:31 +01:00
Łukasz Czajka
a3a2454733
More tests for the VampIR compilation pipeline (#2197) 2023-06-16 12:58:37 +02:00
Paul Cadman
82a6f8c891
Fix runtime C maybe benchmark example (#2195)
The constr_info_t struct has changed, so this example must be changed
accordingly.

The benchmark builds are still broken because I missed this file in
https://github.com/anoma/juvix/pull/2192

I've removed the unsupported wasm target from the `compile.sh` script in
the benchmark directory to make it easier to spot errors.
2023-06-16 09:54:13 +01:00
Jonathan Cubides
56cde347d3
Refactor isValidChar (#2194)
Move common functions to Prelude
2023-06-16 09:43:15 +02:00
Łukasz Czajka
31627a0ce5
Check valid argument names in YAML (#2193)
* Closes #2191
2023-06-15 16:42:58 +02:00
Paul Cadman
121e883a49
Fix benchmark runtime C examples (#2192)
The constr_info_t struct has changed, so these examples must be changed
accordingly.

This should fix the failing benchmark builds
https://github.com/anoma/juvix-nightly-builds/actions/runs/5274325536/jobs/9538974076
2023-06-15 14:38:42 +01:00
Jonathan Cubides
925d7cb749 Bump to version 0.4.0 🎉 2023-06-09 18:44:39 +02:00
Jan Mas Rovira
b7b0e1039e
Store source location of (almost) everything (#2174)
- Closes #2162 

This pr improves formatting of source files with comments.
The concrete ast now stores location information of almost all keywords.
We do not store location information of parentheses. Comments will be
pushed out of parentheses by the formatter.
E.g.
```
( -- comment
 f x)
```
will become
```
-- comment
(f x)
```

This only occurs if the comment appears just after the `(`. So the
following will be respected
```
(f --comment
x)
```

---------

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2023-06-07 19:57:51 +02:00
Veronika Romashkina
216c1cd0e8
Change terminal colours to be more align with the scheme (#2183)
Colouring in the REPL now is a bit closer to the scheme we have for
Juvix.
Because of the allowed colors in the `prettyprinter-ansi-terminal` we
can use one of the standard colours only:
<img width="896" alt="Screenshot 2023-06-07 at 07 05 34"
src="https://github.com/anoma/juvix/assets/8126674/c0077c7c-edba-4ed8-9824-f9b9e773e943">

- Fixes https://github.com/anoma/vscode-juvix/issues/107
2023-06-07 18:21:17 +02:00
Łukasz Czajka
4c2aa499af
Use stderr for errors in the runtime (#2184)
* Closes #1902
2023-06-07 14:38:28 +02:00
Veronika Romashkina
8e59624ff5
Format returns 0 when file is not formatted (#2181)
`format` command now returns code `0` most of the time.

It will return `1` when:
* some error occur, so can not format
* file is unformatted and `--check` option is used
* One or more files are not formatted in a Juvix project.

- Fixes #2171
2023-06-07 13:53:10 +02:00
Łukasz Czajka
4c0e0b13c8
Respect fixity in runtime printer (#2182)
* Closes #2180
2023-06-07 11:44:41 +02:00
Łukasz Czajka
9db16ca87f
Fix 'function not found' error in juvix eval (#2178)
* Closes #2176

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-06-06 13:26:43 +02:00
Łukasz Czajka
5d85cb44f2
Print values in juvix eval (#2179)
* Closes #2177
2023-06-06 12:35:01 +02:00
Paul Cadman
108ccf7dcf
Do not filter unreachable symbols when compiling for REPL (#2172)
Say we have a module that import/open the Prelude:

Test.juvix
```
module Test;
import Stdlib.Prelude open;
```

When the module is compiled, we have a step in the compiler pipeline
which filters out unreachable symbols. For this module all symbols are
filtered because the module contains no definitions.

So if the module is loaded in the REPL, no symbols will be available to
process through the evaluator. The REPL is a place to explore the
symbols in the module so (like with Haskell's GHCi) it would be useful
if all symbols were available in the REPL session. That's what this PR
implements.

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

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-06-05 16:52:52 +01:00
Łukasz Czajka
68b4b38f98
Improve parsing error messages (#2170)
* Closes #2160 
* Closes #2167 
* Closes #2168
2023-06-05 12:06:05 +02:00
Jonathan Cubides
d869ce4dd6 Bump version to v0.3.5 🎉 2023-06-02 17:28:07 +02:00
Jan Mas Rovira
f4aa70b13d
Finish the new pretty printing algorithm and delete the old one (#2151)
- Closes #2128 
- Closes #2161 

This pr fully implements the monadic pretty printer based on
`ExactPrint`, which respects comments. Until now, comments inside
expressions were printed after the current statement. Now they are
printed in the correct place, except when a comment occurs before
something that we don't store its location. E.g. parentheses,
semicolons, braces, colons, etc. I proposed that we irone out this issue
in a separate pr.

Since the old non-monadic algorithm is no longer necessary, I removed
it.
2023-06-02 13:02:35 +02:00
Jan Mas Rovira
02e9f89e5e
Properly scan imports inside local modules (#2165)
- Closes #2163 

Nested imports where not scanned properly when building the Internal
InfoTable. That is no fixed
2023-06-02 12:12:02 +02:00
Łukasz Czajka
e0689801cf
Update standard library for better readability, efficiency and iterator use (#2153)
This does not change any examples or documentation. The interface of the
standard library remains unchanged (except the addition of new
iterators), so this PR can be merged without side effects.

* Closes #2146
2023-06-01 18:21:03 +02:00
Łukasz Czajka
c4c92d5fcf
Allow to specify VampIR variable names (#2141)
* Closes #2134 

Adds the `argnames` pragma which specifies function argument names.
These will be the names used in Core and subsequently in VampIR for the
`main` function.

```
{-# argnames: [x, y] -#}
main : Nat -> Nat -> Nat;
```
2023-06-01 17:36:47 +02:00
Paul Cadman
7e1a641908
Support new import ... open syntax in REPL (#2156)
Similar to https://github.com/anoma/juvix/pull/2098 which introduced the
new `import ... open` syntax the old syntax is still supported.

The `try` must be removed when the old `open import ...` syntax is
removed.

* Closes https://github.com/anoma/juvix/issues/2155
2023-06-01 16:44:08 +02:00
Jan Mas Rovira
c66213e06a
Add extra git dependencies to cabal.project (#2158)
- Closes #2157
2023-06-01 13:32:34 +01:00
Paul Cadman
40e6648ae1
Use theJUVIX_LLVM_DIST_PATH environment variable to search for the clang executable (#2152)
If set, `JUVIX_LLVM_DIST_PATH` should point to the root of a LLVM
installation, i.e clang should be present
in`$JUVIX_LLVM_DIST_PATH`/bin/clang.

If `JUVIX_LLVM_DIST_PATH` is not set, or `clang` is not available there
then the system PATH is used instead, (this is the current behaviour).

The `juvix doctor` clang checks use the same logic as `juvix compile` to
find and check the `clang` executable.

To help with debugging the clang location, this PR also adds `juvix
doctor --verbose` which prints the location of the `clang` executable
and whether it was found using the system PATH or the
JUVIX_LLVM_DIST_PATH environment variable:

```
juvix doctor --verbose
> Checking for clang...
  | Found clang at "/Users/paul/.local/share/juvix/llvmbox/bin/clang" using JUVIX_LLVM_DIST_PATH environment variable
```

or

```
juvix doctor --verbose
> Checking for clang...
  | Found clang at "/Users/paul/.local/bin/clang" using system PATH
```

* Closes https://github.com/anoma/juvix/issues/2133
2023-06-01 12:18:31 +02:00
Łukasz Czajka
757b4ed180
VampIR pipeline: handle booleans in the type of main (#2137)
* Closes #2132

---------

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2023-06-01 11:42:35 +02:00
Łukasz Czajka
d08d8ce7eb
Add the format pragma (#2150)
* Closes #2117
2023-05-31 23:30:59 +02:00
Łukasz Czajka
b293e19ac9
Remove code for Eval and Print statements (#2149)
* Closes #2052
2023-05-31 10:19:58 +02:00
Jan Mas Rovira
88c5dabb6d
Add Semigroup instance for AnsiText (#2140)
`AnsiText` is a type that represents some text that can be printed with
`Ansi` formatting annotations, or as plain text. It is expected that it
should have a `Semigroup` instance. This pr adds that.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-05-31 08:53:08 +01:00
Jan Mas Rovira
f56110b87e
Add :doc command to the repl (#2142) 2023-05-30 18:19:39 +02:00