1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00
juvix/test/Core
Paul Cadman 0a8799a344
Use a Juvix source file to define a package (#2434)
Depends on:
* ~~https://github.com/anoma/juvix/pull/2459~~
* https://github.com/anoma/juvix/pull/2462

This PR is part of a series implementing:
* https://github.com/anoma/juvix/issues/2336

This PR adds the package file loading function, including a file
evaluation effect. It integrates this with the existing `readPackage`
function and adds tests / smoke tests.

## Package.juvix format

Instead of `juvix.yaml` (which is still supported currently) users can
now place a `Package.juvix` file in the root of their project. The
simplest `Package.juvix` file you can write is:

```
module Package;

import PackageDescription open;

package : Package := defaultPackage;
```

The
[PackageDescription](35b2f618f0/include/package/PackageDescription.juvix)
module defines the `Package` type. Users can use "go-to definition" in
their IDE from the Package file to see the documentation and
definitions.

Users may also import `Stdlib.Prelude` in their Package file. This is
loaded from the global project. No other module imports are supported.

Notes:
* If a directory contains both `Package.juvix` and `juvix.yaml` then
`Package.juvix` is used in preference.

## Default stdlib dependency

The `Dependency` type has a constructor called `defaultStdlib`. This
means that any project can use the compiler builtin standard library
dependency. With `juvix.yaml` this dependency is only available when the
`dependencies` field is unspecified.

```
module Package;

import PackageDescription open;

package : Package := defaultPackage { dependencies := [defaultStdlib] };
```

## Validation

As well as the standard type checking validation that the Juvix compiler
provides additional validation is made on the file.

* The Package module must contain the identifier `package` and it must
have type `Package` that's obtained from the global `PackageDescription`
module.
* Every dependency specified in the Package.juvix must be unique.

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

## Examples

### Package with name and version

```
module Package;

import PackageDescription open;

package : Package :=
  defaultPackage {name := "a-package";
                  version := mkVersion 0 1 0};
```

### Package with GitHub dependency

```
module Package;

import PackageDescription open;

package : Package :=
  defaultPackage {name := "a-package";
                  version := mkVersion 0 1 0;
                  dependencies := [defaultStdlib;
                                   github (org := "anoma";
                                           repo := "juvix-containers";
                                           ref := "v0.7.1")]};
```

## Package with main and buildDir fields

```
module Package;

import Stdlib.Prelude open;
import PackageDescription open;

package : Package :=
  defaultPackage {name := "a-package";
                  version := mkVersion 0 1 0;
                  dependencies := [defaultStdlib;
                                   github (org := "anoma";
                                           repo := "juvix-containers";
                                           ref := "v0.7.1")];
                  buildDir := just "/tmp/build";
                  main := just "HelloWorld.juvix"
                };

```
2023-10-27 12:35:20 +01:00
..
Asm Add Bottom node (#2112) 2023-05-23 18:31:28 +02:00
Compile Constant folding (#2450) 2023-10-20 12:03:56 +02:00
Eval Use a Juvix source file to define a package (#2434) 2023-10-27 12:35:20 +01:00
Normalize Switch to Halo2 for VampIR backend tests (#2216) 2023-06-21 13:08:19 +02:00
Print Normalization by Evaluation (#2038) 2023-05-15 18:01:40 +02:00
Recursor Fix de Bruijn indices in rmap (#1898) 2023-03-17 13:11:36 +01:00
Transformation Numeric, ordering and equality traits (#2433) 2023-10-09 18:25:01 +02:00
VampIR Switch to Halo2 for VampIR backend tests (#2216) 2023-06-21 13:08:19 +02:00
Asm.hs JuvixCore to JuvixAsm translation (#1665) 2023-01-09 18:21:30 +01:00
Compile.hs JuvixCore to JuvixAsm translation (#1665) 2023-01-09 18:21:30 +01:00
Eval.hs Add internal core read command (#1517) 2022-09-06 15:26:48 +02:00
Normalize.hs Normalization by Evaluation (#2038) 2023-05-15 18:01:40 +02:00
Print.hs Print JuvixCore correctly (#1875) 2023-03-15 16:41:39 +01:00
Recursor.hs The rmap recursor (#1893) 2023-03-16 14:47:21 +01:00
Transformation.hs Recursion unrolling for functions (#1912) 2023-03-24 15:05:37 +01:00
VampIR.hs Implement core transformation let-hoisting (#2076) 2023-05-16 13:42:44 +02:00