Skip to content

Prettyprinter fixes#1276

Merged
brianhuffman merged 5 commits intomasterfrom
prettyprinter-fixes
Sep 5, 2021
Merged

Prettyprinter fixes#1276
brianhuffman merged 5 commits intomasterfrom
prettyprinter-fixes

Conversation

@brianhuffman
Copy link
Contributor

Here are a couple of tweaks to the line-break heuristics in the prettyprinter. Awkward linebreaks that fall inside sub-expressions are now avoided. Here are some examples:

Cryptol> [ [ x * y : [4] | y <- [0..8] ] | x <- [0..3] ]
[[0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0],
 [0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8],
 [0x0, 0x2, 0x4, 0x6, 0x8, 0xa, 0xc, 0xe, 0x0],
 [0x0, 0x3, 0x6, 0x9, 0xc, 0xf, 0x2, 0x5, 0x8]]
Cryptol> [ [ x * y : [4] | y <- [0..15] ] | x <- [0..3] ]
[[0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0],
 [0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc,
  0xd, 0xe, 0xf],
 [0x0, 0x2, 0x4, 0x6, 0x8, 0xa, 0xc, 0xe, 0x0, 0x2, 0x4, 0x6, 0x8,
  0xa, 0xc, 0xe],
 [0x0, 0x3, 0x6, 0x9, 0xc, 0xf, 0x2, 0x5, 0x8, 0xb, 0xe, 0x1, 0x4,
  0x7, 0xa, 0xd]]
Cryptol> [ (0x0000,x:Integer) | x <- [0..30] ]
[(0x0000, 0), (0x0000, 1), (0x0000, 2), (0x0000, 3), (0x0000, 4),
 (0x0000, 5), (0x0000, 6), (0x0000, 7), (0x0000, 8), (0x0000, 9),
 (0x0000, 10), (0x0000, 11), (0x0000, 12), (0x0000, 13),
 (0x0000, 14), (0x0000, 15), (0x0000, 16), (0x0000, 17),
 (0x0000, 18), (0x0000, 19), (0x0000, 20), (0x0000, 21),
 (0x0000, 22), (0x0000, 23), (0x0000, 24), (0x0000, 25),
 (0x0000, 26), (0x0000, 27), (0x0000, 28), (0x0000, 29),
 (0x0000, 30)]

This avoids an exponential slowdown that occurs with `layoutSmart`
in combination with nested lists or lists of tuples.

Fixes #1274.
The combinator is altered so that if a list item cannot be laid
out on a single line, then we insert a linebreak before it so that
it starts on its own line.

Fixes #1275.
Copy link
Contributor

@robdockins robdockins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for figuring this out, none of the things I tried would work.

@brianhuffman brianhuffman merged commit 5a668a4 into master Sep 5, 2021
@RyanGlScott RyanGlScott deleted the prettyprinter-fixes branch March 22, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New prettyprinter puts line breaks in undesirable places Extremely slow prettyprinting for lists of tuples

2 participants