prettyprinter: generalise alterAnnotationsS to lists - #287
Conversation
|
Since this is a breaking change, it would be good to understand the motivation behind it. Could you explain why you want this change? |
|
Hey @sjakobi, thank you for the speedy reply. The background of the motivation is a little bit involved:
I've implemented the function first in my own codebase, to confirm that it works as intended. Then I researched the Prettyprinter codebase to see why such a function does not yet exist. The I think it's worth the breaking change to generalise this function. That's what semver is for after all. Another possibility is exposing this a separate function, but then I'd question the need for |
|
I agree that this would improve the API. What I'd like to be more sure of:
|
I think one property that we'd want is |
ced901f to
3f57591
Compare
|
Hey @sjakobi Apologies for the long wait, I haven't forgotten about this PR. 🙂 I've added three property tests that I could think of. I wasn't sure where to put them, so I made a new test group for them. I've played around with ways to remove the double traversal, making I've also rebased the PR to the latest master. When running my properties with many thousands of QuickCheck runs, I came across a potential bug in how It's in This is not caused by this PR, you can try this repro on master: ghci> layoutPretty defaultLayoutOptions (nest 4 (line <> annotate () mempty))
SLine 4 (SAnnPush () (SAnnPop SEmpty))
ghci> layoutPretty defaultLayoutOptions (nest 4 (line <> mempty))
SLine 0 SEmptyIn both cases the result should have been I can open a PR with a fix, but I'd like to base it on this one when it is merged. |
3f57591 to
04eddf7
Compare
|
Regarding the bug, do you think this is something that could cause "real" problems in real code? I believe the same buggy logic is the source of of a bad perf bug: #205. I'm still unsure what the best fix would be. I'll try to lay out the options and maybe I could then get your feedback on it? Meanwhile please do file an issue for that bug. I think it might be helpful to decide which approach to take for the perf fix. |
sjakobi
left a comment
There was a problem hiding this comment.
Thank you! I've found some minor perf tweaks that I might add in a follow-up.
We can very simply support reannotating to a list of annotations if we store a counter instead of a boolean in the stack.