1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-04 06:23:13 +03:00
Commit Graph

346 Commits

Author SHA1 Message Date
Ł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
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
Jan Mas Rovira
f56110b87e
Add :doc command to the repl (#2142) 2023-05-30 18:19:39 +02:00
Łukasz Czajka
649d905b85
Fix printing of infix constructor values (#2144)
To print e.g.
```agda
(::) :: nil
```
instead of
```agda
:: :: nil
```
2023-05-30 17:11:18 +02:00
Łukasz Czajka
e9284b3ef6
Iterator syntax (#2126)
* Closes #1992 

A function identifier `fun` can be declared as an iterator with
```
syntax iterator fun;
```
For example:
```haskell
syntax iterator for;
for : {A B : Type} -> (A -> B -> A) -> A -> List B -> List A;
for f acc nil := acc;
for f acc (x :: xs) := for (f acc x) xs;
```
Iterator application syntax allows for a finite number of initializers
`acc := a` followed by a finite number of ranges `x in xs`. For example:
```
for (acc := 0) (x in lst) acc + x
```
The number of initializers plus the number of ranges must be non-zero.

An iterator application
```
fun (acc1 := a1; ..; accn := an) (x1 in b1; ..; xk in bk) body
```
gets desugared to
```
fun \{acc1 .. accn x1 .. xk := body} a1 .. an b1 .. bk
```
The `acc1`, ..., `accn`, `x1`, ..., `xk` can be patterns.

The desugaring works on a purely syntactic level. Without further
restrictions, it is not checked if the number of initializers/ranges
matches the type of the identifier. The restrictions on the number of
initializers/ranges can be specified in iterator declaration:
```
syntax iterator fun {init: n, range: k};
syntax iterator for {init: 1, range: 1};
syntax iterator map {init: 0, range: 1};
```
The attributes (`init`, `range`) in between braces are parsed as YAML to
avoid inventing and parsing a new attribute language. Both attributes
are optional.
2023-05-30 15:30:11 +02:00
Jan Mas Rovira
e944f85074
Add :def command to the repl (#2119)
This pr adds a new command, `:def` to the repl. This command expects a
single identifier that must be in scope and then prints its definition.
For constructors, the whole type definition is printed.

It also applies some refactors to the code for repl command.
1. Before there was a mega `where` block of definitions. I have hoisted
most of the definitions there to the top level. I feel like now it is
easier to navigate and read.
2. Use `ExceptT` instead of local `case` expressions for errors.
3. Use forks of `haskeline` and `repline`. These forks are necessary
because these libraries do not export the constructors `HaskelineT` and
`InputT` respectively, thus, making it impossible to catch errors in
their underlying monad.
2023-05-30 10:19:09 +02:00
Jan Mas Rovira
121063cf0b
Show unicode characters without escaping (#2127)
- Closes #2064
2023-05-24 21:35:07 +02:00
Jan Mas Rovira
4fcb881ebc
Add main field to juvix.yaml (#2120)
- Closes #2067

This pr adds the field `main` to `juvix.yaml`. This field is optional
and should contain a path to a juvix file that is meant to be used for
the `compile` (and `dev compile`) command when no file is given as an
argument in the CLI. This makes it possible to simply run `juvix
compile` if the `main` is specified in the `jvuix.yaml`.

I have updated the `juvix.yaml` of the milestone examples.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2023-05-24 15:42:20 +02:00
Veronika Romashkina
b4e7dbc7fd
Remove --no-format option (#2121)
Instead, always act as `--no-format` option is set to `False` as
previous default.

The change seem to not affect any current formatting, so I assume it
passes the checks on testing.

Fixes #2084 

# Checklist:

- [x] My code follows the style guidelines of this project
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
2023-05-24 10:46:18 +02:00
Jan Mas Rovira
39b797ecfa
Add Bottom node (#2112)
- Closes #2056 
- Depends on #2103 

I am not sure about the implementation of `isType` for `NBot`. (solved).

The `Eq` instance returns `True` for every two `Bottom` terms,
regardless of their type.

---------

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2023-05-23 18:31:28 +02:00
Łukasz Czajka
d576111241
VampIR integration (#2103)
* Closes #2035 
* Depends on #2086 
* Depends on #2096 
* Adds end-to-end tests for the Juvix-to-VampIR compilation pipeline.

---------

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2023-05-22 20:18:18 +02:00
Jonathan Cubides
2148d174f5
Add VampIR to the CI (#2096)
This PR:

- Makes `vamp-ir` available in the CI (pre-release 0.1.2)
- [Use a setup-wasmer action to install
`wasmer`](https://github.com/marketplace/actions/setup-wasmer)
- Fixes cache option value for `jaxxstorm/action-install-gh-release`'s
usages

Adds support for:

- #2103 


Related: 

- https://github.com/anoma/vamp-ir/issues/90

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-05-22 19:49:36 +02:00
Jonathan Cubides
3ec54b7189 Bump version to v0.3.4 🎉 2023-05-22 18:51:42 +02:00
Łukasz Czajka
6bfe727a0e
Add syntax keyword (#2107)
* Closes #2007
2023-05-22 12:50:07 +02:00
Jan Mas Rovira
b25873ac6a
Allow symbol renaming inside using {..} (#2109)
- Closes #2090 
- Depends on #2108
2023-05-22 12:24:29 +02:00
Jan Mas Rovira
ab83749a86
Scope check symbols inside using {..} and hiding {..} (#2108)
- Closes #2089 

Now the symbols inside `using {..}` and `hiding {..}` are properly
scoped, which means that they will be properly colored and will have
goto information. If the referenced module does not contain a symbol in
the list, an error will be thrown.
2023-05-22 11:41:13 +02:00
Jonathan Cubides
e2f2d0a2f4
Fix Makefile target bugs for formatting and type Checking Juvix files (#2057)
This PR resolves a few bugs in the Makefile targets for formatting and
type checking Juvix files, which were preventing the capture of type
checking errors for our examples and bad formatting for all the Juvix
files in the repository. With this PR, our code should now be clean, and
we can expect every file to be properly formatted and type checked.

Changes made:

- [x] Updated `make format-juvix-files`
- [x] Updated `make check-format-juvix-files`
- [x] Formatted all Juvix files
- [x] Comment a fragment in `examples/milestone/Bank/Bank.juvix`

In the future, we will drastically simplify the Makefile once we improve
the `format` and the `type check` command for example posted here:

- #2066 
- #2087 

Related:

- #2063 
- #2040 (due to some typechecking errors we're not capturing before)
- #2105
- https://github.com/anoma/juvix/issues/2059
2023-05-19 17:33:56 +02:00
Łukasz Czajka
fe78ff451c
Direct translation from normalized JuvixCore to VampIR (#2086)
* Closes #2034.
* Adds the `vampir` target to the `compile` command.
* Adds two tests which are not yet enabled because `vamp-ir` is not
available in the CI (these and more tests will be enabled in #2103).
2023-05-19 14:43:45 +02:00
Jan Mas Rovira
9b1011b8ad
Add syntax for Judoc blocks (#2102)
- Closes #2050 

This pr adds the possibility to give judoc documentation in blocks
delimited by `{--` and `--}`.
- Inside these blocks, normal comments are disabled.
- It is allowed to have multiple blocks associated with the same
identifier, e.g.
```
{-- an axiom --}
{-- of type ;Type; --}
axiom a : Type;
```
- Nested blocks are *not* allowed.
- Blocks can be empty: `{-- --}`.
- The formatter respects line breaks inside blocks.
- The formatter normalizes whitespace at both ends of the block to a
single whitespace.
2023-05-19 14:05:32 +02:00
Jan Mas Rovira
d9d72f98eb
Simplify formatting of lambdas with a single clause (#2105)
After this pr, lambdas with a single clause will be printed in one line,
without a preceding `|`. I.e. `\ {x := x}`.
2023-05-19 13:24:02 +02:00
Paul Cadman
ad3607f104
Fix extra whitespace in text rendering of indented empty lines (#2101)
The prettyprinter library takes care avoid adding whitespace to empty
lines when it is rendering indented text.

See:

7e32c010ec/prettyprinter/src/Prettyprinter/Internal.hs (L1999)

However it only does this for unannotated text.

In our code we were stripping annotations from renderings within
`toTextStream` but we must remove the annotations before calling
`layoutPretty` to get the proper handling of whitespace with
indentations. That's what this PR does.
2023-05-19 11:41:28 +02:00
Jan Mas Rovira
a164083b70
Modify open import syntax (#2098) 2023-05-17 11:08:48 +02:00
Jan Mas Rovira
d135f74cf8
Add dangling judoc error (#2099) 2023-05-16 15:39:43 +02:00
Jan Mas Rovira
3ed30dd210
Implement core transformation let-hoisting (#2076)
- Closes #2033 
- Based on #2032
2023-05-16 13:42:44 +02:00
Łukasz Czajka
336a934d18
Normalization by Evaluation (#2038)
* Closes #2032.
* Adds the `juvix dev core normalize` command.
* Adds the `:n` command in JuvixCore REPL.
* Adds the `--normalize` flag to `juvix dev core read` and `juvix dev
core from-concrete`.
* Adds `pipeline-normalize` which denotes pipeline steps necessary
before normalization.
* Adds normalization tests in `tests/VampIR/positive/Core`.
2023-05-15 18:01:40 +02:00
Łukasz Czajka
8aa54ecc28
Inlining (#2036)
* Closes #1989
* Adds optimization phases to the pipline (specified by
`opt-phase-eval`, `opt-phase-exec` and `opt-phase-geb` transformations).
* Adds the `-O` option to the `compile` command to specify the
optimization level.
* Functions can be declared for inlining with the `inline` pragma:
   ```
   {-# inline: true #-}
   const : {A B : Type} -> A -> B -> A;
   const x _ := x;
   ```
By default, the function is inlined only if it's fully applied. One can
specify that a function (partially) applied to at least `n` explicit
arguments should be inlined.
   ```
   {-# inline: 2 #-}
   compose : {A B C : Type} -> (B -> C) -> (A -> B) -> A -> C;
   compose f g x := f (g x);
   ```
Then `compose f g` will be inlined, even though it's not fully applied.
But `compose f` won't be inlined.
* Non-recursive fully applied functions are automatically inlined if the
height of the body term does not exceed the inlining depth limit, which
can be specified with the `--inline` option to the `compile` command.
* The pragma `inline: false` disables automatic inlining on a
per-function basis.
2023-05-15 17:27:05 +02:00
Jan Mas Rovira
3cbf6f5cb6
Fix ordering of statements in Abstract -> Internal (#2040)
- Closes #2039 
- Closes #2055 
- Depends on #2053 

Changes in this pr:
- Local modules are removed (flattened) in the translation abstract ->
internal.
- In the translation abstract -> internal we group definitions in
mutually recursive blocks. These blocks can contain function definitions
and type definitions. Previously we only handled functions.
- The translation of Internal has been enhanced to handle these mutually
recursive blocks.
- Some improvements the pretty printer for internal (e.g. we now print
builtin tags properly).
- A "hack" that puts the builtin bool definition at the beginning of a
module if present. This was the easiest way to handle the implicit
dependency of the builtin stringToNat with bool in the internal-to-core
translation.
- A moderately sized test defining a simple lambda calculus involving
and an evaluator for it. This example showcases mutually recursive types
in juvix.

---------

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2023-05-15 13:02:09 +02:00
Paul Cadman
8eb4c64f5d
Improve error message when input path doesn't exist (#2092)
Previously if you call Juvix on a file that doesn't exist you get the
error:

```
$ juvix compile /i/don't/exist.juvix
juvix: /i/dont: changeWorkingDirectory: does not exist (No such file or directory)
```

After this change you will see:

```
$ juvix compile /i/don't/exist.juvix
The input path "/i/dont/exist.juvix" does not exist
```
2023-05-15 11:03:09 +02:00
Jan Mas Rovira
2b0668b55a
Allow nested block comments (#2075)
- Closes #2070
2023-05-15 09:57:23 +02:00
Łukasz Czajka
0462d623f2
Fix reachability analysis with imports in unreachable nested modules (#2062)
* Closes #2005

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-05-12 09:53:30 +01:00
Paul Cadman
11ebc4acde
Fix format on projects that contain subprojects (#2078)
This PR fixes the behaviour of the `format` command when run on a
project that contains subprojects. Files in subprojects must not be
processed by the formatter.

The format issue was caused by a bug in the `walkDirRel` function that
is used to traverse a file system tree:


9a64184253/src/Juvix/Data/Effect/Files.hs (L36)

In this function, the passed handler can return a function that
determines if a candidate subdirectory should be traversed. The first
argument of this function indicates if the candidate subdirectory
contains a juvix.yaml file. In the formatter and the path resolver we
use this argument to exclude such subdirectories from the traversal.

Previously the first argument was calculated from the files in the
current directory instead of the candidate subdirectory - which was the
source of the bug.

The callers of walkDirRel are also fixed to match the updated behaviour.

* Closes https://github.com/anoma/juvix/issues/2077
2023-05-10 18:34:53 +01:00
Jan Mas Rovira
9a64184253
Arity check types and functions (->) (#2049)
This pr fixes the following:

This example causes the compiler to crash with "implicitness mismatch".
```
f : id Bool -> Bool;
f _ := false;
```
The reason is that `id` expects an implicit argument but finds `Bool`,
which is explicit. The arity checker was not inserting any hole because
it was ignoring the whole type. Moreover the aritychecker was never
checking `->` types as we never expected to
have to insert holes in `->` types (since the only fragment of defined
functions that we accept in types are those which do not have implicit
arguments).

We now properly arity check all types and process the function type `->`
correctly.
2023-05-10 13:07:03 +01:00
Jan Mas Rovira
b0c566f52d
Partial incremental highlighting (#2053) 2023-05-10 13:09:48 +02:00
Veronika Romashkina
4e1fee1c03
Fix: topCommandInputFile for Format command (#2063)
This change, instead of changing the `FormatOptions` data type to have
some `AppPath *`, it just adds the special case on how to handle this
specific command to figure out its input directory.

- Fixes #2058
2023-05-10 08:52:23 +02:00
Jonathan Cubides
8f850c2e5b
Fix a bug in the positivity checker (#1943) (#2054)
# Description

This PR fixes #1943. The primary issue stemmed from an incorrect
insertion in the set designated for storing negative type parameters.
Additionally, there was a call site intended to use the variable `typ`,
but I mistakenly used `ty` (which was for something else). To prevent
such silly typos better to adopt more meaningful names.
2023-05-08 20:13:26 +02:00
Jonathan Cubides
c2d8fa44bc Bump version to v0.3.3 🎉 2023-05-08 12:52:11 +02:00
Paul Cadman
6894300e5a
Support module imports in Juvix REPL (#2029)
This PR adds support for importing modules from within a Juvix project
in the Juvix REPL.

The imported module is checked (parsed, arity-checked, type-checked etc)
as normal and added to the REPL session scope. Any errors during the
checking phase is reported to the user.

### Notes:

* You must load a file before using `import`. This is because the REPL
needs to know which Juvix project is active.
* You may only import modules from within the same Juvix project. 

### Examples

After launching `juvix repl`:

#### `open import`

```
Stdlib.Prelude> open import Stdlib.Data.Int.Ord
Stdlib.Prelude> 1 == 1
true
```

#### `import as`

```
Stdlib.Prelude> import Stdlib.Data.Int.Ord as Int
Stdlib.Prelude> 1 Int.== 1
true
```

#### `import`then `open`

```
Stdlib.Prelude> import Stdlib.Data.Int.Ord as Int
Stdlib.Prelude> open Int
Stdlib.Prelude> 1 == 1
true
```

#### Line-terminating semicolons are ignored:

```
Stdlib.Prelude> import Stdlib.Data.Int.Ord as Int;;;;;
Stdlib.Prelude> 1 Int.== 1
true
```

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

---------

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2023-05-08 12:23:15 +02:00
Paul Cadman
70f27fcede
Update to latest stdlib (#2048)
This PR updates the juvix-stdlib submodule. In particular the update
contains the new traits implemented in
https://github.com/anoma/juvix-stdlib/pull/54.

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-05-04 17:49:10 +02:00
Paul Cadman
cdc2d5fd2e
Fix HasExpressions ConstructorApp (#2044)
Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-05-03 11:24:39 +02:00
Veronika Romashkina
935f6fbfb9
Fix fromSource behaviour when both stdin and filename (#2043)
# Description

While working on highlight command, I noticed that after `format`
command changes the behaviour of the `highlight` command when both
`--stdin` option specified and FILENAME is provided is changed.
Instead on returning the result for the `stdin` input, it started to
return empty result.

This PR fixes that behaviour, it will now act exactly as before
introducing the changes that came with the `format` command fixes.

## Type of change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)

# Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works:
  - [x] smoke test
2023-05-02 11:09:56 +02:00
Veronika Romashkina
8ab4ccd73b
Make format command's filepath optional (#2028)
# Description

No the filepath in the `juvix forma` command is n=made optional.
However, in that case, the `--stdin` command is required.

### Implementation details

~For now, as a quick solution, I have introduce the "fake" path that is
used for `fomat` command with stdin option.~
I needed to do a couple of big changes:
* `format` command FILE is now optional, howvere, I check that in case
of `Nothing` `--stdin` option should be present, otherwise it will fail
 * `entryPointModulePaths` is now `[]` instead of `NonEmpty`
* `ScopeEff` now has `ScopeStdin` constructor as well, which would take
the input from stdin instead of having path passed around
* `RunPipelineNoFileEither` is added to the `App` with the bunch of
`*Stdin` functions that doesn't require filepath argument to be passed

Fixes #2008

## Type of change

- [x] New feature (non-breaking change which adds functionality)

# Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works:
  - [x] smoke tests

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
Co-authored-by: janmasrovira <janmasrovira@gmail.com>
2023-04-27 17:33:08 +02:00
janmasrovira
2017bc0504
Add bank example (#2037)
This PR adds the Juvix program for the `Bank` example provided in the
[Leo
workshop
repository](https://github.com/AleoHQ/workshop/blob/master/basic_bank/src/main.leo).
2023-04-27 10:56:31 +02:00