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
Make -release
more useful, deprecate -target
, align with Scala 3
#9982
Conversation
The test is missing. It said edit: #9981 |
I would like to take a moment to thank Travis for actually showing me the exception, looking at you, Jenkins.
oh, yeah. |
oh right, that thing where CI settings differ from "home" settings even if I bootstrapped publishLocal etc etc etc.
|
Re-rebuilt under 8 and confirmed
and also compiled my 8-averse test file. I wonder if "metaverse" is a contraction of "meta-averse"? |
The glitch at 06d85a5
|
That commit passes locally, so pushing rebase. |
We might drop |
Noting that the Edit: |
Rebased and commented out the Scala 3 aliases so that there can be no objection to this PR. |
@SethTisue also 🤞 Sorry I am so lame, I wish I had the gift for all the things you do. |
-release
more useful, deprecate -target
, align with Scala 3
I'm helpless without someone else's draft to revise! No joke. |
OK here's a draft 🍺 |
@som-snytt @SethTisue Will this been backport to 2.12.x? thanks. |
Thank you @som-snytt |
Also changing sbt compiler option -target to -release as the former got deprecated with scala/scala#9982
//target.value = setting.value // this would trigger deprecation | ||
} | ||
.withAbbreviation("--release") | ||
// .withAbbreviation("-java-output-version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Scala 3, -java-output-version
is the preferred flag name (with the alias of -release
still permitted) - would it be reasonable to uncomment this line, and allow Scala 2.13 to use -java-output-version
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we'd accept a PR that did that — at least I can't think why not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the dotty project is really bad at choosing option names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(to be clear: not suggesting we make it canonical in Scala 2, just an accepted alternative)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see also -Xunchecked-java-output-version
. I didn't want to encourage them (the folks inventing these names). I came close to enabling them (the alt names) on this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we'd accept a PR that did that — at least I can't think why not
Thanks! Opened with #10654.
Because the dotty project is really bad at choosing option names.
This comment reminded me of my favourite video on software development, the 2012 talk by Andrew Dupont How to Argue About Code (sadly, as it's 'Not Yet Rated' on Vimeo, you have to login to view it in UK & EU, but at least after that there's no ads).
Regarding the option name, for myself, when I'm trying to help junior devs understand that if they want to run their code on Java 11, they need to specify -java-output-version 11
, the conversation is a little easier than it is if I say -release 11
. The first name, because it includes 'java', is more self-explanatory. The junior dev is aware of Scala and Java, but doesn't automatically realise that when Scala says -release
, it's referring to a Java-related concern.
Following on from #9982 and discussion in https://github.com/scala/scala/pull/9982/files#r1434172490, this change enables `-java-output-version` as an alternative name for the `-release` flag in Scala 2, as in Scala 3 `-java-output-version` is the preferred flag name (see scala/scala3#14606 ), with the alias of `-release` still permitted. Correspondingly, `-Xunchecked-java-output-version` is also included as an alternative for `-target`, though note use of this flag is discouraged in favour of `-java-output-version`/`-release` for Java 9 and above.
…` instead of `-target` ### What changes were proposed in this pull request? This pr makes the following changes to allow Spark to build with `-release` instead of `-target`: 1. Use `MethodHandle` instead of direct calls to `sun.security.action.GetBooleanAction` and `sun.util.calendar.ZoneInfo`, because they are not `exports` APIs. 2. `Channels.newReader` is used instead of ``,StreamDecoder.forDecoder because `StreamDecoder.forDecoder` is also not `exports` APIs. ```java public static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap) { Objects.requireNonNull(ch, "ch"); return StreamDecoder.forDecoder(ch, dec.reset(), minBufferCap); } ``` 3. Adjusted the import of `java.io._` in `yarn/Client.scala` to fix the compilation error: ``` Error: ] /home/runner/work/spark/spark/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala:20: object FileSystem is not a member of package java.io ``` 4. Replaced `-target` with `-release` in `pom.xml` and `SparkBuild.scala`, and removed the `-source` option, because using `-release` is sufficient. 5. Upgrade `scala-maven-plugin` from 4.7.1 to 4.8.1 to fix the error `[ERROR] -release cannot be less than -target` when executing `build/mvn clean install -DskipTests -Djava.version=21` ### Why are the changes needed? After Scala 2.13.9, the compile option `-target` has been deprecated, it is recommended to use `-release`: - scala/scala#9982 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Pass GitHub Actions ### Was this patch authored or co-authored using generative AI tooling? No Closes #45716 from LuciferYang/scala-maven-plugin-491. Authored-by: yangjie01 <yangjie01@baidu.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
…` instead of `-target` ### What changes were proposed in this pull request? This pr makes the following changes to allow Spark to build with `-release` instead of `-target`: 1. Use `MethodHandle` instead of direct calls to `sun.security.action.GetBooleanAction` and `sun.util.calendar.ZoneInfo`, because they are not `exports` APIs. 2. `Channels.newReader` is used instead of ``,StreamDecoder.forDecoder because `StreamDecoder.forDecoder` is also not `exports` APIs. ```java public static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap) { Objects.requireNonNull(ch, "ch"); return StreamDecoder.forDecoder(ch, dec.reset(), minBufferCap); } ``` 3. Adjusted the import of `java.io._` in `yarn/Client.scala` to fix the compilation error: ``` Error: ] /home/runner/work/spark/spark/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala:20: object FileSystem is not a member of package java.io ``` 4. Replaced `-target` with `-release` in `pom.xml` and `SparkBuild.scala`, and removed the `-source` option, because using `-release` is sufficient. 5. Upgrade `scala-maven-plugin` from 4.7.1 to 4.8.1 to fix the error `[ERROR] -release cannot be less than -target` when executing `build/mvn clean install -DskipTests -Djava.version=21` ### Why are the changes needed? After Scala 2.13.9, the compile option `-target` has been deprecated, it is recommended to use `-release`: - scala/scala#9982 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Pass GitHub Actions ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#45716 from LuciferYang/scala-maven-plugin-491. Authored-by: yangjie01 <yangjie01@baidu.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
Why
-release
?Use
-release
to specify the minimum JVM version that your code requires. This can be version 8 or higher, but is typically an LTS (Long Term Support) version such as-release 8
,-release 11
, or-release 17
.The compiler will compile your code with the Java standard library for the specified version, and it will output class files for that version (that is, that can only even be classloaded by that JVM version or higher).
Using
-release
allows you to decouple the JVM version on which your code is built from the minimum JVM version on which it runs. For example, you might specify-release 8
so your users are free to use 8, but you yourself can use 11 or 17 at build time (locally, or in CI).What has changed?
-release
already existed in earlier Scala versions, but it only controlled the Java standard library version, not the bytecode version (which was controlled by-target
).The old
-target
option is now deprecated, because-release
now includes-target
's behavior.-java-output-version
is now supported as an alias for-release
.Motivation
Improves ergonomics and avoids accidental misuse, since now only
-release
is needed, whereas before two flags were needed.Aligns
-release
s behavior on Scala 2 with its behavior on Scala 3.Fixes scala/bug#12543.