Add -Yfuture-lazy-vals for Scala 3.3.x builds#3059
Open
He-Pin wants to merge 3 commits into
Open
Conversation
Motivation: The Scala 3.3.8 compiler introduced the -Yfuture-lazy-vals flag (scala/scala3-lts#637) to optionally use VarHandle instead of sun.misc.Unsafe for lazy val implementation. This prepares libraries for upcoming JDK releases that restrict Unsafe access. Modification: Add -Yfuture-lazy-vals to DefaultScalacOptions in PekkoBuild.scala, conditionally applied only for Scala 3.3.x via CrossVersion.partialVersion. Result: Pekko's Scala 3.3.x build uses the future-proof VarHandle-based lazy val implementation, compatible with all JDK 9+ versions. Tests: - sbt "++3.3.8; actor/compile" passed (exit 0, 54 pre-existing warnings) References: Refs scala/scala3-lts#637
The -Yfuture-lazy-vals flag changes the generated bytecode for companion objects containing lazy vals: the static <clinit> initializer produced by the old sun.misc.Unsafe-based implementation is no longer emitted. Add a MiMa filter to exclude this expected binary incompatibility for RemoteWatcher#Stats. Tests: - sbt "++3.3.8; remote/mimaReportBinaryIssues" passed (exit 0)
pjfanning
reviewed
Jun 13, 2026
Motivation: PR apache#3059 review feedback from pjfanning requested simplifying the conditional CrossVersion.partialVersion match for -Yfuture-lazy-vals. Modification: Add -Yfuture-lazy-vals directly to the Scala 3 scalac options Seq instead of using a CrossVersion.partialVersion conditional match. Result: Cleaner, simpler build configuration that still applies the flag to all Scala 3.x builds. Tests: Not run - build config simplification only References: Refs apache#3059
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The Scala 3.3.8 compiler introduced the
-Yfuture-lazy-valsflag (scala/scala3-lts#637) to optionally useVarHandleinstead ofsun.misc.Unsafefor lazy val implementation. This prepares libraries for upcoming JDK releases that restrictsun.misc.Unsafeaccess.Modification
-Yfuture-lazy-valstoDefaultScalacOptionsinproject/PekkoBuild.scala, conditionally applied only for Scala 3.3.x viaCrossVersion.partialVersionremote/src/main/mima-filters/2.0.x.backwards.excludes/future-lazy-vals.excludesto exclude the expected<clinit>bytecode change forRemoteWatcher#Stats(the new VarHandle-based lazy val implementation no longer generates the static initializer that the old Unsafe-based implementation produced)Result
Pekko's Scala 3.3.x build uses the future-proof
VarHandle-based lazy val implementation, compatible with all JDK 9+ versions including future releases that restrictsun.misc.Unsafe.Tests
sbt "++3.3.8; actor/compile"— passed (exit 0, only pre-existing warnings)sbt "++3.3.8; remote/mimaReportBinaryIssues"— passed (exit 0)References
Refs scala/scala3-lts#637