Skip to content

Commit

Permalink
Add flag to workaround GHC heisenbug on CI (#2444)
Browse files Browse the repository at this point in the history
In very specific tests in GitLab CI we are affected by GHC bug #19421.
We can work around the issue by passing `-with-rtsopts=-xm20000000` when
compiling an affected binary. This is a stopgap measure until the real
bug is fixed.

We have seen the bug:
- In `clash-testsuite` in `clashLibTest`s
- In `ffi:example` in the `clash` binary itself
- In `prelude:doctests`, probably in the `doctests` binary itself,
  although this is not certain.

and then only in GHC 9.0.2, although the bug should be in other versions
of GHC as well.

This workaround was applied only to GHC 9.0.2 on CI and only to those
cases that were observed to go wrong, although as a consequence now the
`clash` binary is always built with the RTS option.

The `ffi:example` test should no longer be affected by the GHC bug, but
it is a fairly useless test in its current state as it does not fail
when there are issues, and the tested code is actually faulty. It is
disabled to be fixed later.
  • Loading branch information
DigitalBrains1 authored and leonschoorl committed Aug 24, 2023
1 parent 30b96ea commit bb261ae
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .ci/cabal.project.local
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package *

package clash-prelude
ghc-options: -Werror
flags: +doctests
flags: +doctests -workaround-ghc-mmap-crash
tests: True
benchmarks: True

Expand All @@ -24,6 +24,7 @@ package clash-lib

package clash-ghc
ghc-options: -Werror
flags: -workaround-ghc-mmap-crash

package clash-cosim
ghc-options: -Werror
Expand All @@ -47,7 +48,7 @@ package clash-lib-hedgehog
package clash-testsuite
ghc-options: -Werror
-- enable cosim
flags: +cosim
flags: +cosim -workaround-ghc-mmap-crash

package clash-benchmark
ghc-options: -Werror
Expand Down
4 changes: 4 additions & 0 deletions .ci/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ if [ ! -f cabal.project.local ]; then
fi

set +u
if [[ "$WORKAROUND_GHC_MMAP_CRASH" == "yes" ]]; then
sed -i 's/-workaround-ghc-mmap-crash/+workaround-ghc-mmap-crash/g' cabal.project.local
fi

if [[ "$GHC_HEAD" == "yes" ]]; then
cat .ci/cabal.project.local.append-HEAD >> cabal.project.local
fi
Expand Down
4 changes: 3 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ tests:
strategy: depend
parallel:
matrix:
- GHC_VERSION: [8.8.4, 8.10.7, 9.0.2]
- GHC_VERSION: [8.8.4, 8.10.7]
- GHC_VERSION: 9.0.2
WORKAROUND_GHC_MMAP_CRASH: "yes"
- GHC_VERSION: 8.6.5
MULTIPLE_HIDDEN: "no"

Expand Down
14 changes: 13 additions & 1 deletion clash-ghc/clash-ghc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,24 @@ flag use-ghc-paths
default: False
manual: True

flag workaround-ghc-mmap-crash
description:
Only use this flag when hit by GHC bug #19421. See clash-compiler PR #2444.
default: False
manual: True

executable clash
Main-Is: src-ghc/Batch.hs
Build-Depends: base, clash-ghc
GHC-Options: -Wall -Wcompat -threaded -rtsopts -with-rtsopts=-A128m
GHC-Options: -Wall -Wcompat -threaded -rtsopts
if flag(dynamic)
GHC-Options: -dynamic
-- Note that multiple -with-rtsopts are not cumulative, so we can't add the
-- common RTS options in the unconditional GHC-Options
if flag(workaround-ghc-mmap-crash)
GHC-Options: "-with-rtsopts=-A128m -xm20000000"
else
GHC-Options: -with-rtsopts=-A128m
extra-libraries: pthread
default-language: Haskell2010

Expand Down
10 changes: 10 additions & 0 deletions clash-prelude/clash-prelude.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ flag benchmarks
default: True
manual: True

flag workaround-ghc-mmap-crash
description:
Only use this flag when hit by GHC bug #19421. See clash-compiler PR #2444.
default: False
manual: True

common common-options
default-language: Haskell2010
default-extensions: BangPatterns
Expand Down Expand Up @@ -373,6 +379,10 @@ test-suite doctests
doctest-parallel >= 0.2 && < 0.4,
filepath

if flag(workaround-ghc-mmap-crash)
ghc-options: -with-rtsopts=-xm20000000


test-suite unittests
import: common-options
type: exitcode-stdio-1.0
Expand Down
9 changes: 9 additions & 0 deletions tests/clash-testsuite.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ flag multiple-hidden
default: False
manual: True

flag workaround-ghc-mmap-crash
description:
Only use this flag when hit by GHC bug #19421. See clash-compiler PR #2444.
default: False
manual: True

common basic-config
default-language: Haskell2010
ghc-options: -Wall -Wcompat
Expand Down Expand Up @@ -76,6 +82,9 @@ common basic-config
if flag(multiple-hidden)
cpp-options: -DCLASH_MULTIPLE_HIDDEN

if flag(workaround-ghc-mmap-crash)
cpp-options: -DCLASH_WORKAROUND_GHC_MMAP_CRASH

library
import: basic-config
hs-source-dirs:
Expand Down
7 changes: 6 additions & 1 deletion tests/src/Test/Tasty/Clash.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
Expand Down Expand Up @@ -564,7 +565,11 @@ clashLibTest' modName target extraGhcArgs path =
clashBuild workDir = ("clash (exec)", singleTest "clash (exec)" (ClashBinaryTest {
cbBuildTarget=target
, cbSourceDirectory=sourceDir
, cbExtraBuildArgs="-DCLASHLIBTEST" : extraGhcArgs
, cbExtraBuildArgs="-DCLASHLIBTEST" :
#ifdef CLASH_WORKAROUND_GHC_MMAP_CRASH
"-with-rtsopts=-xm20000000" :
#endif
extraGhcArgs
, cbExtraExecArgs=[]
, cbModName=modName
, cbOutputDirectory=workDir
Expand Down

0 comments on commit bb261ae

Please sign in to comment.