Skip to content

Commit 15dc344

Browse files
authored
Merge pull request #2758 from clash-lang/ghc_910_upgrade
Enable building Clash against GHC 9.10
2 parents 96f741d + e565d26 commit 15dc344

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+8062
-262
lines changed

.gitlab-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ tests:
3434
CI_PARENT_PIPELINE_SOURCE: $CI_PIPELINE_SOURCE
3535
parallel:
3636
matrix:
37+
- GHC_VERSION: 9.10.1
38+
RUN_TESTS: "always"
39+
3740
- GHC_VERSION: 9.8.2
3841
RUN_TESTS: "always"
3942

cabal.project

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

2121
-- For some reason the `clash-testsuite` executable fails to run without
2222
-- this, as it cannot find the related library...
@@ -73,7 +73,12 @@ allow-newer:
7373
rewrite-inspector:containers,
7474
vty:deepseq,
7575
derive-storable-plugin:ghc,
76-
derive-storable-plugin:ghci
76+
derive-storable-plugin:ghci,
77+
string-random:text,
78+
string-random:containers,
79+
string-interpolate:template-haskell,
80+
string-interpolate:text,
81+
hint:ghc
7782

7883
-- Works around: https://github.com/recursion-schemes/recursion-schemes/issues/128. This
7984
-- shouldn't harm (runtime) performance of Clash, as we only use recursion-schemes with
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ADDED: Support for GHC 9.10.
2+
A word of caution: When the Clash compiler is compiled against GHC 9.10, it will
3+
currently only work reliably on 64-bit platforms. Compile the Clash compiler with
4+
GHC 9.8 or older if you are on a 32-bit platform.

clash-cores/clash-cores.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ library
186186
reducers >= 3.12.2 && < 4.0,
187187
text >= 1.2.2 && < 2.2,
188188
constraints >= 0.9 && < 1.0,
189-
template-haskell >= 2.12.0.0 && < 2.22
189+
template-haskell >= 2.12.0.0 && < 2.23
190190

191191
test-suite unittests
192192
import: basic-config

clash-ffi/clash-ffi.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ common common-options
2020
ghc-options:
2121
-Wall -Wcompat
2222
build-depends:
23-
base >= 4.11 && < 4.20,
23+
base >= 4.11 && < 4.21,
2424
bytestring >= 0.10 && < 0.13,
2525
clash-prelude >= 1.2 && < 1.10,
2626
deepseq >= 1.4 && < 1.6,

clash-ffi/example/cabal.project

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ write-ghc-environment-files: always
55
allow-newer:
66
hashable,
77
derive-storable-plugin:ghc,
8-
derive-storable-plugin:ghci
8+
derive-storable-plugin:ghci,
9+
string-interpolate:template-haskell,
10+
string-interpolate:text,
11+
hint:ghc

clash-ffi/example/clash-ffi-example.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ category: Hardware
1414
custom-setup
1515
setup-depends:
1616
base >= 4.11 && < 5,
17-
Cabal >= 2.4 && < 3.12,
17+
Cabal >= 2.4 && < 3.14,
1818
directory >= 1.3.6 && < 1.4,
1919
filepath >= 1.4.2 && < 1.5,
2020

clash-ghc/clash-ghc.cabal

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ common common-options
121121
library
122122
import: common-options
123123
HS-Source-Dirs: src-ghc, src-bin-common
124-
if impl(ghc >= 9.8.0)
124+
if impl(ghc >= 9.10.0)
125+
HS-Source-Dirs: src-bin-9.10
126+
elif impl(ghc >= 9.8.0)
125127
HS-Source-Dirs: src-bin-9.8
126128
elif impl(ghc >= 9.6.0)
127129
HS-Source-Dirs: src-bin-9.6
@@ -172,23 +174,23 @@ library
172174
ghc-typelits-natnormalise >= 0.6 && < 0.8,
173175
deepseq >= 1.3.0.2 && < 1.6,
174176
time >= 1.4.0.1 && < 1.15,
175-
ghc-boot >= 8.10.0 && < 9.9,
177+
ghc-boot >= 8.10.0 && < 9.11,
176178
ghc-prim >= 0.3.1.0 && < 0.12,
177-
ghci >= 8.10.0 && < 9.9,
179+
ghci >= 8.10.0 && < 9.11,
178180
uniplate >= 1.6.12 && < 1.8,
179181
reflection >= 2.1.2 && < 3.0,
180182
primitive >= 0.5.0.1 && < 1.0,
181183
string-interpolate ^>= 0.3,
182-
template-haskell >= 2.8.0.0 && < 2.22,
184+
template-haskell >= 2.8.0.0 && < 2.23,
183185
utf8-string >= 1.0.0.0 && < 1.1.0.0,
184186
vector >= 0.11 && < 1.0
185187

186188
if os(darwin)
187189
-- 8.10 is broken on macOS - it exits tests with status code -11
188-
Build-Depends: ghc >= 9.0.0 && < 9.9
190+
Build-Depends: ghc >= 9.0.0 && < 9.11
189191
else
190192
-- Unix
191-
Build-Depends: ghc >= 8.10.0 && < 9.9
193+
Build-Depends: ghc >= 8.10.0 && < 9.11
192194

193195
if impl(ghc >= 8.10.0)
194196
Build-Depends: exceptions >= 0.10.4 && < 0.11,
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{-# LANGUAGE RecordWildCards, LambdaCase #-}
2+
module Clash.GHCi.Leak
3+
( LeakIndicators
4+
, getLeakIndicators
5+
, checkLeakIndicators
6+
) where
7+
8+
import Control.Monad
9+
import Data.Bits
10+
import Foreign.Ptr (ptrToIntPtr, intPtrToPtr)
11+
import GHC
12+
import GHC.Ptr (Ptr (..))
13+
import Clash.GHCi.Util
14+
import GHC.Driver.Env
15+
import GHC.Driver.Ppr
16+
import GHC.Utils.Outputable
17+
import GHC.Unit.Module.ModDetails
18+
import GHC.Unit.Home.ModInfo
19+
import GHC.Platform (target32Bit)
20+
import GHC.Linker.Types
21+
import Prelude
22+
import System.Mem
23+
import System.Mem.Weak
24+
import GHC.Types.Unique.DFM
25+
import Control.Exception
26+
27+
-- Checking for space leaks in GHCi. See #15111, and the
28+
-- -fghci-leak-check flag.
29+
30+
data LeakIndicators = LeakIndicators [LeakModIndicators]
31+
32+
data LeakModIndicators = LeakModIndicators
33+
{ leakMod :: Weak HomeModInfo
34+
, leakIface :: Weak ModIface
35+
, leakDetails :: Weak ModDetails
36+
, leakLinkable :: [Maybe (Weak Linkable)]
37+
}
38+
39+
-- | Grab weak references to some of the data structures representing
40+
-- the currently loaded modules.
41+
getLeakIndicators :: HscEnv -> IO LeakIndicators
42+
getLeakIndicators hsc_env =
43+
fmap LeakIndicators $
44+
forM (eltsUDFM (hsc_HPT hsc_env)) $ \hmi@HomeModInfo{..} -> do
45+
leakMod <- mkWeakPtr hmi Nothing
46+
leakIface <- mkWeakPtr hm_iface Nothing
47+
leakDetails <- mkWeakPtr hm_details Nothing
48+
leakLinkable <- mkWeakLinkables hm_linkable
49+
return $ LeakModIndicators{..}
50+
where
51+
mkWeakLinkables :: HomeModLinkable -> IO [Maybe (Weak Linkable)]
52+
mkWeakLinkables (HomeModLinkable mbc mo) =
53+
mapM (\ln -> traverse (flip mkWeakPtr Nothing <=< evaluate) ln) [mbc, mo]
54+
55+
-- | Look at the LeakIndicators collected by an earlier call to
56+
-- `getLeakIndicators`, and print messasges if any of them are still
57+
-- alive.
58+
checkLeakIndicators :: DynFlags -> LeakIndicators -> IO ()
59+
checkLeakIndicators dflags (LeakIndicators leakmods) = do
60+
performGC
61+
forM_ leakmods $ \LeakModIndicators{..} -> do
62+
deRefWeak leakMod >>= \case
63+
Nothing -> return ()
64+
Just hmi ->
65+
report ("HomeModInfo for " ++
66+
showSDoc dflags (ppr (mi_module (hm_iface hmi)))) (Just hmi)
67+
deRefWeak leakIface >>= \case
68+
Nothing -> return ()
69+
Just miface -> report ("ModIface:" ++ moduleNameString (moduleName (mi_module miface))) (Just miface)
70+
deRefWeak leakDetails >>= report "ModDetails"
71+
forM_ leakLinkable $ \l -> forM_ l $ \l' -> deRefWeak l' >>= report "Linkable"
72+
where
73+
report :: String -> Maybe a -> IO ()
74+
report _ Nothing = return ()
75+
report msg (Just a) = do
76+
addr <- anyToPtr a
77+
putStrLn ("-fghci-leak-check: " ++ msg ++ " is still alive at " ++
78+
show (maskTagBits addr))
79+
80+
tagBits
81+
| target32Bit (targetPlatform dflags) = 2
82+
| otherwise = 3
83+
84+
maskTagBits :: Ptr a -> Ptr a
85+
maskTagBits p = intPtrToPtr (ptrToIntPtr p .&. complement (shiftL 1 tagBits - 1))

0 commit comments

Comments
 (0)