Skip to content

Commit d6277c3

Browse files
authored
Fix Clash.Primitives.DSL.tuple on GHC-9.6 (#2651)
It had the module name of tuples hardcoded to GHC.Tuple, but that changed in GHC-9.6. This would result in type mismatches in the generated VHDL. Fixes #2512
1 parent 5e01ae2 commit d6277c3

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

clash-lib/src/Clash/Primitives/DSL.hs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-|
22
Copyright : (C) 2019, Myrtle Software Ltd.
3-
2020-2023, QBayLogic B.V.
3+
2020-2024, QBayLogic B.V.
44
2021, Myrtle.ai
55
2022-2023, Google Inc
66
License : BSD2 (see the file LICENSE)
@@ -127,7 +127,8 @@ import Clash.Netlist.Types hiding (Component, toBit)
127127
import Clash.Netlist.Util
128128
import Clash.Util (clogBase)
129129
import qualified Data.String.Interpolate as I
130-
import Language.Haskell.TH (Name)
130+
import qualified Language.Haskell.TH as TH
131+
import qualified Language.Haskell.TH.Syntax as TH
131132
import Prelude
132133

133134
-- | Options for 'blackBoxHaskell' function. Use 'def' from package
@@ -164,9 +165,9 @@ instance Default BlackBoxHaskellOpts where
164165
--
165166
-- @[1,2]@ would mean this blackbox __ignores__ its second and third argument.
166167
blackBoxHaskell
167-
:: Name
168+
:: TH.Name
168169
-- ^ blackbox name
169-
-> Name
170+
-> TH.Name
170171
-- ^ template function name
171172
-> BlackBoxHaskellOpts
172173
-- ^ Options, see data structure for more information
@@ -649,14 +650,21 @@ constructProduct ty els =
649650

650651
-- | Create an n-tuple of 'TExpr'
651652
tuple :: HasCallStack => [TExpr] -> TExpr
652-
tuple [] = error $ "nTuple: Cannot create empty tuple"
653+
tuple [] = error $ "tuple: Cannot create empty tuple"
653654
tuple [_] =
654655
-- If we don't put this in: tuple . untuple /= id
655-
error $ "nTuple: Cannot create 1-tuple"
656+
error $ "tuple: Cannot create 1-tuple"
656657
tuple els = constructProduct tupTy els
657658
where
658659
commas = Text.replicate (length els - 1) ","
659-
tupTy = Product ("GHC.Tuple.(" <> commas <> ")") Nothing (map ety els)
660+
tupTy = Product (tupModule <> ".(" <> commas <> ")") Nothing (map ety els)
661+
tupModule =
662+
$(
663+
let tupNm = ''(,)
664+
in case (TH.nameModule tupNm, TH.nameBase tupNm) of
665+
(Just modNm, "(,)") -> TH.lift modNm :: TH.ExpQ
666+
_ -> error $ "tuple: (,) has an unexpected name: " <> show tupNm
667+
)
660668

661669
-- | Try to get the literal string value of an expression.
662670
getStr :: TExpr -> Maybe String

tests/Main.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,15 +526,12 @@ runClashTest = defaultMain $ clashTestRoot
526526
, hdlSim=[Vivado]
527527
, buildTargets=BuildSpecific ["tb" <> show n | n <- [(0::Int)..7]]
528528
}
529-
#if !MIN_VERSION_ghc(9,6,0)
530-
-- XXX: Broken on GHC 9.6. See https://github.com/clash-lang/clash-compiler/issues/2512.
531529
, runTest "XpmCdcHandshake" $ def
532530
{ hdlTargets=[VHDL, Verilog]
533531
, hdlLoad=[Vivado]
534532
, hdlSim=[Vivado]
535533
, buildTargets=BuildSpecific ["tb" <> show n | n <- [(0::Int)..6]]
536534
}
537-
#endif
538535
, runTest "XpmCdcSingle" $ def
539536
{ hdlTargets=[VHDL, Verilog]
540537
, hdlLoad=[Vivado]

0 commit comments

Comments
 (0)