Skip to content

Commit 6def08e

Browse files
committed
remove resident compiler code
The infrastructure for resident compilation still exists, but the actual scalac-side code that was backported is removed. Future work on using a resident scalac will use that invalidation code directly from scalac anyway.
1 parent d6b5485 commit 6def08e

File tree

1 file changed

+10
-176
lines changed

1 file changed

+10
-176
lines changed

compile/interface/src/main/scala/xsbt/CompilerInterface.scala

Lines changed: 10 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,18 @@ private final class CachedCompiler0(args: Array[String], output: Output, initial
103103
{
104104
debug(log, args.mkString("Calling Scala compiler with arguments (CompilerInterface):\n\t", "\n\t", ""))
105105
compiler.set(callback, dreporter)
106-
try {
107-
val run = new compiler.Run with compiler.RunCompat {
108-
override def informUnitStarting(phase: Phase, unit: compiler.CompilationUnit) {
109-
compileProgress.startUnit(phase.name, unit.source.path)
110-
}
111-
override def progress(current: Int, total: Int) {
112-
if (!compileProgress.advance(current, total))
113-
cancel
114-
}
106+
val run = new compiler.Run with compiler.RunCompat {
107+
override def informUnitStarting(phase: Phase, unit: compiler.CompilationUnit) {
108+
compileProgress.startUnit(phase.name, unit.source.path)
109+
}
110+
override def progress(current: Int, total: Int) {
111+
if (!compileProgress.advance(current, total))
112+
cancel
115113
}
116-
if (resident) compiler.reload(changes)
117-
val sortedSourceFiles = sources.map(_.getAbsolutePath).sortWith(_ < _)
118-
run compile sortedSourceFiles
119-
processUnreportedWarnings(run)
120-
} finally {
121-
if(resident) compiler.clear()
122114
}
115+
val sortedSourceFiles = sources.map(_.getAbsolutePath).sortWith(_ < _)
116+
run compile sortedSourceFiles
117+
processUnreportedWarnings(run)
123118
dreporter.problems foreach { p => callback.problem(p.category, p.position, p.message, p.severity, true) }
124119
}
125120
dreporter.printSummary()
@@ -219,7 +214,6 @@ private final class CachedCompiler0(args: Array[String], output: Output, initial
219214
def clear()
220215
{
221216
callback0 = null
222-
atPhase(currentRun.namerPhase) { forgetAll() }
223217
superDropRun()
224218
reporter = null
225219
}
@@ -237,168 +231,8 @@ private final class CachedCompiler0(args: Array[String], output: Output, initial
237231
def findOnClassPath(name: String): Option[AbstractFile] =
238232
classPath.findClass(name).flatMap(_.binary.asInstanceOf[Option[AbstractFile]])
239233

240-
override def registerTopLevelSym(sym: Symbol) = toForget += sym
241-
242-
final def unlinkAll(m: Symbol) {
243-
val scope = m.owner.info.decls
244-
scope unlink m
245-
scope unlink m.companionSymbol
246-
}
247-
248-
def forgetAll()
249-
{
250-
for(sym <- toForget)
251-
unlinkAll(sym)
252-
toForget = mutable.Set()
253-
}
254234

255-
// fine-control over external changes is unimplemented:
256-
// must drop whole CachedCompiler when !changes.isEmpty
257-
def reload(changes: DependencyChanges)
258-
{
259-
for ((_,out) <- settings.outputDirs.outputs) inv(out.path)
260-
}
261-
262-
private[this] var toForget = mutable.Set[Symbol]()
263235
private[this] var callback0: AnalysisCallback = null
264236
def callback: AnalysisCallback = callback0
265-
266-
private[this] def defaultClasspath = new PathResolver(settings).result
267-
268-
// override defaults in order to inject a ClassPath that can change
269-
override lazy val platform = new PlatformImpl
270-
override lazy val classPath = if(resident) classPathCell else defaultClasspath
271-
private[this] lazy val classPathCell = new ClassPathCell(defaultClasspath)
272-
273-
final class PlatformImpl extends JavaPlatform
274-
{
275-
val global: Compiler.this.type = Compiler.this
276-
// This can't be overridden to provide a ClassPathCell, so we have to fix it to the initial classpath
277-
// This is apparently never called except by rootLoader, so we can return the default and warn if someone tries to use it.
278-
override lazy val classPath = {
279-
if(resident)
280-
compiler.warning("platform.classPath should not be called because it is incompatible with sbt's resident compilation. Use Global.classPath")
281-
defaultClasspath
282-
}
283-
override def rootLoader = if(resident) newPackageLoaderCompat(rootLoader)(compiler.classPath) else super.rootLoader
284-
}
285-
286-
private[this] type PlatformClassPath = ClassPath[AbstractFile]
287-
private[this] type OptClassPath = Option[PlatformClassPath]
288-
289-
// converted from Martin's new code in scalac for use in 2.8 and 2.9
290-
private[this] def inv(path: String)
291-
{
292-
classPathCell.delegate match {
293-
case cp: util.MergedClassPath[_] =>
294-
val dir = AbstractFile getDirectory path
295-
val canonical = dir.file.getCanonicalPath
296-
def matchesCanonicalCompat(e: ClassPath[_]) = e.origin.exists { opath =>
297-
(AbstractFile getDirectory opath).file.getCanonicalPath == canonical
298-
}
299-
300-
cp.entries find matchesCanonicalCompat match {
301-
case Some(oldEntry) =>
302-
val newEntry = cp.context.newClassPath(dir)
303-
classPathCell.updateClassPath(oldEntry, newEntry)
304-
reSyncCompat(definitions.RootClass, Some(classPath), Some(oldEntry), Some(newEntry))
305-
case None =>
306-
error("Cannot invalidate: no entry named " + path + " in classpath " + classPath)
307-
}
308-
}
309-
}
310-
private def reSyncCompat(root: ClassSymbol, allEntries: OptClassPath, oldEntry: OptClassPath, newEntry: OptClassPath)
311-
{
312-
val getName: PlatformClassPath => String = (_.name)
313-
def hasClasses(cp: OptClassPath) = cp.exists(_.classes.nonEmpty)
314-
def invalidateOrRemove(root: ClassSymbol) =
315-
allEntries match {
316-
case Some(cp) => root setInfo newPackageLoader0[Type](cp)
317-
case None => root.owner.info.decls unlink root.sourceModule
318-
}
319-
320-
def packageNames(cp: PlatformClassPath): Set[String] = cp.packages.toSet map getName
321-
def subPackage(cp: PlatformClassPath, name: String): OptClassPath =
322-
cp.packages find (_.name == name)
323-
324-
val classesFound = hasClasses(oldEntry) || hasClasses(newEntry)
325-
if (classesFound && !isSystemPackageClass(root)) {
326-
invalidateOrRemove(root)
327-
} else {
328-
if (classesFound && root.isRoot)
329-
invalidateOrRemove(definitions.EmptyPackageClass.asInstanceOf[ClassSymbol])
330-
(oldEntry, newEntry) match {
331-
case (Some(oldcp) , Some(newcp)) =>
332-
for (pstr <- packageNames(oldcp) ++ packageNames(newcp)) {
333-
val pname = newTermName(pstr)
334-
var pkg = root.info decl pname
335-
if (pkg == NoSymbol) {
336-
// package was created by external agent, create symbol to track it
337-
assert(!subPackage(oldcp, pstr).isDefined)
338-
pkg = enterPackageCompat(root, pname, newPackageLoader0[loaders.SymbolLoader](allEntries.get))
339-
}
340-
reSyncCompat(
341-
pkg.moduleClass.asInstanceOf[ClassSymbol],
342-
subPackage(allEntries.get, pstr), subPackage(oldcp, pstr), subPackage(newcp, pstr))
343-
}
344-
case (Some(oldcp), None) => invalidateOrRemove(root)
345-
case (None, Some(newcp)) => invalidateOrRemove(root)
346-
case (None, None) => ()
347-
}
348-
}
349-
}
350-
private[this] def enterPackageCompat(root: ClassSymbol, pname: Name, completer: loaders.SymbolLoader): Symbol =
351-
{
352-
val pkg = root.newPackage(pname)
353-
pkg.moduleClass.setInfo(completer)
354-
pkg.setInfo(pkg.moduleClass.tpe)
355-
root.info.decls.enter(pkg)
356-
pkg
357-
}
358-
359-
// type parameter T, `dummy` value for inference, and reflection are source compatibility hacks
360-
// to work around JavaPackageLoader and PackageLoader changes between 2.9 and 2.10
361-
// and in particular not being able to say JavaPackageLoader in 2.10 in a compatible way (it no longer exists)
362-
private[this] def newPackageLoaderCompat[T](dummy: => T)(classpath: ClassPath[AbstractFile]): T =
363-
newPackageLoader0[T](classpath)
364-
365-
private[this] def newPackageLoader0[T](classpath: ClassPath[AbstractFile]): T =
366-
loaderClassCompat.getConstructor(classOf[SymbolLoaders], classOf[ClassPath[AbstractFile]]).newInstance(loaders, classpath).asInstanceOf[T]
367-
368-
private[this] lazy val loaderClassCompat: Class[_] =
369-
try Class.forName("scala.tools.nsc.symtab.SymbolLoaders$JavaPackageLoader")
370-
catch { case e: Exception =>
371-
Class.forName("scala.tools.nsc.symtab.SymbolLoaders$PackageLoader")
372-
}
373-
374-
private[this] implicit def newPackageCompat(s: ClassSymbol): NewPackageCompat = new NewPackageCompat(s)
375-
private[this] final class NewPackageCompat(s: ClassSymbol) {
376-
def newPackage(name: Name): Symbol = s.newPackage(NoPosition, name)
377-
def newPackage(pos: Position, name: Name): Nothing = throw new RuntimeException("source compatibility only")
378-
}
379-
private[this] def isSystemPackageClass(pkg: Symbol) =
380-
pkg == definitions.RootClass ||
381-
pkg == definitions.ScalaPackageClass || {
382-
val pkgname = pkg.fullName
383-
(pkgname startsWith "scala.") && !(pkgname startsWith "scala.tools")
384-
}
385-
386-
final class ClassPathCell[T](var delegate: MergedClassPath[T]) extends ClassPath[T] {
387-
private[this] class DeltaClassPath[T](original: MergedClassPath[T], oldEntry: ClassPath[T], newEntry: ClassPath[T])
388-
extends MergedClassPath[T](original.entries map (e => if (e == oldEntry) newEntry else e), original.context)
389-
390-
def updateClassPath(oldEntry: ClassPath[T], newEntry: ClassPath[T]) {
391-
delegate = new DeltaClassPath(delegate, oldEntry, newEntry)
392-
}
393-
394-
def name = delegate.name
395-
override def origin = delegate.origin
396-
def asURLs = delegate.asURLs
397-
def asClasspathString = delegate.asClasspathString
398-
def context = delegate.context
399-
def classes = delegate.classes
400-
def packages = delegate.packages
401-
def sourcepaths = delegate.sourcepaths
402-
}
403237
}
404238
}

0 commit comments

Comments
 (0)