Skip to content

Commit e1dcf7f

Browse files
committed
Support name table sharing across Global instances
- Add UI to enable name table sharing - Expose name table caching through PipelineMain
1 parent d28a129 commit e1dcf7f

File tree

4 files changed

+186
-102
lines changed

4 files changed

+186
-102
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import io.{AbstractFile, Path, SourceReader}
2323
import reporters.Reporter
2424
import util.{ClassPath, returning}
2525
import scala.reflect.ClassTag
26+
import scala.reflect.internal.{NameTable, Names}
2627
import scala.reflect.internal.util.{BatchSourceFile, FreshNameCreator, NoSourceFile, ScalaClassLoader, ScriptSourceFile, SourceFile, StatisticsStatics}
2728
import scala.reflect.internal.pickling.PickleBuffer
2829
import symtab.{Flags, SymbolTable, SymbolTrackers}
@@ -35,7 +36,6 @@ import transform.patmat.PatternMatching
3536
import transform._
3637
import backend.{JavaPlatform, ScalaPrimitives}
3738
import backend.jvm.{BackendStats, GenBCode}
38-
import scala.concurrent.Future
3939
import scala.language.postfixOps
4040
import scala.tools.nsc.ast.{TreeGen => AstTreeGen}
4141
import scala.tools.nsc.classpath._
@@ -59,6 +59,13 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
5959

6060
override def isCompilerUniverse = true
6161
override val useOffsetPositions = !currentSettings.Yrangepos
62+
override protected def newNameTable: NameTable[this.type] = {
63+
if (currentSettings.YcacheNameTable) {
64+
val NoFiles = Nil
65+
Global.nameTableCache.getOrCreate(NoFiles, () => new NameTable[Names.dummyNamesInstance.type](synchronizeNames = true, Names.dummyNamesInstance), closeableRegistry, checkStamps = true).asInstanceOf[NameTable[this.type]]
66+
}
67+
else super.newNameTable
68+
}
6269

6370
type RuntimeClass = java.lang.Class[_]
6471
implicit val RuntimeClassTag: ClassTag[RuntimeClass] = ClassTag[RuntimeClass](classOf[RuntimeClass])
@@ -1736,4 +1743,7 @@ object Global {
17361743
override def keepsTypeParams = false
17371744
def run() { throw new Error("InitPhase.run") }
17381745
}
1746+
1747+
// TODO factor reference counting caching out of FileBasedCache for use in spots like this.
1748+
private val nameTableCache = new FileBasedCache[NameTable[_]]
17391749
}

src/compiler/scala/tools/nsc/PipelineMain.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,13 @@ class PipelineMainClass(label: String, parallelism: Int, strategy: BuildStrategy
382382

383383
val cacheMacro = java.lang.Boolean.getBoolean("scala.pipeline.cache.macro.classloader")
384384
val cachePlugin = java.lang.Boolean.getBoolean("scala.pipeline.cache.plugin.classloader")
385+
val cacheNameTable = java.lang.Boolean.getBoolean("scala.pipeline.cache.name.table")
385386
if (cacheMacro)
386387
command.settings.YcacheMacroClassLoader.value = "always"
387388
if (cachePlugin)
388389
command.settings.YcachePluginClassLoader.value = "always"
390+
if (cacheNameTable)
391+
command.settings.YcacheNameTable.value = true
389392

390393
if (strategy != Traditional) {
391394
command.settings.YpickleJava.value = true

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ trait ScalaSettings extends AbsScalaSettings
244244
val YpartialUnification = BooleanSetting ("-Ypartial-unification", "Enable partial unification in type constructor inference")
245245
val Yvirtpatmat = BooleanSetting ("-Yvirtpatmat", "Enable pattern matcher virtualization")
246246
val Youtline = BooleanSetting ("-Youtline", "Don't compile method bodies. Use together with `-Ystop-afer:pickler to generate the pickled signatures for all source files.").internalOnly()
247+
val YcacheNameTable = BooleanSetting ("-Ycache-name-table", "Share a single name table for concurrently running instances of the compiler")
247248

248249
val exposeEmptyPackage = BooleanSetting ("-Yexpose-empty-package", "Internal only: expose the empty package.").internalOnly()
249250
val Ydelambdafy = ChoiceSetting ("-Ydelambdafy", "strategy", "Strategy used for translating lambdas into JVM code.", List("inline", "method"), "method")

0 commit comments

Comments
 (0)