Skip to content

Commit 310d83b

Browse files
committed
Add GHC.Magic.noinline to gcd and lcm
GHC 8.6+ inlines their definitions, which exposes some of their FFI calls to the Clash compiler, which it cannot evaluate at compile-time. Fixes clash-lang/clash-compiler#1019
1 parent 14b5294 commit 310d83b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog for the [`ghc-typelits-extra`](http://hackage.haskell.org/package/ghc-typelits-extra) package
22

3+
# 0.3.2 *January 18th 2020*
4+
* Fix https://github.com/clash-lang/clash-compiler/issues/1019
5+
36
# 0.3.1 *August 26th 2019*
47
* Reduce `a <=? Max a b` to `True`
58
* Reduce `n ~ (Max a b) => a <=? n` to `True`

ghc-typelits-extra.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: ghc-typelits-extra
2-
version: 0.3.1
2+
version: 0.3.2
33
synopsis: Additional type-level operations on GHC.TypeLits.Nat
44
description:
55
Additional type-level operations on @GHC.TypeLits.Nat@:

src/GHC/TypeLits/Extra.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ import Data.Type.Bool (If)
8383
import GHC.Base (Int#,isTrue#,(==#),(+#))
8484
import GHC.Integer.Logarithms (integerLogBase#)
8585
#if MIN_VERSION_ghc(8,2,0)
86+
import GHC.Magic (noinline)
87+
#endif
88+
#if MIN_VERSION_ghc(8,2,0)
8689
import qualified GHC.TypeNats as N
8790
import GHC.Natural
8891
import GHC.Prim (int2Word#)
@@ -217,7 +220,11 @@ type family GCD (x :: Nat) (y :: Nat) :: Nat where
217220
-- Additional equations are provided by the custom solver
218221

219222
instance (KnownNat x, KnownNat y) => KnownNat2 $(nameToSymbol ''GCD) x y where
220-
natSing2 = SNatKn (gcd (N.natVal (Proxy @x)) (N.natVal (Proxy @y)))
223+
natSing2 = SNatKn (
224+
#if MIN_VERSION_ghc(8,2,0)
225+
noinline
226+
#endif
227+
gcd (N.natVal (Proxy @x)) (N.natVal (Proxy @y)))
221228

222229
-- | Type-level least common multiple (LCM).
223230
--
@@ -232,4 +239,8 @@ type family LCM (x :: Nat) (y :: Nat) :: Nat where
232239
-- Additional equations are provided by the custom solver
233240

234241
instance (KnownNat x, KnownNat y) => KnownNat2 $(nameToSymbol ''LCM) x y where
235-
natSing2 = SNatKn (lcm (N.natVal (Proxy @x)) (N.natVal (Proxy @y)))
242+
natSing2 = SNatKn (
243+
#if MIN_VERSION_ghc(8,2,0)
244+
noinline
245+
#endif
246+
lcm (N.natVal (Proxy @x)) (N.natVal (Proxy @y)))

0 commit comments

Comments
 (0)