Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ jobs:
~/.cabal/packages
~/.cabal/store
dist-newstyle
key: cabal-deps-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-${{ matrix.ghc-version }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('linear-base.cabal') }}-${{ github.sha }}
restore-keys: cabal-deps-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-${{ matrix.ghc-version }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('linear-base.cabal') }}-
key: cabal-deps-${{ runner.os }}-${{ hashFiles('flake.lock') }}-${{ matrix.ghc-version }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('linear-base.cabal') }}-${{ github.sha }}
restore-keys: cabal-deps-${{ runner.os }}-${{ hashFiles('flake.lock') }}-${{ matrix.ghc-version }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('linear-base.cabal') }}-
- name: Build Nix dependencies
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "echo '=== Nix dependencies installed ==='"
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command echo '=== Nix dependencies installed ==='
Comment thread
aspiwack marked this conversation as resolved.
- name: Init Cabal's config file
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal --config-file=/home/runner/.cabal/config user-config -f init"
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal --config-file=/home/runner/.cabal/config user-config -f init
Comment thread
aspiwack marked this conversation as resolved.
- name: Update Cabal's database
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal update"
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal update
- name: Build Cabal's dependencies
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal build --dependencies-only"
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal build --dependencies-only
- name: Build
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal build"
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal build
- name: Haddock
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal haddock"
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal haddock
- name: cabal-docspec
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal-docspec"
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal-docspec
- name: Build benchmarks
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal build linear-base:bench:bench"
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal build linear-base:bench:bench
- name: Run benchmarks
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal bench 2>&1 | tee benchmark_ghc${{ matrix.ghc-version }}.txt"
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal bench 2>&1 | tee benchmark_ghc${{ matrix.ghc-version }}.txt
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
Expand All @@ -60,16 +60,10 @@ jobs:
- uses: cachix/install-nix-action@v15
with:
nix_path: "${{ env.nixpkgs-url }}"
- name: Cache Stack dependencies
uses: actions/cache@v4
with:
path: ~/.stack
key: stack-deps-ormolu-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock') }}-${{ github.sha }}
restore-keys: stack-deps-ormolu-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock') }}-
- name: Build Nix dependencies
run: nix-shell --arg installHls 'false' --pure --run "echo '=== Nix dependencies installed ==='"
run: nix develop .#devShells.x86_64-linux.ci-stack --command echo '=== Nix dependencies installed ==='
- name: check formatting
run: nix-shell --arg installHls 'false' --pure --run 'stack build ormolu && stack exec ormolu -- -m check $(find . -type f -name "*.hs-boot" -o -name "*.hs")'
run: nix develop .#devShells.x86_64-linux.ci-stack --command ormolu -m check $(find . -type f -name "*.hs-boot" -o -name "*.hs")
Comment thread
aspiwack marked this conversation as resolved.

stack-build:
name: stack build
Expand All @@ -83,9 +77,9 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.stack
key: stack-deps-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock', 'linear-base.cabal') }}-${{ github.sha }}
restore-keys: stack-deps-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock', 'linear-base.cabal') }}-
key: stack-deps-${{ runner.os }}-${{ hashFiles('flake.lock') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock', 'linear-base.cabal') }}-${{ github.sha }}
restore-keys: stack-deps-${{ runner.os }}-${{ hashFiles('flake.lock') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock', 'linear-base.cabal') }}-
- name: Build Nix dependencies
run: nix-shell --arg installHls 'false' --pure --run "echo '=== Nix dependencies installed ==='"
run: nix develop .#devShells.x86_64-linux.ci-stack --command echo '=== Nix dependencies installed ==='
- name: Build
run: nix-shell --arg installHls 'false' --pure --run "stack build --pedantic --test --bench --no-run-benchmarks"
run: nix develop .#devShells.x86_64-linux.ci-stack --command stack build --pedantic --test --bench --no-run-benchmarks
6 changes: 3 additions & 3 deletions bench/Data/Mutable/HashMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import qualified Data.HashMap.Strict as Map
import qualified Data.HashTable.ST.Basic as BasicST
import qualified Data.HashTable.ST.Cuckoo as CuckooST
import Data.Hashable (Hashable (..), hashWithSalt)
import Data.List (foldl')
import qualified Data.List as List
import qualified Data.Unrestricted.Linear as Linear
import GHC.Generics (Generic)
import qualified Prelude.Linear as Linear
Expand Down Expand Up @@ -199,7 +199,7 @@ vanilla_hashmap_strict inp@(BenchInput {pairs = kvs}) =
bench (descriptions !! n) $ nf (\xs -> f xs Map.empty) kvs

foldlx :: (b -> a -> b) -> [a] -> b -> b
foldlx f xs b = foldl' f b xs
foldlx f xs b = List.foldl' f b xs

look :: Map.HashMap Key Int -> Key -> Map.HashMap Key Int
look m k = case m Map.!? k of
Expand All @@ -208,7 +208,7 @@ vanilla_hashmap_strict inp@(BenchInput {pairs = kvs}) =

bench1 :: Benchmark
bench1 = mkBench 0 $
\xs hm -> foldl' (\m (k, v) -> Map.delete k (Map.insert k v m)) hm xs
\xs hm -> List.foldl' (\m (k, v) -> Map.delete k (Map.insert k v m)) hm xs

bench2 :: Benchmark
bench2 = mkBench 1 $
Expand Down
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ packages: *.cabal
tests: True
benchmarks: True
allow-newer: all
index-state: 2024-09-13T13:31:57Z
index-state: 2026-05-12T09:26:21Z
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
description = "Linear-base";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; inherit overlays; };

# need to match Stackage LTS version from stack.yaml snapshot
stack-ghc-version = "ghc9103";

# Versions used by CI's Cabal-based matrix
ci-ghc-versions = ["96" "98" "910" "912"];

cabal-docspec = import ./nix/cabal-docspec.nix { inherit pkgs; };

buildTools = ghc-ver:
let hask = pkgs.haskell.packages."${ghc-ver}"; in
[
hask.ghc
pkgs.cabal-install
stack-wrapped
cabal-docspec
pkgs.ormolu # Haskell formatter
];

devTools = ghc-ver:
let hask = pkgs.haskell.packages."${ghc-ver}"; in
[
hask.ghcid # Continuous terminal Haskell compile checker
hask.haskell-language-server # LSP server for editor
];
Comment thread
aspiwack marked this conversation as resolved.

mkCIShellFor = ghc-ver: pkgs.mkShell {
# Set UTF-8 local so that run-tests can parse GHC's unicode output.
LANG="C.UTF-8";

buildInputs = buildTools "${ghc-ver}";
};

ci-shells = builtins.listToAttrs (map (ver:
Comment thread
aspiwack marked this conversation as resolved.
{ name = "ci-${ver}"; value = mkCIShellFor "ghc${ver}"; }
) ci-ghc-versions);

mkDevShellFor = ghc-ver: pkgs.mkShell {
# Set UTF-8 local so that run-tests can parse GHC's unicode output.
LANG="C.UTF-8";

buildInputs = buildTools "${ghc-ver}" ++ devTools "${ghc-ver}";

};

cabal-dev-shells = builtins.listToAttrs (map (ver:
{ name = "dev-${ver}"; value = mkDevShellFor "ghc${ver}"; }
) ci-ghc-versions);

# See https://docs.haskellstack.org/en/stable/topics/nix_integration/
stack-wrapped = pkgs.symlinkJoin {
name = "stack"; # will be available as the usual `stack` in terminal
paths = [ pkgs.stack ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/stack \
--add-flags "\
--no-nix \
--system-ghc \
--no-install-ghc \
"
'';
};

overlays = [
];

in {

devShells = ci-shells // cabal-dev-shells // {
default = mkDevShellFor stack-ghc-version;

ci-stack = mkCIShellFor stack-ghc-version;};
}
);
}
12 changes: 4 additions & 8 deletions format.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/usr/bin/env bash
# Format linear-base using the version of Ormolu specified in stack.yaml.
# Format linear-base using the version of Ormolu from the PATH. It's recommended
# using the version provided by `flake.nix`, since it's the one used by the CI
# to enforce formatting.

set -e

export LANG="C.UTF-8"

stack build ormolu
## We can't format cabal at the moment because `cabal format` inlines
## common stanzas, which is very much something that we don't want. See
## https://github.com/haskell/cabal/issues/5734
#
# cabal format
stack exec ormolu -- -m inplace $(find . -type f -name "*.hs-boot" -o -name "*.hs")
ormolu -m inplace $(find . -type f -name "*.hs-boot" -o -name "*.hs")
Comment thread
aspiwack marked this conversation as resolved.
9 changes: 0 additions & 9 deletions nix/shell-stack.nix

This file was deleted.

26 changes: 0 additions & 26 deletions nix/sources.json

This file was deleted.

Loading
Loading