solomono / kiama

Automatically exported from code.google.com/p/kiama
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Control pretty-printer stack usage #60

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The current pretty printer implementation is quite stack hungry. E.g., the 
following code gets a stack overflow exception unless you bump the limit up.

{{{
object pp extends PrettyPrinter {
  def show(n : Int) : Doc = hsep ((1 to n) map {i => string(i)})
}

val many = List() ++ (for(i <- 1 to 1000) yield 4)

val text = pp.pretty(pp.vsep(many map pp.show))
}}}

Original issue reported on code.google.com by inkytonik on 18 Apr 2013 at 4:06

GoogleCodeExporter commented 9 years ago
r5d9a2c897598 contains changes to significantly improve the stack usage of the 
pretty printers. In particular, the following code now runs quickly and without 
overflowing the stack:

{{{
import org.kiama.output.PrettyPrinter
import PrettyPrinter._

def show (n : Int) : Doc = hsep ((1 to n) map value)

val many = List.fill (100000) (4)
pretty (vsep (many map show))
}}}

Note the 100000 instead of 1000 in the bug report.

Original comment by inkytonik on 21 Jun 2013 at 3:58

GoogleCodeExporter commented 9 years ago

Original comment by inkytonik on 4 Jul 2013 at 12:23

GoogleCodeExporter commented 9 years ago

Original comment by inkytonik on 3 Feb 2014 at 4:25