-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Performance tweak for initialization check #11928
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
Conversation
Propagate visited set properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only have one question. Scala has so many useful features! Taking a block as a closure is really convenient
@@ -4,7 +4,7 @@ class Foo { | |||
val fun2: Int => Int = n => 1 + n + list.size | |||
fun2(5) | |||
|
|||
List(5, 9).map(n => 2 + n + list.size) // error | |||
List(5, 9).map(n => 2 + n + list.size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an error before? To what I understand final val
is a "constant" (not assignable) value, so it gets initialized in a different order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only final vals of constant types (such as false
, 2
, etc.) have different behavior due to const-folding.
We don't have a warning now, because at line 5, we already check the effect this.list!
, thus the access this.list!
is skipped here. If we comment out line 5, we will have a warning at this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @natsukagami !
@@ -4,7 +4,7 @@ class Foo { | |||
val fun2: Int => Int = n => 1 + n + list.size | |||
fun2(5) | |||
|
|||
List(5, 9).map(n => 2 + n + list.size) // error | |||
List(5, 9).map(n => 2 + n + list.size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only final vals of constant types (such as false
, 2
, etc.) have different behavior due to const-folding.
We don't have a warning now, because at line 5, we already check the effect this.list!
, thus the access this.list!
is skipped here. If we comment out line 5, we will have a warning at this line.
Performance tweak for initialization check
Propagate visited set properly.