Add evaluator rule for bigNatEq# (copy #3123)#3126
Conversation
|
Cherry-pick of 0b6aa0d has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
6caa869 to
9eaf21d
Compare
|
It turns out, in old GHC's the primitive is probably defined in a different module. I'll fix it. |
|
Starting in GHC 9.0.1 big-number support was changed from integer-gmp (or possibly integer-simple depending on ghc build time configuration) to ghc-bignum. Since |
|
Thanks! I'm aware already. But I do not have a reproducer to test the code path on GHC 9.0 and GHC 9.2, so the backport will only make the primive evaluator rule available in GHC 9.4+. |
|
I looked into it some more, and I believe you're right, this rule isn't needed on GHC < 9.4.
The test can be simplified(?) to module T3084 where
import Clash.Prelude hiding (SNat, Mod)
import GHC.Num.BigNat (bigNatEq#)
import GHC.Num.Natural (Natural(..))
import GHC.Base (isTrue#)
-- | Prevent GHC from constant folding operations. Clash should be able to
-- do it though.
lit
:: Num a
=> Unsigned 64
-> a
lit = fromIntegral
topEntity :: Bool
topEntity = f bigNatural bigNatural
where
bigNatural = lit maxBound + 1
bigNatural :: Natural
f :: Natural -> Natural -> Bool
f (NB x) (NB y) = isTrue# (bigNatEq# x y)
-- f (NS _) (NS _) = ...
f _ _ = FalseWhich compiles on all GHC >= 9.0. On GHC 9.0 & 9.2 this results in I wonder if this means we should be dropping that evaluator rule with ghc-bignum >=1.3. |
|
On a related note it is somewhat problematic that topEntity :: Natural -> Natural -> Bool
topEntity = (==)now results in on GHC >= 9.4 |
Fixes #3084
Still TODO:
This is an automatic copy of pull request Add evaluator rule for
bigNatEq##3123 done by Mergify.