Skip to content

Add -Yfuture-lazy-vals for Scala 3.3.x builds#3059

Open
He-Pin wants to merge 3 commits into
apache:mainfrom
He-Pin:add-Yfuture-lazy-vals-scala3
Open

Add -Yfuture-lazy-vals for Scala 3.3.x builds#3059
He-Pin wants to merge 3 commits into
apache:mainfrom
He-Pin:add-Yfuture-lazy-vals-scala3

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 13, 2026

Copy link
Copy Markdown
Member

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 sun.misc.Unsafe access.

Modification

  • Add -Yfuture-lazy-vals to DefaultScalacOptions in project/PekkoBuild.scala, conditionally applied only for Scala 3.3.x via CrossVersion.partialVersion
  • Add MiMa filter in remote/src/main/mima-filters/2.0.x.backwards.excludes/future-lazy-vals.excludes to exclude the expected <clinit> bytecode change for RemoteWatcher#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 restrict sun.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

He-Pin added 2 commits June 13, 2026 16:43
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)
@He-Pin He-Pin requested a review from pjfanning June 13, 2026 10:19
Comment thread project/PekkoBuild.scala Outdated
@He-Pin He-Pin requested a review from pjfanning June 13, 2026 15:22
@He-Pin He-Pin added this to the 2.0.0-M4 milestone 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
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.

2 participants