Skip to content

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

Merged
merged 1 commit into from
Mar 30, 2021

Conversation

liufengyun
Copy link
Contributor

Performance tweak for initialization check

Propagate visited set properly.

Propagate visited set properly.
@liufengyun liufengyun requested a review from natsukagami March 29, 2021 12:53
Copy link
Contributor

@natsukagami natsukagami left a 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)
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 an error before? To what I understand final val is a "constant" (not assignable) value, so it gets initialized in a different order?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@liufengyun liufengyun left a 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)
Copy link
Contributor Author

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.

@liufengyun liufengyun merged commit 3ebeaa9 into scala:master Mar 30, 2021
@liufengyun liufengyun deleted the improve-init branch March 30, 2021 19:47
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
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.

3 participants