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"))))

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,11 @@ object Scopes {
158158
*/
159159
final def filteredScope(p: Symbol => Boolean)(implicit ctx: Context): Scope = {
160160
var result: MutableScope = null
161-
for (sym <- iterator) {
161+
for (sym <- iterator)
162162
if (!p(sym)) {
163163
if (result == null) result = cloneScope
164164
result.unlink(sym)
165165
}
166-
}
167166
if (result == null) this else result
168167
}
169168

@@ -279,9 +278,8 @@ object Scopes {
279278
enter(sym)
280279
}
281280

282-
private def ensureCapacity(tableSize: Int)(implicit ctx: Context): Unit = {
281+
private def ensureCapacity(tableSize: Int)(implicit ctx: Context): Unit =
283282
if (size >= tableSize * FillFactor) createHash(tableSize * 2)
284-
}
285283

286284
private def createHash(tableSize: Int)(implicit ctx: Context): Unit =
287285
if (size > tableSize * FillFactor) createHash(tableSize * 2)
@@ -291,7 +289,7 @@ object Scopes {
291289
// checkConsistent() // DEBUG
292290
}
293291

294-
private def enterAllInHash(e: ScopeEntry, n: Int = 0)(implicit ctx: Context): Unit = {
292+
private def enterAllInHash(e: ScopeEntry, n: Int = 0)(implicit ctx: Context): Unit =
295293
if (e ne null)
296294
if (n < MaxRecursions) {
297295
enterAllInHash(e.prev, n + 1)
@@ -306,7 +304,6 @@ object Scopes {
306304
}
307305
entries foreach enterInHash
308306
}
309-
}
310307

311308
/** Remove entry from this scope (which is required to be present) */
312309
final def unlink(e: ScopeEntry)(implicit ctx: Context): Unit = {

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,9 @@ object SymDenotations {
13901390
case _ => false
13911391
}
13921392

1393-
def assertNoSkolems(tp: Type): Unit = {
1393+
def assertNoSkolems(tp: Type): Unit =
13941394
if (!this.isSkolem)
13951395
assert(!hasSkolems(tp), s"assigning type $tp containing skolems to $this")
1396-
}
13971396

13981397
// ----- copies and transforms ----------------------------------------
13991398

@@ -2040,10 +2039,9 @@ object SymDenotations {
20402039
private[this] var myCompanion: Symbol = NoSymbol
20412040

20422041
/** Register companion class */
2043-
override def registerCompanion(companion: Symbol)(implicit ctx: Context) = {
2042+
override def registerCompanion(companion: Symbol)(implicit ctx: Context) =
20442043
if (companion.isClass && !isAbsent(canForce = false) && !companion.isAbsent(canForce = false))
20452044
myCompanion = companion
2046-
}
20472045

20482046
override def registeredCompanion(implicit ctx: Context) = { ensureCompleted(); myCompanion }
20492047
override def registeredCompanion_=(c: Symbol) = { myCompanion = c }
@@ -2163,12 +2161,11 @@ object SymDenotations {
21632161
/** Unlink all package members defined in `file` in a previous run. */
21642162
def unlinkFromFile(file: AbstractFile)(implicit ctx: Context): Unit = {
21652163
val scope = unforcedDecls.openForMutations
2166-
for (sym <- scope.toList.iterator) {
2164+
for (sym <- scope.toList.iterator)
21672165
// We need to be careful to not force the denotation of `sym` here,
21682166
// otherwise it will be brought forward to the current run.
21692167
if (sym.defRunId != ctx.runId && sym.isClass && sym.asClass.assocFile == file)
21702168
scope.unlink(sym, sym.lastKnownDenotation.name)
2171-
}
21722169
}
21732170
}
21742171

@@ -2370,14 +2367,13 @@ object SymDenotations {
23702367
* the cache itself. In that case we should cancel invalidation and
23712368
* proceed as usual. However, all cache entries should be cleared.
23722369
*/
2373-
def invalidate(): Unit = {
2370+
def invalidate(): Unit =
23742371
if (cache != null)
23752372
if (locked) cache = SimpleIdentityMap.Empty
23762373
else {
23772374
cache = null
23782375
invalidateDependents()
23792376
}
2380-
}
23812377

23822378
def apply(keepOnly: NameFilter, clsd: ClassDenotation)(implicit onBehalf: MemberNames, ctx: Context) = {
23832379
assert(isValid)
@@ -2407,13 +2403,12 @@ object SymDenotations {
24072403

24082404
final def isValid(implicit ctx: Context): Boolean = valid && isValidAt(ctx.phase)
24092405

2410-
def invalidate(): Unit = {
2406+
def invalidate(): Unit =
24112407
if (valid && !locked) {
24122408
cache = null
24132409
valid = false
24142410
invalidateDependents()
24152411
}
2416-
}
24172412

24182413
def signalProvisional() = provisional = true
24192414

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,14 @@ object SymbolLoaders {
260260
if (!root.isRoot) {
261261
val classReps = classPath.list(packageName).classesAndSources
262262

263-
for (classRep <- classReps) {
263+
for (classRep <- classReps)
264264
if (!maybeModuleClass(classRep) && hasFlatName(classRep) == flat &&
265265
(!flat || isAbsent(classRep))) // on 2nd enter of flat names, check that the name has not been entered before
266266
initializeFromClassPath(root.symbol, classRep)
267-
}
268-
for (classRep <- classReps) {
267+
for (classRep <- classReps)
269268
if (maybeModuleClass(classRep) && hasFlatName(classRep) == flat &&
270269
isAbsent(classRep))
271270
initializeFromClassPath(root.symbol, classRep)
272-
}
273271
}
274272
}
275273

@@ -352,11 +350,10 @@ abstract class SymbolLoader extends LazyType { self =>
352350
throw ex
353351
}
354352
finally {
355-
def postProcess(denot: SymDenotation) = {
353+
def postProcess(denot: SymDenotation) =
356354
if (!denot.isCompleted &&
357355
!denot.completer.isInstanceOf[SymbolLoaders.SecondCompleter])
358356
denot.markAbsent()
359-
}
360357
postProcess(root)
361358
if (!root.isRoot)
362359
postProcess(root.scalacLinkedClass.denot)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,8 @@ object Symbols {
444444
if (myDefTree == null) tpd.EmptyTree else myDefTree
445445

446446
/** Set defining tree if this symbol retains its definition tree */
447-
def defTree_=(tree: Tree)(implicit ctx: Context): Unit = {
447+
def defTree_=(tree: Tree)(implicit ctx: Context): Unit =
448448
if (retainsDefTree) myDefTree = tree
449-
}
450449

451450
/** Does this symbol retain its definition tree?
452451
* A good policy for this needs to balance costs and benefits, where

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,10 +2007,9 @@ object Types {
20072007
setDenot(memberDenot(name, allowPrivate = !symbol.exists || symbol.is(Private)))
20082008

20092009
private def setDenot(denot: Denotation)(implicit ctx: Context): Unit = {
2010-
if (Config.checkNoDoubleBindings) {
2010+
if (Config.checkNoDoubleBindings)
20112011
if (ctx.settings.YnoDoubleBindings.value)
20122012
checkSymAssign(denot.symbol)
2013-
}
20142013

20152014
lastDenotation = denot
20162015
lastSymbol = denot.symbol
@@ -2361,9 +2360,8 @@ object Types {
23612360
}
23622361

23632362
/** Assert current phase does not have erasure semantics */
2364-
private def assertUnerased()(implicit ctx: Context) = {
2363+
private def assertUnerased()(implicit ctx: Context) =
23652364
if (Config.checkUnerased) assert(!ctx.phase.erasedTypes)
2366-
}
23672365

23682366
/** The designator to be used for a named type creation with given prefix, name, and denotation.
23692367
* This is the denotation's symbol, if it exists and the prefix is not the this type
@@ -2844,7 +2842,7 @@ object Types {
28442842
private[this] var myAtoms: Set[Type] = _
28452843
private[this] var myWidened: Type = _
28462844

2847-
private def ensureAtomsComputed()(implicit ctx: Context): Unit = {
2845+
private def ensureAtomsComputed()(implicit ctx: Context): Unit =
28482846
if (atomsRunId != ctx.runId) {
28492847
val atoms1 = tp1.atoms
28502848
val atoms2 = tp2.atoms
@@ -2854,7 +2852,6 @@ object Types {
28542852
myWidened = if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else tp1w | tp2w
28552853
atomsRunId = ctx.runId
28562854
}
2857-
}
28582855

28592856
override def atoms(implicit ctx: Context): Set[Type] = {
28602857
ensureAtomsComputed()

0 commit comments

Comments
 (0)