Skip to content

Commit a08079e

Browse files
committed
Don't always enclose partial ofs in braces
This needs to be done only if the partial if is followed by `else`. Change all dotc code to be stable under the new rewrite scheme.
1 parent fe3562d commit a08079e

35 files changed

+108
-208
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
115115
* or we need to assemble phases on each run, and take -Yskip, -Ystop into
116116
* account. I think the latter would be preferable.
117117
*/
118-
def compileSources(sources: List[SourceFile]): Unit = {
118+
def compileSources(sources: List[SourceFile]): Unit =
119119
if (sources forall (_.exists)) {
120120
units = sources.map(CompilationUnit(_))
121121
compileUnits()
122122
}
123-
}
124123

125124
def compileUnits(us: List[CompilationUnit]): Unit = {
126125
units = us
@@ -152,7 +151,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
152151
var lastPrintedTree: PrintedTree = NoPrintedTree
153152
val profiler = ctx.profiler
154153

155-
for (phase <- ctx.base.allPhases) {
154+
for (phase <- ctx.base.allPhases)
156155
if (phase.isRunnable)
157156
Stats.trackTime(s"$phase ms ") {
158157
val start = System.currentTimeMillis
@@ -168,7 +167,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
168167
for (unit <- units)
169168
Stats.record(s"retained typed trees at end of $phase", unit.tpdTree.treeSize)
170169
}
171-
}
172170

173171
profiler.finished()
174172
}
@@ -190,7 +188,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
190188
* If `typeCheck = true`, also run typer on the compilation unit, and set
191189
* `rootTreeOrProvider`.
192190
*/
193-
def lateCompile(file: AbstractFile, typeCheck: Boolean)(implicit ctx: Context): Unit = {
191+
def lateCompile(file: AbstractFile, typeCheck: Boolean)(implicit ctx: Context): Unit =
194192
if (!files.contains(file) && !lateFiles.contains(file)) {
195193
lateFiles += file
196194
val unit = CompilationUnit(ctx.getSource(file.path))
@@ -209,7 +207,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
209207
}
210208
process()(runContext.fresh.setCompilationUnit(unit))
211209
}
212-
}
213210

214211
private sealed trait PrintedTree
215212
private /*final*/ case class SomePrintedTree(phase: String, tree: String) extends PrintedTree

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,9 +1697,8 @@ object desugar {
16971697
private def getVariables(tree: Tree)(implicit ctx: Context): List[VarInfo] = {
16981698
val buf = ListBuffer[VarInfo]()
16991699
def seenName(name: Name) = buf exists (_._1.name == name)
1700-
def add(named: NameTree, t: Tree): Unit = {
1700+
def add(named: NameTree, t: Tree): Unit =
17011701
if (!seenName(named.name) && named.name.isTermName) buf += ((named, t))
1702-
}
17031702
def collect(tree: Tree): Unit = tree match {
17041703
case Bind(nme.WILDCARD, tree1) =>
17051704
collect(tree1)

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ object Trees {
118118
* - the child tree is an identifier, or
119119
* - errors were reported
120120
*/
121-
private def checkChildrenTyped(it: Iterator[Any])(implicit ctx: Context): Unit = {
121+
private def checkChildrenTyped(it: Iterator[Any])(implicit ctx: Context): Unit =
122122
if (!this.isInstanceOf[Import[_]])
123123
while (it.hasNext)
124124
it.next() match {
@@ -129,7 +129,6 @@ object Trees {
129129
case xs: List[_] => checkChildrenTyped(xs.iterator)
130130
case _ =>
131131
}
132-
}
133132

134133
def withTypeUnchecked(tpe: Type): ThisTree[Type] = {
135134
val tree =

compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ trait DirectoryLookup[FileEntryType <: ClassRepresentation] extends ClassPath {
7171
val packagePrefix = PackageNameUtils.packagePrefix(inPackage)
7272
val packageBuf = collection.mutable.ArrayBuffer.empty[PackageEntry]
7373
val fileBuf = collection.mutable.ArrayBuffer.empty[FileEntryType]
74-
for (file <- files) {
74+
for (file <- files)
7575
if (isPackage(file))
7676
packageBuf += PackageEntryImpl(packagePrefix + getName(file))
7777
else if (isMatchingFile(file))
7878
fileBuf += createFileEntry(toAbstractFile(file))
79-
}
8079
ClassPathEntries(packageBuf, fileBuf)
8180
}
8281
}

compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ trait ZipArchiveFileLookup[FileEntryType <: ClassRepresentation] extends ClassPa
5858
val fileBuf = collection.mutable.ArrayBuffer.empty[FileEntryType]
5959
val prefix = PackageNameUtils.packagePrefix(inPackage)
6060

61-
for (entry <- dirEntry.iterator) {
61+
for (entry <- dirEntry.iterator)
6262
if (entry.isPackage)
6363
pkgBuf += PackageEntryImpl(prefix + entry.name)
6464
else if (isRequiredFileType(entry))
6565
fileBuf += createFileEntry(entry)
66-
}
6766
ClassPathEntries(pkgBuf, fileBuf)
6867
} getOrElse ClassPathEntries(Seq.empty, Seq.empty)
6968
}

compiler/src/dotty/tools/dotc/consumetasty/ConsumeTasty.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ object ConsumeTasty {
3636
case _ => classpath0
3737
}
3838
}
39-
4039
}
40+

compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import config.Printers.{default, typr}
77
trait ConstraintRunInfo { self: Run =>
88
private[this] var maxSize = 0
99
private[this] var maxConstraint: Constraint = _
10-
def recordConstraintSize(c: Constraint, size: Int): Unit = {
10+
def recordConstraintSize(c: Constraint, size: Int): Unit =
1111
if (size > maxSize) {
1212
maxSize = size
1313
maxConstraint = c
1414
}
15-
}
1615
def printMaxConstraint()(implicit ctx: Context): Unit = {
1716
val printer = if (ctx.settings.YdetailedStats.value) default else typr
1817
if (maxSize > 0) printer.println(s"max constraint = ${maxConstraint.show}")

compiler/src/dotty/tools/dotc/core/GadtConstraint.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,8 @@ final class ProperGadtConstraint private(
317317
override def approximation(sym: Symbol, fromBelow: Boolean)(implicit ctx: Context): Type = unsupported("EmptyGadtConstraint.approximation")
318318

319319
override def fresh = new ProperGadtConstraint
320-
override def restore(other: GadtConstraint): Unit = {
320+
override def restore(other: GadtConstraint): Unit =
321321
if (!other.isEmpty) sys.error("cannot restore a non-empty GADTMap")
322-
}
323322

324323
override def debugBoundsDescription(implicit ctx: Context): String = "EmptyGadtConstraint"
325324

compiler/src/dotty/tools/dotc/core/Names.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,8 @@ object Names {
377377
override def replace(from: Char, to: Char): SimpleName = {
378378
val cs = new Array[Char](length)
379379
System.arraycopy(chrs, start, cs, 0, length)
380-
for (i <- 0 until length) {
380+
for (i <- 0 until length)
381381
if (cs(i) == from) cs(i) = to
382-
}
383382
termName(cs, 0, length)
384383
}
385384

@@ -573,13 +572,12 @@ object Names {
573572
val h = hashValue(cs, offset, len) & (table.length - 1)
574573

575574
/** Make sure the capacity of the character array is at least `n` */
576-
def ensureCapacity(n: Int) = {
575+
def ensureCapacity(n: Int) =
577576
if (n > chrs.length) {
578577
val newchrs = new Array[Char](chrs.length * 2)
579578
chrs.copyToArray(newchrs)
580579
chrs = newchrs
581580
}
582-
}
583581

584582
/** Enter characters into chrs array. */
585583
def enterChars(): Unit = {
@@ -593,15 +591,14 @@ object Names {
593591
}
594592

595593
/** Rehash chain of names */
596-
def rehash(name: SimpleName): Unit = {
594+
def rehash(name: SimpleName): Unit =
597595
if (name != null) {
598596
val oldNext = name.next
599597
val h = hashValue(chrs, name.start, name.length) & (table.size - 1)
600598
name.next = table(h)
601599
table(h) = name
602600
rehash(oldNext)
603601
}
604-
}
605602

606603
/** Make sure the hash table is large enough for the given load factor */
607604
def incTableSize() = {

compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,9 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
588588
case TypeParamRef(binder: TypeLambda, _) => !contains(binder)
589589
case _ => false
590590
}
591-
def checkClosedType(tp: Type, where: String) = {
591+
def checkClosedType(tp: Type, where: String) =
592592
if (tp != null)
593593
assert(!tp.existsPart(isFreeTypeParamRef), i"unclosed constraint: $this refers to $tp in $where")
594-
}
595594
boundsMap.foreachBinding((_, tps) => tps.foreach(checkClosedType(_, "bounds")))
596595
lowerMap.foreachBinding((_, paramss) => paramss.foreach(_.foreach(checkClosedType(_, "lower"))))
597596
upperMap.foreachBinding((_, paramss) => paramss.foreach(_.foreach(checkClosedType(_, "upper"))))

0 commit comments

Comments
 (0)