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 #20856: Serialize Waiting and Evaluating as if null. #21243

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Jul 22, 2024

This strategy ensures the "serializability" condition of parallel programs--not to be confused with the data being java.io.Serializable. Indeed, if thread A is evaluating the lazy val while thread B attempts to serialize its owner object, there is also an alternative schedule where thread B serializes the owner object before A starts evaluating the lazy val. Therefore, forcing B to see the non-evaluating state is correct.

@sjrd sjrd linked an issue Jul 22, 2024 that may be closed by this pull request
@sjrd
Copy link
Member Author

sjrd commented Jul 22, 2024

@Gedochao I'm not sure who to ask for review here. All the previous contributors to Scala 3's lazy vals have moved on from the team.

Perhaps @lrytz ?

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

This makes sense, LGTM

byteStream.close()

def main(args: Array[String]): Unit =
val bytes = locally:
Copy link
Member

Choose a reason for hiding this comment

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

why did you use locally here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hum, no reason. I had blindly copy-pasted the reproduction from the issue. I removed it and added a few ends instead.

This strategy ensures the "serializability" condition of parallel
programs--not to be confused with the data being `java.io.Serializable`.
Indeed, if thread A is evaluating the lazy val while thread B attempts
to serialize its owner object, there is also an alternative schedule
where thread B serializes the owner object *before* A starts evaluating
the lazy val. Therefore, forcing B to see the non-evaluating state is
correct.
@sjrd sjrd enabled auto-merge July 31, 2024 08:54
@sjrd sjrd merged commit 927eb5b into scala:main Jul 31, 2024
26 checks passed
@sjrd sjrd deleted the fix-i20856 branch July 31, 2024 10:54
WojciechMazur added a commit that referenced this pull request Aug 27, 2024
…l`." to 3.5.2 (#21465)

Backports #21243 to the 3.5.2 branch.

PR submitted by the release tooling.
[skip ci]
@WojciechMazur WojciechMazur added this to the 3.5.2 milestone Oct 8, 2024
WojciechMazur added a commit that referenced this pull request Dec 3, 2024
…l`." to LTS (#22084)

Backports #21243 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
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.

Scala 3 lazy vals are not serialization-safe
3 participants