From 6b69732bffc71459dbaeebb7a679df9980e68340 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Thu, 10 May 2018 19:17:40 +0200 Subject: [PATCH] Turn SymbolLoaders into an object The extra flexibility of a class isn't useful here and leads to worse code being generated (e.g. it requires PackageLoader to carry an outer accessor). --- compiler/src/dotty/tools/dotc/config/JavaPlatform.scala | 2 +- compiler/src/dotty/tools/dotc/core/Contexts.scala | 3 --- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 2 +- compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala | 9 +++------ .../tools/dotc/core/classfile/ClassfileParser.scala | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala b/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala index 08a67ab3d1f0..f0db0deafb6d 100644 --- a/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala +++ b/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala @@ -35,7 +35,7 @@ class JavaPlatform extends Platform { currentClassPath = Some(subst.getOrElse(cp, cp)) } - def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = new ctx.base.loaders.PackageLoader(root, classPath) + def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = new SymbolLoaders.PackageLoader(root, classPath) /** Is the SAMType `cls` also a SAM under the rules of the JVM? */ def isSam(cls: ClassSymbol)(implicit ctx: Context): Boolean = diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index f00cb5c9050e..18d7ea10e061 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -551,9 +551,6 @@ object Contexts { /** The initial context */ val initialCtx: Context = new InitialContext(this, settings) - /** The symbol loaders */ - val loaders = new SymbolLoaders - /** The platform, initialized by `initPlatform()`. */ private[this] var _platform: Platform = _ diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index af680510de14..269b44c0f859 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -377,7 +377,7 @@ object SymDenotations { * Right now, the only usage is for the AnyRef alias in Definitions. */ final private[core] def currentPackageDecls(implicit ctx: Context): MutableScope = myInfo match { - case pinfo: SymbolLoaders # PackageLoader => pinfo.currentDecls + case pinfo: SymbolLoaders.PackageLoader => pinfo.currentDecls case _ => unforcedDecls.openForMutations } diff --git a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala index 40c3bce68592..e8e5e926c95d 100644 --- a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -19,17 +19,14 @@ import parsing.Parsers.OutlineParser import reporting.trace object SymbolLoaders { + import ast.untpd._ + /** A marker trait for a completer that replaces the original * Symbol loader for an unpickled root. */ trait SecondCompleter -} - -/** A base class for Symbol loaders with some overridable behavior */ -class SymbolLoaders { - import ast.untpd._ - protected def enterNew( + private def enterNew( owner: Symbol, member: Symbol, completer: SymbolLoader, scope: Scope = EmptyScope)(implicit ctx: Context): Symbol = { val comesFromScan = diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 2898db135a3b..00e73fcd4d1e 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -703,7 +703,7 @@ class ClassfileParser( } def enterClassAndModule(entry: InnerClassEntry, file: AbstractFile, jflags: Int) = { - ctx.base.loaders.enterClassAndModule( + SymbolLoaders.enterClassAndModule( getOwner(jflags), entry.originalName, new ClassfileLoader(file),