[GHC] #6040: Adding a type signature changes heap allocation into stack allocation without changing the actual type
GHC
cvs-ghc at haskell.org
Tue Apr 24 22:15:22 CEST 2012
#6040: Adding a type signature changes heap allocation into stack allocation
without changing the actual type
------------------------------+---------------------------------------------
Reporter: tibbe | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler
Version: 7.4.1 | Keywords:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: None/Unknown | Testcase:
Blockedby: | Blocking:
Related: |
------------------------------+---------------------------------------------
According to Milan Straka, changing
{{{
insert :: Ord k => k -> a -> Map k a -> Map k a
insert = go
where
STRICT_1_OF_3(go)
go kx x Tip = singleton kx x
go kx x (Bin sz ky y l r) = ...
}}}
to
{{{
insert :: Ord k => k -> a -> Map k a -> Map k a
insert = go
where
go :: Ord k => k -> a -> Map k a -> Map k a
STRICT_1_OF_3(go)
go kx x Tip = singleton kx x
go kx x (Bin sz ky y l r) = ...
}}}
changes how GHC allocates the argument, from heap to stack. Here's the
relevant commit:
https://github.com/haskell/containers/commit/32d84ba5eb82f34dbb8a8fabf07077d848cdb408
It includes this comment:
{{{
-- [Note: Type of local 'go' function]
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- If the local 'go' function uses an Ord class, it must be given a type
-- which mentions this Ord class. Otherwise it is not passed as an
argument and
-- it is instead heap-allocated at the entry of the outer method.
}}}
I find this quite alarming. The type of `k` above is already Ord k, so the
extra type signature shouldn't make a difference in my opinion.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/6040>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list