Skip to content

Commit 09dbfc2

Browse files
author
Abel Nieto
committed
Pre-calculate the set of wrapXArray methods in Definitions
1 parent 7e18110 commit 09dbfc2

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import scala.collection.{ mutable, immutable }
99
import PartialFunction._
1010
import collection.mutable
1111
import util.common.alwaysZero
12+
import dotty.tools.dotc.transform.TreeGen
1213

1314
object Definitions {
1415

@@ -338,6 +339,12 @@ class Definitions {
338339
def Predef_classOf(implicit ctx: Context) = Predef_classOfR.symbol
339340
lazy val Predef_undefinedR = ScalaPredefModule.requiredMethodRef("???")
340341
def Predef_undefined(implicit ctx: Context) = Predef_undefinedR.symbol
342+
// The set of all wrap{X, Ref}Array methods, where X is a value type
343+
lazy val Predef_wrapArrayR: Set[TermRef] = {
344+
val methodNames = ScalaValueTypes.map(TreeGen.wrapArrayMethodName) + nme.wrapRefArray
345+
methodNames.map(ScalaPredefModule.requiredMethodRef).toSet
346+
}
347+
def Predef_wrapArray(implicit ctx: Context): Set[Symbol] = Predef_wrapArrayR.map(_.symbol)
341348

342349
lazy val ScalaRuntimeModuleRef = ctx.requiredModuleRef("scala.runtime.ScalaRunTime")
343350
def ScalaRuntimeModule(implicit ctx: Context) = ScalaRuntimeModuleRef.symbol

compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
9494
private def seqToArray(tree: Tree, pt: Type)(implicit ctx: Context): Tree = tree match {
9595
case SeqLiteral(elems, elemtpt) =>
9696
JavaSeqLiteral(elems, elemtpt)
97-
case app@Apply(fun, args) if isWrappedArray(app) => // rewrite a call to `wrapXArray(arr)` to `arr`
97+
case app@Apply(fun, args) if defn.Predef_wrapArray.contains(fun.symbol) => // rewrite a call to `wrapXArray(arr)` to `arr`
9898
args.head
9999
case _ =>
100100
val elemType = tree.tpe.elemType
@@ -108,14 +108,6 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
108108
// Because of phantomclasses, the Java array's type might not conform to the return type
109109
}
110110

111-
/** Determines whether `tree` is a method call to Predef.wrapXArray */
112-
private def isWrappedArray(tree: Apply)(implicit ctx: Context): Boolean = {
113-
val elemTpe = tree.tpe.elemType
114-
val wrapMethodName = TreeGen.wrapArrayMethodName(elemTpe)
115-
val wrapMethodSym = defn.ScalaPredefModuleRef.denot.requiredMethod(wrapMethodName)
116-
tree.fun.symbol == wrapMethodSym
117-
}
118-
119111
override def transformTypeApply(tree: TypeApply)(implicit ctx: Context): Tree =
120112
transformTypeOfTree(tree)
121113

0 commit comments

Comments
 (0)