Skip to content

Commit d52edec

Browse files
committed
More invariant rewritings
Additional rewritings to make the compiler source invariant if we also rewrite under braces
1 parent f50e7d7 commit d52edec

23 files changed

+93
-99
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object MainProxies {
4545
def pos = mainFun.sourcePos
4646
val argsRef = Ident(nme.args)
4747

48-
def addArgs(call: untpd.Tree, mt: MethodType, idx: Int): untpd.Tree = {
48+
def addArgs(call: untpd.Tree, mt: MethodType, idx: Int): untpd.Tree =
4949
if (mt.isImplicitMethod) {
5050
ctx.error(s"@main method cannot have implicit parameters", pos)
5151
call
@@ -71,7 +71,6 @@ object MainProxies {
7171
call1
7272
}
7373
}
74-
}
7574

7675
var result: List[TypeDef] = Nil
7776
if (!mainFun.owner.isStaticOwner)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,15 +686,14 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
686686
def defPath(sym: Symbol, root: Tree)(implicit ctx: Context): List[Tree] = trace.onDebug(s"defpath($sym with position ${sym.span}, ${root.show})") {
687687
require(sym.span.exists, sym)
688688
object accum extends TreeAccumulator[List[Tree]] {
689-
def apply(x: List[Tree], tree: Tree)(implicit ctx: Context): List[Tree] = {
689+
def apply(x: List[Tree], tree: Tree)(implicit ctx: Context): List[Tree] =
690690
if (tree.span.contains(sym.span))
691691
if (definedSym(tree) == sym) tree :: x
692692
else {
693693
val x1 = foldOver(x, tree)
694694
if (x1 ne x) tree :: x1 else x1
695695
}
696696
else x
697-
}
698697
}
699698
accum(Nil, root)
700699
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,8 @@ class TreeTypeMap(
189189
val origDcls = cls.info.decls.toList
190190
val mappedDcls = ctx.mapSymbols(origDcls, tmap)
191191
val tmap1 = tmap.withMappedSyms(origDcls, mappedDcls)
192-
if (symsChanged) {
192+
if (symsChanged)
193193
origDcls.lazyZip(mappedDcls).foreach(cls.asClass.replace)
194-
}
195194
tmap1
196195
}
197196
if (symsChanged || (fullMap eq substMap)) fullMap

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
6767
override private[dotty] def hasPackage(pkg: String): Boolean = aggregates.exists(_.hasPackage(pkg))
6868
override private[dotty] def list(inPackage: String): ClassPathEntries = {
6969
val (packages, classesAndSources) = aggregates.map { cp =>
70-
try {
70+
try
7171
cp.list(inPackage).toTuple
72-
} catch {
72+
catch {
7373
case ex: java.io.IOException =>
7474
val e = new FatalError(ex.getMessage)
7575
e.initCause(ex)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,9 @@ object Comments {
371371
superComment(sym) foreach { sc =>
372372
val superSections = tagIndex(sc)
373373
replaceWith(sc.substring(3, startTag(sc, superSections)))
374-
for (sec @ (start, end) <- superSections)
374+
for (sec @ (start, end) <- superSections) {
375375
if (!isMovable(sc, sec)) out append sc.substring(start, end)
376+
}
376377
}
377378
case "" => idx += 1
378379
case vname =>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ 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+
}
1516
def printMaxConstraint()(implicit ctx: Context): Unit = {
1617
val printer = if (ctx.settings.YdetailedStats.value) default else typr
1718
if (maxSize > 0) printer.println(s"max constraint = ${maxConstraint.show}")

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,13 +1328,12 @@ object Denotations {
13281328
def staticRef(path: Name, generateStubs: Boolean = true, isPackage: Boolean = false)(implicit ctx: Context): Denotation = {
13291329
def select(prefix: Denotation, selector: Name): Denotation = {
13301330
val owner = prefix.disambiguate(_.info.isParameterless)
1331-
def isPackageFromCoreLibMissing: Boolean = {
1331+
def isPackageFromCoreLibMissing: Boolean =
13321332
owner.symbol == defn.RootClass &&
13331333
(
13341334
selector == nme.scala_ || // if the scala package is missing, the stdlib must be missing
13351335
selector == nme.scalaShadowing // if the scalaShadowing package is missing, the dotty library must be missing
13361336
)
1337-
}
13381337
if (owner.exists) {
13391338
val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector)
13401339
if (result.exists) result

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,11 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
604604
if (myUninstVars == null || myUninstVars.exists(_.inst.exists)) {
605605
myUninstVars = new mutable.ArrayBuffer[TypeVar]
606606
boundsMap.foreachBinding { (poly, entries) =>
607-
for (i <- 0 until paramCount(entries)) {
607+
for (i <- 0 until paramCount(entries))
608608
typeVar(entries, i) match {
609609
case tv: TypeVar if !tv.inst.exists && isBounds(entries(i)) => myUninstVars += tv
610610
case _ =>
611611
}
612-
}
613612
}
614613
}
615614
myUninstVars

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ abstract class Periods { self: Context =>
3232
def stablePeriod: Period = {
3333
var first = phaseId
3434
val nxTrans = ctx.base.nextDenotTransformerId(first)
35-
while (first - 1 > NoPhaseId && (ctx.base.nextDenotTransformerId(first - 1) == nxTrans)) {
35+
while (first - 1 > NoPhaseId && (ctx.base.nextDenotTransformerId(first - 1) == nxTrans))
3636
first -= 1
37-
}
3837
Period(runId, first, nxTrans)
3938
}
4039

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait Substituters { this: Context =>
2121
.mapOver(tp)
2222
}
2323

24-
final def subst1(tp: Type, from: Symbol, to: Type, theMap: Subst1Map): Type = {
24+
final def subst1(tp: Type, from: Symbol, to: Type, theMap: Subst1Map): Type =
2525
tp match {
2626
case tp: NamedType =>
2727
val sym = tp.symbol
@@ -34,9 +34,8 @@ trait Substituters { this: Context =>
3434
(if (theMap != null) theMap else new Subst1Map(from, to))
3535
.mapOver(tp)
3636
}
37-
}
3837

39-
final def subst2(tp: Type, from1: Symbol, to1: Type, from2: Symbol, to2: Type, theMap: Subst2Map): Type = {
38+
final def subst2(tp: Type, from1: Symbol, to1: Type, from2: Symbol, to2: Type, theMap: Subst2Map): Type =
4039
tp match {
4140
case tp: NamedType =>
4241
val sym = tp.symbol
@@ -50,9 +49,8 @@ trait Substituters { this: Context =>
5049
(if (theMap != null) theMap else new Subst2Map(from1, to1, from2, to2))
5150
.mapOver(tp)
5251
}
53-
}
5452

55-
final def subst(tp: Type, from: List[Symbol], to: List[Type], theMap: SubstMap): Type = {
53+
final def subst(tp: Type, from: List[Symbol], to: List[Type], theMap: SubstMap): Type =
5654
tp match {
5755
case tp: NamedType =>
5856
val sym = tp.symbol
@@ -71,7 +69,6 @@ trait Substituters { this: Context =>
7169
(if (theMap != null) theMap else new SubstMap(from, to))
7270
.mapOver(tp)
7371
}
74-
}
7572

7673
final def substSym(tp: Type, from: List[Symbol], to: List[Symbol], theMap: SubstSymMap): Type =
7774
tp match {

0 commit comments

Comments
 (0)