1
1
mirror of https://github.com/anoma/juvix.git synced 2024-09-11 08:15:41 +03:00
Commit Graph

1348 Commits

Author SHA1 Message Date
Jonathan Cubides
0230a7b848
Fix minor: case and error message (#2407)
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-09-29 16:28:59 +02:00
Łukasz Czajka
5642c82a0e
Update benchmarks (#2415)
* Small style improvements
* Update `mapfun.juvix` to use `Int` instead of `Nat` so that it is
semantically equivalent to the other implementations.
* Adapt to #2396
2023-09-29 15:55:52 +02:00
Łukasz Czajka
1260853583
Improve closure calls in the runtime (#2396)
* Closes #1653 

The running time improvement is 20-30% on benchmarks dominated by
closure calls.
2023-09-29 14:20:00 +02:00
Łukasz Czajka
7c3b70459b
Fix delay instance resolution (#2393)
* Closes #2348
2023-09-29 13:08:05 +02:00
Jonathan Cubides
3e5aa5f2ae
Fix tara url svg (#2406) 2023-09-28 19:05:05 +02:00
Łukasz Czajka
e4a5ca7399
Record creation syntax with function definitions (#2369)
* Closes #2280 
* Record creation syntax uses normal function definition syntax like at
the top-level or in lets.
* It is now allowed to omit the result type annotation in function
definitions (the `: ResultType` part) with `_` inserted by default. This
is allowed only for simple definitions of the form `x := value` in lets
and record creation, but not at the top level.
2023-09-28 17:07:38 +02:00
Jonathan Cubides
ccc993a878
Simplify README (#2399) 2023-09-28 15:32:09 +02:00
Jonathan Cubides
f9e27b52f7
Update pre-commit to check JSON formatting (#2400) 2023-09-28 14:55:35 +02:00
Jonathan Cubides
2b566e0870
Remove unused files (#2398)
Merge after
- #2397

---------

Co-authored-by: Łukasz Czajka <62751+lukaszcz@users.noreply.github.com>
2023-09-28 14:20:19 +02:00
Jonathan Cubides
705f2fa1ba
Minor changes to midsquare (#2397) 2023-09-28 13:39:49 +02:00
Jan Mas Rovira
27df3949f5
Add nodes with no edges to the dependency graph (#2390)
- Closes #2373 

Consider this:
```
let 
 x : _ := 0
in ...
```
When translating the let to internal, we build the dependency graph and
then use that to group definitions in mutually recursive blocks. Since
`x` has no edge, it was not being added to the dependency graph, so it
was not being translated to Internal, thus crashing later during
inference.
2023-09-26 13:17:50 +02:00
Łukasz Czajka
0cf993134e
Add fixity none and make aliases inherit fixity (#2391)
* Closes #2310 
* Makes aliases inherit fixity
* Adds `none` fixity definition to the standard library
2023-09-26 11:28:50 +02:00
Łukasz Czajka
019579bba2
Fix case formatting (#2387)
* Closes #2361 
* Aligns `case` and `let`
2023-09-26 10:11:46 +02:00
Łukasz Czajka
e509a6e16e
Instance holes (#2384)
* Closes #2383
2023-09-25 19:11:58 +02:00
Łukasz Czajka
a058487608
Support functions in instance parameters (#2385)
* Closes #2371
2023-09-25 13:08:55 +01:00
Łukasz Czajka
e67f2ec134
Update standard library list functions to use traits (#2382)
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-09-25 12:30:25 +01:00
Paul Cadman
ea1fe1af3d
Avoid serialization of _packageFile field in juvix.yaml (#2381)
The _packageFile field of the Package record is used internally to track
the package file path and is used in error messages. It is not intended
to be present in the juvix.yaml file.

To express this the PackageFileType family with the Raw index is set to
`()`. However `()` is serialized to an empty array by Aeson, so the
`file: []` field was added to juvix.yaml.

NB: From aeson 2.2, fields with type `()` are ommitted when the
`omitNothingFields` flag is set to True, as it is for the package ToJSON
instance.

The solution in this PR is to set `PackageFileType 'Raw` to `Maybe ()`.
The
`omitNothingFields` flag then omits this field from the serialized
package object.


* Closes https://github.com/anoma/juvix/issues/2380
2023-09-21 19:51:31 +01:00
Łukasz Czajka
e4558975b1
Improve inlining (#2377)
Small improvement of the inlining optimization - types are not counted
toward inlining depth limit
2023-09-21 19:12:39 +01:00
Paul Cadman
135a170b21
Do not call git fetch on git dependency if ref already exists in clone (#2379)
During path resolution, `git fetch` is called on every git dependency
clone. It's desirable to reduce the number of `git fetch` calls because
it makes a network call.

This PR changes the git dependency resolution to only call `git fetch`
if the existing clone does not already contain the specified ref.
2023-09-21 19:27:36 +02:00
Łukasz Czajka
6c08cbb8d8
Avoid the -Os option when generating WebAssembly (#2378)
With `-Os` ill-typed code is generated for the following:
```
module wasmcrash.juvix;

import Stdlib.Prelude open;

{-# inline: false #-}
I {A} (x : A) : A := x;

{-# inline: false #-}
I' {A} (x : A) : A := x;

main : Nat := I' (I I 1);
```
Running the generated WASM file with `wasmer` or `wasmtime` gives an
error:
```
Validation error: type mismatch: expected i32 but nothing on stack (at offset 740)
```
The issue occurs with clang version 16.0.5 but not 16.0.0. The issue
does not occur with any other optimization option (`-O1`, `-O2`, `-O3`).
There is no issue with `-Os` used with the native target.

This is thus likely a bug in a specific version of LLVM. It could be
theoretically some very subtle non-conformance to the C standard in our
generated code, but this seems less likely. Creating a minimum C file
exposing the bug would be very time-consuming, so I propose to just
avoid using the `-Os` option for now.
2023-09-21 13:15:36 +01:00
Łukasz Czajka
fe90da58ed
Error for an instance subsumed by other instances (#2375)
* Closes #2372
2023-09-21 11:12:49 +01:00
Łukasz Czajka
c5d8641142
Error on local instances (#2376)
* Closes #2374

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-09-21 10:34:28 +01:00
Paul Cadman
6050b4061f
Bump version to 0.5.1 (#2370)
Juvix 0.5.1 is a bug fix release that contains just
https://github.com/anoma/juvix/pull/2368

- [x] Package version
- [x] Smoke test
- [x] Changelog
2023-09-15 13:31:23 +01:00
Łukasz Czajka
487fc58ba6
Fix bug in isTrait (#2368)
* Closes #2367
2023-09-14 17:50:38 +01:00
Paul Cadman
f84dcb4a50
Bump version to 0.5.0 and update CHANGELOG (#2366)
This PR updates:
- [x] Package version
- [x] Smoke test
- [x] Changelog
2023-09-14 12:41:54 +01:00
Paul Cadman
d6820f5030
Update stdlib submodule to current stdlib main (#2364)
This PR updates the stdlib submodule reference to point to
anoma/juvix-stdlib:main, after merging
https://github.com/anoma/juvix-stdlib/pull/80 and
https://github.com/anoma/juvix-stdlib/pull/81
2023-09-14 11:01:21 +01:00
Jan Mas Rovira
8daca2ba0a
New fixity/iterator syntax (#2332)
- Closes #2330
- Closes #2329 

This pr implements the syntax changes described in #2330. It drops
support for the old yaml-based syntax.
Some valid examples:
```
syntax iterator for {init := 1; range := 1};

syntax fixity cons := binary {assoc := right};
syntax fixity cmp := binary;
syntax fixity cmp := binary {}; -- debatable whether we want to accept empty {} or not. I think we should
```
# Future work
This pr creates an asymmetry between iterators and operators
definitions. Iterators definition do not require a constructor. We could
add it to make it homogeneous, but it looks a bit redundant:
```
syntax iterator for := mkIterator {init := 1; range := 1};
```

We could consider merging iterator and fixity declarations with this
alternative syntax.
```
syntax XXX for := iterator {init := 1; range := 1};

syntax XXX cons := binary {assoc := right};
```
where `XXX` is a common keyword. Suggestion by @lukaszcz XXX = declare

---------

Co-authored-by: Łukasz Czajka <62751+lukaszcz@users.noreply.github.com>
Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2023-09-14 10:57:38 +02:00
Łukasz Czajka
218e4d3484
Add newlines at end of JSON files (#2360)
* Closes #2349
2023-09-13 17:09:59 +02:00
Łukasz Czajka
95665283ac
Update the standard library to use the trait framework (#2359)
* Updates standard library to use traits
* Updates tests
2023-09-13 14:48:25 +02:00
Łukasz Czajka
fb3c897e9f
Fix instance import (#2350)
Fixes a bug which prevented some instances from being imported from
other modules.
2023-09-13 13:46:30 +02:00
Paul Cadman
c239d4a83d
Add new case syntax (#2353) 2023-09-13 11:58:08 +01:00
Paul Cadman
327cfaa0f6
Remove duplicated implicit pattern check from scoper (#2357)
This PR removes the CaseBranchImplicit error from the scoper. This error
is already handled in the arity/typechecker with a good error message:

 The arity checker error message for

```
   case b of {
      | {{true}} := false
```
is 

```
Expected an explicit pattern but found an implicit instance pattern: {{true}}
```

* Closes https://github.com/anoma/juvix/issues/2356
2023-09-13 12:16:05 +02:00
Łukasz Czajka
1710615fb0
VampIR range checks and error handling (#2344)
* Adds range checks and proper error handling to the Juvix-to-VampIR
pipeline.
* Adds the `--unsafe` option which disables the checks.
2023-09-12 19:56:28 +02:00
Jan Mas Rovira
73e2cf0fa8
Small refactor for traits (#2345)
This pr simplifies parsing by removing `FunctionParameterUnnamed`. It
also removes ghost wildcards introduced during parsing.

It also introduces an error for double braced atoms `{{x}}` that are not
on the left of an arrow `->`
2023-09-08 17:22:21 +02:00
Łukasz Czajka
08f123fa3d
Traits (#2320)
* Closes #1646 

Implements a basic trait framework. A simple instance search mechanism
is included which fails if there is more than one matching instance at
any step.

Example usage:
```
import Stdlib.Prelude open hiding {Show; mkShow; show};

trait
type Show A :=
  mkShow {
    show : A → String
  };

instance
showStringI : Show String := mkShow (show := id);

instance
showBoolI : Show Bool := mkShow (show := λ{x := if x "true" "false"});

instance
showNatI : Show Nat := mkShow (show := natToString);

showList {A} : {{Show A}} → List A → String
  | nil := "nil"
  | (h :: t) := Show.show h ++str " :: " ++str showList t;

instance
showListI {A} {{Show A}} : Show (List A) := mkShow (show := showList);

showMaybe {A} {{Show A}} : Maybe A → String
  | (just x) := "just (" ++str Show.show x ++str ")"
  | nothing := "nothing";

instance
showMaybeI {A} {{Show A}} : Show (Maybe A) := mkShow (show := showMaybe);

main : IO :=
  printStringLn (Show.show true) >>
  printStringLn (Show.show false) >>
  printStringLn (Show.show 3) >>
  printStringLn (Show.show [true; false]) >>
  printStringLn (Show.show [1; 2; 3]) >>
  printStringLn (Show.show [1; 2]) >>
  printStringLn (Show.show [true; false]) >>
  printStringLn (Show.show [just true; nothing; just false]) >>
  printStringLn (Show.show [just [1]; nothing; just [2; 3]]) >>
  printStringLn (Show.show "abba") >>
  printStringLn (Show.show ["a"; "b"; "c"; "d"]);
```

It is possible to manually provide an instance and to match on implicit
instances:
```
f {A} : {{Show A}} -> A -> String
  | {{mkShow s}} x -> s x;

f' {A} : {{Show A}} → A → String
  | {{M}} x := Show.show {{M}} x;
```

The trait parameters in instance types are checked to be structurally
decreasing to avoid looping in the instance search. So the following is
rejected:
```
type Box A := box A;

trait
type T A := mkT { pp : A → A };

instance
boxT {A} : {{T (Box A)}} → T (Box A) := mkT (λ{x := x});
```
We check whether each parameter is a strict subterm of some trait
parameter in the target. This ordering is included in the finite
multiset extension of the subterm ordering, hence terminating.
2023-09-08 12:16:43 +02:00
Jan Mas Rovira
df144ab3a5
Add Internet effect (#2337) 2023-09-07 18:26:19 +02:00
Jan Mas Rovira
36b390fcb0
Improve formatting of single-constructor types and records (#2342)
- Closes #2331.

The rules implemented in this pr are as follows.
1. If a type definition has only one constructor, no pipe is added. The
constructor is printed in the same line if it fits.
2. If a constructor is a record with a single field, the field is
printed in the same line if it fits. If the constructor has multiple
fields, they are printed aligned and indented after a line break.

Examples:
```
type T := constructT : T;

type T-wrapper := mkWrapper {unwrap : T};

type EnumRecord :=
  | --- doc for C1
    C1 {
      c1a : T;
      c1b : T
    }
  | C2 {
      c2a : T;
      c2b : T
    };
```
2023-09-07 16:20:14 +02:00
Jan Mas Rovira
ce58057c44
Allow named arguments in type synonyms (#2343)
- Closes #2338
2023-09-06 14:42:45 +02:00
Paul Cadman
382a4d3cef
Global offline flag (#2335)
This PR introduces a global `--offline` flag.

## Doctor

This replaces the `--offline` flag on the doctor command.

## Juvix package builds

The flag applies to juvix build commands like `juvix compile`, `juvix
repl`. This is so that users can continue to build packages offline that
have external dependencies when there's no network connection (as long
as they built the same package online previously).

Specifically, when the `--offline` flag is used in a package that has
external git dependencies.
* No `git clone` or `git fetch` commands are used
* `git checkout` will continue to be used
* Clones from previous builds are reused

This means that you can update the `ref` field in a git dependency, as
long as the ref existed the last time that the project was built without
the `--offline` flag.

* Closes https://github.com/anoma/juvix/issues/2333
2023-09-05 17:11:17 +02:00
Jan Mas Rovira
9dd9b50517
Add macchiato html theme (#2323)
Cute theme: https://github.com/catppuccin/catppuccin#-palette
2023-09-04 21:07:53 +02:00
Paul Cadman
7a9b21a4f8
External package dependencies (#2272)
This PR adds external git dependency support to the Juvix package
format.

## New dependency Git item

You can now add a `git` block to the dependencies list:

```yaml
name: HelloWorld
main: HelloWorld.juvix
dependencies:
  - .juvix-build/stdlib
  - git:
      url: https://my.git.repo
      name: myGitRepo
      ref: main
version: 0.1.0
```

Git block required fields:
* `url`: The URL of the git repository
* `ref`: The git reference that should be checked out
* `name`: The name for the dependency. This is used to name the
directory of the clone, it is required. Perhaps we could come up with a
way to automatically name the clone directory. Current ideas are to
somehow encode the URL / ref combination or use a UUID. However there's
some value in having the clone directory named in a friendly way.

NB:
* The values of the `name` fields must be unique among the git blocks in
the dependencies list.

## Behaviour

When dependencies for a package are registered, at the beginning of the
compiler pipeline, all remote dependencies are processed:

1. If it doesn't already exist, the remote dependency is cloned to
`.juvix-build/deps/$name`
2. `git fetch` is run in the clone
3. `git checkout` at the specified `ref` is run in the clone

The clone is then processed by the PathResolver in the same way as path
dependencies.

NB:
* Remote dependencies of transitive dependencies are also processed.
* The `git fetch` step is required for the case where the remote is
updated. In this case we want the user to be able to update the `ref`
field.

## Errors

1. Missing fields in the Git dependency block are YAML parse errors
2. Duplicate `name` values in the dependencies list is an error thrown
when the package file is processed
3. The `ref` doesn't exist in the clone or the clone directory is
otherwise corrupt. An error with a suggestion to `juvix clean` is given.
The package file path is used as the location in the error message.
4. Other `git` command errors (command not found, etc.), a more verbose
error is given with the arguments that were passed to the git command.

## Future work

1. Add an offline mode
2. Add a lock file mechanism that resolves branch/tag git refs to commit
hashes

* closes https://github.com/anoma/juvix/issues/2083

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-09-01 12:37:06 +01:00
Jan Mas Rovira
f463aeed0c
Generate documentation for local modules in the html backend (#2326)
![image](https://github.com/anoma/juvix/assets/5511599/bffc47d1-660e-484a-8bca-e61fc7e15cd9)

Local modules are shown as regular statements, with their definitions
displayed nested
2023-08-31 16:31:19 +01:00
Jan Mas Rovira
3c5304ff9d
Show all available html themes in the CLI automatically (#2322) 2023-08-31 16:53:10 +02:00
Jan Mas Rovira
340f1927ae
Generate html documentation for alias and fixity definitions (#2327)
![image](https://github.com/anoma/juvix/assets/5511599/91eb9f54-370b-4036-8aea-a39b1008b7f0)


![image](https://github.com/anoma/juvix/assets/5511599/abc0100b-5f7e-444e-adec-867707d03997)
2023-08-31 15:07:38 +01:00
Jan Mas Rovira
afa5251418
Generate function signatures in the html backend (#2325)
This stopped working when we implemented the new function syntax and
removed the old one.
- Closes #2324
2023-08-31 13:11:17 +02:00
Jan Mas Rovira
da5c1546b8
Add fixity face (#2328) 2023-08-31 11:54:37 +02:00
Jan Mas Rovira
34719bbc4d
Report termination errors after typechecking (#2318)
- Closes #2293.
- Closes #2319 

I've added an effect for termination. It keeps track of which functions
failed the termination checker, which is run just after translating to
Internal. During typechecking, non-terminating functions are not
normalized. After typechecking, if there is at least one function which
failed the termination checker, an error is reported.
Additionally, we now properly check for termination of functions defined
in a let expression in the repl.
2023-08-30 16:38:59 +02:00
Jan Mas Rovira
92714b8254
Add css colors ju-comment and ju-judoc (#2321)
This pr adds colors for comments and judoc for the html backend
2023-08-30 15:55:15 +02:00
Jan Mas Rovira
15574caf02
Add pragma face (#2312)
This pr assigns pragmas their own face, as opposed to the same face as
regular comments.
2023-08-29 19:42:17 +01:00
Łukasz Czajka
3a1c519939
Fix record pattern formatting (#2314)
* Closes #2279
2023-08-28 13:54:22 +02:00