Skip to content

Commit

Permalink
Add help to choices
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Apr 23, 2024
1 parent c460526 commit 825598c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
34 changes: 26 additions & 8 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SourceVersion.*
import reporting.Message
import NameKinds.QualifiedName
import Annotations.ExperimentalAnnotation
import Settings.Setting.ChoiceWithHelp

object Feature:

Expand All @@ -35,14 +36,31 @@ object Feature:
val into = experimental("into")

val values = List(
nme.help,
nme.noAutoTupling, nme.dynamics, nme.unsafeNulls, nme.postfixOps, nme.strictEquality,
nme.implicitConversions, nme.adhocExtensions,
namedTypeArguments, genericNumberLiterals, scala2macros,
dependent, erasedDefinitions, symbolLiterals, fewerBraces, saferExceptions,
clauseInterleaving, pureFunctions, captureChecking, into
(nme.help, "Display all available features"),
(nme.noAutoTupling, "Disable automatic tupling"),
(nme.dynamics, "Allow direct or indirect subclasses of scala.Dynamic"),
(nme.unsafeNulls, "Enable unsafe nulls for explicit nulls"),
(nme.postfixOps, "Allow postfix operator notation"),
(nme.strictEquality, "Enable strict equality (=== and !==)"),
(nme.implicitConversions, "Allow implicit conversions without warnings"),
(nme.adhocExtensions, "Allow ad-hoc extension methods"),
(namedTypeArguments, "Allow named type arguments"),
(genericNumberLiterals, "Allow generic number literals"),
(scala2macros, "Allow Scala 2 macros"),
(dependent, "Allow dependent method types"),
(erasedDefinitions, "Allow erased definitions"),
(symbolLiterals, "Allow symbol literals"),
(fewerBraces, "Allow fewer braces"),
(saferExceptions, "Enable safer exceptions"),
(clauseInterleaving, "Enable clause interleaving"),
(pureFunctions, "Enable pure functions"),
(captureChecking, "Enable experimental capture checking"),
(into, "Allow into clauses in pattern matches")
)

private def enabledLanguageFeaturesBySetting(using Context): List[String] =
ctx.settings.language.value.asInstanceOf

/** Is `feature` enabled by by a command-line setting? The enabling setting is
*
* -language:<prefix>feature
Expand All @@ -51,7 +69,7 @@ object Feature:
* but subtracting the prefix `scala.language.` at the front.
*/
def enabledBySetting(feature: TermName)(using Context): Boolean =
ctx.base.settings.language.value.contains(feature.toString)
enabledLanguageFeaturesBySetting.contains(feature.toString)

/** Is `feature` enabled by by an import? This is the case if the feature
* is imported by a named import
Expand Down Expand Up @@ -172,7 +190,7 @@ object Feature:

/** Check that experimental compiler options are only set for snapshot or nightly compiler versions. */
def checkExperimentalSettings(using Context): Unit =
for setting <- ctx.settings.language.value
for setting <- enabledLanguageFeaturesBySetting
if setting.startsWith("experimental.") && setting != "experimental.macros"
do checkExperimentalFeature(s"feature $setting", NoSourcePosition)

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ trait CommonScalaSettings:
val explainTypes: Setting[Boolean] = BooleanSetting(RootSetting, "explain-types", "Explain type errors in more detail (deprecated, use -explain instead).", aliases = List("--explain-types", "-explaintypes"))
val explainCyclic: Setting[Boolean] = BooleanSetting(RootSetting, "explain-cyclic", "Explain cyclic reference errors in more detail.", aliases = List("--explain-cyclic"))
val unchecked: Setting[Boolean] = BooleanSetting(RootSetting, "unchecked", "Enable additional warnings where generated code depends on assumptions.", initialValue = true, aliases = List("--unchecked"))
val language: Setting[List[String]] = MultiChoiceSetting(RootSetting, "language", "feature", "Enable one or more language features.", choices = ScalaSettingsProperties.supportedLanguageFeatures, aliases = List("--language"))
val language: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(RootSetting, "language", "feature", "Enable one or more language features.", choices = ScalaSettingsProperties.supportedLanguageFeatures, default = Nil, aliases = List("--language"))
val experimental: Setting[Boolean] = BooleanSetting(RootSetting, "experimental", "Annotate all top-level definitions with @experimental. This enables the use of experimental features anywhere in the project.")

/* Coverage settings */
Expand Down Expand Up @@ -448,3 +448,4 @@ private sealed trait YSettings:
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)
val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.")
end YSettings

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dotty.tools.dotc
package config

import Settings.Setting.ChoiceWithHelp
import dotty.tools.backend.jvm.BackendUtils.classfileVersionMap
import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory, NoAbstractFile}
import scala.language.unsafeNulls
Expand All @@ -26,8 +27,8 @@ object ScalaSettingsProperties:
def supportedSourceVersions: List[String] =
SourceVersion.values.toList.map(_.toString)

def supportedLanguageFeatures: List[String] =
Feature.values.toList.map(_.toString)
def supportedLanguageFeatures: List[ChoiceWithHelp[String]] =
Feature.values.map((n, d) => ChoiceWithHelp(n.toString, d))

def defaultClasspath: String = sys.env.getOrElse("CLASSPATH", ".")

Expand Down

0 comments on commit 825598c

Please sign in to comment.