Skip to content

Commit

Permalink
Merge pull request sbt#821 from dwijnand/use-Ypickle-write
Browse files Browse the repository at this point in the history
Replace PickleData with -Ypickle-write
  • Loading branch information
eed3si9n authored Jul 10, 2020
2 parents c5ad959 + 7dc3198 commit 564e484
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 374 deletions.
4 changes: 0 additions & 4 deletions internal/compiler-bridge/src/main/scala/xsbt/API.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ final class API(val global: CallbackGlobal) extends Compat with GlobalHelpers wi
val start = System.currentTimeMillis
super.run()

// We're running right after pickling, so store pickles now.
val pickleData = Compat.picklePaths(currentRun)
callback.pickleData(pickleData.toArray)

// After processing all units, register generated classes
registerGeneratedClasses(nonLocalClassSymbolsInCurrentUnits.iterator)
nonLocalClassSymbolsInCurrentUnits.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package xsbt

import java.io.PrintWriter
import java.nio.file.Path
import xsbti.compile.{ Output, PickleData }
import xsbti.compile.Output
import scala.reflect.{ internal => sri }
import scala.reflect.internal.{ util => sriu }
import scala.reflect.io.AbstractFile
Expand Down Expand Up @@ -190,9 +190,6 @@ object Compat {
}

def plainNioFile(path: Path): AbstractFile = new PlainNioFile(path)

// No pileline pickling in 2.10
def picklePaths(run: Global#Run) = Iterable.empty[PickleData]
}

private trait CachedCompilerCompat { self: CachedCompiler0 =>
Expand Down
38 changes: 3 additions & 35 deletions internal/compiler-bridge/src/main/scala_2.11-12/xsbt/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
package xsbt

import java.io.PrintWriter
import java.nio.file.{ Path, Paths }
import xsbti.compile.{ Output, PickleData }
import scala.collection.mutable
import scala.tools.nsc.{ Global, Settings }
import java.nio.file.Path
import xsbti.compile.Output
import scala.tools.nsc.Settings
import scala.reflect.io.AbstractFile

abstract class Compat
Expand All @@ -29,37 +28,6 @@ object Compat {
def replReporter(settings: Settings, writer: PrintWriter) = writer

def plainNioFile(path: Path): AbstractFile = new PlainNioFile(path)

// Prepare pickle data for eventual storage, computing path within jar file from symbol ownership
// and storing data in a class that does not rely on a shared scala library.
// This is almost verbatim copied from scala.tools.nsc.PipelineMain, except that actually writing to the jar file
// is deferred to AnalysisCallback, after the final incremental compilation cycle.
def picklePaths[G <: Global](run: G#Run): Iterable[PickleData] = {
val rootPath = Paths.get("__ROOT__")
val dirs = mutable.Map[G#Symbol, Path]()
def packageDir(packSymbol: G#Symbol): Path = {
if (packSymbol.isEmptyPackageClass) rootPath
else if (dirs.contains(packSymbol)) dirs(packSymbol)
else if (packSymbol.owner.isRoot) {
val subDir = rootPath.resolve(packSymbol.encodedName)
dirs.put(packSymbol, subDir)
subDir
} else {
val base = packageDir(packSymbol.owner)
val subDir = base.resolve(packSymbol.encodedName)
dirs.put(packSymbol, subDir)
subDir
}
}

for { (s, p) <- run.symData } yield {
val base = packageDir(s.owner)
val path = base.resolve(s.encodedName + ".sig")
// val path = symToPath(s,true)
val fqcn = s.fullNameString
PickleData.of(p, fqcn, p.bytes, p.writeIndex, path)
}
}
}

/** Defines compatibility utils for [[ZincCompiler]]. */
Expand Down
38 changes: 3 additions & 35 deletions internal/compiler-bridge/src/main/scala_2.13/xsbt/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
package xsbt

import java.io.PrintWriter
import java.nio.file.{ Path, Paths }
import xsbti.compile.{ Output, PickleData }
import scala.tools.nsc.{ Global, Settings }
import java.nio.file.Path
import xsbti.compile.Output
import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.shell.ReplReporterImpl
import scala.reflect.io.AbstractFile
import scala.collection.mutable

abstract class Compat
object Compat {
Expand All @@ -31,37 +30,6 @@ object Compat {
new ReplReporterImpl(settings, writer)

def plainNioFile(path: Path): AbstractFile = new PlainNioFile(path)

// Prepare pickle data for eventual storage, computing path within jar file from symbol ownership
// and storing data in a class that does not rely on a shared scala library.
// This is almost verbatim copied from scala.tools.nsc.PipelineMain, except that actually writing to the jar file
// is deferred to AnalysisCallback, after the final incremental compilation cycle.
def picklePaths[G <: Global](run: G#Run): Iterable[PickleData] = {
val rootPath = Paths.get("__ROOT__")
val dirs = mutable.Map[G#Symbol, Path]()
def packageDir(packSymbol: G#Symbol): Path = {
if (packSymbol.isEmptyPackageClass) rootPath
else if (dirs.contains(packSymbol)) dirs(packSymbol)
else if (packSymbol.owner.isRoot) {
val subDir = rootPath.resolve(packSymbol.encodedName)
dirs.put(packSymbol, subDir)
subDir
} else {
val base = packageDir(packSymbol.owner)
val subDir = base.resolve(packSymbol.encodedName)
dirs.put(packSymbol, subDir)
subDir
}
}

for { (s, p) <- run.symData } yield {
val base = packageDir(s.owner)
val path = base.resolve(s.encodedName + ".sig")
// val path = symToPath(s,true)
val fqcn = s.fullNameString
PickleData.of(p, fqcn, p.bytes, p.writeIndex, path)
}
}
}

/** Defines compatibility utils for [[ZincCompiler]]. */
Expand Down

This file was deleted.

11 changes: 0 additions & 11 deletions internal/compiler-interface/src/main/contraband/pickle.contra

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package xsbti;

import xsbti.api.DependencyContext;
import xsbti.compile.PickleData;

import java.io.File;
import java.nio.file.Path;
Expand Down Expand Up @@ -205,11 +204,6 @@ void problem(String what,
*/
java.util.Set<String> classesInOutputJar();

/**
* Pass new pickle data as of this point.
*/
void pickleData(PickleData[] data);

/**
* Returns true if -Ypickle-java is on.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import sbt.internal.inc.Analysis.{ LocalProduct, NonLocalProduct }
import sbt.util.{ InterfaceUtil, Level, Logger }
import sbt.util.InterfaceUtil.jo2o
import scala.collection.JavaConverters._
import scala.collection.mutable
import xsbti.{ FileConverter, Position, Problem, Severity, UseScope, VirtualFile, VirtualFileRef }
import xsbt.api.{ APIUtil, HashAPI, NameHashing }
import xsbti.api._
Expand All @@ -32,7 +31,6 @@ import xsbti.compile.{
IncOptions,
MiniSetup,
Output,
PickleData,
ClassFileManager => XClassFileManager
}
import xsbti.compile.analysis.{ ReadStamps, Stamp => XStamp }
Expand Down Expand Up @@ -479,7 +477,6 @@ private final class AnalysisCallback(
// Results of invalidation calculations (including whether to continue cycles) - the analysis at this point is
// not useful and so isn't included.
private[this] var invalidationResults: Option[CompileCycleResult] = None
private[this] val pklData: mutable.ArrayBuffer[PickleData] = new mutable.ArrayBuffer()

private def add[A, B](map: TrieMap[A, ConcurrentSet[B]], a: A, b: B): Unit = {
map.getOrElseUpdate(a, ConcurrentHashMap.newKeySet[B]()).add(b)
Expand Down Expand Up @@ -835,12 +832,6 @@ private final class AnalysisCallback(
outputJarContent.get().asJava
}

override def pickleData(data: Array[PickleData]): Unit = {
if (options.pipelining && data.nonEmpty) {
pklData ++= data
}
}

def hasAnyMacro(merged: Analysis): Boolean =
merged.apis.internal.values.exists(p => p.hasMacro)

Expand All @@ -859,7 +850,7 @@ private final class AnalysisCallback(
val knownProducts = merged.relations.allSources
.flatMap(merged.relations.products)
.flatMap(extractProductPath)
PickleJar.write(pickleJarPath, pklData, knownProducts, currentSetup.compilerVersion, log)
PickleJar.write(pickleJarPath, knownProducts.toSet)
}
progress foreach { p =>
p.earlyOutputComplete(true)
Expand Down
Loading

0 comments on commit 564e484

Please sign in to comment.