Pretty: improving the space/time performance of vcat, hsep, hcat (#10735)
Pretty: improving the space/time performance of vcat, hsep, hcat (#10735)

After 5d57087e314bd484dbe14958f9b422be3ac6641a ("Pretty: fix a broken
invariant"), T3294 showed 50% more max_bytes_used (#3294). After this
commit, max_bytes_used is back to what it was before, and the test
passes again.

This is a backport of a bug fix by Benedikt Huber (#2393), from commit
1e50748beaa4bd2281d323b18ea51c786bba04a1 in the pretty library.

From https://mail.haskell.org/pipermail/libraries/2008-June/009991.html:

    vcat (hsep,cat) is implemented in an unneccessarily strict way.
    We only get some output after all of vcat's arguments are evaluated
    and checked against being Empty.
    This can be improved by only checking the right argument of foldr
    against being Empty, and
    then applying an Empty-filter on the resulting Doc. Space improvement
    is obvious.
    The microbenchmark (code.haskell.org/~bhuber/Text/PrettyPrint/
    HughesPJPerfCheck.hs) suggests that
    the improvements in time are remarkable too.

shlevy/ghc,anton-dessiatov/ghc,mcschroeder/ghc,mfine/ghc,da-x/ghc,mfine/ghc,shlevy/ghc,mfine/ghc,mettekou/ghc,da-x/ghc,ml9951/ghc,da-x/ghc,wxwxwwxxx/ghc,nushio3/ghc,nkaretnikov/ghc,mfine/ghc,AlexanderPankiv/ghc,AlexanderPankiv/ghc,GaloisInc/halvm-ghc,vTurbine/ghc,mcschroeder/ghc,tjakway/ghcjvm,ghc-android/ghc,GaloisInc/halvm-ghc,tjakway/ghcjvm,mcschroeder/ghc,oldmanmike/ghc,mcschroeder/ghc,da-x/ghc,oldmanmike/ghc,ezyang/ghc,vikraman/ghc,siddhanathan/ghc,olsner/ghc,ml9951/ghc,vTurbine/ghc,ezyang/ghc,shlevy/ghc,TomMD/ghc,tjakway/ghcjvm,sgillespie/ghc,vTurbine/ghc,wxwxwwxxx/ghc,acowley/ghc,nushio3/ghc,ml9951/ghc,oldmanmike/ghc,nkaretnikov/ghc,mfine/ghc,mcschroeder/ghc,vikraman/ghc,elieux/ghc,vikraman/ghc,wxwxwwxxx/ghc,tjakway/ghcjvm,wxwxwwxxx/ghc,GaloisInc/halvm-ghc,sgillespie/ghc,sdiehl/ghc,snoyberg/ghc,AlexanderPankiv/ghc,snoyberg/ghc,TomMD/ghc,mettekou/ghc,siddhanathan/ghc,tjakway/ghcjvm,oldmanmike/ghc,elieux/ghc,mettekou/ghc,ezyang/ghc,TomMD/ghc,TomMD/ghc,tjakway/ghcjvm,mfine/ghc,vikraman/ghc,sdiehl/ghc,mettekou/ghc,acowley/ghc,GaloisInc/halvm-ghc,elieux/ghc,elieux/ghc,gridaphobe/ghc,elieux/ghc,olsner/ghc,ezyang/ghc,mcschroeder/ghc,anton-dessiatov/ghc,vTurbine/ghc,nkaretnikov/ghc,acowley/ghc,sgillespie/ghc,sgillespie/ghc,AlexanderPankiv/ghc,vTurbine/ghc,TomMD/ghc,AlexanderPankiv/ghc,sgillespie/ghc,anton-dessiatov/ghc,sdiehl/ghc,TomMD/ghc,sdiehl/ghc,oldmanmike/ghc,mcschroeder/ghc,sdiehl/ghc,ml9951/ghc,ml9951/ghc,anton-dessiatov/ghc,shlevy/ghc,olsner/ghc,nushio3/ghc,shlevy/ghc,nkaretnikov/ghc,acowley/ghc,ghc-android/ghc,nkaretnikov/ghc,olsner/ghc,da-x/ghc,acowley/ghc,elieux/ghc,GaloisInc/halvm-ghc,AlexanderPankiv/ghc,GaloisInc/halvm-ghc,da-x/ghc,nushio3/ghc,olsner/ghc,siddhanathan/ghc,oldmanmike/ghc,ml9951/ghc,sgillespie/ghc,nkaretnikov/ghc,shlevy/ghc,snoyberg/ghc,gridaphobe/ghc,vikraman/ghc,vTurbine/ghc,ezyang/ghc,ezyang/ghc,vikraman/ghc,mettekou/ghc,elieux/ghc,wxwxwwxxx/ghc,sgillespie/ghc,snoyberg/ghc,tjakway/ghcjvm,acowley/ghc,gridaphobe/ghc,ezyang/ghc,wxwxwwxxx/ghc,nkaretnikov/ghc,siddhanathan/ghc,ml9951/ghc,nushio3/ghc,nushio3/ghc,ghc-android/ghc,shlevy/ghc,siddhanathan/ghc,vTurbine/ghc,vikraman/ghc,gridaphobe/ghc,TomMD/ghc,anton-dessiatov/ghc,ghc-android/ghc,olsner/ghc,nushio3/ghc,ghc-android/ghc,wxwxwwxxx/ghc,mettekou/ghc,oldmanmike/ghc,GaloisInc/halvm-ghc,anton-dessiatov/ghc,sdiehl/ghc,snoyberg/ghc,gridaphobe/ghc,mfine/ghc,ghc-android/ghc,mettekou/ghc,ghc-android/ghc,siddhanathan/ghc,olsner/ghc,siddhanathan/ghc,anton-dessiatov/ghc,AlexanderPankiv/ghc,snoyberg/ghc,gridaphobe/ghc,ml9951/ghc,da-x/ghc,snoyberg/ghc,acowley/ghc,gridaphobe/ghc,sdiehl/ghc