Skip to content

Commit d9d7658

Browse files
committed
Use jvm 8 compatible API, refactor deprecation, schedule YoutputOnlyTasty for removal
1 parent 9af7daa commit d9d7658

File tree

5 files changed

+42
-32
lines changed

5 files changed

+42
-32
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ object projects:
503503
project = "verify",
504504
sbtTestCommand = "verifyJVM/test",
505505
sbtDocCommand = "verifyJVM/doc",
506-
scalacOptions = SbtCommunityProject.scalacOptions.filter(flag != "-Xcheck-macros" && flag != "-Xlint") // TODO enable -Xcheck-macros, wrong flag -Xlint
506+
scalacOptions = SbtCommunityProject.scalacOptions.filter(flag => flag != "-Xcheck-macros" && flag != "-Xlint") // TODO enable -Xcheck-macros, wrong flag -Xlint
507507
)
508508

509509
lazy val discipline = SbtCommunityProject(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ object PostProcessorFrontendAccess {
127127
override val jarCompressionLevel: Int = s.XjarCompressionLevel.value
128128
override val backendParallelism: Int = s.YbackendParallelism.value
129129
override val backendMaxWorkerQueue: Option[Int] = s.YbackendWorkerQueue.valueSetByUser
130+
131+
@annotation.nowarn("cat=deprecation")
130132
override val outputOnlyTasty: Boolean = s.YoutputOnlyTasty.value
131133
}
132134

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private sealed trait XSettings:
371371
ChoiceWithHelp("type-parameter-shadow", "Warn when a type parameter shadows a type already in the scope"),
372372
),
373373
default = Nil,
374-
deprecation = Some(Deprecation("Use -Wshadow to enable shadowing lints.", "-Wshadow")),
374+
deprecation = Deprecation.renamed("-Wshadow"),
375375
)
376376

377377
end XSettings
@@ -435,7 +435,6 @@ private sealed trait YSettings:
435435
val YnoExperimental: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-experimental", "Disable experimental language features by default in NIGHTLY/SNAPSHOT versions of the compiler.")
436436
val YlegacyLazyVals: Setting[Boolean] = BooleanSetting(ForkSetting, "Ylegacy-lazy-vals", "Use legacy (pre 3.3.0) implementation of lazy vals.")
437437
val YcompileScala2Library: Setting[Boolean] = BooleanSetting(ForkSetting, "Ycompile-scala2-library", "Used when compiling the Scala 2 standard library.")
438-
val YoutputOnlyTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Youtput-only-tasty", "Used to only generate the TASTy file without the classfiles")
439438
val YprofileEnabled: Setting[Boolean] = BooleanSetting(ForkSetting, "Yprofile-enabled", "Enable profiling.")
440439
val YprofileDestination: Setting[String] = StringSetting(ForkSetting, "Yprofile-destination", "file", "Where to send profiling output - specify a file, default is to the console.", "")
441440
//.withPostSetHook( _ => YprofileEnabled.value = true )
@@ -469,36 +468,40 @@ private sealed trait YSettings:
469468

470469
// Deprecated: lifted from -Y to -X
471470
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
472-
val YtermConflict: Setting[String] = ChoiceSetting(ForkSetting, "Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error", deprecation = Some(Deprecation("Use -Xresolve-term-conflict instead.", "-Xresolve-term-conflict")))
471+
val YtermConflict: Setting[String] = ChoiceSetting(ForkSetting, "Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error", deprecation = Deprecation.renamed("-Xresolve-term-conflict"))
473472
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
474-
val YnoGenericSig: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-generic-signatures", "Suppress generation of generic signatures for Java.", deprecation = Some(Deprecation("Use -Xno-generic-signatures instead.", "-Xno-generic-signatures")))
473+
val YnoGenericSig: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-generic-signatures", "Suppress generation of generic signatures for Java.", deprecation = Deprecation.renamed("-Xno-generic-signatures"))
475474
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
476-
val Ydumpclasses: Setting[String] = StringSetting(ForkSetting, "Ydump-classes", "dir", "Dump the generated bytecode to .class files (useful for reflective compilation that utilizes in-memory classloaders).", default = "", deprecation = Some(Deprecation("Use -Xdump-classes instead.", "-Xdump-classes")))
475+
val Ydumpclasses: Setting[String] = StringSetting(ForkSetting, "Ydump-classes", "dir", "Dump the generated bytecode to .class files (useful for reflective compilation that utilizes in-memory classloaders).", default = "", deprecation = Deprecation.renamed("-Xdump-classes"))
477476
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
478-
val YjarCompressionLevel: Setting[Int] = IntChoiceSetting(ForkSetting, "Yjar-compression-level", "compression level to use when writing jar files", Deflater.DEFAULT_COMPRESSION to Deflater.BEST_COMPRESSION, Deflater.DEFAULT_COMPRESSION, deprecation = Some(Deprecation("Use -Xjar-compression-level instead.", "-Xjar-compression-level")))
477+
val YjarCompressionLevel: Setting[Int] = IntChoiceSetting(ForkSetting, "Yjar-compression-level", "compression level to use when writing jar files", Deflater.DEFAULT_COMPRESSION to Deflater.BEST_COMPRESSION, Deflater.DEFAULT_COMPRESSION, deprecation = Deprecation.renamed("-Xjar-compression-level"))
479478
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
480-
val YkindProjector: Setting[String] = ChoiceSetting(ForkSetting, "Ykind-projector", "[underscores, enable, disable]", "Allow `*` as type lambda placeholder to be compatible with kind projector. When invoked as -Ykind-projector:underscores will repurpose `_` to be a type parameter placeholder, this will disable usage of underscore as a wildcard.", List("disable", "", "underscores"), "disable", legacyArgs = true, deprecation = Some(Deprecation("Use -Xkind-projector instead.", "-Xkind-projector")))
479+
val YkindProjector: Setting[String] = ChoiceSetting(ForkSetting, "Ykind-projector", "[underscores, enable, disable]", "Allow `*` as type lambda placeholder to be compatible with kind projector. When invoked as -Ykind-projector:underscores will repurpose `_` to be a type parameter placeholder, this will disable usage of underscore as a wildcard.", List("disable", "", "underscores"), "disable", legacyArgs = true, deprecation = Deprecation.renamed("-Xkind-projector"))
481480
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
482-
val YdropComments: Setting[Boolean] = BooleanSetting(ForkSetting, "Ydrop-docs", "Drop documentation when scanning source files.", aliases = List("-Ydrop-comments"), deprecation = Some(Deprecation("Use -Xdrop-docs instead.", "-Xdrop-docs")))
481+
val YdropComments: Setting[Boolean] = BooleanSetting(ForkSetting, "Ydrop-docs", "Drop documentation when scanning source files.", aliases = List("-Ydrop-comments"), deprecation = Deprecation.renamed("-Xdrop-docs"))
483482
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
484-
val YcookComments: Setting[Boolean] = BooleanSetting(ForkSetting, "Ycook-docs", "Cook the documentation (type check `@usecase`, etc.)", aliases = List("-Ycook-comments"), deprecation = Some(Deprecation("Use -Xcook-docs instead.", "-Xcook-docs")))
483+
val YcookComments: Setting[Boolean] = BooleanSetting(ForkSetting, "Ycook-docs", "Cook the documentation (type check `@usecase`, etc.)", aliases = List("-Ycook-comments"), deprecation = Deprecation.renamed("-Xcook-docs"))
485484
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
486-
val YreadComments: Setting[Boolean] = BooleanSetting(ForkSetting, "Yread-docs", "Read documentation from tasty.", deprecation = Some(Deprecation("Use -Xread-docs instead.", "-Xread-docs")))
485+
val YreadComments: Setting[Boolean] = BooleanSetting(ForkSetting, "Yread-docs", "Read documentation from tasty.", deprecation = Deprecation.renamed("-Xread-docs"))
487486
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
488-
val YnoDecodeStacktraces: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-decode-stacktraces", "Show raw StackOverflow stacktraces, instead of decoding them into triggering operations.", deprecation = Some(Deprecation("Use -Xno-decode-stacktraces instead.", "-Xno-decode-stacktraces")))
487+
val YnoDecodeStacktraces: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-decode-stacktraces", "Show raw StackOverflow stacktraces, instead of decoding them into triggering operations.", deprecation = Deprecation.renamed("-Xno-decode-stacktraces"))
489488
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
490-
val YnoEnrichErrorMessages: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-enrich-error-messages", "Show raw error messages, instead of enriching them with contextual information.", deprecation = Some(Deprecation("Use -Xno-enrich-error-messages instead.", "-Xno-enrich-error-messages")))
489+
val YnoEnrichErrorMessages: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-enrich-error-messages", "Show raw error messages, instead of enriching them with contextual information.", deprecation = Deprecation.renamed("-Xno-enrich-error-messages"))
491490
@deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0")
492-
val YdebugMacros: Setting[Boolean] = BooleanSetting(ForkSetting, "Ydebug-macros", "Show debug info when quote pattern match fails", deprecation = Some(Deprecation("Use -Xdebug-macros instead.", "-Xdebug-macros")))
491+
val YdebugMacros: Setting[Boolean] = BooleanSetting(ForkSetting, "Ydebug-macros", "Show debug info when quote pattern match fails", deprecation = Deprecation.renamed("-Xdebug-macros"))
493492

494493
// @deprecated(message = "Lifted to -X, Scheduled for removal in 3.8.0", since = "3.7.0")
495-
// val YjavaTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Ypickle-java"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xjava-tasty instead.", "-Xjava-tasty")))
494+
// val YjavaTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Ypickle-java"), preferPrevious = true, deprecation = Deprecation.lifted("-Xjava-tasty"))
496495
// @deprecated(message = "Lifted to -X, Scheduled for removal in 3.8.0", since = "3.7.0")
497-
// val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting(ForkSetting, "Yearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Ypickle-write"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xearly-tasty-output instead.", "-Xearly-tasty-output")))
496+
// val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting(ForkSetting, "Yearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Ypickle-write"), preferPrevious = true, deprecation = Deprecation.lifted("-Xearly-tasty-output"))
498497
// @deprecated(message = "Lifted to -X, Scheduled for removal in 3.8.0", since = "3.7.0")
499-
// val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.", deprecation = Some(Deprecation("Use -Xallow-outline-from-tasty instead.", "-Xallow-outline-from-tasty")))
498+
// val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.", deprecation = Deprecation.lifted("-Xallow-outline-from-tasty"))
500499

501500
// Deprecated: lifted from -Y to -W
502501
@deprecated(message = "Lifted to -W, Scheduled for removal in 3.6.0", since = "3.5.0")
503-
val YcheckInit: Setting[Boolean] = BooleanSetting(ForkSetting, "Ysafe-init", "Ensure safe initialization of objects.", deprecation = Some(Deprecation("Use -Wsafe-init instead.", "-Wsafe-init")))
502+
val YcheckInit: Setting[Boolean] = BooleanSetting(ForkSetting, "Ysafe-init", "Ensure safe initialization of objects.", deprecation = Deprecation.renamed("-Wsafe-init"))
503+
504+
// Deprecated: Scheduled for removal
505+
@deprecated(message = "Scheduled for removal in 3.6.0", since = "3.5.0")
506+
val YoutputOnlyTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Youtput-only-tasty", "Used to only generate the TASTy file without the classfiles", deprecation = Deprecation.removed("3.6.0"))
504507
end YSettings

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ object Settings:
6161
def warn(msg: String): Settings.ArgsSummary =
6262
ArgsSummary(sstate, arguments.tail, errors, warnings :+ msg)
6363

64-
def deprecated(extraArg: String, msg: String): Settings.ArgsSummary =
65-
ArgsSummary(sstate, extraArg +: arguments.tail, errors, warnings :+ msg)
64+
def deprecated(msg: String, extraArgs: List[String] = Nil): Settings.ArgsSummary =
65+
ArgsSummary(sstate, extraArgs ++ arguments.tail, errors, warnings :+ msg)
6666

6767
@unshared
6868
val settingCharacters = "[a-zA-Z0-9_\\-]*".r
@@ -129,11 +129,12 @@ object Settings:
129129
*/
130130
def update(getValue: => Any, argStringValue: String, args: List[String]): ArgsSummary =
131131
deprecation match
132-
case Some(Deprecation(msg, replacedBy)) =>
132+
case Some(Deprecation(msg, Some(replacedBy))) =>
133133
val deprecatedMsg = s"Option $name is deprecated: $msg"
134-
if argStringValue.isEmpty then state.deprecated(replacedBy, deprecatedMsg)
135-
else state.deprecated(s"$replacedBy:$argStringValue", deprecatedMsg)
134+
if argStringValue.isEmpty then state.deprecated(deprecatedMsg, List(replacedBy))
135+
else state.deprecated(deprecatedMsg, List(s"$replacedBy:$argStringValue"))
136136

137+
case Some(Deprecation(msg, _)) => state.deprecated(msg)
137138
case None =>
138139
val value = getValue
139140
var dangers = warnings
@@ -262,11 +263,15 @@ object Settings:
262263
* @param msg deprecation message that will be displayed in following format: s"Option $name is deprecated: $msg"
263264
* @param replacedBy option that is substituting current option
264265
*/
265-
case class Deprecation(
266+
case class Deprecation private(
266267
msg: String,
267-
replacedBy: String,
268+
replacedBy: Option[String] = None,
268269
)
269270

271+
object Deprecation:
272+
def renamed(replacement: String) = Some(Deprecation(s"Use $replacement instead.", Some(replacement)))
273+
def removed(removedVersion: String) = Some(Deprecation(s"Scheduled for removal in s$removedVersion", None))
274+
270275
object Setting:
271276
extension [T](setting: Setting[T])
272277
def value(using Context): T = setting.valueIn(ctx.settingsState)

compiler/test/dotty/tools/dotc/SettingsTests.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,28 +232,28 @@ class SettingsTests {
232232

233233
import Settings._
234234

235-
Files.writeString(file1, "test1")
236-
Files.writeString(file2, "test2")
235+
Files.write(file1, "test1".getBytes())
236+
Files.write(file2, "test2".getBytes())
237237

238-
val file1StateBefore = Files.readString(file1)
239-
val file2StateBefore = Files.readString(file2)
238+
val file1StateBefore = String(Files.readAllBytes(file1))
239+
val file2StateBefore = String(Files.readAllBytes(file2))
240240

241241
val creationTime = Files.getLastModifiedTime(file1)
242242
val args = List(s"-testOutput:${file1.toString}", s"-testOutput:${file2.toString}")
243243
val summary = processArguments(args, processAll = true)
244244

245245
// The output is a new filesystem without information of original path
246246
// We can't check the `testOutput.value` as in other tests.
247-
assertNotEquals(file1StateBefore, Files.readString(file1))
248-
assertEquals(file2StateBefore, Files.readString(file2))
247+
assertNotEquals(file1StateBefore, String(Files.readAllBytes(file1)))
248+
assertEquals(file2StateBefore, String(Files.readAllBytes(file2)))
249249

250250
}(Files.deleteIfExists(_), Files.deleteIfExists(_))
251251

252252
@Test def `Output side effect is not present when setting is deprecated`: Unit =
253253
val result = Using.resource(Files.createTempFile("myfile", ".jar").nn){ file =>
254254
object Settings extends SettingGroup:
255255
val defaultDir = new PlainDirectory(Directory("."))
256-
val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir, preferPrevious = true, deprecation = Some(Deprecation("deprecated", "XtestOutput")))
256+
val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir, preferPrevious = true, deprecation = Deprecation.renamed("XtestOutput"))
257257

258258
import Settings._
259259

0 commit comments

Comments
 (0)