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

Fix #5350: Fix purity of local lazy vals #5703

Merged
merged 3 commits into from
Jan 15, 2019

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@@ -0,0 +1,10 @@
object Test {
def foo = {
lazy val bar: Unit = println("Hello")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Blaisorblade does it make sense for this lazy val to be stable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. The definition of isStable doesn't check for Lazy, so Symbol.isStable should only imply idempotence.

To detect if a value is pure, Realizability checks sym.isStable && !sym.is(Lazy | Erased, butNot = Module). Maybe here you should check
sym.isStable && !sym.is(Lazy, butNot = Module)? But on modules, this overlaps with #2266 and #4765.

That all needs testcases and consideration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually modules do not reach this line. Hence the current condition does not affect the module init elimination.

Copy link
Contributor

@Blaisorblade Blaisorblade left a comment

Choose a reason for hiding this comment

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

Requested changes per comment...


resultValue.map(value => s"$dcl = $value")
if (d.symbol.is(Flags.Lazy)) Some(dcl)
else valueOf(d.symbol).map(value => s"$dcl = $value")
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 on printing the flag to the left (in ReplPrinter). On this change, FWIW, Scala 2 also uses <lazy> here. Not sure anybody cares tho, so merging anyway.

scala> lazy val x = 1
x: Int = <lazy>

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Jan 15, 2019

Tests confirm this doesn't affect the handling of modules, and that modules don't get to the changed code (because that code tests stability of functions, hence not of objects).

Hence can be merged once tests pass. @nicolasstucki can you do it?

@Blaisorblade Blaisorblade merged commit c975760 into scala:master Jan 15, 2019
@Blaisorblade Blaisorblade deleted the fix-#5350 branch January 15, 2019 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants