Skip to content

Commit cf54051

Browse files
Adress review
1 parent f824164 commit cf54051

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/Devalify.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import core.Types._
1010
import ast.Trees._
1111
import scala.collection.mutable
1212
import config.Printers.simplify
13-
import Simplify.{desugarIdent, isMutable}
13+
import Simplify.{desugarIdent, isEffectivelyMutable}
1414
import transform.SymUtils._
1515

1616
/** Inline vals and remove vals that are aliases to other vals
@@ -201,7 +201,7 @@ class Devalify extends Optimisation {
201201
readingOnlyVals(rec)
202202
else false
203203

204-
case t @ Select(qual, _) if !isMutable(t) =>
204+
case t @ Select(qual, _) if !isEffectivelyMutable(t) =>
205205
readingOnlyVals(qual)
206206

207207
case t: Ident if !t.symbol.is(Mutable | Method) && !t.symbol.info.dealias.isInstanceOf[ExprType] =>

compiler/src/dotty/tools/dotc/transform/localopt/DropGoodCasts.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import core.Types._
1010
import core.Flags._
1111
import ast.Trees._
1212
import transform.SymUtils._
13-
import Simplify.isMutable
13+
import Simplify.isEffectivelyMutable
1414

1515
/** Eliminated casts and equality tests whose results can be locally
1616
* determined at compile time:
@@ -78,7 +78,7 @@ import Simplify.isMutable
7878

7979
case TypeApply(fun @ Select(x, _), List(tp))
8080
if fun.symbol.eq(defn.Any_isInstanceOf) &&
81-
!isMutable(x) &&
81+
!isEffectivelyMutable(x) &&
8282
!x.symbol.is(Method) &&
8383
x.symbol.exists && !x.symbol.owner.isClass =>
8484
(x.symbol, tp.tpe) :: Nil
@@ -99,7 +99,7 @@ import Simplify.isMutable
9999

100100
case Apply(fun @ Select(x, _), List(tp))
101101
if fun.symbol.eq(defn.Object_ne) &&
102-
!isMutable(x) &&
102+
!isEffectivelyMutable(x) &&
103103
!x.symbol.is(Method) &&
104104
x.symbol.exists && !x.symbol.owner.isClass =>
105105
x.symbol :: Nil

compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ object Simplify {
147147
}
148148
}
149149

150-
// System.in is static final fields that, for legacy reasons, must be
151-
// allowed to be changed by the methods System.setIn. `isMutable` is true
152-
// is the field is Mutable or if it's a field of java.lang.System.
153-
// https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.4
154-
def isMutable(t: Tree)(implicit ctx: Context): Boolean = t match {
150+
/** Is this tree mutable, or java.lang.System.{in, out, err}? These three
151+
* System members are the only static final fields that are mutable.
152+
* See https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.4
153+
*/
154+
def isEffectivelyMutable(t: Tree)(implicit ctx: Context): Boolean = t match {
155155
case _ if t.symbol.is(Mutable) => true
156-
case s: Symbol => (s.symbol == defn.SystemModule)
157-
case i: Ident => desugarIdent(i).exists(isMutable)
156+
case s: Select => (s.symbol == defn.SystemModule)
157+
case i: Ident => desugarIdent(i).exists(isEffectivelyMutable)
158158
case _ => false
159159
}
160160
}

docs/docs/reference/optimisations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ title: "Local Optimisations"
55

66
The Dotty compiler implements several local optimisations to generate faster bytecode. These optimisations can be enabled by compiling with the `-optimise` flag. The current best source of documentation about what tree transformations are performed under `-optimise` is the Scaladoc classes in the [localopt package](https://github.com/lampepfl/dotty/tree/master/compiler/src/dotty/tools/dotc/transform/localopt).
77

8-
Local optimisations assumes no use of Java Reflection to mutate static final fields.
8+
Local optimisations assumes no use of Java Reflection to mutate final fields.

0 commit comments

Comments
 (0)