ekmett / ad

Automatic Differentiation
http://hackage.haskell.org/package/ad
BSD 3-Clause "New" or "Revised" License
368 stars 73 forks source link

Properly drop GHC-7.4 support #93

Closed phadej closed 3 years ago

phadej commented 3 years ago
phadej commented 3 years ago

Hmm, this doesn't look good. I have to check what is wrong.

ekmett commented 3 years ago

It might be the code I just merged that moved the reverse double mode to use ffi. Guessing we need to run some doctests with -fobject-code now?

phadej commented 3 years ago

No, cabal-docspec doesn't need -fobject-code (check the manual, it explains that bit). Anyway, I'll check soon.

ekmett commented 3 years ago

k

phadej commented 3 years ago

In particular, maybe fixing tests/CI is worth only after the master is settled with whatever changes are there incoming. Trying to catch moving target is not fun.

ekmett commented 3 years ago

it does seem to be dying on the new tape code at least. works locally on my machine, so yay fun.

ekmett commented 3 years ago

i'd be willing to punt sofus' improvements off to a branch and work there if we must, but they are pretty significant, so i'd like to see why machine works fine and why the haskell-ci machine barfs before bailing out on it.

phadej commented 3 years ago

FWIW, does FFI means that this package is now have to be used with care in GHCJS and alike? Well, let's wait until someone complains.

ekmett commented 3 years ago

I can probably flop things around so that the FFI stuff is a build flag, as the old code still works.

phadej commented 3 years ago

For the record, works on my machine too. Hard to say. I'll check later. Maybe it's something silly as -lm thingie messing in (minimal) CI environment.

RyanGlScott commented 3 years ago

In the interest of making CI green, should we build ad with the ffi flag disabled on CI for now? I've pushed a proof-of-concept to this branch.

RyanGlScott commented 3 years ago

With bd1c03ee8cf49241889d28eea53eb405d2c206e6, we've come to a point where CI is green, although the ffi constraint set isn't ran through cabal-docspec.

RyanGlScott commented 3 years ago

Investigating the cabal-docspec timeout a little further, I am able to reproduce it on the commit 642c10c514cc851aba5b0c7b29b8391fb57b2f56, but not on current master (bd1c03e). I suspect that the older commit has some sort of memory corruption bug which is tripping up cabal-docspec. If I run the same steps as in the GitHub Actions workflow, but passing -v to cabal-docspec, here is what I get:

``` $ docker run --rm -it buildpack-deps:bionic root@c45d0e33c5c0:/# cat >> bug.sh << 'EOF' > #!/usr/bin/env bash > > set -e > > export CABAL_VERSION=3.2 > export GHC_VERSION=8.10.4 > export PATH=$HOME/.cabal/bin:/opt/cabal/$CABAL_VERSION/bin:/opt/ghc/$GHC_VERSION/bin:$PATH > > apt-get update > apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common > apt-add-repository -y 'ppa:hvr/ghc' > apt-get update > apt-get install -y ghc-$GHC_VERSION cabal-install-$CABAL_VERSION > > mkdir -p $HOME/.cabal/bin > curl -sL https://github.com/phadej/cabal-extras/releases/download/cabal-docspec-0.0.0.20210111/cabal-docspec-0.0.0.20210111.xz > cabal-docspec.xz > echo '0829bd034fba901cbcfe491d98ed8b28fd54f9cb5c91fa8e1ac62dc4413c9562 cabal-docspec.xz' | sha256sum -c - > xz -d < cabal-docspec.xz > $HOME/.cabal/bin/cabal-docspec > rm -f cabal-docspec.xz > chmod a+x $HOME/.cabal/bin/cabal-docspec > cabal-docspec --version > > git clone https://github.com/ekmett/ad > cd ad/ > git reset --hard 642c10c514cc851aba5b0c7b29b8391fb57b2f56 > cabal v2-update > cabal v2-build -fffi > cabal-docspec -v > EOF root@c45d0e33c5c0:/# chmod a+x bug.sh root@c45d0e33c5c0:/# ./bug.sh [ 0.00001] ghc.info: ghc [ 0.00042] process.0.start: cwd=/tmp ghc --info [ 0.05131] docspec.component: ad-4.5 lib [ 0.05312] docspec.phase1: Numeric.AD: /ad/./src/Numeric/AD.hs [ 0.05687] docspec.phase1: Numeric.AD.Halley: /ad/./src/Numeric/AD/Halley.hs [ 0.05717] docspec.phase1: Numeric.AD.Internal.Dense: /ad/./src/Numeric/AD/Internal/Dense.hs [ 0.06342] docspec.phase1: Numeric.AD.Internal.Dense.Representable: /ad/./src/Numeric/AD/Internal/Dense/Representable.hs [ 0.06949] docspec.phase1: Numeric.AD.Internal.Doctest: /ad/./src/Numeric/AD/Internal/Doctest.hs [ 0.06987] docspec.phase1: Numeric.AD.Internal.Forward: /ad/./src/Numeric/AD/Internal/Forward.hs [ 0.07646] docspec.phase1: Numeric.AD.Internal.Forward.Double: /ad/./src/Numeric/AD/Internal/Forward/Double.hs [ 0.08615] docspec.phase1: Numeric.AD.Internal.Identity: /ad/./src/Numeric/AD/Internal/Identity.hs [ 0.08846] docspec.phase1: Numeric.AD.Internal.Kahn: /ad/./src/Numeric/AD/Internal/Kahn.hs [ 0.09522] docspec.phase1: Numeric.AD.Internal.On: /ad/./src/Numeric/AD/Internal/On.hs [ 0.09715] docspec.phase1: Numeric.AD.Internal.Or: /ad/./src/Numeric/AD/Internal/Or.hs [ 0.10147] docspec.phase1: Numeric.AD.Internal.Reverse: /ad/./src/Numeric/AD/Internal/Reverse.hs [ 0.10886] docspec.phase1: Numeric.AD.Internal.Reverse.Double: /ad/./src/Numeric/AD/Internal/Reverse/Double.hs [ 0.11505] docspec.phase1: Numeric.AD.Internal.Sparse: /ad/./src/Numeric/AD/Internal/Sparse.hs [ 0.12751] docspec.phase1: Numeric.AD.Internal.Tower: /ad/./src/Numeric/AD/Internal/Tower.hs [ 0.13243] docspec.phase1: Numeric.AD.Internal.Type: /ad/./src/Numeric/AD/Internal/Type.hs [ 0.13275] docspec.phase1: Numeric.AD.Jacobian: /ad/./src/Numeric/AD/Jacobian.hs [ 0.13468] docspec.phase1: Numeric.AD.Jet: /ad/./src/Numeric/AD/Jet.hs [ 0.13780] docspec.phase1: Numeric.AD.Mode: /ad/./src/Numeric/AD/Mode.hs [ 0.14057] docspec.phase1: Numeric.AD.Mode.Dense: /ad/./src/Numeric/AD/Mode/Dense.hs [ 0.14371] docspec.phase1: Numeric.AD.Mode.Dense.Representable: /ad/./src/Numeric/AD/Mode/Dense/Representable.hs [ 0.14638] docspec.phase1: Numeric.AD.Mode.Forward: /ad/./src/Numeric/AD/Mode/Forward.hs [ 0.15573] docspec.phase1: Numeric.AD.Mode.Forward.Double: /ad/./src/Numeric/AD/Mode/Forward/Double.hs [ 0.16094] docspec.phase1: Numeric.AD.Mode.Kahn: /ad/./src/Numeric/AD/Mode/Kahn.hs [ 0.16529] docspec.phase1: Numeric.AD.Mode.Reverse: /ad/./src/Numeric/AD/Mode/Reverse.hs [ 0.16911] docspec.phase1: Numeric.AD.Mode.Reverse.Double: /ad/./src/Numeric/AD/Mode/Reverse/Double.hs [ 0.17399] docspec.phase1: Numeric.AD.Mode.Sparse: /ad/./src/Numeric/AD/Mode/Sparse.hs [ 0.17691] docspec.phase1: Numeric.AD.Mode.Tower: /ad/./src/Numeric/AD/Mode/Tower.hs [ 0.17758] docspec.phase1: Numeric.AD.Newton: /ad/./src/Numeric/AD/Newton.hs [ 0.18877] docspec.phase1: Numeric.AD.Newton.Double: /ad/./src/Numeric/AD/Newton/Double.hs [ 0.18915] docspec.phase1: Numeric.AD.Rank1.Dense: /ad/./src/Numeric/AD/Rank1/Dense.hs [ 0.19159] docspec.phase1: Numeric.AD.Rank1.Dense.Representable: /ad/./src/Numeric/AD/Rank1/Dense/Representable.hs [ 0.19413] docspec.phase1: Numeric.AD.Rank1.Forward: /ad/./src/Numeric/AD/Rank1/Forward.hs [ 0.19791] docspec.phase1: Numeric.AD.Rank1.Forward.Double: /ad/./src/Numeric/AD/Rank1/Forward/Double.hs [ 0.20249] docspec.phase1: Numeric.AD.Rank1.Halley: /ad/./src/Numeric/AD/Rank1/Halley.hs [ 0.20527] docspec.phase1: Numeric.AD.Rank1.Kahn: /ad/./src/Numeric/AD/Rank1/Kahn.hs [ 0.20883] docspec.phase1: Numeric.AD.Rank1.Newton: /ad/./src/Numeric/AD/Rank1/Newton.hs [ 0.21337] docspec.phase1: Numeric.AD.Rank1.Newton.Double: /ad/./src/Numeric/AD/Rank1/Newton/Double.hs [ 0.21599] docspec.phase1: Numeric.AD.Rank1.Sparse: /ad/./src/Numeric/AD/Rank1/Sparse.hs [ 0.21888] docspec.phase1: Numeric.AD.Rank1.Tower: /ad/./src/Numeric/AD/Rank1/Tower.hs [ 0.22201] ghci: ghc --interactive -ignore-dot-ghci -v0 -i -hide-all-packages -no-user-package-db -package-db=/root/.cabal/store/ghc-8.10.4/package.db -package-db=/ad/dist-newstyle/packagedb/ghc-8.10.4 -package-id=ad-4.5-inplace -package-id=adjunctions-4.4-3eec42b3d0e36eb316b8fea59504b7ee0bcac398b37190ab0cf686015f5fc9ad -package-id=array-0.5.4.0 -package-id=base-4.14.1.0 -package-id=comonad-5.0.8-262f0f0e2af8c9f7f652caeb56486ae4062916e480b6d049a87f84bc93964829 -package-id=containers-0.6.2.1 -package-id=data-reify-0.6.3-eea2b7fa436542a8b583fa488f613b3495b27b365f81826477c2ce942bdf8c8b -package-id=erf-2.0.0.0-4ef6c7f8d8e28c776dbf39f5496433642d8c68627d816f70bbbad06d63091476 -package-id=free-5.1.6-f5b0a99fe6be0e571fe085c189dc1c3e410b3ae8354068327f05c56b13732fa6 -package-id=nats-1.1.2-f64b5777448a6bd6bdc36f9c6f49524e4c9d779d0be64513fb8ba21acd7fdb94 -package-id=reflection-2.1.6-bc119d9927a405dbd42187799cc5f636fb8aa5fee9b009c5d1a56c21bac6f5ab -package-id=semigroups-0.19.1-9bd2a5a836db517f37cc75e4855c48fac208d217260aee35dd472bf6367f488b -package-id=transformers-0.5.6.2 -package-id=distributive-0.6.2.1-744776ee91045549e0fe4c724bd0101ffbc636f653bf4f8705fcd75219ee4124 [ 0.31758] docspec.phase2: Numeric.AD [ 0.31789] ghci.input: :m Numeric.AD [ 0.35235] ghci.input: :r [ 0.35516] ghci.input: import Numeric.AD.Internal.Doctest [ 0.35855] ghci.input: :m Numeric.AD [ 0.36205] ghci.input: :r [ 0.36408] ghci.input: import Numeric.AD.Internal.Doctest [ 0.36600] ghci.input: hessian (\[x,y] -> x*y) [1,2] [ 0.42066] ghci.input: :m Numeric.AD [ 0.42625] ghci.input: :r [ 0.42878] ghci.input: import Numeric.AD.Internal.Doctest [ 0.43127] ghci.input: hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble] [ 0.44213] docspec.phase2: Numeric.AD.Halley [ 0.44250] ghci.input: :m Numeric.AD.Halley [ 0.44429] ghci.input: :r [ 0.44604] ghci.input: import Data.Complex [ 0.44837] ghci.input: :m Numeric.AD.Halley [ 0.45040] ghci.input: :r [ 0.45425] ghci.input: import Data.Complex [ 0.45643] ghci.input: take 10 $ findZero (\x->x^2-4) 1 [ 0.48154] ghci.input: last $ take 10 $ findZero ((+1).(^2)) (1 :+ 1) [ 0.49051] ghci.input: :m Numeric.AD.Halley [ 0.49198] ghci.input: :r [ 0.49432] ghci.input: import Data.Complex [ 0.49709] ghci.input: last $ take 10 $ fixedPoint cos 1 [ 0.50751] ghci.input: :m Numeric.AD.Halley [ 0.51023] ghci.input: :r [ 0.51291] ghci.input: import Data.Complex [ 0.51563] ghci.input: take 10 $ extremum cos 1 [ 0.52737] docspec.phase2: Numeric.AD.Mode.Dense [ 0.52770] ghci.input: :m Numeric.AD.Mode.Dense [ 0.52958] ghci.input: :r [ 0.53111] ghci.input: :m Numeric.AD.Mode.Dense [ 0.53335] ghci.input: :r [ 0.53523] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 0.54384] docspec.phase2: Numeric.AD.Mode.Dense.Representable [ 0.54424] ghci.input: :m Numeric.AD.Mode.Dense.Representable [ 0.54701] ghci.input: :r [ 0.54945] ghci.input: :set -XDeriveGeneric -XDeriveFunctor [ 0.55117] ghci.input: import GHC.Generics (Generic1) [ 0.56014] ghci.input: import Data.Distributive (Distributive (..)) [ 0.56589] ghci.input: import Data.Functor.Rep (Representable, distributeRep) [ 0.57042] ghci.input: data V3 a = V3 a a a deriving (Generic1, Functor, Show) [ 0.58435] ghci.input: instance Representable V3; instance Distributive V3 where distribute = distributeRep [ 0.59597] ghci.input: :m Numeric.AD.Mode.Dense.Representable [ 0.59766] ghci.input: :r [ 0.59931] ghci.input: :set -XDeriveGeneric -XDeriveFunctor [ 0.60126] ghci.input: import GHC.Generics (Generic1) [ 0.60303] ghci.input: import Data.Distributive (Distributive (..)) [ 0.60498] ghci.input: import Data.Functor.Rep (Representable, distributeRep) [ 0.60694] ghci.input: data V3 a = V3 a a a deriving (Generic1, Functor, Show) [ 0.61792] ghci.input: instance Representable V3; instance Distributive V3 where distribute = distributeRep [ 0.62557] ghci.input: grad (\(V3 x y z) -> x*y+z) (V3 1 2 3) [ 0.68777] docspec.phase2: Numeric.AD.Mode.Forward [ 0.68814] ghci.input: :m Numeric.AD.Mode.Forward [ 0.69020] ghci.input: :r [ 0.69183] ghci.input: :m Numeric.AD.Mode.Forward [ 0.69441] ghci.input: :r [ 0.69686] ghci.input: diff sin 0 [ 0.70319] ghci.input: :m Numeric.AD.Mode.Forward [ 0.70493] ghci.input: :r [ 0.70652] ghci.input: diff' sin 0 [ 0.71288] ghci.input: diff' exp 0 [ 0.71756] ghci.input: :m Numeric.AD.Mode.Forward [ 0.72017] ghci.input: :r [ 0.72290] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 0.73169] ghci.input: :m Numeric.AD.Mode.Forward [ 0.73392] ghci.input: :r [ 0.73677] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 0.74520] ghci.input: :m Numeric.AD.Mode.Forward [ 0.74811] ghci.input: :r [ 0.75068] ghci.input: jacobian (\[x,y] -> [y,x,x+y,x*y,exp x * sin y]) [pi,1] [ 0.76658] ghci.input: :m Numeric.AD.Mode.Forward [ 0.76825] ghci.input: :r [ 0.76987] ghci.input: gradWith' (,) sum [0..4] [ 0.77498] docspec.phase2: Numeric.AD.Mode.Forward.Double [ 0.77532] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.77723] ghci.input: :r [ 0.77892] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.78108] ghci.input: :r [ 0.78325] ghci.input: diff sin 0 [ 0.79227] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.79540] ghci.input: :r [ 0.79835] ghci.input: diff' sin 0 [ 0.80322] ghci.input: diff' exp 0 [ 0.80618] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.80812] ghci.input: :r [ 0.80979] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 0.81516] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.81692] ghci.input: :r [ 0.81846] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 0.82221] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.82391] ghci.input: :r [ 0.82746] ghci.input: jacobian (\[x,y] -> [y,x,x+y,x*y,exp x * sin y]) [pi,1] [ 0.83264] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.83532] ghci.input: :r [ 0.83790] ghci.input: gradWith' (,) sum [0..4] [ 0.84503] docspec.phase2: Numeric.AD.Mode.Kahn [ 0.84537] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.84802] ghci.input: :r [ 0.84959] ghci.input: import Numeric.AD.Internal.Doctest [ 0.85234] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.85395] ghci.input: :r [ 0.85553] ghci.input: import Numeric.AD.Internal.Doctest [ 0.85852] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 0.86967] ghci.input: grad (\[x,y] -> x**y) [0,2] [ 0.87903] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.88099] ghci.input: :r [ 0.88294] ghci.input: import Numeric.AD.Internal.Doctest [ 0.88469] ghci.input: grad' (\[x,y,z] -> 4*x*exp y+cos z) [1,2,3] [ 0.89151] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.89323] ghci.input: :r [ 0.89634] ghci.input: import Numeric.AD.Internal.Doctest [ 0.90065] ghci.input: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 0.91047] ghci.input: jacobian (\[x,y] -> [exp y,cos x,x+y]) [1,2] [ 0.91911] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.92077] ghci.input: :r [ 0.92280] ghci.input: import Numeric.AD.Internal.Doctest [ 0.92516] ghci.input: diff sin 0 [ 0.93078] ghci.input: cos 0 [ 0.93626] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.93919] ghci.input: :r [ 0.94203] ghci.input: import Numeric.AD.Internal.Doctest [ 0.94490] ghci.input: diff' sin 0 [ 0.95102] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.95323] ghci.input: :r [ 0.95494] ghci.input: import Numeric.AD.Internal.Doctest [ 0.95670] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 0.96440] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.96656] ghci.input: :r [ 0.96868] ghci.input: import Numeric.AD.Internal.Doctest [ 0.97102] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 0.97919] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.98132] ghci.input: :r [ 0.98349] ghci.input: import Numeric.AD.Internal.Doctest [ 0.98570] ghci.input: hessian (\[x,y] -> x*y) [1,2] [ 0.99116] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.99284] ghci.input: :r [ 0.99447] ghci.input: import Numeric.AD.Internal.Doctest [ 0.99638] ghci.input: hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble] [ 1.00222] docspec.phase2: Numeric.AD.Mode.Reverse [ 1.00256] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.00450] ghci.input: :r [ 1.00674] ghci.input: import Numeric.AD.Internal.Doctest [ 1.00970] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.01285] ghci.input: :r [ 1.01543] ghci.input: import Numeric.AD.Internal.Doctest [ 1.01806] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 1.02552] ghci.input: grad (\[x,y] -> x**y) [0,2] [ 1.03163] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.03429] ghci.input: :r [ 1.03596] ghci.input: import Numeric.AD.Internal.Doctest [ 1.03837] ghci.input: grad' (\[x,y,z] -> x*y+z) [1,2,3] [ 1.04712] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.04941] ghci.input: :r [ 1.05151] ghci.input: import Numeric.AD.Internal.Doctest [ 1.05369] ghci.input: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 1.06140] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.06344] ghci.input: :r [ 1.06507] ghci.input: import Numeric.AD.Internal.Doctest [ 1.06678] ghci.input: jacobian' (\[x,y] -> [y,x,x*y]) [2,1] [ 1.07252] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.07523] ghci.input: :r [ 1.07852] ghci.input: import Numeric.AD.Internal.Doctest [ 1.08108] ghci.input: diff sin 0 [ 1.08904] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.09179] ghci.input: :r [ 1.09436] ghci.input: import Numeric.AD.Internal.Doctest [ 1.09705] ghci.input: diff' sin 0 [ 1.10341] ghci.input: diff' exp 0 [ 1.11061] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.11290] ghci.input: :r [ 1.11511] ghci.input: import Numeric.AD.Internal.Doctest [ 1.11728] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 1.12523] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.12805] ghci.input: :r [ 1.13084] ghci.input: import Numeric.AD.Internal.Doctest [ 1.13376] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 1.13890] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.14058] ghci.input: :r [ 1.14213] ghci.input: import Numeric.AD.Internal.Doctest [ 1.14377] ghci.input: hessian (\[x,y] -> x*y) [1,2] [ 1.14932] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.15100] ghci.input: :r [ 1.15298] ghci.input: import Numeric.AD.Internal.Doctest [ 1.15478] ghci.input: hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble] [ 1.16069] docspec.phase2: Numeric.AD.Mode.Reverse.Double [ 1.16101] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.16292] ghci.input: :r [ 1.16457] ghci.input: import Numeric.AD.Internal.Doctest [ 1.16621] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.16876] ghci.input: :r [ 1.17127] ghci.input: import Numeric.AD.Internal.Doctest [ 1.17349] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 1.18001] ghci.input: grad (\[x,y] -> x**y) [0,2] [ 1.18471] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.18742] ghci.input: :r [ 1.18940] ghci.input: import Numeric.AD.Internal.Doctest [ 1.19174] ghci.input: grad' (\[x,y,z] -> x*y+z) [1,2,3] [ 1.19858] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.20155] ghci.input: :r [ 1.20429] ghci.input: import Numeric.AD.Internal.Doctest [ 1.20736] ghci.input: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 1.21214] error: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 1.21250] error: in comment at 113:1 expected: [[0.0,1.0],[1.0,0.0],[1.0,2.0]] but got: *** Exception: Ix{Int}.index: Index (3) out of range ((0,2)) ^ [[ [ 1.21336] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.21504] ghci.input: :r [ 1.21706] ghci.input: import Numeric.AD.Internal.Doctest [ 1.22007] ghci.input: jacobian' (\[x,y] -> [y,x,x*y]) [2,1] [ 4.22123] warning[-Wtimeout]: timeout... [ 14.23163] peu.die: ghci exited ExitFailure (-11) proci: canceling proci: terminating proci: pid Nothing proci: waiting for termination ```

Curiously, if I run this without Docker, cabal-docspec -v doesn't show the exception at all. Moreover, cabal-docspec normally does display the results of thrown exceptions, so I'm inclined to blame this on memory corruption weirdness.

In any case, I'm not able to reproduce this on the latest commit (bd1c03e), either locally or with Docker. I'm going to optimistically deem this a bug in the older commit (642c10c514cc851aba5b0c7b29b8391fb57b2f56), not with cabal-docspec itself.

ekmett commented 3 years ago

Index (3) out of range ((0,2))

seems to be pretty telling. Let me go check for an off-by-1 in Sofus's code just to be sure.

On Sun, Feb 21, 2021 at 4:08 PM Ryan Scott notifications@github.com wrote:

Investigating the cabal-docspec timeout a little further, I am able to reproduce it on the commit 642c10c https://github.com/ekmett/ad/commit/642c10c514cc851aba5b0c7b29b8391fb57b2f56, but not on current master (bd1c03e https://github.com/ekmett/ad/commit/bd1c03ee8cf49241889d28eea53eb405d2c206e6). I suspect that the older commit has some sort of memory corruption bug which is tripping up cabal-docspec. If I run the same steps as in the GitHub Actions workflow, but passing -v to cabal-docspec, here is what I get:

$ docker run --rm -it buildpack-deps:bionic root@c45d0e33c5c0:/# cat >> bug.sh << 'EOF'

!/usr/bin/env bash

set -e

export CABAL_VERSION=3.2 export GHC_VERSION=8.10.4 export PATH=$HOME/.cabal/bin:/opt/cabal/$CABAL_VERSION/bin:/opt/ghc/$GHC_VERSION/bin:$PATH

apt-get update apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common apt-add-repository -y 'ppa:hvr/ghc' apt-get update apt-get install -y ghc-$GHC_VERSION cabal-install-$CABAL_VERSION

mkdir -p $HOME/.cabal/bin curl -sL https://github.com/phadej/cabal-extras/releases/download/cabal-docspec-0.0.0.20210111/cabal-docspec-0.0.0.20210111.xz > cabal-docspec.xz echo '0829bd034fba901cbcfe491d98ed8b28fd54f9cb5c91fa8e1ac62dc4413c9562 cabal-docspec.xz' | sha256sum -c - xz -d < cabal-docspec.xz > $HOME/.cabal/bin/cabal-docspec rm -f cabal-docspec.xz chmod a+x $HOME/.cabal/bin/cabal-docspec cabal-docspec --version

git clone https://github.com/ekmett/ad cd ad/ git reset --hard 642c10c514cc851aba5b0c7b29b8391fb57b2f56 cabal v2-update cabal v2-build -fffi cabal-docspec -v EOF root@c45d0e33c5c0:/# chmod a+x bug.sh root@c45d0e33c5c0:/# ./bug.sh

[ 0.00001] ghc.info: ghc [ 0.00042] process.0.start: cwd=/tmp ghc --info [ 0.05131] docspec.component: ad-4.5 lib [ 0.05312] docspec.phase1: Numeric.AD: /ad/./src/Numeric/AD.hs [ 0.05687] docspec.phase1: Numeric.AD.Halley: /ad/./src/Numeric/AD/Halley.hs [ 0.05717] docspec.phase1: Numeric.AD.Internal.Dense: /ad/./src/Numeric/AD/Internal/Dense.hs [ 0.06342] docspec.phase1: Numeric.AD.Internal.Dense.Representable: /ad/./src/Numeric/AD/Internal/Dense/Representable.hs [ 0.06949] docspec.phase1: Numeric.AD.Internal.Doctest: /ad/./src/Numeric/AD/Internal/Doctest.hs [ 0.06987] docspec.phase1: Numeric.AD.Internal.Forward: /ad/./src/Numeric/AD/Internal/Forward.hs [ 0.07646] docspec.phase1: Numeric.AD.Internal.Forward.Double: /ad/./src/Numeric/AD/Internal/Forward/Double.hs [ 0.08615] docspec.phase1: Numeric.AD.Internal.Identity: /ad/./src/Numeric/AD/Internal/Identity.hs [ 0.08846] docspec.phase1: Numeric.AD.Internal.Kahn: /ad/./src/Numeric/AD/Internal/Kahn.hs [ 0.09522] docspec.phase1: Numeric.AD.Internal.On: /ad/./src/Numeric/AD/Internal/On.hs [ 0.09715] docspec.phase1: Numeric.AD.Internal.Or: /ad/./src/Numeric/AD/Internal/Or.hs [ 0.10147] docspec.phase1: Numeric.AD.Internal.Reverse: /ad/./src/Numeric/AD/Internal/Reverse.hs [ 0.10886] docspec.phase1: Numeric.AD.Internal.Reverse.Double: /ad/./src/Numeric/AD/Internal/Reverse/Double.hs [ 0.11505] docspec.phase1: Numeric.AD.Internal.Sparse: /ad/./src/Numeric/AD/Internal/Sparse.hs [ 0.12751] docspec.phase1: Numeric.AD.Internal.Tower: /ad/./src/Numeric/AD/Internal/Tower.hs [ 0.13243] docspec.phase1: Numeric.AD.Internal.Type: /ad/./src/Numeric/AD/Internal/Type.hs [ 0.13275] docspec.phase1: Numeric.AD.Jacobian: /ad/./src/Numeric/AD/Jacobian.hs [ 0.13468] docspec.phase1: Numeric.AD.Jet: /ad/./src/Numeric/AD/Jet.hs [ 0.13780] docspec.phase1: Numeric.AD.Mode: /ad/./src/Numeric/AD/Mode.hs [ 0.14057] docspec.phase1: Numeric.AD.Mode.Dense: /ad/./src/Numeric/AD/Mode/Dense.hs [ 0.14371] docspec.phase1: Numeric.AD.Mode.Dense.Representable: /ad/./src/Numeric/AD/Mode/Dense/Representable.hs [ 0.14638] docspec.phase1: Numeric.AD.Mode.Forward: /ad/./src/Numeric/AD/Mode/Forward.hs [ 0.15573] docspec.phase1: Numeric.AD.Mode.Forward.Double: /ad/./src/Numeric/AD/Mode/Forward/Double.hs [ 0.16094] docspec.phase1: Numeric.AD.Mode.Kahn: /ad/./src/Numeric/AD/Mode/Kahn.hs [ 0.16529] docspec.phase1: Numeric.AD.Mode.Reverse: /ad/./src/Numeric/AD/Mode/Reverse.hs [ 0.16911] docspec.phase1: Numeric.AD.Mode.Reverse.Double: /ad/./src/Numeric/AD/Mode/Reverse/Double.hs [ 0.17399] docspec.phase1: Numeric.AD.Mode.Sparse: /ad/./src/Numeric/AD/Mode/Sparse.hs [ 0.17691] docspec.phase1: Numeric.AD.Mode.Tower: /ad/./src/Numeric/AD/Mode/Tower.hs [ 0.17758] docspec.phase1: Numeric.AD.Newton: /ad/./src/Numeric/AD/Newton.hs [ 0.18877] docspec.phase1: Numeric.AD.Newton.Double: /ad/./src/Numeric/AD/Newton/Double.hs [ 0.18915] docspec.phase1: Numeric.AD.Rank1.Dense: /ad/./src/Numeric/AD/Rank1/Dense.hs [ 0.19159] docspec.phase1: Numeric.AD.Rank1.Dense.Representable: /ad/./src/Numeric/AD/Rank1/Dense/Representable.hs [ 0.19413] docspec.phase1: Numeric.AD.Rank1.Forward: /ad/./src/Numeric/AD/Rank1/Forward.hs [ 0.19791] docspec.phase1: Numeric.AD.Rank1.Forward.Double: /ad/./src/Numeric/AD/Rank1/Forward/Double.hs [ 0.20249] docspec.phase1: Numeric.AD.Rank1.Halley: /ad/./src/Numeric/AD/Rank1/Halley.hs [ 0.20527] docspec.phase1: Numeric.AD.Rank1.Kahn: /ad/./src/Numeric/AD/Rank1/Kahn.hs [ 0.20883] docspec.phase1: Numeric.AD.Rank1.Newton: /ad/./src/Numeric/AD/Rank1/Newton.hs [ 0.21337] docspec.phase1: Numeric.AD.Rank1.Newton.Double: /ad/./src/Numeric/AD/Rank1/Newton/Double.hs [ 0.21599] docspec.phase1: Numeric.AD.Rank1.Sparse: /ad/./src/Numeric/AD/Rank1/Sparse.hs [ 0.21888] docspec.phase1: Numeric.AD.Rank1.Tower: /ad/./src/Numeric/AD/Rank1/Tower.hs [ 0.22201] ghci: ghc --interactive -ignore-dot-ghci -v0 -i -hide-all-packages -no-user-package-db -package-db=/root/.cabal/store/ghc-8.10.4/package.db -package-db=/ad/dist-newstyle/packagedb/ghc-8.10.4 -package-id=ad-4.5-inplace -package-id=adjunctions-4.4-3eec42b3d0e36eb316b8fea59504b7ee0bcac398b37190ab0cf686015f5fc9ad -package-id=array-0.5.4.0 -package-id=base-4.14.1.0 -package-id=comonad-5.0.8-262f0f0e2af8c9f7f652caeb56486ae4062916e480b6d049a87f84bc93964829 -package-id=containers-0.6.2.1 -package-id=data-reify-0.6.3-eea2b7fa436542a8b583fa488f613b3495b27b365f81826477c2ce942bdf8c8b -package-id=erf-2.0.0.0-4ef6c7f8d8e28c776dbf39f5496433642d8c68627d816f70bbbad06d63091476 -package-id=free-5.1.6-f5b0a99fe6be0e571fe085c189dc1c3e410b3ae8354068327f05c56b13732fa6 -package-id=nats-1.1.2-f64b5777448a6bd6bdc36f9c6f49524e4c9d779d0be64513fb8ba21acd7fdb94 -package-id=reflection-2.1.6-bc119d9927a405dbd42187799cc5f636fb8aa5fee9b009c5d1a56c21bac6f5ab -package-id=semigroups-0.19.1-9bd2a5a836db517f37cc75e4855c48fac208d217260aee35dd472bf6367f488b -package-id=transformers-0.5.6.2 -package-id=distributive-0.6.2.1-744776ee91045549e0fe4c724bd0101ffbc636f653bf4f8705fcd75219ee4124 [ 0.31758] docspec.phase2: Numeric.AD [ 0.31789] ghci.input: :m Numeric.AD [ 0.35235] ghci.input: :r [ 0.35516] ghci.input: import Numeric.AD.Internal.Doctest [ 0.35855] ghci.input: :m Numeric.AD [ 0.36205] ghci.input: :r [ 0.36408] ghci.input: import Numeric.AD.Internal.Doctest [ 0.36600] ghci.input: hessian (\[x,y] -> x*y) [1,2] [ 0.42066] ghci.input: :m Numeric.AD [ 0.42625] ghci.input: :r [ 0.42878] ghci.input: import Numeric.AD.Internal.Doctest [ 0.43127] ghci.input: hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble] [ 0.44213] docspec.phase2: Numeric.AD.Halley [ 0.44250] ghci.input: :m Numeric.AD.Halley [ 0.44429] ghci.input: :r [ 0.44604] ghci.input: import Data.Complex [ 0.44837] ghci.input: :m Numeric.AD.Halley [ 0.45040] ghci.input: :r [ 0.45425] ghci.input: import Data.Complex [ 0.45643] ghci.input: take 10 $ findZero (\x->x^2-4) 1 [ 0.48154] ghci.input: last $ take 10 $ findZero ((+1).(^2)) (1 :+ 1) [ 0.49051] ghci.input: :m Numeric.AD.Halley [ 0.49198] ghci.input: :r [ 0.49432] ghci.input: import Data.Complex [ 0.49709] ghci.input: last $ take 10 $ fixedPoint cos 1 [ 0.50751] ghci.input: :m Numeric.AD.Halley [ 0.51023] ghci.input: :r [ 0.51291] ghci.input: import Data.Complex [ 0.51563] ghci.input: take 10 $ extremum cos 1 [ 0.52737] docspec.phase2: Numeric.AD.Mode.Dense [ 0.52770] ghci.input: :m Numeric.AD.Mode.Dense [ 0.52958] ghci.input: :r [ 0.53111] ghci.input: :m Numeric.AD.Mode.Dense [ 0.53335] ghci.input: :r [ 0.53523] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 0.54384] docspec.phase2: Numeric.AD.Mode.Dense.Representable [ 0.54424] ghci.input: :m Numeric.AD.Mode.Dense.Representable [ 0.54701] ghci.input: :r [ 0.54945] ghci.input: :set -XDeriveGeneric -XDeriveFunctor [ 0.55117] ghci.input: import GHC.Generics (Generic1) [ 0.56014] ghci.input: import Data.Distributive (Distributive (..)) [ 0.56589] ghci.input: import Data.Functor.Rep (Representable, distributeRep) [ 0.57042] ghci.input: data V3 a = V3 a a a deriving (Generic1, Functor, Show) [ 0.58435] ghci.input: instance Representable V3; instance Distributive V3 where distribute = distributeRep [ 0.59597] ghci.input: :m Numeric.AD.Mode.Dense.Representable [ 0.59766] ghci.input: :r [ 0.59931] ghci.input: :set -XDeriveGeneric -XDeriveFunctor [ 0.60126] ghci.input: import GHC.Generics (Generic1) [ 0.60303] ghci.input: import Data.Distributive (Distributive (..)) [ 0.60498] ghci.input: import Data.Functor.Rep (Representable, distributeRep) [ 0.60694] ghci.input: data V3 a = V3 a a a deriving (Generic1, Functor, Show) [ 0.61792] ghci.input: instance Representable V3; instance Distributive V3 where distribute = distributeRep [ 0.62557] ghci.input: grad (\(V3 x y z) -> x*y+z) (V3 1 2 3) [ 0.68777] docspec.phase2: Numeric.AD.Mode.Forward [ 0.68814] ghci.input: :m Numeric.AD.Mode.Forward [ 0.69020] ghci.input: :r [ 0.69183] ghci.input: :m Numeric.AD.Mode.Forward [ 0.69441] ghci.input: :r [ 0.69686] ghci.input: diff sin 0 [ 0.70319] ghci.input: :m Numeric.AD.Mode.Forward [ 0.70493] ghci.input: :r [ 0.70652] ghci.input: diff' sin 0 [ 0.71288] ghci.input: diff' exp 0 [ 0.71756] ghci.input: :m Numeric.AD.Mode.Forward [ 0.72017] ghci.input: :r [ 0.72290] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 0.73169] ghci.input: :m Numeric.AD.Mode.Forward [ 0.73392] ghci.input: :r [ 0.73677] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 0.74520] ghci.input: :m Numeric.AD.Mode.Forward [ 0.74811] ghci.input: :r [ 0.75068] ghci.input: jacobian (\[x,y] -> [y,x,x+y,x*y,exp x * sin y]) [pi,1] [ 0.76658] ghci.input: :m Numeric.AD.Mode.Forward [ 0.76825] ghci.input: :r [ 0.76987] ghci.input: gradWith' (,) sum [0..4] [ 0.77498] docspec.phase2: Numeric.AD.Mode.Forward.Double [ 0.77532] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.77723] ghci.input: :r [ 0.77892] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.78108] ghci.input: :r [ 0.78325] ghci.input: diff sin 0 [ 0.79227] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.79540] ghci.input: :r [ 0.79835] ghci.input: diff' sin 0 [ 0.80322] ghci.input: diff' exp 0 [ 0.80618] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.80812] ghci.input: :r [ 0.80979] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 0.81516] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.81692] ghci.input: :r [ 0.81846] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 0.82221] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.82391] ghci.input: :r [ 0.82746] ghci.input: jacobian (\[x,y] -> [y,x,x+y,x*y,exp x * sin y]) [pi,1] [ 0.83264] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.83532] ghci.input: :r [ 0.83790] ghci.input: gradWith' (,) sum [0..4] [ 0.84503] docspec.phase2: Numeric.AD.Mode.Kahn [ 0.84537] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.84802] ghci.input: :r [ 0.84959] ghci.input: import Numeric.AD.Internal.Doctest [ 0.85234] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.85395] ghci.input: :r [ 0.85553] ghci.input: import Numeric.AD.Internal.Doctest [ 0.85852] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 0.86967] ghci.input: grad (\[x,y] -> x**y) [0,2] [ 0.87903] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.88099] ghci.input: :r [ 0.88294] ghci.input: import Numeric.AD.Internal.Doctest [ 0.88469] ghci.input: grad' (\[x,y,z] -> 4*x*exp y+cos z) [1,2,3] [ 0.89151] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.89323] ghci.input: :r [ 0.89634] ghci.input: import Numeric.AD.Internal.Doctest [ 0.90065] ghci.input: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 0.91047] ghci.input: jacobian (\[x,y] -> [exp y,cos x,x+y]) [1,2] [ 0.91911] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.92077] ghci.input: :r [ 0.92280] ghci.input: import Numeric.AD.Internal.Doctest [ 0.92516] ghci.input: diff sin 0 [ 0.93078] ghci.input: cos 0 [ 0.93626] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.93919] ghci.input: :r [ 0.94203] ghci.input: import Numeric.AD.Internal.Doctest [ 0.94490] ghci.input: diff' sin 0 [ 0.95102] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.95323] ghci.input: :r [ 0.95494] ghci.input: import Numeric.AD.Internal.Doctest [ 0.95670] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 0.96440] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.96656] ghci.input: :r [ 0.96868] ghci.input: import Numeric.AD.Internal.Doctest [ 0.97102] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 0.97919] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.98132] ghci.input: :r [ 0.98349] ghci.input: import Numeric.AD.Internal.Doctest [ 0.98570] ghci.input: hessian (\[x,y] -> x*y) [1,2] [ 0.99116] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.99284] ghci.input: :r [ 0.99447] ghci.input: import Numeric.AD.Internal.Doctest [ 0.99638] ghci.input: hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble] [ 1.00222] docspec.phase2: Numeric.AD.Mode.Reverse [ 1.00256] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.00450] ghci.input: :r [ 1.00674] ghci.input: import Numeric.AD.Internal.Doctest [ 1.00970] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.01285] ghci.input: :r [ 1.01543] ghci.input: import Numeric.AD.Internal.Doctest [ 1.01806] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 1.02552] ghci.input: grad (\[x,y] -> x**y) [0,2] [ 1.03163] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.03429] ghci.input: :r [ 1.03596] ghci.input: import Numeric.AD.Internal.Doctest [ 1.03837] ghci.input: grad' (\[x,y,z] -> x*y+z) [1,2,3] [ 1.04712] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.04941] ghci.input: :r [ 1.05151] ghci.input: import Numeric.AD.Internal.Doctest [ 1.05369] ghci.input: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 1.06140] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.06344] ghci.input: :r [ 1.06507] ghci.input: import Numeric.AD.Internal.Doctest [ 1.06678] ghci.input: jacobian' (\[x,y] -> [y,x,x*y]) [2,1] [ 1.07252] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.07523] ghci.input: :r [ 1.07852] ghci.input: import Numeric.AD.Internal.Doctest [ 1.08108] ghci.input: diff sin 0 [ 1.08904] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.09179] ghci.input: :r [ 1.09436] ghci.input: import Numeric.AD.Internal.Doctest [ 1.09705] ghci.input: diff' sin 0 [ 1.10341] ghci.input: diff' exp 0 [ 1.11061] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.11290] ghci.input: :r [ 1.11511] ghci.input: import Numeric.AD.Internal.Doctest [ 1.11728] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 1.12523] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.12805] ghci.input: :r [ 1.13084] ghci.input: import Numeric.AD.Internal.Doctest [ 1.13376] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 1.13890] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.14058] ghci.input: :r [ 1.14213] ghci.input: import Numeric.AD.Internal.Doctest [ 1.14377] ghci.input: hessian (\[x,y] -> x*y) [1,2] [ 1.14932] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.15100] ghci.input: :r [ 1.15298] ghci.input: import Numeric.AD.Internal.Doctest [ 1.15478] ghci.input: hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble] [ 1.16069] docspec.phase2: Numeric.AD.Mode.Reverse.Double [ 1.16101] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.16292] ghci.input: :r [ 1.16457] ghci.input: import Numeric.AD.Internal.Doctest [ 1.16621] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.16876] ghci.input: :r [ 1.17127] ghci.input: import Numeric.AD.Internal.Doctest [ 1.17349] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 1.18001] ghci.input: grad (\[x,y] -> x**y) [0,2] [ 1.18471] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.18742] ghci.input: :r [ 1.18940] ghci.input: import Numeric.AD.Internal.Doctest [ 1.19174] ghci.input: grad' (\[x,y,z] -> x*y+z) [1,2,3] [ 1.19858] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.20155] ghci.input: :r [ 1.20429] ghci.input: import Numeric.AD.Internal.Doctest [ 1.20736] ghci.input: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 1.21214] error: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 1.21250] error: in comment at 113:1 expected: [[0.0,1.0],[1.0,0.0],[1.0,2.0]] but got: *** Exception: Ix{Int}.index: Index (3) out of range ((0,2)) ^ [[

[ 1.21336] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.21504] ghci.input: :r [ 1.21706] ghci.input: import Numeric.AD.Internal.Doctest [ 1.22007] ghci.input: jacobian' ([x,y] -> [y,x,x*y]) [2,1]

[ 14.23163] peu.die: ghci exited ExitFailure (-11) proci: canceling proci: terminating proci: pid Nothing proci: waiting for termination

Curiously, if I run this without Docker, cabal-docspec -v doesn't show the exception at all. Moreover, cabal-docspec normally does display the results of thrown exceptions, so I'm inclined to blame this on memory corruption weirdness.

In any case, I'm not able to reproduce this on the latest commit (bd1c03e https://github.com/ekmett/ad/commit/bd1c03ee8cf49241889d28eea53eb405d2c206e6), either locally or with Docker. I'm going to optimistically deem this a bug in the older commit (642c10c https://github.com/ekmett/ad/commit/642c10c514cc851aba5b0c7b29b8391fb57b2f56), not with cabal-docspec itself.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ekmett/ad/pull/93#issuecomment-782956811, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACKMEOOFFI7U3YONMYSUYLTAGOBNANCNFSM4XTITEQQ .

ekmett commented 3 years ago

The original version of Sofus's code that you are investigating that was live at the time of that build used IORef (Ptr ()) to hold the tape.

The IORef did nothing as the Ptr () never changed. It relied on strictness to hopefully be safe. Neither are valid.

So I switched it to a ForeignPtr Tape before we made it to HEAD. There were also issues with it passing Ints to FFI, without using capi, which meant that on a 32-bit platform it probably went very wrong, likely leading to memory corruption.

-Edward

On Sun, Feb 21, 2021 at 4:47 PM Edward Kmett ekmett@gmail.com wrote:

Index (3) out of range ((0,2))

seems to be pretty telling. Let me go check for an off-by-1 in Sofus's code just to be sure.

On Sun, Feb 21, 2021 at 4:08 PM Ryan Scott notifications@github.com wrote:

Investigating the cabal-docspec timeout a little further, I am able to reproduce it on the commit 642c10c https://github.com/ekmett/ad/commit/642c10c514cc851aba5b0c7b29b8391fb57b2f56, but not on current master (bd1c03e https://github.com/ekmett/ad/commit/bd1c03ee8cf49241889d28eea53eb405d2c206e6). I suspect that the older commit has some sort of memory corruption bug which is tripping up cabal-docspec. If I run the same steps as in the GitHub Actions workflow, but passing -v to cabal-docspec, here is what I get:

$ docker run --rm -it buildpack-deps:bionic root@c45d0e33c5c0:/# cat >> bug.sh << 'EOF'

!/usr/bin/env bash

set -e

export CABAL_VERSION=3.2 export GHC_VERSION=8.10.4 export PATH=$HOME/.cabal/bin:/opt/cabal/$CABAL_VERSION/bin:/opt/ghc/$GHC_VERSION/bin:$PATH

apt-get update apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common apt-add-repository -y 'ppa:hvr/ghc' apt-get update apt-get install -y ghc-$GHC_VERSION cabal-install-$CABAL_VERSION

mkdir -p $HOME/.cabal/bin curl -sL https://github.com/phadej/cabal-extras/releases/download/cabal-docspec-0.0.0.20210111/cabal-docspec-0.0.0.20210111.xz > cabal-docspec.xz echo '0829bd034fba901cbcfe491d98ed8b28fd54f9cb5c91fa8e1ac62dc4413c9562 cabal-docspec.xz' | sha256sum -c - xz -d < cabal-docspec.xz > $HOME/.cabal/bin/cabal-docspec rm -f cabal-docspec.xz chmod a+x $HOME/.cabal/bin/cabal-docspec cabal-docspec --version

git clone https://github.com/ekmett/ad cd ad/ git reset --hard 642c10c514cc851aba5b0c7b29b8391fb57b2f56 cabal v2-update cabal v2-build -fffi cabal-docspec -v EOF root@c45d0e33c5c0:/# chmod a+x bug.sh root@c45d0e33c5c0:/# ./bug.sh

[ 0.00001] ghc.info: ghc [ 0.00042] process.0.start: cwd=/tmp ghc --info [ 0.05131] docspec.component: ad-4.5 lib [ 0.05312] docspec.phase1: Numeric.AD: /ad/./src/Numeric/AD.hs [ 0.05687] docspec.phase1: Numeric.AD.Halley: /ad/./src/Numeric/AD/Halley.hs [ 0.05717] docspec.phase1: Numeric.AD.Internal.Dense: /ad/./src/Numeric/AD/Internal/Dense.hs [ 0.06342] docspec.phase1: Numeric.AD.Internal.Dense.Representable: /ad/./src/Numeric/AD/Internal/Dense/Representable.hs [ 0.06949] docspec.phase1: Numeric.AD.Internal.Doctest: /ad/./src/Numeric/AD/Internal/Doctest.hs [ 0.06987] docspec.phase1: Numeric.AD.Internal.Forward: /ad/./src/Numeric/AD/Internal/Forward.hs [ 0.07646] docspec.phase1: Numeric.AD.Internal.Forward.Double: /ad/./src/Numeric/AD/Internal/Forward/Double.hs [ 0.08615] docspec.phase1: Numeric.AD.Internal.Identity: /ad/./src/Numeric/AD/Internal/Identity.hs [ 0.08846] docspec.phase1: Numeric.AD.Internal.Kahn: /ad/./src/Numeric/AD/Internal/Kahn.hs [ 0.09522] docspec.phase1: Numeric.AD.Internal.On: /ad/./src/Numeric/AD/Internal/On.hs [ 0.09715] docspec.phase1: Numeric.AD.Internal.Or: /ad/./src/Numeric/AD/Internal/Or.hs [ 0.10147] docspec.phase1: Numeric.AD.Internal.Reverse: /ad/./src/Numeric/AD/Internal/Reverse.hs [ 0.10886] docspec.phase1: Numeric.AD.Internal.Reverse.Double: /ad/./src/Numeric/AD/Internal/Reverse/Double.hs [ 0.11505] docspec.phase1: Numeric.AD.Internal.Sparse: /ad/./src/Numeric/AD/Internal/Sparse.hs [ 0.12751] docspec.phase1: Numeric.AD.Internal.Tower: /ad/./src/Numeric/AD/Internal/Tower.hs [ 0.13243] docspec.phase1: Numeric.AD.Internal.Type: /ad/./src/Numeric/AD/Internal/Type.hs [ 0.13275] docspec.phase1: Numeric.AD.Jacobian: /ad/./src/Numeric/AD/Jacobian.hs [ 0.13468] docspec.phase1: Numeric.AD.Jet: /ad/./src/Numeric/AD/Jet.hs [ 0.13780] docspec.phase1: Numeric.AD.Mode: /ad/./src/Numeric/AD/Mode.hs [ 0.14057] docspec.phase1: Numeric.AD.Mode.Dense: /ad/./src/Numeric/AD/Mode/Dense.hs [ 0.14371] docspec.phase1: Numeric.AD.Mode.Dense.Representable: /ad/./src/Numeric/AD/Mode/Dense/Representable.hs [ 0.14638] docspec.phase1: Numeric.AD.Mode.Forward: /ad/./src/Numeric/AD/Mode/Forward.hs [ 0.15573] docspec.phase1: Numeric.AD.Mode.Forward.Double: /ad/./src/Numeric/AD/Mode/Forward/Double.hs [ 0.16094] docspec.phase1: Numeric.AD.Mode.Kahn: /ad/./src/Numeric/AD/Mode/Kahn.hs [ 0.16529] docspec.phase1: Numeric.AD.Mode.Reverse: /ad/./src/Numeric/AD/Mode/Reverse.hs [ 0.16911] docspec.phase1: Numeric.AD.Mode.Reverse.Double: /ad/./src/Numeric/AD/Mode/Reverse/Double.hs [ 0.17399] docspec.phase1: Numeric.AD.Mode.Sparse: /ad/./src/Numeric/AD/Mode/Sparse.hs [ 0.17691] docspec.phase1: Numeric.AD.Mode.Tower: /ad/./src/Numeric/AD/Mode/Tower.hs [ 0.17758] docspec.phase1: Numeric.AD.Newton: /ad/./src/Numeric/AD/Newton.hs [ 0.18877] docspec.phase1: Numeric.AD.Newton.Double: /ad/./src/Numeric/AD/Newton/Double.hs [ 0.18915] docspec.phase1: Numeric.AD.Rank1.Dense: /ad/./src/Numeric/AD/Rank1/Dense.hs [ 0.19159] docspec.phase1: Numeric.AD.Rank1.Dense.Representable: /ad/./src/Numeric/AD/Rank1/Dense/Representable.hs [ 0.19413] docspec.phase1: Numeric.AD.Rank1.Forward: /ad/./src/Numeric/AD/Rank1/Forward.hs [ 0.19791] docspec.phase1: Numeric.AD.Rank1.Forward.Double: /ad/./src/Numeric/AD/Rank1/Forward/Double.hs [ 0.20249] docspec.phase1: Numeric.AD.Rank1.Halley: /ad/./src/Numeric/AD/Rank1/Halley.hs [ 0.20527] docspec.phase1: Numeric.AD.Rank1.Kahn: /ad/./src/Numeric/AD/Rank1/Kahn.hs [ 0.20883] docspec.phase1: Numeric.AD.Rank1.Newton: /ad/./src/Numeric/AD/Rank1/Newton.hs [ 0.21337] docspec.phase1: Numeric.AD.Rank1.Newton.Double: /ad/./src/Numeric/AD/Rank1/Newton/Double.hs [ 0.21599] docspec.phase1: Numeric.AD.Rank1.Sparse: /ad/./src/Numeric/AD/Rank1/Sparse.hs [ 0.21888] docspec.phase1: Numeric.AD.Rank1.Tower: /ad/./src/Numeric/AD/Rank1/Tower.hs [ 0.22201] ghci: ghc --interactive -ignore-dot-ghci -v0 -i -hide-all-packages -no-user-package-db -package-db=/root/.cabal/store/ghc-8.10.4/package.db -package-db=/ad/dist-newstyle/packagedb/ghc-8.10.4 -package-id=ad-4.5-inplace -package-id=adjunctions-4.4-3eec42b3d0e36eb316b8fea59504b7ee0bcac398b37190ab0cf686015f5fc9ad -package-id=array-0.5.4.0 -package-id=base-4.14.1.0 -package-id=comonad-5.0.8-262f0f0e2af8c9f7f652caeb56486ae4062916e480b6d049a87f84bc93964829 -package-id=containers-0.6.2.1 -package-id=data-reify-0.6.3-eea2b7fa436542a8b583fa488f613b3495b27b365f81826477c2ce942bdf8c8b -package-id=erf-2.0.0.0-4ef6c7f8d8e28c776dbf39f5496433642d8c68627d816f70bbbad06d63091476 -package-id=free-5.1.6-f5b0a99fe6be0e571fe085c189dc1c3e410b3ae8354068327f05c56b13732fa6 -package-id=nats-1.1.2-f64b5777448a6bd6bdc36f9c6f49524e4c9d779d0be64513fb8ba21acd7fdb94 -package-id=reflection-2.1.6-bc119d9927a405dbd42187799cc5f636fb8aa5fee9b009c5d1a56c21bac6f5ab -package-id=semigroups-0.19.1-9bd2a5a836db517f37cc75e4855c48fac208d217260aee35dd472bf6367f488b -package-id=transformers-0.5.6.2 -package-id=distributive-0.6.2.1-744776ee91045549e0fe4c724bd0101ffbc636f653bf4f8705fcd75219ee4124 [ 0.31758] docspec.phase2: Numeric.AD [ 0.31789] ghci.input: :m Numeric.AD [ 0.35235] ghci.input: :r [ 0.35516] ghci.input: import Numeric.AD.Internal.Doctest [ 0.35855] ghci.input: :m Numeric.AD [ 0.36205] ghci.input: :r [ 0.36408] ghci.input: import Numeric.AD.Internal.Doctest [ 0.36600] ghci.input: hessian (\[x,y] -> x*y) [1,2] [ 0.42066] ghci.input: :m Numeric.AD [ 0.42625] ghci.input: :r [ 0.42878] ghci.input: import Numeric.AD.Internal.Doctest [ 0.43127] ghci.input: hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble] [ 0.44213] docspec.phase2: Numeric.AD.Halley [ 0.44250] ghci.input: :m Numeric.AD.Halley [ 0.44429] ghci.input: :r [ 0.44604] ghci.input: import Data.Complex [ 0.44837] ghci.input: :m Numeric.AD.Halley [ 0.45040] ghci.input: :r [ 0.45425] ghci.input: import Data.Complex [ 0.45643] ghci.input: take 10 $ findZero (\x->x^2-4) 1 [ 0.48154] ghci.input: last $ take 10 $ findZero ((+1).(^2)) (1 :+ 1) [ 0.49051] ghci.input: :m Numeric.AD.Halley [ 0.49198] ghci.input: :r [ 0.49432] ghci.input: import Data.Complex [ 0.49709] ghci.input: last $ take 10 $ fixedPoint cos 1 [ 0.50751] ghci.input: :m Numeric.AD.Halley [ 0.51023] ghci.input: :r [ 0.51291] ghci.input: import Data.Complex [ 0.51563] ghci.input: take 10 $ extremum cos 1 [ 0.52737] docspec.phase2: Numeric.AD.Mode.Dense [ 0.52770] ghci.input: :m Numeric.AD.Mode.Dense [ 0.52958] ghci.input: :r [ 0.53111] ghci.input: :m Numeric.AD.Mode.Dense [ 0.53335] ghci.input: :r [ 0.53523] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 0.54384] docspec.phase2: Numeric.AD.Mode.Dense.Representable [ 0.54424] ghci.input: :m Numeric.AD.Mode.Dense.Representable [ 0.54701] ghci.input: :r [ 0.54945] ghci.input: :set -XDeriveGeneric -XDeriveFunctor [ 0.55117] ghci.input: import GHC.Generics (Generic1) [ 0.56014] ghci.input: import Data.Distributive (Distributive (..)) [ 0.56589] ghci.input: import Data.Functor.Rep (Representable, distributeRep) [ 0.57042] ghci.input: data V3 a = V3 a a a deriving (Generic1, Functor, Show) [ 0.58435] ghci.input: instance Representable V3; instance Distributive V3 where distribute = distributeRep [ 0.59597] ghci.input: :m Numeric.AD.Mode.Dense.Representable [ 0.59766] ghci.input: :r [ 0.59931] ghci.input: :set -XDeriveGeneric -XDeriveFunctor [ 0.60126] ghci.input: import GHC.Generics (Generic1) [ 0.60303] ghci.input: import Data.Distributive (Distributive (..)) [ 0.60498] ghci.input: import Data.Functor.Rep (Representable, distributeRep) [ 0.60694] ghci.input: data V3 a = V3 a a a deriving (Generic1, Functor, Show) [ 0.61792] ghci.input: instance Representable V3; instance Distributive V3 where distribute = distributeRep [ 0.62557] ghci.input: grad (\(V3 x y z) -> x*y+z) (V3 1 2 3) [ 0.68777] docspec.phase2: Numeric.AD.Mode.Forward [ 0.68814] ghci.input: :m Numeric.AD.Mode.Forward [ 0.69020] ghci.input: :r [ 0.69183] ghci.input: :m Numeric.AD.Mode.Forward [ 0.69441] ghci.input: :r [ 0.69686] ghci.input: diff sin 0 [ 0.70319] ghci.input: :m Numeric.AD.Mode.Forward [ 0.70493] ghci.input: :r [ 0.70652] ghci.input: diff' sin 0 [ 0.71288] ghci.input: diff' exp 0 [ 0.71756] ghci.input: :m Numeric.AD.Mode.Forward [ 0.72017] ghci.input: :r [ 0.72290] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 0.73169] ghci.input: :m Numeric.AD.Mode.Forward [ 0.73392] ghci.input: :r [ 0.73677] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 0.74520] ghci.input: :m Numeric.AD.Mode.Forward [ 0.74811] ghci.input: :r [ 0.75068] ghci.input: jacobian (\[x,y] -> [y,x,x+y,x*y,exp x * sin y]) [pi,1] [ 0.76658] ghci.input: :m Numeric.AD.Mode.Forward [ 0.76825] ghci.input: :r [ 0.76987] ghci.input: gradWith' (,) sum [0..4] [ 0.77498] docspec.phase2: Numeric.AD.Mode.Forward.Double [ 0.77532] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.77723] ghci.input: :r [ 0.77892] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.78108] ghci.input: :r [ 0.78325] ghci.input: diff sin 0 [ 0.79227] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.79540] ghci.input: :r [ 0.79835] ghci.input: diff' sin 0 [ 0.80322] ghci.input: diff' exp 0 [ 0.80618] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.80812] ghci.input: :r [ 0.80979] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 0.81516] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.81692] ghci.input: :r [ 0.81846] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 0.82221] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.82391] ghci.input: :r [ 0.82746] ghci.input: jacobian (\[x,y] -> [y,x,x+y,x*y,exp x * sin y]) [pi,1] [ 0.83264] ghci.input: :m Numeric.AD.Mode.Forward.Double [ 0.83532] ghci.input: :r [ 0.83790] ghci.input: gradWith' (,) sum [0..4] [ 0.84503] docspec.phase2: Numeric.AD.Mode.Kahn [ 0.84537] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.84802] ghci.input: :r [ 0.84959] ghci.input: import Numeric.AD.Internal.Doctest [ 0.85234] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.85395] ghci.input: :r [ 0.85553] ghci.input: import Numeric.AD.Internal.Doctest [ 0.85852] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 0.86967] ghci.input: grad (\[x,y] -> x**y) [0,2] [ 0.87903] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.88099] ghci.input: :r [ 0.88294] ghci.input: import Numeric.AD.Internal.Doctest [ 0.88469] ghci.input: grad' (\[x,y,z] -> 4*x*exp y+cos z) [1,2,3] [ 0.89151] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.89323] ghci.input: :r [ 0.89634] ghci.input: import Numeric.AD.Internal.Doctest [ 0.90065] ghci.input: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 0.91047] ghci.input: jacobian (\[x,y] -> [exp y,cos x,x+y]) [1,2] [ 0.91911] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.92077] ghci.input: :r [ 0.92280] ghci.input: import Numeric.AD.Internal.Doctest [ 0.92516] ghci.input: diff sin 0 [ 0.93078] ghci.input: cos 0 [ 0.93626] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.93919] ghci.input: :r [ 0.94203] ghci.input: import Numeric.AD.Internal.Doctest [ 0.94490] ghci.input: diff' sin 0 [ 0.95102] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.95323] ghci.input: :r [ 0.95494] ghci.input: import Numeric.AD.Internal.Doctest [ 0.95670] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 0.96440] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.96656] ghci.input: :r [ 0.96868] ghci.input: import Numeric.AD.Internal.Doctest [ 0.97102] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 0.97919] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.98132] ghci.input: :r [ 0.98349] ghci.input: import Numeric.AD.Internal.Doctest [ 0.98570] ghci.input: hessian (\[x,y] -> x*y) [1,2] [ 0.99116] ghci.input: :m Numeric.AD.Mode.Kahn [ 0.99284] ghci.input: :r [ 0.99447] ghci.input: import Numeric.AD.Internal.Doctest [ 0.99638] ghci.input: hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble] [ 1.00222] docspec.phase2: Numeric.AD.Mode.Reverse [ 1.00256] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.00450] ghci.input: :r [ 1.00674] ghci.input: import Numeric.AD.Internal.Doctest [ 1.00970] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.01285] ghci.input: :r [ 1.01543] ghci.input: import Numeric.AD.Internal.Doctest [ 1.01806] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 1.02552] ghci.input: grad (\[x,y] -> x**y) [0,2] [ 1.03163] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.03429] ghci.input: :r [ 1.03596] ghci.input: import Numeric.AD.Internal.Doctest [ 1.03837] ghci.input: grad' (\[x,y,z] -> x*y+z) [1,2,3] [ 1.04712] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.04941] ghci.input: :r [ 1.05151] ghci.input: import Numeric.AD.Internal.Doctest [ 1.05369] ghci.input: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 1.06140] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.06344] ghci.input: :r [ 1.06507] ghci.input: import Numeric.AD.Internal.Doctest [ 1.06678] ghci.input: jacobian' (\[x,y] -> [y,x,x*y]) [2,1] [ 1.07252] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.07523] ghci.input: :r [ 1.07852] ghci.input: import Numeric.AD.Internal.Doctest [ 1.08108] ghci.input: diff sin 0 [ 1.08904] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.09179] ghci.input: :r [ 1.09436] ghci.input: import Numeric.AD.Internal.Doctest [ 1.09705] ghci.input: diff' sin 0 [ 1.10341] ghci.input: diff' exp 0 [ 1.11061] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.11290] ghci.input: :r [ 1.11511] ghci.input: import Numeric.AD.Internal.Doctest [ 1.11728] ghci.input: diffF (\a -> [sin a, cos a]) 0 [ 1.12523] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.12805] ghci.input: :r [ 1.13084] ghci.input: import Numeric.AD.Internal.Doctest [ 1.13376] ghci.input: diffF' (\a -> [sin a, cos a]) 0 [ 1.13890] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.14058] ghci.input: :r [ 1.14213] ghci.input: import Numeric.AD.Internal.Doctest [ 1.14377] ghci.input: hessian (\[x,y] -> x*y) [1,2] [ 1.14932] ghci.input: :m Numeric.AD.Mode.Reverse [ 1.15100] ghci.input: :r [ 1.15298] ghci.input: import Numeric.AD.Internal.Doctest [ 1.15478] ghci.input: hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble] [ 1.16069] docspec.phase2: Numeric.AD.Mode.Reverse.Double [ 1.16101] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.16292] ghci.input: :r [ 1.16457] ghci.input: import Numeric.AD.Internal.Doctest [ 1.16621] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.16876] ghci.input: :r [ 1.17127] ghci.input: import Numeric.AD.Internal.Doctest [ 1.17349] ghci.input: grad (\[x,y,z] -> x*y+z) [1,2,3] [ 1.18001] ghci.input: grad (\[x,y] -> x**y) [0,2] [ 1.18471] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.18742] ghci.input: :r [ 1.18940] ghci.input: import Numeric.AD.Internal.Doctest [ 1.19174] ghci.input: grad' (\[x,y,z] -> x*y+z) [1,2,3] [ 1.19858] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.20155] ghci.input: :r [ 1.20429] ghci.input: import Numeric.AD.Internal.Doctest [ 1.20736] ghci.input: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 1.21214] error: jacobian (\[x,y] -> [y,x,x*y]) [2,1] [ 1.21250] error: in comment at 113:1 expected: [[0.0,1.0],[1.0,0.0],[1.0,2.0]] but got: *** Exception: Ix{Int}.index: Index (3) out of range ((0,2)) ^ [[

[ 1.21336] ghci.input: :m Numeric.AD.Mode.Reverse.Double [ 1.21504] ghci.input: :r [ 1.21706] ghci.input: import Numeric.AD.Internal.Doctest [ 1.22007] ghci.input: jacobian' ([x,y] -> [y,x,x*y]) [2,1]

[ 14.23163] peu.die: ghci exited ExitFailure (-11) proci: canceling proci: terminating proci: pid Nothing proci: waiting for termination

Curiously, if I run this without Docker, cabal-docspec -v doesn't show the exception at all. Moreover, cabal-docspec normally does display the results of thrown exceptions, so I'm inclined to blame this on memory corruption weirdness.

In any case, I'm not able to reproduce this on the latest commit (bd1c03e https://github.com/ekmett/ad/commit/bd1c03ee8cf49241889d28eea53eb405d2c206e6), either locally or with Docker. I'm going to optimistically deem this a bug in the older commit (642c10c https://github.com/ekmett/ad/commit/642c10c514cc851aba5b0c7b29b8391fb57b2f56), not with cabal-docspec itself.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ekmett/ad/pull/93#issuecomment-782956811, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACKMEOOFFI7U3YONMYSUYLTAGOBNANCNFSM4XTITEQQ .

RyanGlScott commented 3 years ago

Cool, thanks the explanation! In that case, I think we should be able to make sure that cabal-docspec runs the doctests both with and without FFI. I can submit a PR for that as soon as the necessary infrastructure in haskell-ci is in place (see haskell-CI/haskell-ci#485).