Skip to content

Commit cab060c

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

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 {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ trait SymDenotations { this: Context =>
6767
|| (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol)
6868
|| denot.isSelfSym
6969
|| denot.isLocalDummy)
70-
} catch {
70+
}
71+
catch {
7172
case ex: StaleSymbol => false
7273
}
7374

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ abstract class SymbolLoader extends LazyType { self =>
340340
else
341341
doComplete(root)
342342
ctx.informTime("loaded " + description, start)
343-
} catch {
343+
}
344+
catch {
344345
case ex: IOException =>
345346
signalError(ex)
346347
case NonFatal(ex: TypeError) =>
@@ -349,11 +350,13 @@ abstract class SymbolLoader extends LazyType { self =>
349350
case NonFatal(ex) =>
350351
println(s"exception caught when loading $root: $ex")
351352
throw ex
352-
} finally {
353-
def postProcess(denot: SymDenotation) =
353+
}
354+
finally {
355+
def postProcess(denot: SymDenotation) = {
354356
if (!denot.isCompleted &&
355357
!denot.completer.isInstanceOf[SymbolLoaders.SecondCompleter])
356358
denot.markAbsent()
359+
}
357360
postProcess(root)
358361
if (!root.isRoot)
359362
postProcess(root.scalacLinkedClass.denot)

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
8989
}
9090
}
9191

92-
/*>|>*/ trace.conditionally(TypeOps.track, s"asSeen ${tp.show} from (${pre.show}, ${cls.show})", show = true) /*<|<*/ { // !!! DEBUG
92+
trace.conditionally(TypeOps.track, s"asSeen ${tp.show} from (${pre.show}, ${cls.show})", show = true) { // !!! DEBUG
9393
// All cases except for ThisType are the same as in Map. Inlined for performance
9494
// TODO: generalize the inlining trick?
9595
tp match {
@@ -649,16 +649,14 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
649649
parent.argInfos.nonEmpty && minTypeMap.apply(parent) <:< maxTypeMap.apply(tp2)
650650
}
651651

652-
if (protoTp1 <:< tp2) {
652+
if (protoTp1 <:< tp2)
653653
if (isFullyDefined(protoTp1, force)) protoTp1
654654
else instUndetMap.apply(protoTp1)
655-
}
656655
else {
657656
val protoTp2 = maxTypeMap.apply(tp2)
658-
if (protoTp1 <:< protoTp2 || parentQualify) {
657+
if (protoTp1 <:< protoTp2 || parentQualify)
659658
if (isFullyDefined(AndType(protoTp1, protoTp2), force)) protoTp1
660659
else instUndetMap.apply(protoTp1)
661-
}
662660
else {
663661
typr.println(s"$protoTp1 <:< $protoTp2 = false")
664662
NoType

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,10 +1869,9 @@ object Types {
18691869
* Assumes that symbols do not change between periods in the same run.
18701870
* Used to get the class underlying a ThisType.
18711871
*/
1872-
private[Types] def stableInRunSymbol(implicit ctx: Context): Symbol = {
1872+
private[Types] def stableInRunSymbol(implicit ctx: Context): Symbol =
18731873
if (checkedPeriod.runId == ctx.runId) lastSymbol
18741874
else symbol
1875-
}
18761875

18771876
def info(implicit ctx: Context): Type = denot.info
18781877

@@ -2008,9 +2007,10 @@ object Types {
20082007
setDenot(memberDenot(name, allowPrivate = !symbol.exists || symbol.is(Private)))
20092008

20102009
private def setDenot(denot: Denotation)(implicit ctx: Context): Unit = {
2011-
if (Config.checkNoDoubleBindings)
2010+
if (Config.checkNoDoubleBindings) {
20122011
if (ctx.settings.YnoDoubleBindings.value)
20132012
checkSymAssign(denot.symbol)
2013+
}
20142014

20152015
lastDenotation = denot
20162016
lastSymbol = denot.symbol
@@ -2107,9 +2107,9 @@ object Types {
21072107
} finally {
21082108
ctx.pendingUnderlying -= this
21092109
}
2110-
} finally {
2111-
ctx.base.underlyingRecursions -= 1
21122110
}
2111+
finally
2112+
ctx.base.underlyingRecursions -= 1
21132113

21142114
/** The argument corresponding to class type parameter `tparam` as seen from
21152115
* prefix `pre`. Can produce a TypeBounds type in case prefix is an & or | type
@@ -3139,19 +3139,18 @@ object Types {
31393139
* def f(x: C)(y: x.T) // dependencyStatus = FalseDeps, i.e.
31403140
* // dependency can be eliminated by dealiasing.
31413141
*/
3142-
private def dependencyStatus(implicit ctx: Context): DependencyStatus = {
3142+
private def dependencyStatus(implicit ctx: Context): DependencyStatus =
31433143
if (myDependencyStatus != Unknown) myDependencyStatus
31443144
else {
31453145
val result = depStatus(NoDeps, resType)
31463146
if ((result & Provisional) == 0) myDependencyStatus = result
31473147
(result & StatusMask).toByte
31483148
}
3149-
}
31503149

31513150
/** The parameter dependency status of this method. Analogous to `dependencyStatus`,
31523151
* but tracking dependencies in same parameter list.
31533152
*/
3154-
private def paramDependencyStatus(implicit ctx: Context): DependencyStatus = {
3153+
private def paramDependencyStatus(implicit ctx: Context): DependencyStatus =
31553154
if (myParamDependencyStatus != Unknown) myParamDependencyStatus
31563155
else {
31573156
val result =
@@ -3160,7 +3159,6 @@ object Types {
31603159
if ((result & Provisional) == 0) myParamDependencyStatus = result
31613160
(result & StatusMask).toByte
31623161
}
3163-
}
31643162

31653163
/** Does result type contain references to parameters of this method type,
31663164
* which cannot be eliminated by de-aliasing?
@@ -4722,7 +4720,7 @@ object Types {
47224720
* If the expansion is a wildcard parameter reference, convert its
47234721
* underlying bounds to a range, otherwise return the expansion.
47244722
*/
4725-
def expandParam(tp: NamedType, pre: Type): Type = {
4723+
def expandParam(tp: NamedType, pre: Type): Type =
47264724
tp.argForParam(pre) match {
47274725
case arg @ TypeRef(pre, _) if pre.isArgPrefixOf(arg.symbol) =>
47284726
arg.info match {
@@ -4732,7 +4730,6 @@ object Types {
47324730
case arg: TypeBounds => expandBounds(arg)
47334731
case arg => reapply(arg)
47344732
}
4735-
}
47364733

47374734
/** Derived selection.
47384735
* @pre the (upper bound of) prefix `pre` has a member named `tp.name`.
@@ -4858,9 +4855,8 @@ object Types {
48584855
if (underlying.isBottomType) underlying
48594856
else tp.derivedAnnotatedType(underlying, annot)
48604857
}
4861-
override protected def derivedWildcardType(tp: WildcardType, bounds: Type): WildcardType = {
4858+
override protected def derivedWildcardType(tp: WildcardType, bounds: Type): WildcardType =
48624859
tp.derivedWildcardType(rangeToBounds(bounds))
4863-
}
48644860

48654861
override protected def derivedSkolemType(tp: SkolemType, info: Type): Type = info match {
48664862
case Range(lo, hi) =>

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,8 @@ object Completion {
293293
addMember(imp.site, name.toTypeName, nameInScope.toTypeName)
294294
}
295295
imp.reverseMapping.foreachBinding { (nameInScope, original) =>
296-
if (original != nameInScope || !imp.excluded.contains(original)) {
296+
if (original != nameInScope || !imp.excluded.contains(original))
297297
addImport(original, nameInScope)
298-
}
299298
}
300299
if (imp.isWildcardImport)
301300
for (mbr <- accessibleMembers(imp.site) if !imp.excluded.contains(mbr.name.toTermName))

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
236236
for {
237237
tastySuffix <- tastySuffixes
238238
if name.endsWith(tastySuffix)
239-
} {
239+
}
240+
{
240241
buffer += dir.relativize(path).toString.replace("/", ".").stripSuffix(tastySuffix).toTypeName
241242
}
242243
}

0 commit comments

Comments
 (0)