Skip to content

Commit f20f92a

Browse files
Merge pull request #4312 from dotty-staging/cleanup-megamorphic-calls-3
Remove some implicit conversions
2 parents f39943d + a55dae9 commit f20f92a

29 files changed

+164
-166
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ compiler/test/debug/Gen.jar
7171

7272
compiler/before-pickling.txt
7373
compiler/after-pickling.txt
74+
bench/compile.txt
7475
*.dotty-ide-version
7576

7677
*.decompiled.out

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
365365
def getAnnotPickle(jclassName: String, sym: Symbol): Option[Annotation] = None
366366

367367

368-
def getRequiredClass(fullname: String): Symbol = ctx.requiredClass(fullname.toTermName)
368+
def getRequiredClass(fullname: String): Symbol = ctx.requiredClass(fullname)
369369

370370
def getClassIfDefined(fullname: String): Symbol = NoSymbol // used only for android. todo: implement
371371

@@ -375,12 +375,12 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
375375
}
376376

377377
def requiredClass[T](implicit evidence: ClassTag[T]): Symbol =
378-
ctx.requiredClass(erasureString(evidence.runtimeClass).toTermName)
378+
ctx.requiredClass(erasureString(evidence.runtimeClass))
379379

380380
def requiredModule[T](implicit evidence: ClassTag[T]): Symbol = {
381381
val moduleName = erasureString(evidence.runtimeClass)
382382
val className = if (moduleName.endsWith("$")) moduleName.dropRight(1) else moduleName
383-
ctx.requiredModule(className.toTermName)
383+
ctx.requiredModule(className)
384384
}
385385

386386

@@ -1193,8 +1193,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11931193
val arity = field.meth.tpe.widenDealias.paramTypes.size - _1.size
11941194
val returnsUnit = field.meth.tpe.widenDealias.resultType.classSymbol == UnitClass
11951195
if (returnsUnit)
1196-
ctx.requiredClass(("scala.compat.java8.JProcedure" + arity).toTermName)
1197-
else ctx.requiredClass(("scala.compat.java8.JFunction" + arity).toTermName)
1196+
ctx.requiredClass(("scala.compat.java8.JProcedure" + arity))
1197+
else ctx.requiredClass(("scala.compat.java8.JFunction" + arity))
11981198
}
11991199
}
12001200
}

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
4444
*/
4545
protected[this] def rootContext(implicit ctx: Context): Context = {
4646
ctx.initialize()(ctx)
47-
ctx.setPhasePlan(comp.phases)
47+
ctx.base.setPhasePlan(comp.phases)
4848
val rootScope = new MutableScope
4949
val bootstrap = ctx.fresh
5050
.setPeriod(Period(comp.nextRunId, FirstPhaseId))
@@ -149,7 +149,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
149149

150150
protected def compileUnits()(implicit ctx: Context) = Stats.maybeMonitored {
151151
if (!ctx.mode.is(Mode.Interactive)) // IDEs might have multi-threaded access, accesses are synchronized
152-
ctx.checkSingleThreaded()
152+
ctx.base.checkSingleThreaded()
153153

154154
compiling = true
155155

@@ -158,16 +158,16 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
158158
if (ctx.settings.YtestPickler.value) List("pickler")
159159
else ctx.settings.YstopAfter.value
160160

161-
val pluginPlan = ctx.addPluginPhases(ctx.phasePlan)
162-
val phases = ctx.squashPhases(pluginPlan,
161+
val pluginPlan = ctx.addPluginPhases(ctx.base.phasePlan)
162+
val phases = ctx.base.squashPhases(pluginPlan,
163163
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
164-
ctx.usePhases(phases)
164+
ctx.base.usePhases(phases)
165165

166166
def runPhases(implicit ctx: Context) = {
167167
var lastPrintedTree: PrintedTree = NoPrintedTree
168168
val profiler = ctx.profiler
169169

170-
for (phase <- ctx.allPhases)
170+
for (phase <- ctx.base.allPhases)
171171
if (phase.isRunnable)
172172
Stats.trackTime(s"$phase ms ") {
173173
val start = System.currentTimeMillis
@@ -228,7 +228,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
228228
private def printTree(last: PrintedTree)(implicit ctx: Context): PrintedTree = {
229229
val unit = ctx.compilationUnit
230230
val prevPhase = ctx.phase.prev // can be a mini-phase
231-
val squashedPhase = ctx.squashed(prevPhase)
231+
val squashedPhase = ctx.base.squashed(prevPhase)
232232
val treeString = unit.tpdTree.show(ctx.withProperty(XprintMode, Some(())))
233233

234234
ctx.echo(s"result of $unit after $squashedPhase:")
@@ -274,4 +274,4 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
274274
myUnits = null
275275
myUnitsCached = null
276276
}
277-
}
277+
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ object Trees {
7979
/** The type constructor at the root of the tree */
8080
type ThisTree[T >: Untyped] <: Tree[T]
8181

82-
private[this] var myTpe: T = _
82+
protected var myTpe: T @uncheckedVariance = _
8383

8484
/** Destructively set the type of the tree. This should be called only when it is known that
8585
* it is safe under sharing to do so. One use-case is in the withType method below
@@ -92,7 +92,7 @@ object Trees {
9292
/** The type of the tree. In case of an untyped tree,
9393
* an UnAssignedTypeException is thrown. (Overridden by empty trees)
9494
*/
95-
def tpe: T @uncheckedVariance = {
95+
final def tpe: T @uncheckedVariance = {
9696
if (myTpe == null)
9797
throw new UnAssignedTypeException(this)
9898
myTpe
@@ -756,7 +756,6 @@ object Trees {
756756
}
757757

758758
trait WithoutTypeOrPos[-T >: Untyped] extends Tree[T] {
759-
override def tpe: T @uncheckedVariance = NoType.asInstanceOf[T]
760759
override def withTypeUnchecked(tpe: Type) = this.asInstanceOf[ThisTree[Type]]
761760
override def pos = NoPosition
762761
override def setPos(pos: Position) = {}
@@ -769,6 +768,8 @@ object Trees {
769768
*/
770769
case class Thicket[-T >: Untyped](trees: List[Tree[T]])
771770
extends Tree[T] with WithoutTypeOrPos[T] {
771+
myTpe = NoType.asInstanceOf[T]
772+
772773
type ThisTree[-T >: Untyped] = Thicket[T]
773774
override def isEmpty: Boolean = trees.isEmpty
774775
override def toList: List[Tree[T]] = flatten(trees)
@@ -787,6 +788,7 @@ object Trees {
787788

788789
class EmptyValDef[T >: Untyped] extends ValDef[T](
789790
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T]) with WithoutTypeOrPos[T] {
791+
myTpe = NoType.asInstanceOf[T]
790792
override def isEmpty: Boolean = true
791793
setMods(untpd.Modifiers(PrivateLocal))
792794
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
7070
override private[dotty] def list(inPackage: String): ClassPathEntries = {
7171
val (packages, classesAndSources) = aggregates.map { cp =>
7272
try {
73-
cp.list(inPackage)
73+
cp.list(inPackage).toTuple
7474
} catch {
7575
case ex: java.io.IOException =>
7676
val e = new FatalError(ex.getMessage)

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ package dotty.tools.dotc.classpath
66
import dotty.tools.io.AbstractFile
77
import dotty.tools.io.ClassRepresentation
88

9-
case class ClassPathEntries(packages: Seq[PackageEntry], classesAndSources: Seq[ClassRepresentation])
10-
11-
object ClassPathEntries {
12-
import scala.language.implicitConversions
13-
// to have working unzip method
14-
implicit def entry2Tuple(entry: ClassPathEntries): (Seq[PackageEntry], Seq[ClassRepresentation]) = (entry.packages, entry.classesAndSources)
9+
case class ClassPathEntries(packages: Seq[PackageEntry], classesAndSources: Seq[ClassRepresentation]) {
10+
def toTuple = (packages, classesAndSources)
1511
}
1612

1713
trait ClassFileEntry extends ClassRepresentation {

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,32 @@ object Contexts {
428428
"Context(\n" +
429429
(outersIterator map ( ctx => s" owner = ${ctx.owner}, scope = ${ctx.scope}, import = ${iinfo(ctx)}") mkString "\n")
430430
}
431+
432+
def typerPhase = base.typerPhase
433+
def sbtExtractDependenciesPhase = base.sbtExtractDependenciesPhase
434+
def picklerPhase = base.picklerPhase
435+
def refchecksPhase = base.refchecksPhase
436+
def patmatPhase = base.patmatPhase
437+
def elimRepeatedPhase = base.elimRepeatedPhase
438+
def extensionMethodsPhase = base.extensionMethodsPhase
439+
def explicitOuterPhase = base.explicitOuterPhase
440+
def gettersPhase = base.gettersPhase
441+
def erasurePhase = base.erasurePhase
442+
def elimErasedValueTypePhase = base.elimErasedValueTypePhase
443+
def lambdaLiftPhase = base.lambdaLiftPhase
444+
def flattenPhase = base.flattenPhase
445+
def genBCodePhase = base.genBCodePhase
446+
def phases = base.phases
447+
448+
def settings = base.settings
449+
def definitions = base.definitions
450+
def platform = base.platform
451+
def pendingUnderlying = base.pendingUnderlying
452+
def uniqueNamedTypes = base.uniqueNamedTypes
453+
def uniques = base.uniques
454+
def nextId = base.nextId
455+
456+
def initialize()(implicit ctx: Context) = base.initialize()(ctx)
431457
}
432458

433459
/** A condensed context provides only a small memory footprint over
@@ -520,7 +546,7 @@ object Contexts {
520546
/** A class defining the initial context with given context base
521547
* and set of possible settings.
522548
*/
523-
private class InitialContext(val base: ContextBase, settings: SettingGroup) extends FreshContext {
549+
private class InitialContext(val base: ContextBase, settingsGroup: SettingGroup) extends FreshContext {
524550
outer = NoContext
525551
period = InitialPeriod
526552
mode = Mode.None
@@ -529,7 +555,7 @@ object Contexts {
529555
tree = untpd.EmptyTree
530556
typeAssigner = TypeAssigner
531557
moreProperties = Map.empty
532-
store = initialStore.updated(settingsStateLoc, settings.defaultState)
558+
store = initialStore.updated(settingsStateLoc, settingsGroup.defaultState)
533559
typeComparer = new TypeComparer(this)
534560
searchHistory = new SearchHistory(0, Map())
535561
gadt = EmptyGADTMap
@@ -684,17 +710,6 @@ object Contexts {
684710
else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase")
685711
}
686712

687-
object Context {
688-
689-
/** Implicit conversion that injects all printer operations into a context */
690-
implicit def toPrinter(ctx: Context): Printer = ctx.printer
691-
692-
/** implicit conversion that injects all ContextBase members into a context */
693-
implicit def toBase(ctx: Context): ContextBase = ctx.base
694-
695-
// @sharable val theBase = new ContextBase // !!! DEBUG, so that we can use a minimal context for reporting even in code that normally cannot access a context
696-
}
697-
698713
class GADTMap(initBounds: SimpleIdentityMap[Symbol, TypeBounds]) extends util.DotClass {
699714
private[this] var myBounds = initBounds
700715
def setBounds(sym: Symbol, b: TypeBounds): Unit =

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,19 @@ class Definitions {
188188
}
189189

190190
lazy val RootClass: ClassSymbol = ctx.newPackageSymbol(
191-
NoSymbol, nme.ROOT, (root, rootcls) => ctx.rootLoader(root)).moduleClass.asClass
191+
NoSymbol, nme.ROOT, (root, rootcls) => ctx.base.rootLoader(root)).moduleClass.asClass
192192
lazy val RootPackage: TermSymbol = ctx.newSymbol(
193193
NoSymbol, nme.ROOTPKG, PackageCreationFlags, TypeRef(NoPrefix, RootClass))
194194

195195
lazy val EmptyPackageVal = ctx.newPackageSymbol(
196-
RootClass, nme.EMPTY_PACKAGE, (emptypkg, emptycls) => ctx.rootLoader(emptypkg)).entered
196+
RootClass, nme.EMPTY_PACKAGE, (emptypkg, emptycls) => ctx.base.rootLoader(emptypkg)).entered
197197
lazy val EmptyPackageClass = EmptyPackageVal.moduleClass.asClass
198198

199199
/** A package in which we can place all methods that are interpreted specially by the compiler */
200200
lazy val OpsPackageVal = ctx.newCompletePackageSymbol(RootClass, nme.OPS_PACKAGE).entered
201201
lazy val OpsPackageClass = OpsPackageVal.moduleClass.asClass
202202

203-
lazy val ScalaPackageVal = ctx.requiredPackage("scala")
203+
lazy val ScalaPackageVal = ctx.requiredPackage(nme.scala_)
204204
lazy val ScalaMathPackageVal = ctx.requiredPackage("scala.math")
205205
lazy val ScalaPackageClass = {
206206
val cls = ScalaPackageVal.moduleClass.asClass
@@ -211,8 +211,8 @@ class Definitions {
211211
cls
212212
}
213213
lazy val ScalaPackageObjectRef = ctx.requiredModuleRef("scala.package")
214-
lazy val JavaPackageVal = ctx.requiredPackage("java")
215-
lazy val JavaLangPackageVal = ctx.requiredPackage("java.lang")
214+
lazy val JavaPackageVal = ctx.requiredPackage(nme.java)
215+
lazy val JavaLangPackageVal = ctx.requiredPackage(jnme.JavaLang)
216216
// fundamental modules
217217
lazy val SysPackage = ctx.requiredModule("scala.sys.package")
218218
lazy val Sys_errorR = SysPackage.moduleClass.requiredMethodRef(nme.error)
@@ -342,11 +342,11 @@ class Definitions {
342342

343343
lazy val Predef_ConformsR = ScalaPredefModule.requiredClass("<:<").typeRef
344344
def Predef_Conforms(implicit ctx: Context) = Predef_ConformsR.symbol
345-
lazy val Predef_conformsR = ScalaPredefModule.requiredMethodRef("$conforms")
345+
lazy val Predef_conformsR = ScalaPredefModule.requiredMethodRef(nme.conforms_)
346346
def Predef_conforms(implicit ctx: Context) = Predef_conformsR.symbol
347-
lazy val Predef_classOfR = ScalaPredefModule.requiredMethodRef("classOf")
347+
lazy val Predef_classOfR = ScalaPredefModule.requiredMethodRef(nme.classOf)
348348
def Predef_classOf(implicit ctx: Context) = Predef_classOfR.symbol
349-
lazy val Predef_undefinedR = ScalaPredefModule.requiredMethodRef("???")
349+
lazy val Predef_undefinedR = ScalaPredefModule.requiredMethodRef(nme.???)
350350
def Predef_undefined(implicit ctx: Context) = Predef_undefinedR.symbol
351351

352352
lazy val ScalaRuntimeModuleRef = ctx.requiredModuleRef("scala.runtime.ScalaRunTime")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object DenotTransformers {
2222
trait DenotTransformer extends Phase {
2323

2424
/** The last phase during which the transformed denotations are valid */
25-
def lastPhaseId(implicit ctx: Context) = ctx.nextDenotTransformerId(id + 1)
25+
def lastPhaseId(implicit ctx: Context) = ctx.base.nextDenotTransformerId(id + 1)
2626

2727
/** The validity period of the transformed denotations in the given context */
2828
def validFor(implicit ctx: Context): Period =

0 commit comments

Comments
 (0)