Re: [GHC] #876: Length is not a good consumer

my apologies, sorry for the terrible bug report
On Sun, Dec 11, 2016 at 11:05 AM GHC
#876: Length is not a good consumer -------------------------------------+------------------------------------- Reporter: ariep@… | Owner: Type: bug | Status: new Priority: lowest | Milestone: 7.6.2 Component: libraries/base | Version: 6.5 Resolution: | Keywords: length Operating System: Linux | Architecture: | Unknown/Multiple Type of failure: Runtime | Test Case: performance bug | perf/should_run/T876 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+-------------------------------------
Comment (by nomeata):
This code, compiled with `-O, does fuse, and allocates nothing (or constant amounts) {{{#!hs
module Foo where x :: Int -> Int x n = length [0..(10^n)::Int] }}}
{{{ $ ghci -fobject-code -O Foo GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Foo ( Foo.hs, Foo.o ) Ok, modules loaded: Foo. Prelude Foo> :set +s Prelude Foo> x 1 11 (0.03 secs, 14,976,744 bytes) Prelude Foo> x 7 10000001 (0.02 secs, 0 bytes) Prelude Foo> x 8 100000001 (0.04 secs, 0 bytes) }}}
(almost) HEAD: {{{ GHCi, version 8.1.20161117: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Foo (.hs -> .o) WARNING: file compiler/simplCore/SimplCore.hs, line 663 Simplifier bailing out after 4 iterations [58, 14, 2, 2] Size = {terms: 96, types: 32, coercions: 0} Ok, modules loaded: Foo (Foo.o). Prelude Foo> :set +s Prelude Foo> x 1 11 (0.19 secs, 94,792 bytes) Prelude Foo> x 2 101 (0.01 secs, 94,648 bytes) Prelude Foo> x 7 10000001 (0.01 secs, 98,568 bytes) Prelude Foo> x 8 100000001 (0.05 secs, 98,448 bytes) }}}
Testing this in with interpreted code is not sufficient, as the optimizer does less in that case. So so far, everything seems as expected to me.
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/876#comment:30 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Am Montag, den 12.12.2016, 12:44 +0000 schrieb George Colpitts:
my apologies, sorry for the terrible bug report
No worries! Better a bug report closed as invalid than a real bug unreported. Greetings, Joachim -- -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

Joachim, thanks for the kind words but I'll be more careful not to waste
people's time with bad bug reports like that.
I got confused; when I I google "haskell list length" I end up at
https://hackage.haskell.org/package/base-4.9.0.0/docs/*Data-List*.html
https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-List.html.
When I look at the source code for length by clicking on "Source" It takes
me to the start of the file
https://hackage.haskell.org/package/base-4.9.0.0/docs/src/*Data.Foldable*
.html#length
https://hackage.haskell.org/package/base-4.9.0.0/docs/src/Data.Foldable.html....
instead of the definition of length in
https://hackage.haskell.org/package/base-4.9.0.0/docs/src/*GHC.List.*
html#length
https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.List.html#leng...
.
To me, this seems like a bug in haddock. In *Data.List*.html when I click
on the source code for init I go to
https://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.List.html#init.
This is the file I should go to for the source code for length also.
Perhaps the problem is that the type of length in Data.List is Foldable t
=> t a -> Int while init is [a] -> [a] ? Should I file a haddock bug for
the preceding?
There seems to be two minor related problems with the Users Guide
(8.0.1.20161117) in section 10.32.6,List fusion. First, it should mention
length as a good consumer. Secondly, it says: "If you want to write your
own good consumers or producers, look at the Prelude definitions of the
above functions to see how to do so." However if you go to
https://hackage.haskell.org/package/base-4.9.0.0/docs/Prelude.html and look
at the source code for length you end up at
https://hackage.haskell.org/package/base-4.9.0.0/docs/src/Data.Foldable.html...
which
is not a good consumer. I think the User's Guide should be changed to
replace "Prelude" with "Data.List" in the quoted sentence. I'll file a doc
bug on the User's Guide for these two issues. Also making a function
implement list fusion is not always easy, e.g. the bug, length is not a
good consumer, was open for six years before being fixed. Thus I will
suggest in the bug that we delete "readily" and change "Prelude" to
"Data.List" in "This list could readily be extended; if there are Prelude
functions that you use a lot which are not included, please tell us."
Of course the preceding is not an excuse for giving space allocations of
interpreted code when I reopened the bug but at that point I was convinced
that there was a problem and wasn't critical of the "evidence" I was giving
to support my claim.
Thanks
George
On Mon, Dec 12, 2016 at 11:44 AM Joachim Breitner
my apologies, sorry for the terrible bug report
No worries! Better a bug report closed as invalid than a real bug unreported. Greetings, Joachim -- -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

Dear George, Am Dienstag, den 13.12.2016, 12:24 +0000 schrieb George Colpitts:
I got confused; when I I google "haskell list length" I end up at https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-List.html. When I look at the source code for length by clicking on "Source" It takes me to the start of the file https://hackage.haskell.org/package /base-4.9.0.0/docs/src/Data.Foldable.html#length. instead of the definition of length in https://hackage.haskell.org/package/base-4.9. 0.0/docs/src/GHC.List.html#length.
To me, this seems like a bug in haddock. In Data.List.html when I click on the source code for init I go to https://hackage.haskell.org /package/base-4.9.0.0/docs/src/GHC.List.html#init. This is the file I should go to for the source code for length also. Perhaps the problem is that the type of length in Data.List is Foldable t => t a -> Int while init is [a] -> [a] ? Should I file a haddock bug for the preceding?
not, this is all right and intentional. Data.List re-exports Data.Foldable.length so that you do not get import conflicts when importing both. This was a design decision back then when the FTP (Foldable/Traversable) proposal was enacted.
There seems to be two minor related problems with the Users Guide (8.0.1.20161117) in section 10.32.6,List fusion. First, it should mention length as a good consumer. Secondly, it says: "If you want to write your own good consumers or producers, look at the Prelude definitions of the above functions to see how to do so." However if you go to https://hackage.haskell.org/package/base- 4.9.0.0/docs/Prelude.html and look at the source code for length you end up at https://hackage.haskell.org/package/base- 4.9.0.0/docs/src/Data.Foldable.html#length which is not a good consumer. I think the User's Guide should be changed to replace "Prelude" with "Data.List" in the quoted sentence. I'll file a doc bug on the User's Guide for these two issues.
Yes, that would be helpful. The text has not been added since FTP. Maybe even better, the user’s guide could simply contain a section that explains how to make good consumers and producer, including the hoops that one has to jump through when one wants to use the library’s version of a function when no fusion happens. Maybe together with David Feuer, who most recently battled with that. Maybe I can write that, I just had to write about list fusion for a paper anyways. Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org
participants (2)
-
George Colpitts
-
Joachim Breitner