Skip to content

Commit

Permalink
Merge pull request #2790 from clash-lang/mergify/copy/1.8/pr-2758
Browse files Browse the repository at this point in the history
Enable building Clash against GHC 9.10 (copy #2758)
  • Loading branch information
christiaanb authored Nov 26, 2024
2 parents 03aa6d9 + d26a06b commit bace7a5
Show file tree
Hide file tree
Showing 52 changed files with 8,062 additions and 262 deletions.
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ tests:
CI_PARENT_PIPELINE_SOURCE: $CI_PIPELINE_SOURCE
parallel:
matrix:
- GHC_VERSION: 9.10.1
RUN_TESTS: "always"

- GHC_VERSION: 9.8.2
RUN_TESTS: "always"

Expand Down
9 changes: 7 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ write-ghc-environment-files: always
-- index state, to go along with the cabal.project.freeze file. update the index
-- state by running `cabal update` twice and looking at the index state it
-- displays to you (as the second update will be a no-op)
index-state: 2024-07-06T09:03:11Z
index-state: 2024-07-18T12:39:16Z

-- For some reason the `clash-testsuite` executable fails to run without
-- this, as it cannot find the related library...
Expand Down Expand Up @@ -72,7 +72,12 @@ allow-newer:
rewrite-inspector:containers,
vty:deepseq,
derive-storable-plugin:ghc,
derive-storable-plugin:ghci
derive-storable-plugin:ghci,
string-random:text,
string-random:containers,
string-interpolate:template-haskell,
string-interpolate:text,
hint:ghc

-- Works around: https://github.com/recursion-schemes/recursion-schemes/issues/128. This
-- shouldn't harm (runtime) performance of Clash, as we only use recursion-schemes with
Expand Down
4 changes: 4 additions & 0 deletions changelog/2024-07-26T07_36_58+02_00_ghc_910_upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ADDED: Support for GHC 9.10.
A word of caution: When the Clash compiler is compiled against GHC 9.10, it will
currently only work reliably on 64-bit platforms. Compile the Clash compiler with
GHC 9.8 or older if you are on a 32-bit platform.
2 changes: 1 addition & 1 deletion clash-ffi/clash-ffi.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ common common-options
ghc-options:
-Wall -Wcompat
build-depends:
base >= 4.11 && < 4.20,
base >= 4.11 && < 4.21,
bytestring >= 0.10 && < 0.13,
clash-prelude >= 1.2 && < 1.10,
deepseq >= 1.4 && < 1.6,
Expand Down
5 changes: 4 additions & 1 deletion clash-ffi/example/cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ write-ghc-environment-files: always
allow-newer:
hashable,
derive-storable-plugin:ghc,
derive-storable-plugin:ghci
derive-storable-plugin:ghci,
string-interpolate:template-haskell,
string-interpolate:text,
hint:ghc
2 changes: 1 addition & 1 deletion clash-ffi/example/clash-ffi-example.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ category: Hardware
custom-setup
setup-depends:
base >= 4.11 && < 5,
Cabal >= 2.4 && < 3.12,
Cabal >= 2.4 && < 3.14,
directory >= 1.3.6 && < 1.4,
filepath >= 1.4.2 && < 1.5,

Expand Down
16 changes: 9 additions & 7 deletions clash-ghc/clash-ghc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ common common-options
library
import: common-options
HS-Source-Dirs: src-ghc, src-bin-common
if impl(ghc >= 9.8.0)
if impl(ghc >= 9.10.0)
HS-Source-Dirs: src-bin-9.10
elif impl(ghc >= 9.8.0)
HS-Source-Dirs: src-bin-9.8
elif impl(ghc >= 9.6.0)
HS-Source-Dirs: src-bin-9.6
Expand Down Expand Up @@ -176,26 +178,26 @@ library
ghc-typelits-natnormalise >= 0.6 && < 0.8,
deepseq >= 1.3.0.2 && < 1.6,
time >= 1.4.0.1 && < 1.15,
ghc-boot >= 8.6.0 && < 9.9,
ghc-boot >= 8.6.0 && < 9.11,
ghc-prim >= 0.3.1.0 && < 0.12,
ghci >= 8.6.0 && < 9.9,
ghci >= 8.6.0 && < 9.11,
uniplate >= 1.6.12 && < 1.8,
reflection >= 2.1.2 && < 3.0,
primitive >= 0.5.0.1 && < 1.0,
string-interpolate ^>= 0.3,
template-haskell >= 2.8.0.0 && < 2.22,
template-haskell >= 2.8.0.0 && < 2.23,
utf8-string >= 1.0.0.0 && < 1.1.0.0,
vector >= 0.11 && < 1.0

if os(windows)
-- 8.8 is broken on Windows - it randomly segfaults
Build-Depends: ghc >= 8.6.0 && < 8.8.0 || >= 8.10.0 && < 9.9
Build-Depends: ghc >= 8.6.0 && < 8.8.0 || >= 8.10.0 && < 9.11
elif os(darwin)
-- 8.10 is broken on macOS - it exits tests with status code -11
Build-Depends: ghc >= 8.6.0 && < 8.10.0 || >= 9.0.0 && < 9.9
Build-Depends: ghc >= 8.6.0 && < 8.10.0 || >= 9.0.0 && < 9.11
else
-- Unix
Build-Depends: ghc >= 8.6.0 && < 9.9
Build-Depends: ghc >= 8.6.0 && < 9.11

if impl(ghc >= 8.10.0)
Build-Depends: exceptions >= 0.10.4 && < 0.11,
Expand Down
85 changes: 85 additions & 0 deletions clash-ghc/src-bin-9.10/Clash/GHCi/Leak.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{-# LANGUAGE RecordWildCards, LambdaCase #-}
module Clash.GHCi.Leak
( LeakIndicators
, getLeakIndicators
, checkLeakIndicators
) where

import Control.Monad
import Data.Bits
import Foreign.Ptr (ptrToIntPtr, intPtrToPtr)
import GHC
import GHC.Ptr (Ptr (..))
import Clash.GHCi.Util
import GHC.Driver.Env
import GHC.Driver.Ppr
import GHC.Utils.Outputable
import GHC.Unit.Module.ModDetails
import GHC.Unit.Home.ModInfo
import GHC.Platform (target32Bit)
import GHC.Linker.Types
import Prelude
import System.Mem
import System.Mem.Weak
import GHC.Types.Unique.DFM
import Control.Exception

-- Checking for space leaks in GHCi. See #15111, and the
-- -fghci-leak-check flag.

data LeakIndicators = LeakIndicators [LeakModIndicators]

data LeakModIndicators = LeakModIndicators
{ leakMod :: Weak HomeModInfo
, leakIface :: Weak ModIface
, leakDetails :: Weak ModDetails
, leakLinkable :: [Maybe (Weak Linkable)]
}

-- | Grab weak references to some of the data structures representing
-- the currently loaded modules.
getLeakIndicators :: HscEnv -> IO LeakIndicators
getLeakIndicators hsc_env =
fmap LeakIndicators $
forM (eltsUDFM (hsc_HPT hsc_env)) $ \hmi@HomeModInfo{..} -> do
leakMod <- mkWeakPtr hmi Nothing
leakIface <- mkWeakPtr hm_iface Nothing
leakDetails <- mkWeakPtr hm_details Nothing
leakLinkable <- mkWeakLinkables hm_linkable
return $ LeakModIndicators{..}
where
mkWeakLinkables :: HomeModLinkable -> IO [Maybe (Weak Linkable)]
mkWeakLinkables (HomeModLinkable mbc mo) =
mapM (\ln -> traverse (flip mkWeakPtr Nothing <=< evaluate) ln) [mbc, mo]

-- | Look at the LeakIndicators collected by an earlier call to
-- `getLeakIndicators`, and print messasges if any of them are still
-- alive.
checkLeakIndicators :: DynFlags -> LeakIndicators -> IO ()
checkLeakIndicators dflags (LeakIndicators leakmods) = do
performGC
forM_ leakmods $ \LeakModIndicators{..} -> do
deRefWeak leakMod >>= \case
Nothing -> return ()
Just hmi ->
report ("HomeModInfo for " ++
showSDoc dflags (ppr (mi_module (hm_iface hmi)))) (Just hmi)
deRefWeak leakIface >>= \case
Nothing -> return ()
Just miface -> report ("ModIface:" ++ moduleNameString (moduleName (mi_module miface))) (Just miface)
deRefWeak leakDetails >>= report "ModDetails"
forM_ leakLinkable $ \l -> forM_ l $ \l' -> deRefWeak l' >>= report "Linkable"
where
report :: String -> Maybe a -> IO ()
report _ Nothing = return ()
report msg (Just a) = do
addr <- anyToPtr a
putStrLn ("-fghci-leak-check: " ++ msg ++ " is still alive at " ++
show (maskTagBits addr))

tagBits
| target32Bit (targetPlatform dflags) = 2
| otherwise = 3

maskTagBits :: Ptr a -> Ptr a
maskTagBits p = intPtrToPtr (ptrToIntPtr p .&. complement (shiftL 1 tagBits - 1))
Loading

0 comments on commit bace7a5

Please sign in to comment.