Skip to content

Commit a9e51dd

Browse files
committed
Merge pull request scala#901 from paulp/topic/no-aesthetics
Removed AestheticSettings.
2 parents e46ee69 + d9c9e58 commit a9e51dd

File tree

18 files changed

+74
-140
lines changed

18 files changed

+74
-140
lines changed

src/compiler/scala/reflect/reify/Phases.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait Phases extends Reshape
2626
if (reifyDebug) println("[reshape phase]")
2727
tree = reshape.transform(tree)
2828
if (reifyDebug) println("[interlude]")
29-
if (reifyDebug) println("reifee = " + (if (opt.showTrees) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString))
29+
if (reifyDebug) println("reifee = " + (if (settings.Xshowtrees.value || settings.XshowtreesCompact.value || settings.XshowtreesStringified.value) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString))
3030

3131
if (reifyDebug) println("[calculate phase]")
3232
calculate.traverse(tree)

src/compiler/scala/reflect/reify/Reifier.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ abstract class Reifier extends States
5858

5959
val result = reifee match {
6060
case tree: Tree =>
61-
reifyTrace("reifying = ")(if (opt.showTrees) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString)
61+
reifyTrace("reifying = ")(if (settings.Xshowtrees.value || settings.XshowtreesCompact.value || settings.XshowtreesStringified.value) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString)
6262
reifyTrace("reifee is located at: ")(tree.pos)
6363
reifyTrace("universe = ")(universe)
6464
reifyTrace("mirror = ")(mirror)

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 44 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import reporters.{ Reporter, ConsoleReporter }
1515
import util.{ Exceptional, ClassPath, MergedClassPath, StatisticsInfo, ScalaClassLoader, returning }
1616
import scala.reflect.internal.util.{ NoPosition, SourceFile, NoSourceFile, BatchSourceFile, ScriptSourceFile }
1717
import scala.reflect.internal.pickling.{ PickleBuffer, PickleFormat }
18-
import settings.{ AestheticSettings }
1918
import symtab.{ Flags, SymbolTable, SymbolLoaders, SymbolTrackers }
2019
import symtab.classfile.Pickler
2120
import dependencies.DependencyAnalysis
@@ -224,7 +223,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
224223
def globalError(msg: String) = reporter.error(NoPosition, msg)
225224
def inform(msg: String) = reporter.echo(msg)
226225
def warning(msg: String) =
227-
if (opt.fatalWarnings) globalError(msg)
226+
if (settings.fatalWarnings.value) globalError(msg)
228227
else reporter.warning(NoPosition, msg)
229228

230229
// Getting in front of Predef's asserts to supplement with more info.
@@ -265,7 +264,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
265264
msg + " in " + (currentTime - start) + "ms"
266265

267266
def informComplete(msg: String): Unit = reporter.withoutTruncating(inform(msg))
268-
def informProgress(msg: String) = if (opt.verbose) inform("[" + msg + "]")
267+
def informProgress(msg: String) = if (settings.verbose.value) inform("[" + msg + "]")
269268
def inform[T](msg: String, value: T): T = returning(value)(x => inform(msg + x))
270269
def informTime(msg: String, start: Long) = informProgress(elapsedMessage(msg, start))
271270

@@ -310,7 +309,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
310309
None
311310
}
312311

313-
val charset = opt.encoding flatMap loadCharset getOrElse {
312+
val charset = ( if (settings.encoding.isSetByUser) Some(settings.encoding.value) else None ) flatMap loadCharset getOrElse {
314313
settings.encoding.value = defaultEncoding // A mandatory charset
315314
Charset.forName(defaultEncoding)
316315
}
@@ -325,62 +324,20 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
325324
}
326325
}
327326

328-
opt.sourceReader flatMap loadReader getOrElse {
327+
( if (settings.sourceReader.isSetByUser) Some(settings.sourceReader.value) else None ) flatMap loadReader getOrElse {
329328
new SourceReader(charset.newDecoder(), reporter)
330329
}
331330
}
332331

333332
if (!dependencyAnalysis.off)
334333
dependencyAnalysis.loadDependencyAnalysis()
335334

336-
if (opt.verbose || opt.logClasspath) {
335+
if (settings.verbose.value || settings.Ylogcp.value) {
337336
// Uses the "do not truncate" inform
338337
informComplete("[search path for source files: " + classPath.sourcepaths.mkString(",") + "]")
339338
informComplete("[search path for class files: " + classPath.asClasspathString + "]")
340339
}
341340

342-
object opt extends AestheticSettings {
343-
def settings = Global.this.settings
344-
345-
// protected implicit lazy val globalPhaseOrdering: Ordering[Phase] = Ordering[Int] on (_.id)
346-
def isActive(ph: Settings#PhasesSetting) = ph containsPhase globalPhase
347-
def wasActive(ph: Settings#PhasesSetting) = ph containsPhase globalPhase.prev
348-
349-
// Allows for syntax like scalac -Xshow-class Random@erasure,typer
350-
private def splitClassAndPhase(str: String, term: Boolean): Name = {
351-
def mkName(s: String) = if (term) newTermName(s) else newTypeName(s)
352-
(str indexOf '@') match {
353-
case -1 => mkName(str)
354-
case idx =>
355-
val phasePart = str drop (idx + 1)
356-
settings.Yshow.tryToSetColon(phasePart split ',' toList)
357-
mkName(str take idx)
358-
}
359-
}
360-
361-
// behavior
362-
363-
// debugging
364-
def checkPhase = wasActive(settings.check)
365-
def logPhase = isActive(settings.log)
366-
367-
// Write *.icode files right after GenICode when -Xprint-icode was given.
368-
def writeICodeAtICode = settings.writeICode.isSetByUser && isActive(settings.writeICode)
369-
370-
// showing/printing things
371-
def browsePhase = isActive(settings.browse)
372-
def echoFilenames = opt.debug && (opt.verbose || currentRun.size < 5)
373-
def noShow = settings.Yshow.isDefault
374-
def printLate = settings.printLate.value
375-
def printPhase = isActive(settings.Xprint)
376-
def showNames = List(showClass, showObject).flatten
377-
def showPhase = isActive(settings.Yshow)
378-
def showSymbols = settings.Yshowsyms.value
379-
def showTrees = settings.Xshowtrees.value || settings.XshowtreesCompact.value || settings.XshowtreesStringified.value
380-
val showClass = optSetting[String](settings.Xshowcls) map (x => splitClassAndPhase(x, false))
381-
val showObject = optSetting[String](settings.Xshowobj) map (x => splitClassAndPhase(x, true))
382-
}
383-
384341
// The current division between scala.reflect.* and scala.tools.nsc.* is pretty
385342
// clunky. It is often difficult to have a setting influence something without having
386343
// to create it on that side. For this one my strategy is a constant def at the file
@@ -389,11 +346,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
389346
// Here comes another one...
390347
override protected val enableTypeVarExperimentals = settings.Xexperimental.value
391348

392-
// True if -Xscript has been set, indicating a script run.
393-
def isScriptRun = opt.script.isDefined
394-
395349
def getSourceFile(f: AbstractFile): BatchSourceFile =
396-
if (isScriptRun) ScriptSourceFile(f, reader read f)
350+
if (settings.script.isSetByUser) ScriptSourceFile(f, reader read f)
397351
else new BatchSourceFile(f, reader read f)
398352

399353
def getSourceFile(name: String): SourceFile = {
@@ -448,7 +402,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
448402
if ((unit ne null) && unit.exists)
449403
lastSeenSourceFile = unit.source
450404

451-
if (opt.echoFilenames)
405+
if (settings.debug.value && (settings.verbose.value || currentRun.size < 5))
452406
inform("[running phase " + name + " on " + unit + "]")
453407

454408
val unit0 = currentUnit
@@ -1171,7 +1125,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
11711125
val info3: List[String] = (
11721126
( List("== Enclosing template or block ==", nodePrinters.nodeToString(enclosing).trim) )
11731127
++ ( if (tpe eq null) Nil else List("== Expanded type of tree ==", typeDeconstruct.show(tpe)) )
1174-
++ ( if (!opt.debug) Nil else List("== Current unit body ==", nodePrinters.nodeToString(currentUnit.body)) )
1128+
++ ( if (!settings.debug.value) Nil else List("== Current unit body ==", nodePrinters.nodeToString(currentUnit.body)) )
11751129
++ ( List(errorMessage) )
11761130
)
11771131

@@ -1185,7 +1139,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
11851139

11861140
def echoPhaseSummary(ph: Phase) = {
11871141
/** Only output a summary message under debug if we aren't echoing each file. */
1188-
if (opt.debug && !opt.echoFilenames)
1142+
if (settings.debug.value && !(settings.verbose.value || currentRun.size < 5))
11891143
inform("[running phase " + ph.name + " on " + currentRun.size + " compilation units]")
11901144
}
11911145

@@ -1490,8 +1444,24 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
14901444
}
14911445
}
14921446

1493-
private def showMembers() =
1494-
opt.showNames foreach (x => showDef(x, opt.declsOnly, globalPhase))
1447+
private def showMembers() = {
1448+
// Allows for syntax like scalac -Xshow-class Random@erasure,typer
1449+
def splitClassAndPhase(str: String, term: Boolean): Name = {
1450+
def mkName(s: String) = if (term) newTermName(s) else newTypeName(s)
1451+
(str indexOf '@') match {
1452+
case -1 => mkName(str)
1453+
case idx =>
1454+
val phasePart = str drop (idx + 1)
1455+
settings.Yshow.tryToSetColon(phasePart split ',' toList)
1456+
mkName(str take idx)
1457+
}
1458+
}
1459+
if (settings.Xshowcls.isSetByUser)
1460+
showDef(splitClassAndPhase(settings.Xshowcls.value, false), false, globalPhase)
1461+
1462+
if (settings.Xshowobj.isSetByUser)
1463+
showDef(splitClassAndPhase(settings.Xshowobj.value, true), false, globalPhase)
1464+
}
14951465

14961466
// Similarly, this will only be created under -Yshow-syms.
14971467
object trackerFactory extends SymbolTrackers {
@@ -1576,37 +1546,40 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
15761546
// progress update
15771547
informTime(globalPhase.description, startTime)
15781548
phaseTimings(globalPhase) = currentTime - startTime
1579-
1580-
if (opt.writeICodeAtICode || (opt.printPhase && runIsAtOptimiz)) {
1549+
val shouldWriteIcode = (
1550+
(settings.writeICode.isSetByUser && (settings.writeICode containsPhase globalPhase))
1551+
|| (!settings.Xprint.doAllPhases && (settings.Xprint containsPhase globalPhase) && runIsAtOptimiz)
1552+
)
1553+
if (shouldWriteIcode) {
15811554
// Write *.icode files when -Xprint-icode or -Xprint:<some-optimiz-phase> was given.
15821555
writeICode()
1583-
} else if (opt.printPhase || opt.printLate && runIsAt(cleanupPhase)) {
1556+
} else if ((settings.Xprint containsPhase globalPhase) || settings.printLate.value && runIsAt(cleanupPhase)) {
15841557
// print trees
1585-
if (opt.showTrees) nodePrinters.printAll()
1558+
if (settings.Xshowtrees.value || settings.XshowtreesCompact.value || settings.XshowtreesStringified.value) nodePrinters.printAll()
15861559
else printAllUnits()
15871560
}
15881561

15891562
// print the symbols presently attached to AST nodes
1590-
if (opt.showSymbols)
1563+
if (settings.Yshowsyms.value)
15911564
trackerFactory.snapshot()
15921565

15931566
// print members
1594-
if (opt.showPhase)
1567+
if (settings.Yshow containsPhase globalPhase)
15951568
showMembers()
15961569

15971570
// browse trees with swing tree viewer
1598-
if (opt.browsePhase)
1571+
if (settings.browse containsPhase globalPhase)
15991572
treeBrowser browse (phase.name, units)
16001573

16011574
// move the pointer
16021575
globalPhase = globalPhase.next
16031576

16041577
// run tree/icode checkers
1605-
if (opt.checkPhase)
1578+
if (settings.check containsPhase globalPhase.prev)
16061579
runCheckers()
16071580

16081581
// output collected statistics
1609-
if (opt.printStats)
1582+
if (settings.Ystatistics.value)
16101583
statistics.print(phase)
16111584

16121585
advancePhase
@@ -1616,7 +1589,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
16161589
units map (_.body) foreach (traceSymbols recordSymbolsInTree _)
16171590

16181591
// In case no phase was specified for -Xshow-class/object, show it now for sure.
1619-
if (opt.noShow)
1592+
if (settings.Yshow.isDefault)
16201593
showMembers()
16211594

16221595
reportCompileErrors()
@@ -1648,7 +1621,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
16481621
def compile(filenames: List[String]) {
16491622
try {
16501623
val sources: List[SourceFile] =
1651-
if (isScriptRun && filenames.size > 1) returning(Nil)(_ => globalError("can only compile one script at a time"))
1624+
if (settings.script.isSetByUser && filenames.size > 1) returning(Nil)(_ => globalError("can only compile one script at a time"))
16521625
else filenames map getSourceFile
16531626

16541627
compileSources(sources)
@@ -1795,7 +1768,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
17951768
informProgress("wrote " + file)
17961769
} catch {
17971770
case ex: IOException =>
1798-
if (opt.debug) ex.printStackTrace()
1771+
if (settings.debug.value) ex.printStackTrace()
17991772
globalError("could not write file " + file)
18001773
}
18011774
})
@@ -1806,8 +1779,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
18061779
// and forScaladoc default to onlyPresentation, which is the same as defaulting
18071780
// to false except in old code. The downside is that this leaves us calling a
18081781
// deprecated method: but I see no simple way out, so I leave it for now.
1809-
def forJVM = opt.jvm
1810-
override def forMSIL = opt.msil
1782+
def forJVM = settings.target.value startsWith "jvm"
1783+
override def forMSIL = settings.target.value startsWith "msil"
18111784
def forInteractive = onlyPresentation
18121785
def forScaladoc = onlyPresentation
18131786
def createJavadoc = false

src/compiler/scala/tools/nsc/ast/TreeGen.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ abstract class TreeGen extends reflect.internal.TreeGen with TreeDSL {
9191
case Block((vd: ValDef) :: Nil, orig@Match(selector, cases)) => // println("block match: "+ (selector, cases, vd) + "for:\n"+ matchExpr )
9292
caseMatch(matchExpr, selector, cases, m => copyBlock(matchExpr, List(vd), m))
9393
// virtpatmat
94-
case Apply(Apply(TypeApply(Select(tgt, nme.runOrElse), targs), List(scrut)), List(matcher)) if opt.virtPatmat => // println("virt match: "+ (tgt, targs, scrut, matcher) + "for:\n"+ matchExpr )
94+
case Apply(Apply(TypeApply(Select(tgt, nme.runOrElse), targs), List(scrut)), List(matcher)) if !settings.XoldPatmat.value => // println("virt match: "+ (tgt, targs, scrut, matcher) + "for:\n"+ matchExpr )
9595
caseVirtualizedMatch(matchExpr, tgt, targs, scrut, matcher)
9696
// optimized version of virtpatmat
97-
case Block(stats, matchEndDef) if opt.virtPatmat && (stats forall hasSynthCaseSymbol) =>
97+
case Block(stats, matchEndDef) if !settings.XoldPatmat.value && (stats forall hasSynthCaseSymbol) =>
9898
// the assumption is once we encounter a case, the remainder of the block will consist of cases
9999
// the prologue may be empty, usually it is the valdef that stores the scrut
100100
val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef])
101101
caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, identity)
102102
// optimized version of virtpatmat
103-
case Block(outerStats, orig@Block(stats, matchEndDef)) if opt.virtPatmat && (stats forall hasSynthCaseSymbol) =>
103+
case Block(outerStats, orig@Block(stats, matchEndDef)) if !settings.XoldPatmat.value && (stats forall hasSynthCaseSymbol) =>
104104
val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef])
105105
caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, m => copyBlock(matchExpr, outerStats, m))
106106
case other =>
@@ -111,7 +111,7 @@ abstract class TreeGen extends reflect.internal.TreeGen with TreeDSL {
111111
def copyBlock(orig: Tree, stats: List[Tree], expr: Tree): Block = Block(stats, expr)
112112

113113
def dropSyntheticCatchAll(cases: List[CaseDef]): List[CaseDef] =
114-
if (!opt.virtPatmat) cases
114+
if (settings.XoldPatmat.value) cases
115115
else cases filter {
116116
case CaseDef(pat, EmptyTree, Throw(Apply(Select(New(exTpt), nme.CONSTRUCTOR), _))) if (treeInfo.isWildcardArg(pat) && (exTpt.tpe.typeSymbol eq MatchErrorClass)) => false
117117
case CaseDef(pat, guard, body) => true

src/compiler/scala/tools/nsc/ast/parser/Scanners.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ trait Scanners extends ScannersCommon {
398398
* there a realistic situation where one would need it?
399399
*/
400400
if (isDigit(ch)) {
401-
if (opt.future) syntaxError("Non-zero numbers may not have a leading zero.")
401+
if (settings.future.value) syntaxError("Non-zero numbers may not have a leading zero.")
402402
else deprecationWarning("Treating numbers with a leading zero as octal is deprecated.")
403403
}
404404
base = 8
@@ -975,9 +975,9 @@ trait Scanners extends ScannersCommon {
975975
val c = lookahead.getc()
976976

977977
/** As of scala 2.11, it isn't a number unless c here is a digit, so
978-
* opt.future excludes the rest of the logic.
978+
* settings.future.value excludes the rest of the logic.
979979
*/
980-
if (opt.future && !isDigit(c))
980+
if (settings.future.value && !isDigit(c))
981981
return setStrVal()
982982

983983
val isDefinitelyNumber = (c: @switch) match {

src/compiler/scala/tools/nsc/backend/icode/ICodes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class ICodes extends AnyRef
4242

4343
/** Debugging flag */
4444
def shouldCheckIcode = settings.check contains global.genicode.phaseName
45-
def checkerDebug(msg: String) = if (shouldCheckIcode && global.opt.debug) println(msg)
45+
def checkerDebug(msg: String) = if (shouldCheckIcode && global.settings.debug.value) println(msg)
4646

4747
/** The ICode linearizer. */
4848
val linearizer: Linearizer = settings.Xlinearizer.value match {

src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
755755
}
756756
}
757757
val index = jmember.getConstantPool.addUtf8(sig).toShort
758-
if (opt.verboseDebug)
758+
if (settings.verbose.value && settings.debug.value)
759759
beforeErasure(println("add generic sig "+sym+":"+sym.info+" ==> "+sig+" @ "+index))
760760

761761
val buf = ByteBuffer.allocate(2)

src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ abstract class GenMSIL extends SubComponent {
4545

4646
//classes is ICodes.classes, a HashMap[Symbol, IClass]
4747
classes.values foreach codeGenerator.findEntryPoint
48-
if( opt.showClass.isDefined && (codeGenerator.entryPoint == null) ) { // TODO introduce dedicated setting instead
49-
val entryclass = opt.showClass.get.toString
48+
if( settings.Xshowcls.isSetByUser && (codeGenerator.entryPoint == null) ) { // TODO introduce dedicated setting instead
49+
val entryclass = settings.Xshowcls.value.toString
5050
warning("Couldn't find entry class " + entryclass)
5151
}
5252

@@ -1731,8 +1731,8 @@ abstract class GenMSIL extends SubComponent {
17311731
false
17321732
}
17331733

1734-
if((entryPoint == null) && opt.showClass.isDefined) { // TODO introduce dedicated setting instead
1735-
val entryclass = opt.showClass.get.toString
1734+
if((entryPoint == null) && settings.Xshowcls.isSetByUser) { // TODO introduce dedicated setting instead
1735+
val entryclass = settings.Xshowcls.value.toString
17361736
val cfn = cls.symbol.fullName
17371737
if(cfn == entryclass) {
17381738
for (m <- cls.methods; if isEntryPoint(m.symbol)) { entryPoint = m.symbol }

src/compiler/scala/tools/nsc/backend/opt/Inliners.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ abstract class Inliners extends SubComponent {
240240
}
241241

242242
val tfa = new analysis.MTFAGrowable()
243-
tfa.stat = global.opt.printStats
243+
tfa.stat = global.settings.Ystatistics.value
244244
val staleOut = new mutable.ListBuffer[BasicBlock]
245245
val splicedBlocks = mutable.Set.empty[BasicBlock]
246246
val staleIn = mutable.Set.empty[BasicBlock]

src/compiler/scala/tools/nsc/interpreter/Power.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
7373
pass += 1
7474
val (repeats, unseen) = todo partition seen
7575
unseenHistory += unseen.size
76-
if (opt.verbose) {
76+
if (settings.verbose.value) {
7777
println("%3d %s accumulated, %s discarded. This pass: %s unseen, %s repeats".format(
7878
pass, keep.size, discarded, unseen.size, repeats.size))
7979
}

0 commit comments

Comments
 (0)