Skip to content

Commit b368c22

Browse files
som-snyttlrytz
authored andcommitted
Align compiler options to VWXY scheme
1 parent d81d8d9 commit b368c22

File tree

8 files changed

+135
-87
lines changed

8 files changed

+135
-87
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import Settings._
77
import core.Contexts._
88
import Properties._
99

10-
import scala.collection.JavaConverters._
10+
import scala.PartialFunction.cond
11+
import scala.collection.JavaConverters._
1112

1213
trait CliCommand:
1314

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

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

125126
protected def isStandard(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
126-
!isAdvanced(s) && !isPrivate(s)
127+
!isVerbose(s) && !isWarning(s) && !isAdvanced(s) && !isPrivate(s) || s.name == "-Werror" || s.name == "-Wconf"
128+
protected def isVerbose(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
129+
s.name.startsWith("-V") && s.name != "-V"
130+
protected def isWarning(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
131+
s.name.startsWith("-W") && s.name != "-W" || s.name == "-Xlint"
127132
protected def isAdvanced(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
128133
s.name.startsWith("-X") && s.name != "-X"
129134
protected def isPrivate(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
130135
s.name.startsWith("-Y") && s.name != "-Y"
136+
protected def shortHelp(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): String =
137+
s.description.linesIterator.next()
138+
protected def isHelping(s: Setting[?])(using settings: ConcreteSettings)(using SettingsState): Boolean =
139+
cond(s.value) {
140+
case ss: List[?] if s.isMultivalue => ss.contains("help")
141+
case s: String => "help" == s
142+
}
131143

132144
/** Messages explaining usage and options */
133145
protected def usageMessage(using settings: ConcreteSettings)(using SettingsState) =
134146
createUsageMsg("where possible standard", shouldExplain = false, isStandard)
147+
protected def vusageMessage(using settings: ConcreteSettings)(using SettingsState) =
148+
createUsageMsg("Possible verbose", shouldExplain = true, isVerbose)
149+
protected def wusageMessage(using settings: ConcreteSettings)(using SettingsState) =
150+
createUsageMsg("Possible warning", shouldExplain = true, isWarning)
135151
protected def xusageMessage(using settings: ConcreteSettings)(using SettingsState) =
136152
createUsageMsg("Possible advanced", shouldExplain = true, isAdvanced)
137153
protected def yusageMessage(using settings: ConcreteSettings)(using SettingsState) =

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ abstract class CompilerCommand extends CliCommand:
1414

1515
final def helpMsg(using settings: ScalaSettings)(using SettingsState, Context): String =
1616
if (settings.help.value) usageMessage
17+
else if (settings.Vhelp.value) vusageMessage
18+
else if (settings.Whelp.value) wusageMessage
1719
else if (settings.Xhelp.value) xusageMessage
1820
else if (settings.Yhelp.value) yusageMessage
1921
else if (settings.showPlugins.value) ctx.base.pluginDescriptions
2022
else if (settings.XshowPhases.value) phasesMessage
2123
else ""
2224

2325
final def isHelpFlag(using settings: ScalaSettings)(using SettingsState): Boolean =
24-
Set(settings.help, settings.Xhelp, settings.Yhelp, settings.showPlugins, settings.XshowPhases) exists (_.value)
26+
import settings._
27+
val flags = Set(help, Vhelp, Whelp, Xhelp, Yhelp, showPlugins, XshowPhases)
28+
flags.exists(_.value) || allSettings.exists(isHelping)

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

Lines changed: 98 additions & 72 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import language.existentials
1111
import reflect.ClassTag
1212
import scala.util.{Success, Failure}
1313

14-
object Settings {
14+
object Settings:
1515

1616
val BooleanTag: ClassTag[Boolean] = ClassTag.Boolean
1717
val IntTag: ClassTag[Int] = ClassTag.Int
@@ -166,13 +166,11 @@ object Settings {
166166
}
167167
}
168168

169-
object Setting {
170-
extension [T](setting: Setting[T]) {
169+
object Setting:
170+
extension [T](setting: Setting[T])
171171
def value(using Context): T = setting.valueIn(ctx.settingsState)
172172
def update(x: T)(using Context): SettingsState = setting.updateIn(ctx.settingsState, x)
173173
def isDefault(using Context): Boolean = setting.isDefaultIn(ctx.settingsState)
174-
}
175-
}
176174

177175
class SettingGroup {
178176

@@ -279,4 +277,4 @@ object Settings {
279277
def OptionSetting[T: ClassTag](name: String, descr: String, aliases: List[String] = Nil): Setting[Option[T]] =
280278
publish(Setting(name, descr, None, propertyClass = Some(implicitly[ClassTag[T]].runtimeClass), aliases = aliases))
281279
}
282-
}
280+
end Settings

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ object Parsers {
132132
* and update lastErrorOffset.
133133
*/
134134
def syntaxError(msg: Message, offset: Int = in.offset): Unit =
135-
if (offset > lastErrorOffset) {
136-
val length = if (offset == in.offset && in.name != null) in.name.show.length else 0
135+
if offset > lastErrorOffset then
136+
val length = if offset == in.offset && in.name != null then in.name.show.length else 0
137137
syntaxError(msg, Span(offset, offset + length))
138138
lastErrorOffset = in.offset
139-
}
139+
end if
140140

141141
/** Unconditionally issue an error at given span, without
142142
* updating lastErrorOffset.

compiler/src/dotty/tools/dotc/reporting/Message.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ object Message {
1212
* not yet been ported to the new scheme. Comment out this `implicit def` to
1313
* see where old errors still exist
1414
*/
15-
implicit def toNoExplanation(str: => String): Message =
16-
NoExplanation(str)
15+
implicit def toNoExplanation(str: => String): Message = NoExplanation(str)
1716
}
1817

1918
/** A `Message` contains all semantic information necessary to easily

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class CompilationTests {
193193
compileFile("tests/run-custom-args/fors.scala", defaultOptions.and("-source", "future")),
194194
compileFile("tests/run-custom-args/no-useless-forwarders.scala", defaultOptions and "-Xmixin-force-forwarders:false"),
195195
compileFile("tests/run-custom-args/defaults-serizaliable-no-forwarders.scala", defaultOptions and "-Xmixin-force-forwarders:false"),
196+
compileFile("tests/run-custom-args/help.scala", defaultOptions.and("-help", "-V", "-W", "-X", "-Y")),
196197
compileFilesInDir("tests/run-custom-args/erased", defaultOptions.and("-language:experimental.erasedDefinitions")),
197198
compileFilesInDir("tests/run-deep-subtype", allowDeepSubtypes),
198199
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init"))

tests/run-custom-args/help.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
// dummy source for exercising information flags
3+
//
4+
class Help

0 commit comments

Comments
 (0)