diff --git a/clash-prelude/src/Clash/Magic.hs b/clash-prelude/src/Clash/Magic.hs index 4df15eed52..0de40d0afd 100644 --- a/clash-prelude/src/Clash/Magic.hs +++ b/clash-prelude/src/Clash/Magic.hs @@ -44,6 +44,7 @@ module Clash.Magic ) where import Data.String.Interpolate (__i) +import GHC.Magic (noinline) import GHC.Stack (HasCallStack, withFrozenCallStack) import Clash.NamedTypes ((:::)) import GHC.TypeLits (Nat,Symbol) @@ -259,7 +260,8 @@ noDeDup = id -- | 'True' in Haskell/Clash simulation. Replaced by 'False' when generating HDL. clashSimulation :: Bool -clashSimulation = True +clashSimulation = noinline True +-- The 'noinline' is here to prevent SpecConstr from poking through the OPAQUE, see #2736 -- See: https://github.com/clash-lang/clash-compiler/pull/2511 {-# CLASH_OPAQUE clashSimulation #-} diff --git a/tests/Main.hs b/tests/Main.hs index b800b58cf2..e5887a6cb5 100755 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -387,7 +387,7 @@ runClashTest = defaultMain $ clashTestRoot , runTest "NameInstance" def{hdlSim=[]} , outputTest "NameInstance" def , outputTest "SetName" def{hdlTargets=[VHDL]} - , outputTest "SimulationMagic" def{hdlTargets=[VHDL]} + , outputTest "SimulationMagic2736" def{hdlTargets=[VHDL]} , runTest "PatError" def{hdlSim=[]} , runTest "ByteSwap32" def , runTest "CharTest" def diff --git a/tests/clash-testsuite.cabal b/tests/clash-testsuite.cabal index df6cf11486..43dfa1e3ec 100644 --- a/tests/clash-testsuite.cabal +++ b/tests/clash-testsuite.cabal @@ -104,6 +104,7 @@ library -- an external interface file. See -- https://github.com/clash-lang/clash-compiler/issues/1796 for an example. shouldwork/LoadModules/precompiled + shouldwork/Basic/precompiled exposed-modules: Test.Tasty.Common @@ -122,6 +123,9 @@ library -- From tests/shouldwork/LoadModules/precompiled T1796a + -- From tests/shouldwork/Basic/precompiled + SimulationMagic2736a + other-modules: Paths_clash_testsuite diff --git a/tests/shouldwork/Basic/SimulationMagic.hs b/tests/shouldwork/Basic/SimulationMagic2736.hs similarity index 85% rename from tests/shouldwork/Basic/SimulationMagic.hs rename to tests/shouldwork/Basic/SimulationMagic2736.hs index 3d992d1566..3cf4608510 100644 --- a/tests/shouldwork/Basic/SimulationMagic.hs +++ b/tests/shouldwork/Basic/SimulationMagic2736.hs @@ -1,4 +1,6 @@ -module SimulationMagic where +{-# LANGUAGE TemplateHaskellQuotes #-} +{-# OPTIONS_GHC -O2 -fspec-constr #-} +module SimulationMagic2736 where import Prelude as P import Data.List (isInfixOf) @@ -6,11 +8,10 @@ import System.Environment (getArgs) import System.FilePath (()) import Clash.Prelude -import Clash.Magic (clashSimulation) +import SimulationMagic2736a f :: Int -f | clashSimulation = 123 - | otherwise = 456 +f = f0 {-# ANN f (defSyn "f") #-} assertNotIn :: String -> String -> IO () diff --git a/tests/shouldwork/Basic/precompiled/SimulationMagic2736a.hs b/tests/shouldwork/Basic/precompiled/SimulationMagic2736a.hs new file mode 100644 index 0000000000..090e227591 --- /dev/null +++ b/tests/shouldwork/Basic/precompiled/SimulationMagic2736a.hs @@ -0,0 +1,8 @@ +{-# OPTIONS_GHC -O2 -fspec-constr #-} +module SimulationMagic2736a where + +import Clash.Prelude + +f0 :: Int +f0 | clashSimulation = 123 + | otherwise = 456