GHC makes thunks for Integers we are strict in
We know that timesInteger is strict in both arguments:
$ ./ghc --show-iface ~/ghc/darcs/val/libraries/base/dist/build/GHC/Num.hi | grep -C2 "^timesInteger"
plusInteger :: GHC.Num.Integer -> GHC.Num.Integer -> GHC.Num.Integer
{- Arity: 2 HasNoCafRefs Strictness: SS -}
timesInteger :: GHC.Num.Integer -> GHC.Num.Integer -> GHC.Num.Integer
{- Arity: 2 HasNoCafRefs Strictness: SS -}
class (GHC.Base.Eq a, GHC.Show.Show a) => Num a
but given this code:
module W where
f :: Integer -> Integer
f x = let x' = x + 3
in x' * x'
we still make a thunk for x':
$ ./ghc -c w.hs -O -fforce-recomp -ddump-simpl
==================== Tidy Core ====================
W.lvl :: GHC.Num.Integer
[GlobalId]
[NoCafRefs
Str: DmdType]
W.lvl = GHC.Num.S# 3
W.f :: GHC.Num.Integer -> GHC.Num.Integer
[GlobalId]
[Arity 1
NoCafRefs
Str: DmdType S]
W.f =
\ (x_a5h :: GHC.Num.Integer) ->
let {
x'_sa7 [ALWAYS Just S] :: GHC.Num.Integer
[Str: DmdType]
x'_sa7 = GHC.Num.plusInteger x_a5h W.lvl } in
GHC.Num.timesInteger x'_sa7 x'_sa7
The same is true in both the 6.8 branch and the HEAD.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 6.9 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |