1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-13 11:16:48 +03:00
Commit Graph

1282 Commits

Author SHA1 Message Date
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
Łukasz Czajka
e8fa77a58d
Fix record update formatting (#2315)
* Closes #2287
2023-08-28 13:11:26 +02:00
Paul Cadman
227a51a56d
Install wasmer binary from Github releases (#2317)
The wasmerio/setup-wasmer action is causing failures on CI

e.g
https://github.com/anoma/juvix/actions/runs/5978292661/job/16220075597

This PR installs wasmer directly from GitHub releases instead.
2023-08-28 09:32:26 +02:00
Jan Mas Rovira
491f7f7508
Update ci to use ormolu 0.5.3.0 and reformat project (#2313)
Updates ormolu to 0.5.3.0 and formats the project
2023-08-25 17:37:23 +01:00
Łukasz Czajka
93a91a70a7
Remove open import syntax (#2307)
* Closes #2252 
* Depends on #2305
2023-08-25 16:43:34 +02:00
Jan Mas Rovira
ef16b45ca6
Aliasing (#2301)
- Closes #2188.

This pr introduces a new syntactical statement for defining aliases:
```
syntax alias newName := oldName;
```
where `oldName` can be any name in the expression namespace. Fixity and
module aliases are not supported at the moment.

- The `newName` does not inherit the fixity of `oldName`. We have agreed
that the goal is to inherit the fixity of `oldName` except if `newName`
has a fixity statement, but this will be done in a separate pr as it
requires #2310.
2023-08-25 15:28:58 +02:00
Łukasz Czajka
2baad15a41 Remove old function syntax (#2305)
* Enables new function syntax in local let-declarations
* Closes #2251
2023-08-24 16:24:47 +02:00
Jonathan Cubides
56871a204c Bump version to v0.4.3 2023-08-24 16:24:40 +02:00
Paul Cadman
a167fee9d8
Fix shell variables in linux static build stack install (#2309) 2023-08-23 23:36:26 +01:00
Paul Cadman
06346d18de
Replace gitrev with githash for obtaining build-time git info (#2308)
This PR replaces [gitrev](https://hackage.haskell.org/package/gitrev)
with [githash](https://hackage.haskell.org/package/githash) which
provides more reliable git information about the current git info, it
seems to work as expected. githash originated as a fork of gitrev
containing fixes https://github.com/snoyberg/githash/issues/11

This PR also fixes the issue with git info detection in the linux static
build. There was a permission issue in the build container that caused
git cli calls to fail.

Closes:
* https://github.com/anoma/juvix/issues/2294
* https://github.com/anoma/juvix/issues/2130
2023-08-23 15:53:23 +01:00
Jan Mas Rovira
5194e7c2cd
Check that type functions are supported (#2306)
- Closes #2297 

When the type of function definition is of the form `... -> Type` it has
to have only one clause and no pattern matching.
2023-08-23 13:18:57 +02:00
Łukasz Czajka
fa7489a9cb
Minor comment updates (#2303) 2023-08-22 15:26:45 +02:00
Paul Cadman
da9e511bab
Update stdlib to use new ADT and record syntax (#2302)
The associated stdliib PR is:

* https://github.com/anoma/juvix-stdlib/pull/76
2023-08-22 13:50:14 +02:00
Jan Mas Rovira
d57f1a3d64
Fix bug in arity checker with pi types (#2300)
All variables bound in a pi type were assumed to be of arity unit. This
pr fixes that.

- Closes #2296
2023-08-22 11:40:12 +02:00
Łukasz Czajka
63a94bb976
Allow omitting : Type in implicit function argument definitions and in type definitions (#2291)
* Closes #2281

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-08-22 10:32:26 +02:00
Łukasz Czajka
4b29f551b4
Allow wildcard arguments in new function definition syntax (#2295)
* Closes #2288
2023-08-16 17:51:09 +02:00
Łukasz Czajka
8095e52c21
Check for incomparable precedences (#2289)
Give an error when there are two operators with incomparable precedences
instead of linearising the ordering arbitrarily.
2023-08-16 16:33:29 +02:00