From ea8c73a3f848345949814333703ecbcae29e2716 Mon Sep 17 00:00:00 2001 From: Drew Hess Date: Tue, 23 Apr 2024 17:16:03 +0100 Subject: [PATCH 1/5] chore(nix): use `treefmt` This allows `nix fmt` in the dev shell for a one-shot formatting pass of all source files. Signed-off-by: Drew Hess --- flake.lock | 23 ++++++++++++- flake.nix | 95 ++++++++++++++++++++++++++++++------------------------ 2 files changed, 75 insertions(+), 43 deletions(-) diff --git a/flake.lock b/flake.lock index bae49d232..9aa8137cb 100644 --- a/flake.lock +++ b/flake.lock @@ -1100,7 +1100,8 @@ "haskell-nix", "nixpkgs-unstable" ], - "pre-commit-hooks-nix": "pre-commit-hooks-nix_2" + "pre-commit-hooks-nix": "pre-commit-hooks-nix_2", + "treefmt-nix": "treefmt-nix_2" } }, "stackage": { @@ -1184,6 +1185,26 @@ "repo": "treefmt-nix", "type": "github" } + }, + "treefmt-nix_2": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711963903, + "narHash": "sha256-N3QDhoaX+paWXHbEXZapqd1r95mdshxToGowtjtYkGI=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "49dc4a92b02b8e68798abd99184f228243b6e3ac", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 98f5f0390..6801d1d94 100644 --- a/flake.nix +++ b/flake.nix @@ -16,11 +16,14 @@ flake-parts.url = "github:hercules-ci/flake-parts"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + # Let haskell.nix dictate the nixpkgs we use, as that will ensure # better haskell.nix cache hits. nixpkgs.follows = "haskell-nix/nixpkgs-unstable"; hacknix.inputs.nixpkgs.follows = "nixpkgs"; pre-commit-hooks-nix.inputs.nixpkgs.follows = "nixpkgs"; + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; ghc-wasm.url = "git+https://gitlab.haskell.org/ghc/ghc-wasm-meta"; }; @@ -73,6 +76,7 @@ imports = [ inputs.pre-commit-hooks-nix.flakeModule + inputs.treefmt-nix.flakeModule ]; systems = [ "x86_64-linux" "aarch64-darwin" ]; @@ -195,49 +199,16 @@ overlays = allOverlays; }; - pre-commit = - let - # Override the default nix-pre-commit-hooks tools with the version - # we're using. - haskellNixTools = pkgs.haskell-nix.tools ghcVersion { - hlint = "latest"; - fourmolu = fourmoluVersion; - cabal-fmt = cabal-fmt-override; - }; - in - { - check.enable = true; - settings = { - src = ./.; - hooks = { - hlint.enable = true; - fourmolu.enable = true; - cabal-fmt.enable = true; - nixpkgs-fmt.enable = true; - # Note: doesn't appear to pick up `bugreport.sh`. - # https://github.com/hackworthltd/primer/issues/1018 - shellcheck.enable = true; - actionlint.enable = true; - }; - - # We need to force these due to - # - # https://github.com/cachix/pre-commit-hooks.nix/issues/204 - tools = { - nixpkgs-fmt = pkgs.lib.mkForce pkgs.nixpkgs-fmt; - hlint = pkgs.lib.mkForce haskellNixTools.hlint; - fourmolu = pkgs.lib.mkForce haskellNixTools.fourmolu; - cabal-fmt = pkgs.lib.mkForce haskellNixTools.cabal-fmt; - }; - - excludes = [ - "primer/test/outputs" - "primer-api/test/outputs" - "primer-service/test/outputs" - ".buildkite/" - ]; + pre-commit = { + check.enable = true; + settings = { + src = ./.; + hooks = { + treefmt.enable = true; + actionlint.enable = true; }; }; + }; packages = { inherit (pkgs) primer-service primer-client primer-openapi-spec; @@ -319,8 +290,48 @@ }) // primerFlake.apps; + treefmt.config = + let + haskellExcludes = [ + "primer/test/outputs" + "primer-api/test/outputs" + "primer-service/test/outputs" + ]; + + haskellNixTools = pkgs.haskell-nix.tools ghcVersion { + hlint = "latest"; + fourmolu = fourmoluVersion; + cabal-fmt = cabal-fmt-override; + }; + in + { + projectRootFile = "flake.nix"; + + programs.hlint = { + enable = true; + package = haskellNixTools.hlint; + }; + programs.cabal-fmt = { + enable = true; + package = haskellNixTools.cabal-fmt; + }; + programs.fourmolu = { + enable = true; + package = haskellNixTools.fourmolu; + }; + programs.nixpkgs-fmt.enable = true; + programs.shellcheck.enable = true; + + settings.formatter.hlint.excludes = haskellExcludes; + settings.formatter.fourmolu.excludes = haskellExcludes; + }; + devShells = { - default = primerFlake.devShell; + default = primerFlake.devShell // { + inputsFrom = [ + config.treefmt.build.devShell + ]; + }; } // (pkgs.lib.optionalAttrs (system == "x86_64-linux")) { # Unfortunately, this is only available on x86_64-linux. wasm = pkgs.mkShell { From 3e82c295daaf3b13d5a68a476d7e47dfceabc9fe Mon Sep 17 00:00:00 2001 From: Drew Hess Date: Tue, 23 Apr 2024 17:32:42 +0100 Subject: [PATCH 2/5] doc: fix Buildkite badge Signed-off-by: Drew Hess --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 26a02655c..747adbf94 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build status](https://badge.buildkite.com/7a9fd1213265a375385deec0a418bc4a6f26b17b7f4efe3cad.svg?branch=main)](https://buildkite.com/hackworthltd/primer) +[![Build status](https://badge.buildkite.com/210c4de83d47809721c2b4269b1d00393f3fa24c202abd4d45.svg?branch=main)](https://buildkite.com/hackworthltd/primer-ci) [![Benchmarks](https://github.com/hackworthltd/primer/actions/workflows/benchmark-action.yaml/badge.svg?branch=main)](https://benchmarks.primer.dev) # Primer From ec1914b37ba0e9df1f0abbd3e0aca3be777bc4ee Mon Sep 17 00:00:00 2001 From: Drew Hess Date: Tue, 23 Apr 2024 17:36:21 +0100 Subject: [PATCH 3/5] doc: add a note to the README about the interpreter Signed-off-by: Drew Hess --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 747adbf94..51bffd048 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,14 @@ subject to change. [DoS](https://en.wikipedia.org/wiki/Denial-of-service_attack) the server on which it runs. -* The current implementation of the evaluator is very slow. Running - very large programs, or even small programs that generate many - reduction steps, is not practical at this time. We're well aware of - this limitation, and we plan to focus on evaluation performance once - version 1.0 of the language specification is complete. +* The current implementation of the step evaluator is very slow. + Running very large programs, or even small programs that generate + many reduction steps, is not practical at this time. Primer now also + features an interpreter which is up to a few orders of magnitude + faster than the step evaluator, but we lose the ability to step + through programs redex-at-a-time as we can with the step evaluator. + We plan to do future research to attempt to combine the two + approaches somehow. * Even the most minor frontend requests result in the entire program AST being sent over the network, rather than only what's changed. From dfe3d1ee249563b1333613ca04c1639fd56e0e77 Mon Sep 17 00:00:00 2001 From: Drew Hess Date: Tue, 23 Apr 2024 17:38:00 +0100 Subject: [PATCH 4/5] doc: add a caveat to the README about an effect system in 2.0 Signed-off-by: Drew Hess --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 51bffd048..aa202ba96 100644 --- a/README.md +++ b/README.md @@ -86,9 +86,10 @@ subject to change. * At the moment, Primer is a pure functional programming language, with no effects system. This means, for example, it's not currently possible to [draw animated cats](https://scratch.mit.edu) using - Primer. We plan to implement an effects system in version 2.0 of the - language specification, but that will work will not begin for some - time. + Primer. We're currently undecided on whether to add an effects + system to version 2.0 of the language, or to eschew language-level + effects entirely in favor of a different approach more suited to + novices. * We've yet to do any rigorous testing of Primer with students, and none at all in classrooms. Primer may turn out not be an effective From c4ee566abf97e928b212ea8f83eec115579bd785 Mon Sep 17 00:00:00 2001 From: Drew Hess Date: Tue, 23 Apr 2024 17:45:19 +0100 Subject: [PATCH 5/5] doc: note that we now use `GHC2021` Signed-off-by: Drew Hess --- docs/haskell-style-guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/haskell-style-guide.md b/docs/haskell-style-guide.md index 4860a2fe9..d81524226 100644 --- a/docs/haskell-style-guide.md +++ b/docs/haskell-style-guide.md @@ -86,7 +86,7 @@ import Foreword ## Cabal -* Start all new Cabal projects with `default-language: Haskell2010`. +* Start all new Cabal projects with `default-language: GHC2021`. * Frequently-enabled GHC extensions should be considered for use in Cabal's `default-extensions` stanza. ## Tests