Skip to content

Align compiler options to VWXY scheme #12751

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

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions community-build/src/scala/dotty/communitybuild/projects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ object projects:
lazy val stdLib213 = SbtCommunityProject(
project = "stdLib213",
extraSbtArgs = List("-Dscala.build.compileWithDotty=true"),
sbtTestCommand = """library/compile""",
sbtPublishCommand = """set library/Compile/packageDoc/publishArtifact := false; library/publishLocal""",
sbtTestCommand = """set Global / fatalWarnings := false; library/compile""",
sbtPublishCommand = """set Global / fatalWarnings := false; set library/Compile/packageDoc/publishArtifact := false; library/publishLocal""",
// sbtDocCommand = "library/doc" // Does no compile? No idea :/
)

Expand Down
22 changes: 19 additions & 3 deletions compiler/src/dotty/tools/dotc/config/CliCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import Settings._
import core.Contexts._
import Properties._

import scala.collection.JavaConverters._
import scala.PartialFunction.cond
import scala.collection.JavaConverters._

trait CliCommand:

Expand Down Expand Up @@ -107,7 +108,7 @@ trait CliCommand:
// For now, skip the default values that do not make sense for the end user.
// For example 'false' for the version command.
""
s"${formatName(s.name)} ${formatDescription(s.description)}${formatSetting("Default", defaultValue)}${formatSetting("Choices", s.legalChoices)}"
s"${formatName(s.name)} ${formatDescription(shortHelp(s))}${formatSetting("Default", defaultValue)}${formatSetting("Choices", s.legalChoices)}"
ss.map(helpStr).mkString("", "\n", s"\n${formatName("@<file>")} ${formatDescription("A text file containing compiler arguments (options and source files).")}\n")
end availableOptionsMsg

Expand All @@ -123,15 +124,30 @@ trait CliCommand:
prefix + "\n" + availableOptionsMsg(cond)

protected def isStandard(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
!isAdvanced(s) && !isPrivate(s)
!isVerbose(s) && !isWarning(s) && !isAdvanced(s) && !isPrivate(s) || s.name == "-Werror" || s.name == "-Wconf"
protected def isVerbose(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
s.name.startsWith("-V") && s.name != "-V"
protected def isWarning(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
s.name.startsWith("-W") && s.name != "-W" || s.name == "-Xlint"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one option of a kind -V and -W each added in this PR. Is it worth creating these two categories? What's the motivation?

Copy link
Contributor

@som-snytt som-snytt Jun 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets a thousand flowers bloom and still be manageable. https://github.com/lampepfl/dotty/issues/12785

If I want more output merely (not change in behavior), -V is more succinct than checking -X and -Y (which become a long list eventually). Everyone needs -Vprint at some point, not just compiler coders.

(But here, I just wanted to say -Wconf.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another motivation is alignment with Scala 2.

protected def isAdvanced(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
s.name.startsWith("-X") && s.name != "-X"
protected def isPrivate(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
s.name.startsWith("-Y") && s.name != "-Y"
protected def shortHelp(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): String =
s.description.linesIterator.next()
protected def isHelping(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
cond(s.value) {
case ss: List[?] if s.isMultivalue => ss.contains("help")
case s: String => "help" == s
}

/** Messages explaining usage and options */
protected def usageMessage(using settings: ConcreteSettings)(using SettingsState) =
createUsageMsg("where possible standard", shouldExplain = false, isStandard)
protected def vusageMessage(using settings: ConcreteSettings)(using SettingsState) =
createUsageMsg("Possible verbose", shouldExplain = true, isVerbose)
protected def wusageMessage(using settings: ConcreteSettings)(using SettingsState) =
createUsageMsg("Possible warning", shouldExplain = true, isWarning)
protected def xusageMessage(using settings: ConcreteSettings)(using SettingsState) =
createUsageMsg("Possible advanced", shouldExplain = true, isAdvanced)
protected def yusageMessage(using settings: ConcreteSettings)(using SettingsState) =
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/config/CompilerCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ abstract class CompilerCommand extends CliCommand:

final def helpMsg(using settings: ScalaSettings)(using SettingsState, Context): String =
if (settings.help.value) usageMessage
else if (settings.Vhelp.value) vusageMessage
else if (settings.Whelp.value) wusageMessage
else if (settings.Xhelp.value) xusageMessage
else if (settings.Yhelp.value) yusageMessage
else if (settings.showPlugins.value) ctx.base.pluginDescriptions
else if (settings.XshowPhases.value) phasesMessage
else ""

final def isHelpFlag(using settings: ScalaSettings)(using SettingsState): Boolean =
Set(settings.help, settings.Xhelp, settings.Yhelp, settings.showPlugins, settings.XshowPhases) exists (_.value)
import settings._
val flags = Set(help, Vhelp, Whelp, Xhelp, Yhelp, showPlugins, XshowPhases)
flags.exists(_.value) || allSettings.exists(isHelping)
Loading