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

Make sure default impls for BoundedEnum are TCO'd #37

Merged
merged 2 commits into from
Jan 31, 2019

Conversation

hdgarrood
Copy link
Contributor

The implementations for defaultCardinality, defaultToEnum, and
defaultFromEnum don't trigger tail-call optimization, which means that
they are quite a bit slower than they could be (and in some cases will
produce a stack overflow when they needn't).

This commit will also have the fortunate effect that this library won't
break if the compiler stops inlining function composition in the
(arguably broken) way that it does currently; see
purescript/purescript#3439 (comment)

The implementations for `defaultCardinality`, `defaultToEnum`, and
`defaultFromEnum` don't trigger tail-call optimization, which means that
they are quite a bit slower than they could be (and in some cases will
produce a stack overflow when they needn't).

This commit will also have the fortunate effect that this library won't
break if the compiler stops inlining function composition in the
(arguably broken) way that it does currently; see
purescript/purescript#3439 (comment)
@hdgarrood hdgarrood requested a review from natefaubion January 30, 2019 23:45
-- | A newtype over Int which is supposed to represent Ints bounded between 0
-- | and 10,000. Why 10,000? It's just about large enough that we'll most
-- | likely see stack overflow errors if we've managed to break TCO.
newtype Upto10k = Upto10k Int

Choose a reason for hiding this comment

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

I've seen stack-unsafe code work up to 30k iterations in the past. I always do 100k.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh, news to me - good to know, thanks! I'll change this.

@hdgarrood hdgarrood merged commit c22de83 into master Jan 31, 2019
@hdgarrood hdgarrood deleted the tco-default-bounded-enum branch January 31, 2019 22:40
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