Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Haskell code from the Agda spec #1315

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

javierdiaz72
Copy link
Contributor

@javierdiaz72 javierdiaz72 commented Nov 21, 2024

This PR resolves #1312 and #1343.

@javierdiaz72 javierdiaz72 added enhancement New feature or request formal-spec Changes related to formal specifications conformance Changes related to conformance testing labels Nov 21, 2024
@javierdiaz72 javierdiaz72 self-assigned this Nov 21, 2024
@javierdiaz72
Copy link
Contributor Author

Perhaps at this point, before I move forward with other STS's, there is a good opportunity to properly integrate this work into the current Cabal project.

@amesgen: What's your opinion? Is this perhaps something you can do? (no pressure 🙂).

@abailly
Copy link
Contributor

abailly commented Nov 25, 2024

I have tried make hs locally, without using nix, and it fails with the following error:

    Checking Interface.HasOrder.Instance (ouroboros-consensus/docs/agda-spec/src/Interface/HasOrder/Instance.agda).
ouroboros-consensus/docs/agda-spec/src/Interface/HasOrder/Instance.agda:34,55-64
No instance of type
((HasPartialOrder.hasPreorder ℚ-hasPartialOrder HasPreorder.≤ x) y
 ⁇)
was found in scope.
when checking that the expression record {} has type
HasDecPartialOrder
make: *** [latex/Spec/PDF.tex] Error 42

I am using agda-stdlib 2.0. What am I doing wrong?

@amesgen
Copy link
Member

amesgen commented Nov 25, 2024

Perhaps at this point, before I move forward with other STS's, there is a good opportunity to properly integrate this work into the current Cabal project.

@amesgen: What's your opinion? Is this perhaps something you can do? (no pressure 🙂).

Will have a look 👍


I have tried make hs locally, without using nix, and it fails with the following error:

    Checking Interface.HasOrder.Instance (ouroboros-consensus/docs/agda-spec/src/Interface/HasOrder/Instance.agda).
ouroboros-consensus/docs/agda-spec/src/Interface/HasOrder/Instance.agda:34,55-64
No instance of type
((HasPartialOrder.hasPreorder ℚ-hasPartialOrder HasPreorder.≤ x) y
 ⁇)
was found in scope.
when checking that the expression record {} has type
HasDecPartialOrder
make: *** [latex/Spec/PDF.tex] Error 42

I am using agda-stdlib 2.0. What am I doing wrong?

I am not sure exactly, but maybe you need to setup agda-stdlib-classes and agda-stdlib-meta?

agdaStdlibClasses = customAgda.agdaPackages.mkDerivation {
inherit (locales) LANG LC_ALL LOCALE_ARCHIVE;
pname = "agda-stdlib-classes";
version = "2.0";
src = pkgs.fetchFromGitHub {
owner = "omelkonian";
repo = "agda-stdlib-classes";
rev = "v2.0";
hash = "sha256-PcieRRnctjCzFCi+gUYAgyIAicMOAZPl8Sw35fZdt0E=";
};
meta = { };
libraryFile = "agda-stdlib-classes.agda-lib";
everythingFile = "Classes.agda";
buildInputs = [ agdaStdlib ];
};
agdaStdlibMeta = customAgda.agdaPackages.mkDerivation {
inherit (locales) LANG LC_ALL LOCALE_ARCHIVE;
pname = "agda-stdlib-meta";
version = "2.0";
src = pkgs.fetchFromGitHub {
owner = "omelkonian";
repo = "agda-stdlib-meta";
rev = "v2.1.1";
hash = "sha256-qOoThYMG0dzjKvwmzzVZmGcerfb++MApbaGRzLEq3/4=";
};
meta = { };
libraryFile = "agda-stdlib-meta.agda-lib";
everythingFile = "Main.agda";
buildInputs = [ agdaStdlib agdaStdlibClasses ];
};

@abailly
Copy link
Contributor

abailly commented Nov 25, 2024

@amesgen thanks for your answer 🙏 So I have those setup, they are in my ~/.agda/libraries definition. I will double check the versions.
Thing is: when I use nix, eg. nix develop agda, I don't seem to have the needed libraries either. It does not even bring agda into scope so I am probably misusing nix here. It would be nice to add some documentation in does/agda-spec/README.d for example to help the poor soul ending up here how to hack on these things.

@abailly
Copy link
Contributor

abailly commented Nov 25, 2024

It seems I had outdated version of agda-stdlib-classes and agda-stdlib-meta. Refreshing to match the revisions given in nix file does yield to different errors.

@amesgen
Copy link
Member

amesgen commented Nov 25, 2024

Thing is: when I use nix, eg. nix develop agda, I don't seem to have the needed libraries either. It does not even bring agda into scope so I am probably misusing nix here. It would be nice to add some documentation in does/agda-spec/README.d for example to help the poor soul ending up here how to hack on these things.

It should work with

nix develop .#agda-spec

We definitely want a good readme for docs/agda-spec, hopefully we can get to that soon (the spec is still fairly new and evolving).

@abailly
Copy link
Contributor

abailly commented Nov 25, 2024

It's funny that nix develop agda-spec does not work, but nix develop agda worked although it yielded me no usable environment

@amesgen
Copy link
Member

amesgen commented Nov 25, 2024

It's funny that nix develop agda-spec does not work, but nix develop agda worked although it yielded me no usable environment

Just to explain this behavior: These two commands use the Nix registry which is completely independent of the local project you are working on. Therefore, nix develop agda works because agda is a registry entry in the global flake, but agda-spec is not. However, nix develop agda will drop you in a shell that you can use to work on Agda (https://github.com/agda/agda), but this is not what you want here, in a project that uses Agda.

In contrast, nix develop .#agda-spec uses the agda-spec shell defined in the local flake (ie in . or in a parent directory):

agda-spec = pkgs.agda-spec.shell;

@abailly
Copy link
Contributor

abailly commented Nov 25, 2024

I still wish I could make hs without needing nix though :)

@javierdiaz72 javierdiaz72 force-pushed the javierdiaz72/agda-spec-to-haskell branch 3 times, most recently from 43c9f54 to f3361a3 Compare December 12, 2024 19:07
@javierdiaz72 javierdiaz72 force-pushed the javierdiaz72/agda-spec-to-haskell branch from f3361a3 to a98ba32 Compare December 12, 2024 19:14
Fixes #1343
Note that this PR targets the branch of
#1315 and not
`main`.

This PR adds Nix derivations that:
- generate Haskell code from the Agda spec using the `Makefile`-based
build system in `./docs/agda-spec/`
- wrap the generated code into Nix using `cabal2nix`

In combination with the existing set-up in `flake.nix`, we can now build
the generated code and run it's tests using the following flake output:
```
nix build .#hydraJobs.x86_64-linux.native.agda-spec.hsExe
```
which will also be done in CI, i.e. see the logs from testing this PR
- the job
[x86_64-linux.native.agda-spec.hsExe](https://ci.iog.io/build/6263029/log)
builds and runs tests for the generated code

some other jobs, e.g. the linting of the unit tests for the generated
code, are failing, but we can fix those in
#1315
@geo2a geo2a linked an issue Dec 16, 2024 that may be closed by this pull request
3 tasks
…pec-to-haskell' into javierdiaz72/agda-spec-to-haskell
@geo2a geo2a force-pushed the javierdiaz72/agda-spec-to-haskell branch 2 times, most recently from b307ad4 to 5987184 Compare December 18, 2024 10:41
- dos2unix
- hlint
- make `cardano-consensus-executable-spec.cabal` pass `cabal.check`

Make `cardano-consensus-executable-spec.cabal` pass `cabal.check`

Copy licence files instead of linking

fix cabal file
@geo2a geo2a force-pushed the javierdiaz72/agda-spec-to-haskell branch from 5987184 to f2af22c Compare December 18, 2024 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conformance Changes related to conformance testing enhancement New feature or request formal-spec Changes related to formal specifications
Projects
Status: 🏗 In progress
4 participants