8000 More elegant holders for local lazy vals. by adriaanm · Pull Request #5374 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

More elegant holders for local lazy vals. #5374

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

Merged
merged 1 commit into from
Sep 3, 2016

Conversation

adriaanm
Copy link
Contributor
@adriaanm adriaanm commented Sep 2, 2016

Follow up for #5294 based on @retronym's feedback.

I'm going to defer teaching the optimizer about stack allocating the lazy holders: scala/scala-dev#215

@adriaanm adriaanm added this to the 2.12.0-RC1 milestone Sep 2, 2016
@lrytz
Copy link
Member
lrytz commented Sep 2, 2016

LGTM!

@retronym
Copy link
Member
retronym commented Sep 3, 2016

LGTM

@retronym retronym merged commit 04c7fae into scala:2.12.x Sep 3, 2016
@adriaanm adriaanm added the 2.12 label Oct 29, 2016

class LazyRef[T] {
var value: T = _
@volatile var initialized: Boolean = false
@volatile private[this] var _initialized: Boolean = _
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this @volatile btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quoting @retronym:

In double checked locking, the write to the value is in a synchronized block
the fast path (already initialized) just needs to volatile read on the initialized field. if that is set, we know the value was safely published

Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies, I guess what threw me of course is that this class (or rather these classes) are public, and non-final, classes which cannot be used properly without sprinkling of "magic"/macros. Are these intended to be possible to use directly by users?

Copy link
Contributor Author

Choose a 10000 reason for hiding this comment

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

True, the runtime package is not meant for public consumption. Good point
that they should likely be final. They have to be public though, as they
are referenced from compiler-generated code.

scala/scala-dev#339

allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Oct 31, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Oct 31, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Oct 31, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Nov 1, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Nov 1, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Nov 1, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Nov 1, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Nov 6, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Nov 8, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
allanrenucci added a commit to dotty-staging/dotty that referenced this pull request Nov 8, 2018
Reduce the amount of code generated for local lazy val by moving some of
the generated code to the runtime library.

This is a port of scala/scala#5374
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.

5 participants
0