Fix #83 by changing the choice of minNestingLevel#89
Conversation
|
I'll try to explain this later… ;) |
| minNestingLevel = min lineIndent currentColumn | ||
| minNestingLevel = case y of | ||
| SLine _ _ -> lineIndent | ||
| _ -> currentColumn |
There was a problem hiding this comment.
We check whether the second alternative (y) starts with a line break in order to detect hanging layouts as (partially) explained in #83 (comment).
There was a problem hiding this comment.
The loss of laziness in y is a bit unfortunate. Since best seems to be quite lazy, I hope it's not too bad though.
There was a problem hiding this comment.
The loss of laziness in
yis a bit unfortunate.
I think this is probably outweighed by the efficiencies gained from the greater minNestingLevel when we select currentColumn:
- We don't have to check
xas far as withlineIndent. - We can more often stick with
xinstead of switching toy.
There was a problem hiding this comment.
Also note that layoutPretty is completely unaffected since it ignores the minNestingLevel:
There was a problem hiding this comment.
If y starts with one of the annotation constructors, we should probably look further for the first "proper" constructor…
There was a problem hiding this comment.
I went with the »annotations might mean something important even if they contain something unimportant« elsewhere (strip trailing whitespace), so I think ignoring annotations here is alright. What do you think?
There was a problem hiding this comment.
I'm actually not really familiar with how annotations work or how they are used.
But it seems to me that the result of layoutWadlerLeijen should not depend on the presence of annotations. Wouldn't the following property be desirable?
layoutWadlerLeijen fp opts (unAnnotate doc) === unAnnotateS (layoutWadlerLeijen fp opts doc)
So I think it would be better to check what's behind the annotations.
|
Ha nice! At first I was concerned about your pattern matching on I agree the loss of laziness in I’ll add another test to make sure Thanks for all your work! I’m not sure how long it would have taken me to spot this one… |
e84417c to
a4d633b
Compare
a4d633b to
4a8b609
Compare
| -- See https://github.com/quchen/prettyprinter/issues/83. | ||
| if startsWithLine y | ||
| -- y might be a (more compact) hanging layout. Let's check x | ||
| -- thoroughly with the smaller lineIndent. |
There was a problem hiding this comment.
If we wanted to detect hanging layouts more precisely, we could also check that the indentation of the SLine is < currentColumn. But what we have right now is the slightly more conservative change.
| | fits pWidth minNestingLevel availableWidth x = x | ||
| | otherwise = y | ||
| where | ||
| minNestingLevel = min lineIndent currentColumn |
There was a problem hiding this comment.
Any idea why this was computed with min and didn't just return lineIndent?
Doesn't the invariant from above hold here?
-- * current column >= current nesting level
| -- y definitely isn't a hanging layout. Let's allow the first | ||
| -- line of x to be checked on its own and format it consistently | ||
| -- with subsequent lines with the same indentation. | ||
| else currentColumn |
There was a problem hiding this comment.
These are the general conditions under which layoutSmart, given a Union x y, will change its behaviour to return x instead of y with this change:
ydoesn't start with a line breaklineIndentmust be< currentColumn- a line of
x(but not the first) with an indentation oflineIndent < i <= currentColumnis too wide.
There was a problem hiding this comment.
- a line of
x(but not the first) with an indentation oflineIndent < i <= currentColumnis too wide.
Actually that line must be "reachable" too. I.e. there's no other line with an indentation <= lineIndent before it.
|
@quchen Did you get a chance to look at this further? Ideally I'd like to smoke-test this patch in projects that are likely to be impacted. Do you know any suitable projects? The next best thing would IMHO be to just release this and wait for feedback. :) |
|
Released 1.5. I don’t have that much time on my hands right now, sorry for the delays! |
|
No worries. Thanks for the releases! :) |
No description provided.