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

1055 Commits

Author SHA1 Message Date
Paul Cadman
264ac10f17
Fix PrettyCode (Maybe a) instance "Just" case (#1966)
`PrettyCode (Maybe a)` should print "Just" instead of "Nothing" in the
Just case.
2023-04-03 15:36:43 +02:00
Paul Cadman
9e1e72d6b6
repl: Run disambiguateNames on result node (#1961)
There were two bugs here:

1. The _replNoDisambiguate option was set to True for `juvix repl`.
2. The disambiguateNames pass was being applied after the result node
had already been fetched from the infotable.

* Closes https://github.com/anoma/juvix/issues/1958
2023-04-03 10:58:08 +02:00
janmasrovira
ff495ef326
Support local modules (#1872)
Support local modules.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-03-31 14:57:37 +01:00
Jonathan Cubides
bd43ee9f10 Bump version to 0.3.1 🎉 2023-03-31 11:50:06 +02:00
Łukasz Czajka
2c49f0e5fe
Let-folding after lifting (#1955)
Now that lifting preserves the types, we can fold the lets afterwards.
This is a cheap optimisation that should always be done. In the WASM
pipeline it avoids allocating closures for constant functions assigned
to let-variables. In the GEB pipeline it reduces the size of the term
and the number of variables.
2023-03-31 09:48:42 +02:00
Paul Cadman
5d4cb904e8
Add juvix dev repl command (#1941)
The new `juvix dev repl` command is a copy of the `juvix repl` with the
addition of `--no-disambiguate` flag that is present on the `juvix dev
core from-concrete` command.

The `juvix repl` command now does not have the `--transforms`,
`--show-de-bruijn` flags as these are only relevant for compiler
developers. The eval transforms are always applied.

By default `juvix dev repl` uses the eval transforms. You can override
this by specifying the `-t` flag.

Also we now run `disambiguateNames` transform on the info table in the
`dev repl` (unless the `--no-disambiguate-names` flag is set). This is
so the output of the `juvix dev repl` will match that of `juvix dev core
from-concrete` and also so the output can be parsed by back the core
parser.

* Closes https://github.com/anoma/juvix/issues/1914
2023-03-31 00:57:44 +02:00
Łukasz Czajka
93750570df
Add fail nodes to Geb (#1947)
* Adds `fail` morphisms to Geb.Language and Geb.Evaluator.
* Enables recursion in the Core-to-Geb pipeline.
* Adds recursion tests.
2023-03-30 20:52:23 +02:00
Łukasz Czajka
74a83e4489
Fix a bug in closure traversal (#1953)
The number of binders was not correct, which made the evaluator crash
sometimes when printing error messages.
2023-03-30 20:15:22 +02:00
Łukasz Czajka
58dbf62520
Fix removal of polymorphic type arguments (#1954)
* Closes #1930
2023-03-30 19:56:07 +02:00
janmasrovira
23824610c2
Update typecheck command to check for coverage (#1952) 2023-03-30 19:36:38 +02:00
janmasrovira
9e9a884fdb
Preserve the target type in letrec lifting (#1945)
- Closes #1887
2023-03-30 18:02:37 +02:00
janmasrovira
e1e4216504
Add Judoc syntax reference (#1934)
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-03-30 16:18:02 +01:00
janmasrovira
90a7a5e7e0
Fix REPL state to include enough information to rerun the pipeline (#1911)
Previously we were:
* discarding the types table 
* discarding the name ids state
after processing an expression in the REPL.

For example evaluating:
```
let even : _; odd : _; odd zero := false; odd (suc n) := not (even n); even zero := true; even (suc n) := not (odd n) in even 10
```
would loop in the REPL.

We noticed that the `n` in `suc n` was being given type `Type` instead
of `Nat`. This was because the name id given to n was incorrect, the
REPL started using name ids from 0 again.

We fixed this issue by storing information, including the types table
and name ids state in the Artifacts data structure that is returned when
we run the pipeline for the first time. This information is then used
when we call functions to compile / type check REPL expressions.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-03-30 13:39:27 +02:00
Łukasz Czajka
bcf1d0f779
Option --show-args-num (#1946)
* Adds an options to display the `_identifierArgsNum` field when
printing Core definitions.
2023-03-30 12:23:40 +01:00
Łukasz Czajka
dd11ed2a42
Filter out type synonyms in RemoveTypeArgs (#1949) 2023-03-30 12:40:05 +02:00
Paul Cadman
c4be202dc0
CI: Ignore errors linux typecheck / format examples step (#1950)
There's an error with this step on linux only, but we cannot see it
because of the `-s` flag on the Makefile call.

This commit removes the `-s` flag so we can diagnose the problem, but
also temporarily ignores the error to avoid blocking other PRs.

NB: This step passes on macOS.
2023-03-30 11:25:01 +02:00
Łukasz Czajka
fb06d78484
Refactor Geb values (#1940)
* Geb value representation changed to match more closely with the
morphism representation.
* Implements quoting Geb values
2023-03-29 17:53:45 +02:00
Paul Cadman
1ab3aa06da
Add juvix format command (#1886)
This PR adds `juvix format` that can be used to format either a single
Juvix file or all files in a Juvix project.

## Usage

```
$ juvix format --help
Usage: juvix format JUVIX_FILE_OR_PROJECT [--check] [--in-place]

  Format a Juvix file or Juvix project

  When the command is run with an unformatted file it prints the reformatted source to standard output.
  When the command is run with a project directory it prints a list of unformatted files in the project.

Available options:
  JUVIX_FILE_OR_PROJECT    Path to a .juvix file or to a directory containing a
                           Juvix project.
  --check                  Do not print reformatted sources or unformatted file
                           paths to standard output.
  --in-place               Do not print reformatted sources to standard output.
                           Overwrite the target's contents with the formatted
                           version if the formatted version differs from the
                           original content.
  -h,--help                Show this help text
```

## Location of main implementation

The implementation is split into two components:
* The src API: `format` and `formatProject`
73952ba15c/src/Juvix/Formatter.hs
* The CLI interface:  

73952ba15c/app/Commands/Format.hs

## in-place uses polysemy Resource effect

The `--in-place` option makes a backup of the target file and restores
it if there's an error during processing to avoid data loss. The
implementation of this uses the polysemy [Resource
effect](https://hackage.haskell.org/package/polysemy-1.9.0.0/docs/Polysemy-Resource.html).
The recommended way to interpret the resource effect is to use
`resourceToIOFinal` which makes it necessary to change the effects
interpretation in main to use `Final IO`:
73952ba15c/app/Main.hs (L15)

## Format input is `FilePath`

The format options uses `FilePath` instead of `AppFile f` for the input
file/directory used by other commands. This is because we cannot
determine if the input string is a file or directory in the CLI parser
(we require IO). I discussed some ideas with @janmasrovira on how to
improve this in a way that would also solve other issues with CLI input
file/parsing but I want to defer this to a separate PR as this one is
already quite large.

One consequence of Format using `FilePath` as the input option is that
the code that changes the working directory to the root of the project
containing the CLI input file is changed to work with `FilePath`:


f715ef6a53/app/TopCommand/Options.hs (L33)

## New dependencies

This PR adds new dependencies on `temporary` and `polysemy-zoo`.

`temporary` is used for `emptySystemTempFile` in the implementation of
the TempFile interpreter for IO:


73952ba15c/src/Juvix/Data/Effect/Files/IO.hs (L49)

`polysemy-zoo` is used for the `Fresh` effect and `absorbMonadThrow` in
the implementation of the pure TempFile interpreter:

73952ba15c/src/Juvix/Data/Effect/Files/Pure.hs (L91)

NB: The pure TempFile interpreter is not used, but it seemed a good idea
to include it while it's fresh in my mind.

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

---------

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2023-03-29 15:51:04 +02:00
Łukasz Czajka
3c3e442c81
End-to-end Geb compilation tests (#1942)
* Adds end-to-end tests for compiling Juvix to Geb
* Fixes bugs in the Core-to-Geb translation (`<=` and `let`)
* Fixes a bug in the Geb evaluator (equality on integers)
2023-03-29 14:02:40 +02:00
Łukasz Czajka
fac6be3bf8
Add syntax highlighting to Core error messages (#1938)
* Closes #1927
2023-03-28 16:46:18 +02:00
janmasrovira
9c90dd1390
Avoid capturing the same free variable multiple times in letrec lifting (#1939)
- Fixes #1666
2023-03-28 13:38:45 +02:00
Łukasz Czajka
df27dc8e3f
Add the --unroll option (#1935)
* Closes #1928

---------

Co-authored-by: janmasrovira <janmasrovira@gmail.com>
2023-03-28 11:41:05 +02:00
Łukasz Czajka
2b5524ded1
Preserve name and location information in Internal-to-Core (#1933)
* Closes #1846 
* Preserves location information for all created `Match` nodes so that
match-to-case always has a location available.
2023-03-28 10:29:24 +02:00
Łukasz Czajka
09d307c37b
Polymorphic type inference in Core (#1931)
* Modifies `ComputeTypeInfo` to handle polymorphism and the dynamic type
(doesn't check for correctness but infers the types under the assumption
that binder type annotations and type info for identifiers are correct).
* Add the `:t expr` command in JuvixCore repl to print the inferred
type.
* Adds a smoke test.
2023-03-27 19:27:10 +02:00
janmasrovira
073b7f706d
Fix spacing of judoc in the formatter (#1932)
- Closes https://github.com/anoma/juvix/issues/1922
2023-03-27 17:32:26 +02:00
Jonathan Cubides
9f22eaa1cf
Test core to geb translation (#1865)
This PR adds testing for the core-to-geb translation.
It works as follows:

  1. Parse the Juvix Core file.
  2. Prepare the Juvix Core node for translation to Geb.
  3. Translate the Juvix Core node to Geb.
5. Perform type checking on the translated Geb node to ensure that the
types
from the core node make sense in the Geb context and avoid any Geb
runtime
     errors.
6. Evaluate the Juvix Core node to see if it produces the expected
result.
7. Translate the result of the evaluated Juvix Core node to Geb for
comparison
     with the expected output later.
8. Compare the result of the evaluation of the Geb term produced in step
3
with the result of the evaluation of the Geb term produced in step 6 to
     ensure consistency.
9. If step 8 succeeds, then compare the output of step 6 (the evaluation
of the core
     node) with the expected output (given in Geb format) to ensure that
     the program is functioning as intended.

This PR goes after:

- https://github.com/anoma/juvix/pull/1863
and
https://github.com/anoma/juvix/pull/1832
2023-03-27 15:32:03 +02:00
Łukasz Czajka
c9b8cdd5e9
Pattern matching compilation (#1874)
This implements a basic version of the algorithm from: Luc Maranget,
[Compiling pattern matching to good decision
trees](http://moscova.inria.fr/~maranget/papers/ml05e-maranget.pdf). No
heuristics are used - the first column is always chosen.

* Closes #1798 
* Closes #1225 
* Closes #1926 
* Adds a global `--no-coverage` option which turns off coverage checking
in favour of generating runtime failures
* Changes the representation of Match patterns in JuvixCore to achieve a
more streamlined implementation
* Adds options to the Core pipeline
2023-03-27 10:42:27 +02:00
Łukasz Czajka
55374ec96a
Recursion unrolling for functions (#1912)
* Depends on PR #1909 
* Closes #1750 
* Adds recursion unrolling tests on JuvixCore
* Adds a version of the mid-square hash example without the recursion
manually unrolled

For now, the recursion is always unrolled to a fixed depth (140). In the
future, we want to add a global option to override this depth, as well
as a mechanism to specify it on a per-function basis. In a more distant
future, we might want to try deriving the unrolling depth heuristically
for each function.
2023-03-24 15:05:37 +01:00
Paul Cadman
4044676628
Add a test suite for milestone examples (#1920)
In this PR I will add tests for the example programs in
`examples/milestone`.

There's currently an runtime assertion error generated by the Hanoi
example https://github.com/anoma/juvix/issues/1919, so it'd be good to
test these programs in the future.
2023-03-24 13:16:26 +00:00
Łukasz Czajka
86c18f37af
Let folding (#1921)
* Closes #1899
2023-03-24 12:35:47 +01:00
Jonathan Cubides
c7e4056077
Add --numeric-version flag (#1918)
As the title says. 

```
❯ juvix --numeric-version
0.3.0
```
2023-03-24 10:45:53 +01:00
Łukasz Czajka
8d7e669f74
Fix bug with unregistered builtin bool (#1917)
* Closes #1884
2023-03-24 10:29:57 +01:00
Paul Cadman
ebb4a27b69
bench: Fix juvix compile flag for wasm (#1925) 2023-03-23 21:42:42 +00:00
Jonathan Cubides
c22cd5cc45
Update README.md with Juvix nightly builds badge (#1923) 2023-03-23 21:50:27 +01:00
Łukasz Czajka
6eae6c405c
Fix memory count for string operations (#1924)
* Closes #1919
2023-03-23 19:47:51 +00:00
Jonathan Cubides
dbe9ff61d7
Update GitHub pages deployment using deploy-pages action (#1910)
This PR changes two things:

- Deploy the documentation website using the (official) deploy action:
  - https://github.com/actions/deploy-pages
- Check the documentation generation for all the PRs. 

- PR on top of:
  - #1905 
  - #1908   

After merging this PR, we could delete the github-pages branch.
2023-03-23 15:07:54 +01:00
Jonathan Cubides
2baab83847
Create clean-up-cache.yaml (#1915)
This pull request introduces a new workflow that automatically deletes
caches created for closed pull requests. This is necessary because these
caches can quickly accumulate and take up valuable server space, which
is especially important now that we have many pull requests being
created regularly.
2023-03-23 14:48:21 +01:00
Łukasz Czajka
906720cb02
Check for recursive inductive types in the GEB pipeline (#1909)
Currently, only recursion in functions is checked. This PR also adds
some utilities (TypeDependencyInfo) that will be useful for issue #1907.

---------

Co-authored-by: janmasrovira <janmasrovira@gmail.com>
2023-03-23 14:08:10 +01:00
Jonathan Cubides
839093cdbd
CI pre-commit maintenance (#1905)
This PR goes after:
- #1797 

Included in this PR:

- Add Clang formatting (v.15) as part of the pre-commits.
- Add new pre-commits:
   - forbid binary files 
   - check toml files for mdbook
   - detect-private-key
- format-juvix-examples: check all the Juvix programs in the `examples`
folder type-check for local runs.
- Remove .pre-commit-hooks and add ormolu for local pre-commit runs
instead.
2023-03-23 08:57:38 +00:00
Jonathan Cubides
22ba8f15fd
Add new README and md files (#1904)
In this PR, I have updated the README file to reflect the new goals of
the project and highlight related products to Juvix. The ORG files have
been replaced with Markdown for better readability and maintainability.
Additionally, I have added a couple of files to fine-tune the mdbook
settings. These changes, I believe, will make it easier for users to
understand and contribute to the project.🤞

- Closes #1878
- New pre-commit hook to format md, yaml, js, CSS files.

To check the website generation, I have deployed the result here:
Work in progress.

- https://jonaprieto.github.io/juvix
- https://github.com/jonaprieto/juvix

---------

Co-authored-by: Paul Cadman <pcadman@gmail.com>
Co-authored-by: Christopher Goes <cwgoes@pluranimity.org>
Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-03-21 20:01:48 +01:00
Jonathan Cubides
6a538029e1
CI Haskell fix for macOS build (#1908)
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-03-21 18:16:24 +00:00
Jonathan Cubides
72f1586d12
CI Haskell maintenance (#1797)
This PR does CI maintenance consisting of the following:

- Use https://github.com/freckle/stack-action to build and test the
Haskell codebase
- Update Gh-release action:
https://github.com/jaxxstorm/action-install-gh-release/pull/39 is merged
into the main branch, so we return to the original GitHub action.
- Simplifies pre-commit action. Use the `SKIP` environmental variable to
avoid running ormolu in the CI.
- The ormolu Github action now supports version input since v11. Fixed
to use `Ormolu v0.5.2`.
  - https://github.com/mrkkrp/ormolu-action/issues/26),
2023-03-21 16:45:21 +01:00
Łukasz Czajka
2a8585ede0
Fix bug in IO runtime (#1906)
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-03-21 14:34:46 +00:00
Łukasz Czajka
2803f3feee
Fix JuvixAsm validation (#1903)
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-03-20 12:01:35 +00:00
Paul Cadman
51978f947c
Fix registration of builtin inductive axioms (#1901)
builtin inductive axioms must be registered in the same pass as
inductive types becuase inductive types may use builtin inductives in
the types of their constructors.

```
builtin string axiom String : Type;

type BoxedString :=
  | boxed : String -> BoxedString;
```

The separate passes for processing functions and inductives was
unnecessary. This commit combines `registerInductiveDefs` and
`registerFunctionDefs` into a single pass over a modules statements
2023-03-20 10:00:22 +00:00
Łukasz Czajka
ac6d08e259
Add errors to the Core pipeline and check GEB prerequisites (#1871)
* Depends on #1832 
* Closes #1844
* Adds errors to the Core pipeline
* Checks for no recursion in the GEB pipeline
* Checks for no polymorphism in the GEB pipeline
* Checks for no dynamic type in the GEB pipeline
* Checks for no IO in the GEB pipeline
* Checks for no unsupported builtins in the GEB pipeline
2023-03-20 10:13:07 +01:00
Paul Cadman
786ff9d075
internal-to-core: Fix index shifting of pattern arguments (#1900) 2023-03-18 00:30:51 +01:00
Łukasz Czajka
bd17e957a1
Fix de Bruijn indices in rmap (#1898)
There was a subtle bug in `rmap` when `recur` was called on a variable.
This PR fixes it.
2023-03-17 13:11:36 +01:00
janmasrovira
3dac3c87c9
Normalize types in repl (#1897) 2023-03-17 12:44:45 +01:00
janmasrovira
934a273e2d
Automatically detect and split mutually recursive blocks in let expressions (#1894)
- Closes #1677
2023-03-17 11:05:55 +00:00