Skip to content

Add -Yfuture-lazy-vals for Scala 3 builds#1060

Merged
He-Pin merged 3 commits into
apache:mainfrom
He-Pin:add-Yfuture-lazy-vals-scala3
Jun 13, 2026
Merged

Add -Yfuture-lazy-vals for Scala 3 builds#1060
He-Pin merged 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 Common.scala scalacOptions using the existing onlyOnScala3 helper:

scalacOptions ++= onlyOnScala3(Seq("-Yfuture-lazy-vals")).value,

Result

pekko-http's Scala 3 build uses the future-proof VarHandle-based lazy val implementation, compatible with all JDK 9+ versions.

Tests

  • sbt "++3.3.8; http/compile" — passed (exit 0, 66s, only pre-existing warnings)

References

Refs scala/scala3-lts#637

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 Common.scala scalacOptions using the
existing onlyOnScala3 helper.

Result:
pekko-http's Scala 3 build uses the future-proof VarHandle-based lazy
val implementation, compatible with all JDK 9+ versions.

Tests:
- sbt "++3.3.8; http/compile" passed (exit 0, 66s)

References:
Refs scala/scala3-lts#637
@pjfanning

Copy link
Copy Markdown
Member

mima issues

[error] (validatePullRequest) Pull request validation failed! Mima failures: List(KeyValue(ScopedKey(Select(ProjectRef(file:/home/runner/work/pekko-http/pekko-http/,http)) / This / This,mimaResult),Problems(pekko-http: found 3 potential binary incompatibilities while checking against org.apache.pekko:pekko-http_3:1.0.0  (filtered 90)
[error]  * static method <clinit>()Unit in object org.apache.pekko.http.scaladsl.server.Directives does not have a correspondent in current version
[error]    filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.scaladsl.server.Directives.<clinit>")
[error]  * static method <clinit>()Unit in object org.apache.pekko.http.scaladsl.server.PathMatchers does not have a correspondent in current version
[error]    filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.scaladsl.server.PathMatchers.<clinit>")
[error]  * static method <clinit>()Unit in object org.apache.pekko.http.scaladsl.server.directives.PathDirectives does not have a correspondent in current version
[error]    filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.scaladsl.server.directives.PathDirectives.<clinit>")
[error] )))

Motivation:
The -Yfuture-lazy-vals flag added in 6d25f5e changes the Scala 3
bytecode generated for object lazy vals. As a side effect, the synthetic
<clinit> static initializers on Directives, PathMatchers, and
PathDirectives are no longer emitted, causing MiMa to flag three
DirectMissingMethodProblem errors against the 1.0.0 baseline.

These are compiler-internal initialization methods, not part of the
public API, so the change is binary compatible in practice.

Modification:
Add a new mima-filters exclude file under
2.0.x.backwards.excludes/ to suppress the three <clinit> missing-method
warnings on the Scala 3 build.

Result:
sbt "++3.3.8; http/mimaReportBinaryIssues" and validatePullRequest
MiMa checks pass again.

References:
Refs apache#1060
@He-Pin He-Pin requested a review from pjfanning June 13, 2026 11:44
Comment thread project/Common.scala Outdated
Motivation:
Code review requested combining the two onlyOnScala3 calls into one.

Modification:
Merge "-Wconf:cat=deprecation:s" and "-Yfuture-lazy-vals" into a single
onlyOnScala3(Seq(...)) call.

Result:
Cleaner build definition with both Scala 3 options in one place.

Tests:
Not run - build config only

References:
Refs apache#1060
@He-Pin He-Pin requested a review from pjfanning June 13, 2026 13:21

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm

@He-Pin He-Pin merged commit 44e2755 into apache:main Jun 13, 2026
5 checks passed
@He-Pin He-Pin deleted the add-Yfuture-lazy-vals-scala3 branch June 13, 2026 13:46
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