Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack-safe implementation of Pretty.break. #495

Merged
merged 1 commit into from
Aug 7, 2019

Conversation

non
Copy link
Contributor

@non non commented Aug 7, 2019

The motivation for this is #476. I wanted to ensure we had stronger
tests for Pretty.break before refactoring it, and also thought that
this implementation was a little bit nicer.

This PR includes a test for stack-safety, a test to ensure we never
create lines longer than the maximum allowed, and that we can
reassemble the original string from the output. The old code passed
all of these (apart from the stack safety test which it failed), which
helps give confidence and that the new implementation is equivalent.

It also includes a Scaladoc method to explain what the method does.

Thanks to @GytisZ for reporting the issue and providing an initial PR.

The motivation for this is typelevel#476. I wanted to ensure we had stronger
tests for Pretty.break before refactoring it, and also thought that
this implementation was a little bit nicer.

This PR includes a test for stack-safety, a test to ensure we never
create lines longer than the maximum allowed, and that we can
reassemble the original string from the output. The old code passed
all of these (apart from the stack safety test which it failed), which
helps give confidence and that the new implementation is equivalent.

It also includes a Scaladoc method to explain what the method does.

Thanks to @GytisZ for reporting the issue and providing an initial PR.
Copy link
Contributor

@ashawley ashawley left a comment

Choose a reason for hiding this comment

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

LGTM. I wouldn't have thought to write a test that reconstructs the input. Very cool.

@non non merged commit aaffe1e into typelevel:master Aug 7, 2019
@non non deleted the topic/pretty-break-tailrec branch August 7, 2019 17:16
@ashawley
Copy link
Contributor

ashawley commented Aug 7, 2019

I'm pretty confident that #468 in 2.12 is the reason this weakness suddenly showed up for Pretty.break.

However, there's no reason not to fix the possible stack overflow. Toying with it in #477, I also found it to be really slow, so it's good to optimize, as well, so users don't have to wait long to see their output.

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.

2 participants