From 1ae9593f357ee30077f809000dd3a9de7c015ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=ADaz?= Date: Sat, 27 Apr 2024 15:25:09 +0200 Subject: [PATCH] Add generically, rework doctests. --- .github/workflows/haskell-ci.yml | 202 +++++++++++++++++++++++++++++++ CHANGELOG.md | 3 + lib/Data/RBR/Internal.hs | 10 +- red-black-record.cabal | 42 +++---- tests/doctests.hs | 8 -- 5 files changed, 235 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/haskell-ci.yml delete mode 100644 tests/doctests.hs diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml new file mode 100644 index 0000000..314420c --- /dev/null +++ b/.github/workflows/haskell-ci.yml @@ -0,0 +1,202 @@ +# This GitHub workflow config has been generated by a script via +# +# haskell-ci 'github' 'red-black-record.cabal' +# +# To regenerate the script (for example after adjusting tested-with) run +# +# haskell-ci regenerate +# +# For more information, see https://github.com/haskell-CI/haskell-ci +# +# version: 0.17.20240109 +# +# REGENDATA ("0.17.20240109",["github","red-black-record.cabal"]) +# +name: Haskell-CI +on: + - push + - pull_request +jobs: + linux: + name: Haskell-CI - Linux - ${{ matrix.compiler }} + runs-on: ubuntu-20.04 + timeout-minutes: + 60 + container: + image: buildpack-deps:bionic + continue-on-error: ${{ matrix.allow-failure }} + strategy: + matrix: + include: + - compiler: ghc-9.8.1 + compilerKind: ghc + compilerVersion: 9.8.1 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.6.3 + compilerKind: ghc + compilerVersion: 9.6.3 + setup-method: ghcup + allow-failure: false + fail-fast: false + steps: + - name: apt + run: | + apt-get update + apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5 + mkdir -p "$HOME/.ghcup/bin" + curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup" + chmod a+x "$HOME/.ghcup/bin/ghcup" + "$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false) + "$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + env: + HCKIND: ${{ matrix.compilerKind }} + HCNAME: ${{ matrix.compiler }} + HCVER: ${{ matrix.compilerVersion }} + - name: Set PATH and environment variables + run: | + echo "$HOME/.cabal/bin" >> $GITHUB_PATH + echo "LANG=C.UTF-8" >> "$GITHUB_ENV" + echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV" + echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV" + HCDIR=/opt/$HCKIND/$HCVER + HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER") + HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#') + HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#') + # doctest needs ghc and ghc-pkg to be on the path. + echo $(dirname "$HC") >> "$GITHUB_PATH" + echo "HC=$HC" >> "$GITHUB_ENV" + echo "HCPKG=$HCPKG" >> "$GITHUB_ENV" + echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))') + echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV" + echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV" + echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV" + echo "HEADHACKAGE=false" >> "$GITHUB_ENV" + echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV" + echo "GHCJSARITH=0" >> "$GITHUB_ENV" + env: + HCKIND: ${{ matrix.compilerKind }} + HCNAME: ${{ matrix.compiler }} + HCVER: ${{ matrix.compilerVersion }} + - name: env + run: | + env + - name: write cabal config + run: | + mkdir -p $CABAL_DIR + cat >> $CABAL_CONFIG <> $CABAL_CONFIG < cabal-plan.xz + echo 'f62ccb2971567a5f638f2005ad3173dba14693a45154c1508645c52289714cb2 cabal-plan.xz' | sha256sum -c - + xz -d < cabal-plan.xz > $HOME/.cabal/bin/cabal-plan + rm -f cabal-plan.xz + chmod a+x $HOME/.cabal/bin/cabal-plan + cabal-plan --version + - name: checkout + uses: actions/checkout@v3 + with: + path: source + - name: initial cabal.project for sdist + run: | + touch cabal.project + echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project + cat cabal.project + - name: sdist + run: | + mkdir -p sdist + $CABAL sdist all --output-dir $GITHUB_WORKSPACE/sdist + - name: unpack + run: | + mkdir -p unpacked + find sdist -maxdepth 1 -type f -name '*.tar.gz' -exec tar -C $GITHUB_WORKSPACE/unpacked -xzvf {} \; + - name: generate cabal.project + run: | + PKGDIR_red_black_record="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/red-black-record-[0-9.]*')" + echo "PKGDIR_red_black_record=${PKGDIR_red_black_record}" >> "$GITHUB_ENV" + rm -f cabal.project cabal.project.local + touch cabal.project + touch cabal.project.local + echo "packages: ${PKGDIR_red_black_record}" >> cabal.project + echo "package red-black-record" >> cabal.project + echo " ghc-options: -Werror=missing-methods" >> cabal.project + cat >> cabal.project <> cabal.project.local + cat cabal.project + cat cabal.project.local + - name: dump install plan + run: | + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all + cabal-plan + - name: restore cache + uses: actions/cache/restore@v3 + with: + key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} + path: ~/.cabal/store + restore-keys: ${{ runner.os }}-${{ matrix.compiler }}- + - name: install dependencies + run: | + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --dependencies-only -j2 all + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dependencies-only -j2 all + - name: build w/o tests + run: | + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all + - name: build + run: | + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always + - name: tests + run: | + $CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct + - name: doctests + run: | + $CABAL v2-install $ARG_COMPILER --ghc-options="-rtsopts" doctest --overwrite-policy=always + $CABAL v2-repl all --build-depends=QuickCheck --build-depends=template-haskell --with-ghc=doctest --repl-options='-w -Wdefault' + - name: cabal check + run: | + cd ${PKGDIR_red_black_record} || false + ${CABAL} -vnormal check + - name: haddock + run: | + $CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all + - name: unconstrained build + run: | + rm -f cabal.project.local + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all + - name: save cache + uses: actions/cache/save@v3 + if: always() + with: + key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} + path: ~/.cabal/store diff --git a/CHANGELOG.md b/CHANGELOG.md index 92020cf..869521c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Revision history for red-black-record +## 2.1.6.0 +- Added ToRecord instance for Generically + ## 2.1.5.0 - Added cliftA_Record and cliftA2_Record. diff --git a/lib/Data/RBR/Internal.hs b/lib/Data/RBR/Internal.hs index 7004e40..27ffb49 100644 --- a/lib/Data/RBR/Internal.hs +++ b/lib/Data/RBR/Internal.hs @@ -40,7 +40,7 @@ import Data.Monoid (Endo(..)) import Data.List (intersperse) import Data.Foldable (asum) import GHC.TypeLits -import GHC.Generics (D1,C1,S1(..),M1(..),K1(..),Rec0(..)) +import GHC.Generics (D1,C1,S1(..),M1(..),K1(..),Rec0(..), Generically(..)) import qualified GHC.Generics as G import Data.SOP (I(..),K(..),unI,unK,NP(..),NS(..),All,SListI,type (-.->)(Fn,apFn),mapKIK,(:.:)(..),Top) @@ -1354,6 +1354,14 @@ class ToRecord (r :: Type) where default toRecord :: (G.Generic r,ToRecordHelper E (G.Rep r),RecordCode r ~ RecordCode' E (G.Rep r)) => r -> Record I (RecordCode r) toRecord r = toRecord' unit (G.from r) +instance ( + G.Generic r, + ToRecordHelper E (G.Rep r), + RecordCode r ~ RecordCode' E (G.Rep r)) => + ToRecord (Generically (r :: Type)) where + type RecordCode (Generically (r :: Type)) = RecordCode' E (G.Rep r) + toRecord (Generically r) = toRecord' unit (G.from r) + class ToRecordHelper (start :: Map Symbol Type) (g :: Type -> Type) where type RecordCode' start g :: Map Symbol Type toRecord' :: Record I start -> g x -> Record I (RecordCode' start g) diff --git a/red-black-record.cabal b/red-black-record.cabal index e2a8fb7..9d1e3ef 100644 --- a/red-black-record.cabal +++ b/red-black-record.cabal @@ -1,24 +1,23 @@ -cabal-version: 2.0 +cabal-version: 3.4 name: red-black-record -version: 2.1.5.0 +version: 2.1.6.0 synopsis: Extensible records and variants indexed by a type-level Red-Black tree. description: A library that provides extensible records and variants, both indexed by a type-level red-black tree that maps Symbol keys to value types of any kind. - . + The keys correspond to fields names in records, and to branch names in variants. - . + At the term level, value types come wrapped in a type constructor of kind @q -> Type@, where @q@ is the kind of value types. - . The records and variants can be converted to and from regular Haskell datatypes; also to and from the unlabelled n-ary products and sums of the @sop-core@ package. -license: BSD3 +license: BSD-3-Clause license-file: LICENSE author: Daniel Diaz maintainer: diaz_carrete@yahoo.com @@ -26,6 +25,7 @@ category: Data extra-source-files: CHANGELOG.md, README.md build-type: Simple +tested-with: GHC ==9.8.1 || ==9.6.3 source-repository head type: git @@ -49,20 +49,20 @@ library demoted hs-source-dirs: lib-demoted default-language: Haskell2010 -test-suite doctests - type: exitcode-stdio-1.0 - hs-source-dirs: tests - ghc-options: -threaded - main-is: doctests.hs - build-depends: base >= 4.10.0.0 && < 5, - sop-core >= 0.4.0.0 && < 0.6, - red-black-record, - aeson >= 1.4.0.0 && < 1.6, - bytestring >= 0.10, - text >= 1.1, - profunctors >= 5, - doctest >= 0.16.2 - default-language: Haskell2010 +-- test-suite doctests +-- type: exitcode-stdio-1.0 +-- hs-source-dirs: tests +-- ghc-options: -threaded +-- main-is: doctests.hs +-- build-depends: base >= 4.10.0.0 && < 5, +-- sop-core >= 0.4.0.0 && < 0.6, +-- red-black-record, +-- aeson >= 1.4.0.0 && < 3.0, +-- bytestring >= 0.10, +-- text >= 1.1, +-- profunctors >= 5, +-- doctest >= 0.16.2 +-- default-language: Haskell2010 test-suite tests type: exitcode-stdio-1.0 @@ -74,5 +74,5 @@ test-suite tests tasty >= 0.10.1.1, tasty-hunit >= 0.9.2, red-black-record, - demoted + red-black-record:demoted default-language: Haskell2010 diff --git a/tests/doctests.hs b/tests/doctests.hs deleted file mode 100644 index 85c0e75..0000000 --- a/tests/doctests.hs +++ /dev/null @@ -1,8 +0,0 @@ -import Test.DocTest - -main = doctest ["-ilib", - "lib/Data/RBR.hs", - "lib/Data/RBR/Subset.hs", - "lib/Data/RBR/Examples.hs", - "lib/Data/RBR/Internal.hs" - ]