Skip to content

Generate Haskell code from the Agda spec #1315

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

Merged
merged 19 commits into from
Mar 27, 2025
Merged

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 4 times, most recently from f3361a3 to a98ba32 Compare December 12, 2024 19:14
geo2a added a commit that referenced this pull request Dec 16, 2024
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
@geo2a geo2a force-pushed the javierdiaz72/agda-spec-to-haskell branch 3 times, most recently from 5987184 to f2af22c Compare December 18, 2024 11:22
@geo2a
Copy link
Contributor

geo2a commented Jan 13, 2025

Hi @javierdiaz72, Happy New Year! Shall we merge this PR so that it does not bit-rot?

@javierdiaz72
Copy link
Contributor Author

Hi @javierdiaz72, Happy New Year! Shall we merge this PR so that it does not bit-rot?

Hi, @geo2a! Happy New Year to you too! There is still quite a bit of work to do regarding this PR (that's why it's still in draft mode), so we should not merge it yet.

@javierdiaz72
Copy link
Contributor Author

javierdiaz72 commented Jan 23, 2025

Hi, @geo2a! Do you have an idea why some of the CI checks are still failing?

@amesgen
Copy link
Member

amesgen commented Jan 23, 2025

CI is complaining about the fact that some files don't have LF (unix style) line endings: https://ci.iog.io/build/6541916/nixlog/1 (also see #1253/#1252).
Concretely, the file in question is docs/agda-spec/src/Spec/hs-src/test/OperationalCertificateSpec.hs. Maybe this is something you could configure in your editor?

@javierdiaz72
Copy link
Contributor Author

CI is complaining about the fact that some files don't have LF (unix style) line endings: https://ci.iog.io/build/6541916/nixlog/1 (also see #1253/#1252). Concretely, the file in question is docs/agda-spec/src/Spec/hs-src/test/OperationalCertificateSpec.hs. Maybe this is something you could configure in your editor?

Thanks for pointing that out, Alex! I've just fixed the issue with the file and now the CI is not complaining anymore. 🙂

@javierdiaz72
Copy link
Contributor Author

Hey, folks! I'm not sure why the last CI check is failing. Could anybody help me out?

@geo2a geo2a force-pushed the javierdiaz72/agda-spec-to-haskell branch from b8c7b99 to 55d59a4 Compare March 25, 2025 11:38
@jasagredo
Copy link
Contributor

jasagredo commented Mar 25, 2025

Some issues I encountered when trying to build this outside of Nix:

  • It seems the versions pulled in the nix setup are from a repository owned by github.com/omelkonian/... and not by agda but the links in the README point to github.com/agda/....
  • There is no pin for agda-stdlib. Judging by the fact that the readme mentions 2.7.0 and I saw a compatibility matrix on agda-stdlib-meta, I guesses it would be version 2.1.1?
  • If some rules generate PDFs via latex, there should be a section specifying that one needs pdflatex or xelatex or whichever latex tool is neede to produce those.

@javierdiaz72
Copy link
Contributor Author

Some issues I encountered when trying to build this outside of Nix:

Addressed in 88bdc09, please check.

@geo2a geo2a force-pushed the javierdiaz72/agda-spec-to-haskell branch from 88bdc09 to 5b1203d Compare March 27, 2025 12:30
@geo2a geo2a self-requested a review March 27, 2025 12:33
Copy link
Contributor

@geo2a geo2a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @javierdiaz72 for addressing the comments! I've rebased and signed your commits with my signature, as the repository settings require signing the commits. Your authorship seems to be retained and correctly displayed, but please let me know if you'd like to re-sign your commits with your own signature.

@geo2a geo2a added this pull request to the merge queue Mar 27, 2025
Merged via the queue into main with commit af0e6ae Mar 27, 2025
19 checks passed
@geo2a geo2a deleted the javierdiaz72/agda-spec-to-haskell branch March 27, 2025 16:13
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Consensus Team Backlog Mar 27, 2025
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: ✅ Done
5 participants