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

Make -release more useful, deprecate -target, align with Scala 3 #9982

Merged
merged 4 commits into from Jun 13, 2022

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Mar 26, 2022

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 -releases behavior on Scala 2 with its behavior on Scala 3.

Fixes scala/bug#12543.

@scala-jenkins scala-jenkins added this to the 2.13.9 milestone Mar 26, 2022
@som-snytt
Copy link
Contributor Author

som-snytt commented Mar 28, 2022

The test is missing. It said -release 8 which would have failed. It must be sitting on a different branch.

edit: #9981

@som-snytt
Copy link
Contributor Author

I would like to take a moment to thank Travis for actually showing me the exception, looking at you, Jenkins.

Caused by: java.lang.NumberFormatException: For input string: "1.8"

oh, yeah.

@som-snytt
Copy link
Contributor Author

oh right, that thing where CI settings differ from "home" settings even if I bootstrapped publishLocal etc etc etc.

[error] /home/travis/build/scala/scala/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala:103:38: match may not be exhaustive.

[error] It would fail on the following inputs: AnyScalaVersion, NoScalaVersion

[error]   val MaxTargetVersion = ScalaVersion(javaSpecVersion) match {

@som-snytt
Copy link
Contributor Author

Re-rebuilt under 8 and confirmed -help shows

  -release:<release>           Compile for a version of the Java API and target class file. ([8])

and also compiled my 8-averse test file.

I wonder if "metaverse" is a contraction of "meta-averse"?

@som-snytt
Copy link
Contributor Author

The glitch at 06d85a5

!!  1 - presentation/t12308                       [output differs]
% diff /home/jenkins/workspace/scala-2.13.x-validate-main/test/files/presentation/t12308.check /home/jenkins/workspace/scala-2.13.x-validate-main/test/files/presentation/t12308-presentation.log
@@ -46,5 +46,4 @@ askType at Foo.scala(4,37)
 [response] askTypeAt (4,37)
 1
 ================================================================================
-Problem(RangePosition(t12308/src/Foo.scala, 67, 67, 72),A try without a catch or finally is equivalent to putting its body in a block; no exceptions are handled.,1)
-Problem(RangePosition(t12308/src/Foo.scala, 109, 109, 114),A try without a catch or finally is equivalent to putting its body in a block; no exceptions are handled.,1)

@som-snytt
Copy link
Contributor Author

That commit passes locally, so pushing rebase.

@dwijnand
Copy link
Member

We might drop -scala-output-version, so let's wait on aligning things here.

@som-snytt
Copy link
Contributor Author

som-snytt commented Apr 20, 2022

Noting that the -scala-output-version is just an alias.

Edit: -java-output-version. The other option is not optionable on Scala 2.

@som-snytt som-snytt mentioned this pull request Apr 22, 2022
@som-snytt
Copy link
Contributor Author

Rebased and commented out the Scala 3 aliases so that there can be no objection to this PR.

@som-snytt som-snytt changed the title Align -release with Scala 3 Make -release more useful, deprecate -target Apr 22, 2022
@som-snytt som-snytt marked this pull request as ready for review April 22, 2022 18:17
@som-snytt
Copy link
Contributor Author

@SethTisue also 🤞 Sorry I am so lame, I wish I had the gift for all the things you do.

@SethTisue SethTisue changed the title Make -release more useful, deprecate -target, align with Scala 3 Make -release more useful, deprecate -target, align with Scala 3 Sep 1, 2022
@SethTisue
Copy link
Member

I'm helpless without someone else's draft to revise! No joke.

@som-snytt
Copy link
Contributor Author

OK here's a draft 🍺

@xuwei-k
Copy link
Contributor

xuwei-k commented Sep 21, 2022

@He-Pin
Copy link
Contributor

He-Pin commented Oct 11, 2022

@som-snytt @SethTisue Will this been backport to 2.12.x? thanks.

@som-snytt
Copy link
Contributor Author

@He-Pin Yes, but #10109

@He-Pin
Copy link
Contributor

He-Pin commented Oct 11, 2022

Thank you @som-snytt

//target.value = setting.value // this would trigger deprecation
}
.withAbbreviation("--release")
// .withAbbreviation("-java-output-version")
Copy link
Contributor

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?

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

som-snytt pushed a commit that referenced this pull request Jan 13, 2024
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.
dongjoon-hyun pushed a commit to apache/spark that referenced this pull request Apr 1, 2024
…` 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>
sweisdb pushed a commit to sweisdb/spark that referenced this pull request Apr 1, 2024
…` 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio:hi high priority (used only by core team, only near release time) release-notes worth highlighting in next release notes
Projects
None yet
9 participants