[GHC] #10830: maximumBy has a space leak
GHC
ghc-devs at haskell.org
Wed Sep 2 22:56:18 UTC 2015
#10830: maximumBy has a space leak
-------------------------------------+-------------------------------------
Reporter: NeilMitchell | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: libraries/base | Version: 7.10.2
Resolution: | Keywords:
Operating System: Windows | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by nomeata):
In 7.8, the core is nice and fully inlined:
{{{#!hs
Rec {
main_lgo
main_lgo =
\ z_a1k8 ds2_a1k9 ->
case ds2_a1k9 of _ {
[] -> z_a1k8;
: x_a1kh xs_a1ki ->
case compareInteger z_a1k8 x_a1kh of _ {
__DEFAULT -> main_lgo x_a1kh xs_a1ki;
GT -> main_lgo z_a1k8 xs_a1ki
}
}
end Rec }
}}}
In HEAD, we have a call to `foldr1`:
{{{#!hs
main5 =
\ x_a2pT y_a2pU ->
case compareInteger x_a2pT y_a2pU of _ {
__DEFAULT -> y_a2pU;
GT -> x_a2pT
}
main2 = enumDeltaToInteger1 main4 main3
main1 =
\ eta_B1 ->
case foldr1 main5 main2 of _ { __DEFAULT -> (# eta_B1, () #) }
}}}
I think you are right that this is some BBP-fallout. Note that `maximumBy`
is implemented in `Data.Foldable` using `foldr1`.
If I make `foldr1` inlinable (by using a local worker), I get
{{{#!hs
Rec {
-- RHS size: {terms: 19, types: 9, coercions: 0}
main_go
main_go =
\ ds2_a1Fi eta_a1Fj ->
case ds2_a1Fi of _ {
[] -> eta_a1Fj;
: y_a1Fr ys_a1Fs ->
case compareInteger eta_a1Fj y_a1Fr of _ {
__DEFAULT -> main_go ys_a1Fs y_a1Fr;
GT -> main_go ys_a1Fs eta_a1Fj
}
}
end Rec }
}}}
which is equivalent to the 7.8 code.
Given that we inline `foldr`, I do not see a reason not to inline
`foldr1`. DR coming soon...
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10830#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list