Skip to content

Non-parametric derived instances now lazy vals #6905

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

Closed
wants to merge 2 commits into from

Conversation

milessabin
Copy link
Contributor

@milessabin milessabin commented Jul 22, 2019

Currently all derived instances would be compiled as given defs, which have caching logic added, where possible, in CacheAliasImplicits. These caches are unsynchronized, which is a reasonable default in circumstances where the programmer has the option to manually insert a lazy val or some other form of synchronization.

That option isn't available for derived instances, however, because these givens aren't written explicitly. In this case the more appropriate default is to compile non-parametric derived instances as given lazy vals.

This PR makes that change. Unfortunately the tests aren't all that convincing because an identity test isn't sufficient to distinguish between a lazy val and a def with unsynchronized caching logic. Suggestions for a better approach to the test would be very welcome.

@milessabin milessabin requested a review from odersky July 22, 2019 11:17
Previously all derived instances would be compiled as given defs, which
have caching logic added, where possible, in CacheAliasImplicits. These
caches are unsynchronized, which is a reasonable default in
circumstances where the progammer has the option to manually insert a
lazy val or some other form of synchronization. That option isn't
available for derived instances, however, because these givens aren't
written explicitly. In this case the more appropriate default is to
compile non-parametric derived instances as given lazy vals.
@milessabin milessabin force-pushed the topic/lazy-derives branch from 2ea2c57 to 42579af Compare July 23, 2019 11:59
@milessabin
Copy link
Contributor Author

@odersky this is ready for review now.

@odersky
Copy link
Contributor

odersky commented Jul 25, 2019

Is there an urgency to merge this now? We might decide to use lazy vals everywhere (see thread in #6909) in which case this change would be redundant.

If it's not urgent, then maybe we can discuss #6909 next Monday and then decide what to do.

@milessabin
Copy link
Contributor Author

milessabin commented Jul 25, 2019

@odersky it can definitely wait until we've had a chance to discuss #6909.

@odersky
Copy link
Contributor

odersky commented Aug 7, 2019

If #7006 gets in, this PR will no longer be necessary.

@milessabin
Copy link
Contributor Author

Happy to close this one :-)

@milessabin milessabin closed this Aug 7, 2019
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