Skip to content

Commit cbe27ae

Browse files
authored
Merge pull request #14613 from prolativ/backport-rename-output-version-settings
Consistent naming of output-version settings
2 parents f0bed40 + df5f661 commit cbe27ae

File tree

10 files changed

+21
-20
lines changed

10 files changed

+21
-20
lines changed

community-build/src/scala/dotty/communitybuild/projects.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ final case class SbtCommunityProject(
161161

162162
def withScalaRelease(release: String): SbtCommunityProject =
163163
this.copy(
164-
scalacOptions = scalacOptions ++ Seq("-Yscala-release", release)
164+
scalacOptions = scalacOptions ++ Seq("-scala-output-version", release)
165165
)
166166

167167
object SbtCommunityProject:

compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ trait BCodeIdiomatic {
2727

2828

2929
lazy val target =
30-
val releaseValue = Option(ctx.settings.release.value).filter(_.nonEmpty)
31-
val targetValue = Option(ctx.settings.Xtarget.value).filter(_.nonEmpty)
30+
val releaseValue = Option(ctx.settings.javaOutputVersion.value).filter(_.nonEmpty)
31+
val targetValue = Option(ctx.settings.XuncheckedJavaOutputVersion.value).filter(_.nonEmpty)
3232
val defaultTarget = "8"
3333
(releaseValue, targetValue) match
3434
case (Some(release), None) => release
3535
case (None, Some(target)) => target
3636
case (Some(release), Some(_)) =>
37-
report.warning(s"The value of ${ctx.settings.Xtarget.name} was overridden by ${ctx.settings.release.name}")
37+
report.warning(s"The value of ${ctx.settings.XuncheckedJavaOutputVersion.name} was overridden by ${ctx.settings.javaOutputVersion.name}")
3838
release
3939
case (None, None) => "8" // least supported version by default
4040

compiler/src/dotty/tools/dotc/classpath/ZipAndJarFileLookupFactory.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ sealed trait ZipAndJarFileLookupFactory {
2424
private val cache = new FileBasedCache[ClassPath]
2525

2626
def create(zipFile: AbstractFile)(using Context): ClassPath =
27-
val release = Option(ctx.settings.release.value).filter(_.nonEmpty)
27+
val release = Option(ctx.settings.javaOutputVersion.value).filter(_.nonEmpty)
2828
if (ctx.settings.YdisableFlatCpCaching.value || zipFile.file == null) createForZipFile(zipFile, release)
2929
else createUsingCache(zipFile, release)
3030

compiler/src/dotty/tools/dotc/config/PathResolver.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class PathResolver(using c: Context) {
207207

208208
// Assemble the elements!
209209
def basis: List[Traversable[ClassPath]] =
210-
val release = Option(ctx.settings.release.value).filter(_.nonEmpty)
210+
val release = Option(ctx.settings.javaOutputVersion.value).filter(_.nonEmpty)
211211

212212
List(
213213
JrtClassPath(release), // 1. The Java 9+ classpath (backed by the jrt:/ virtual system, if available)

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ trait CommonScalaSettings:
103103
val pageWidth: Setting[Int] = IntSetting("-pagewidth", "Set page width", ScalaSettings.defaultPageWidth, aliases = List("--page-width"))
104104
val silentWarnings: Setting[Boolean] = BooleanSetting("-nowarn", "Silence all warnings.", aliases = List("--no-warnings"))
105105

106-
val release: Setting[String] = ChoiceSetting("-release", "release", "Compile code with classes specific to the given version of the Java platform available on the classpath and emit bytecode for this version.", ScalaSettings.supportedReleaseVersions, "", aliases = List("--release"))
106+
val javaOutputVersion: Setting[String] = ChoiceSetting("-java-output-version", "version", "Compile code with classes specific to the given version of the Java platform available on the classpath and emit bytecode for this version. Corresponds to -release flag in javac.", ScalaSettings.supportedReleaseVersions, "", aliases = List("-release", "--release"))
107+
val scalaOutputVersion: Setting[String] = ChoiceSetting("-scala-output-version", "version", "Emit TASTy files that can be consumed by specified version of the compiler. The compilation will fail if for any reason valid TASTy cannot be produced (e.g. the code contains references to some parts of the standard library API that are missing in the older stdlib or uses language features unexpressible in the older version of TASTy format)", ScalaSettings.supportedScalaReleaseVersions, "")
108+
107109
val deprecation: Setting[Boolean] = BooleanSetting("-deprecation", "Emit warning and location for usages of deprecated APIs.", aliases = List("--deprecation"))
108110
val feature: Setting[Boolean] = BooleanSetting("-feature", "Emit warning and location for usages of features that should be imported explicitly.", aliases = List("--feature"))
109111
val explain: Setting[Boolean] = BooleanSetting("-explain", "Explain errors in more detail.", aliases = List("--explain"))
@@ -221,7 +223,7 @@ private sealed trait XSettings:
221223
val XignoreScala2Macros: Setting[Boolean] = BooleanSetting("-Xignore-scala2-macros", "Ignore errors when compiling code that calls Scala2 macros, these will fail at runtime.")
222224
val XimportSuggestionTimeout: Setting[Int] = IntSetting("-Ximport-suggestion-timeout", "Timeout (in ms) for searching for import suggestions when errors are reported.", 8000)
223225
val Xsemanticdb: Setting[Boolean] = BooleanSetting("-Xsemanticdb", "Store information in SemanticDB.", aliases = List("-Ysemanticdb"))
224-
val Xtarget: Setting[String] = ChoiceSetting("-Xtarget", "target", "Emit bytecode for the specified version of the Java platform. This might produce bytecode that will break at runtime. When on JDK 9+, consider -release as a safer alternative.", ScalaSettings.supportedTargetVersions, "", aliases = List("--Xtarget"))
226+
val XuncheckedJavaOutputVersion: Setting[String] = ChoiceSetting("-Xunchecked-java-output-version", "target", "Emit bytecode for the specified version of the Java platform. This might produce bytecode that will break at runtime. Corresponds to -target flag in javac. When on JDK 9+, consider -java-output-version as a safer alternative.", ScalaSettings.supportedTargetVersions, "", aliases = List("-Xtarget", "--Xtarget"))
225227
val XcheckMacros: Setting[Boolean] = BooleanSetting("-Xcheck-macros", "Check some invariants of macro generated code while expanding macros", aliases = List("--Xcheck-macros"))
226228
val XmainClass: Setting[String] = StringSetting("-Xmain-class", "path", "Class for manifest's Main-Class entry (only useful with -d <jar>)", "")
227229
val XimplicitSearchLimit: Setting[Int] = IntSetting("-Ximplicit-search-limit", "Maximal number of expressions to be generated in an implicit search", 50000)
@@ -310,7 +312,6 @@ private sealed trait YSettings:
310312
val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
311313
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ysafe-init", "Ensure safe initialization of objects")
312314
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
313-
val YscalaRelease: Setting[String] = ChoiceSetting("-Yscala-release", "release", "Emit TASTy files that can be consumed by specified version of the compiler. The compilation will fail if for any reason valid TASTy cannot be produced (e.g. the code contains references to some parts of the standard library API that are missing in the older stdlib or uses language features unexpressible in the older version of TASTy format)", ScalaSettings.supportedScalaReleaseVersions, "", aliases = List("--Yscala-release"))
314315

315316
/** Area-specific debug output */
316317
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

compiler/src/dotty/tools/dotc/core/Contexts.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,15 @@ object Contexts {
486486
fresh.setImportInfo(ImportInfo(sym, imp.selectors, imp.expr))
487487

488488
def scalaRelease: ScalaRelease =
489-
val releaseName = base.settings.YscalaRelease.value
489+
val releaseName = base.settings.scalaOutputVersion.value
490490
if releaseName.nonEmpty then ScalaRelease.parse(releaseName).get else ScalaRelease.latest
491491

492492
def tastyVersion: TastyVersion =
493493
import math.Ordered.orderingToOrdered
494494
val latestRelease = ScalaRelease.latest
495495
val specifiedRelease = scalaRelease
496496
if specifiedRelease < latestRelease then
497-
// This is needed to make -Yscala-release a no-op when set to the latest release for unstable versions of the compiler
497+
// This is needed to make -scala-output-version a no-op when set to the latest release for unstable versions of the compiler
498498
// (which might have the tasty format version numbers set to higher values before they're decreased during a release)
499499
TastyVersion.fromStableScalaRelease(specifiedRelease.majorVersion, specifiedRelease.minorVersion)
500500
else

compiler/test/dotty/tools/dotc/classpath/MultiReleaseJarTest.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
3838
given ctx: Context = initCtx.fresh
3939
ctx.settings.usejavacp.update(true)
4040
ctx.settings.classpath.update(jarPath.toAbsolutePath.toString)
41-
ctx.settings.release.update(release)
41+
ctx.settings.javaOutputVersion.update(release)
4242
ctx.initialize()
4343
val classNames = Seq("p1.Foo", "p2.Bar")
4444
val classFiles = classNames.flatMap(ctx.platform.classPath.findClassFile)
@@ -75,7 +75,7 @@ class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
7575
def classExists(className: String, release: String): Boolean = {
7676
given ctx: Context = initCtx.fresh
7777
ctx.settings.usejavacp.update(true)
78-
ctx.settings.release.update(release)
78+
ctx.settings.javaOutputVersion.update(release)
7979
ctx.initialize()
8080
val classFile = ctx.platform.classPath.findClassFile(className)
8181
classFile.isDefined

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
215215

216216
case testSource @ SeparateCompilationSource(_, dir, flags, outDir) =>
217217
testSource.compilationGroups.map { (group, files) =>
218-
val flags1 = if group.release.isEmpty then flags else flags.and("-Yscala-release", group.release)
218+
val flags1 = if group.release.isEmpty then flags else flags.and("-scala-output-version", group.release)
219219
if group.compiler.isEmpty then
220220
compile(files, flags1, suppressErrors, outDir)
221221
else

docs/docs/contributing/testing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ When the sources of a test consist of multiple source files places in a single d
134134
There are also other suffixes indicating how some particular files are compiled:
135135
* `_c${compilerVersion}` - compile a file with a specific version of the compiler instead of the one developed on the current branch
136136
(e.g. `Foo_c3.0.2.scala`)
137-
* `_r${release}` - compile a file with a given value of `-Yscala-release` flag (e.g. `Foo_r3.0.scala`)
137+
* `_r${release}` - compile a file with a given value of `-scala-output-version` flag (e.g. `Foo_r3.0.scala`)
138138

139139
Different suffixes can be mixed together (their order is not important although consistency is advised), e.g. `Foo_1_r3.0`, `Bar_2_c3.0.2`.
140140

docs/docs/reference/language-versions/binary-compatibility.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ TASTy version number has the format of `<major_version>.<minor_version>-<experim
1414
Being able to bump the compiler version in a project without having to wait for all of its dependencies to do the same is already a big leap forward when compared to Scala 2. However, we might still try to do better, especially from the perspective of authors of libraries.
1515
If you maintain a library and you would like it to be usable as a dependency for all Scala 3 projects, you would have to always emit TASTy in a version that would be readble by everyone, which would normally mean getting stuck at 3.0.x forever.
1616

17-
To solve this problem a new experimental compiler flag `-Yscala-release <release-version>` (available since 3.1.2-RC1) has been added. Setting this flag makes the compiler produce TASTy files that should be possible to use by all Scala 3 compilers in version `<release-version>` or newer (this flag was inspired by how `-release` works for specifying the target version of JDK). More specifically this enforces emitting TASTy files in an older format ensuring that:
18-
* the code contains no references to parts of the standard library which were added to the API after `<release-version>` and would crash at runtime when a program is executed with the older version of the standard library on the classpath
19-
* no dependency found on the classpath during compilation (except for the standard library itself) contains TASTy files produced by a compiler newer than `<release-version>` (otherwise they could potentially leak such disallowed references to the standard library).
17+
To solve this problem a new experimental compiler flag `-scala-output-version <version>` (available since 3.1.2) has been added. Setting this flag makes the compiler produce TASTy files that should be possible to use by all Scala 3 compilers in version `<version>` or newer. This flag was inspired by how `-java-output-version` (formerly `-release`) works for specifying the target version of JDK. More specifically this enforces emitting TASTy files in an older format ensuring that:
18+
* the code contains no references to parts of the standard library which were added to the API after `<version>` and would crash at runtime when a program is executed with the older version of the standard library on the classpath
19+
* no dependency found on the classpath during compilation (except for the standard library itself) contains TASTy files produced by a compiler newer than `<version>` (otherwise they could potentially leak such disallowed references to the standard library).
2020

2121
If any of the checks above is not fulfilled or for any other reason older TASTy cannot be emitted (e.g. the code uses some new language features which cannot be expressed the the older format) the entire compilation fails (with errors reported for each of such issues).
2222

2323
As this feature is experimental it does not have any special support in build tools yet (at least not in sbt 1.6.1 or lower).
24-
E.g. when a project gets compiled with Scala compiler `3.x1.y1` and `-Yscala-release 3.x2` option and then published using sbt
24+
E.g. when a project gets compiled with Scala compiler `3.x1.y1` and `-scala-output-version 3.x2` option and then published using sbt
2525
then the standard library in version `3.x1.y1` gets added to the project's dependencies instead of `3.x2.y2`.
2626
When the dependencies are added to the classpath during compilation with Scala `3.x2.y2` the compiler will crash while trying to read TASTy files in the newer format.
2727
A currently known workaround is to modify the build definition of the dependent project by explicitly overriding the version of Scala standard library in dependencies, e.g.
@@ -33,4 +33,4 @@ dependencyOverrides ++= Seq(
3333
)
3434
```
3535

36-
The behaviour of `-Yscala-release` flag might still change in the future, especially it's not guaranteed that every new version of the compiler would be able to generate TASTy in all older formats going back to the one produced by `3.0.x` compiler.
36+
The behaviour of `-scala-output-version` flag might still change in the future, especially it's not guaranteed that every new version of the compiler would be able to generate TASTy in all older formats going back to the one produced by `3.0.x` compiler.

0 commit comments

Comments
 (0)