Skip to content

Commit 0b8923e

Browse files
committed
Remove stale ClassToSourceMapper functions
And inline the actual used function in the companion of `IncrementalCommon`, with a better and simpler implementation.
1 parent 2dc226d commit 0b8923e

2 files changed

Lines changed: 28 additions & 102 deletions

File tree

internal/zinc-core/src/main/scala/sbt/internal/inc/ClassToSourceMapper.scala

Lines changed: 0 additions & 90 deletions
This file was deleted.

internal/zinc-core/src/main/scala/sbt/internal/inc/IncrementalCommon.scala

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ package inc
1111

1212
import java.io.File
1313

14-
import xsbti.api.{ AnalyzedClass, DefinitionType }
14+
import xsbt.api.APIUtil
15+
import xsbti.api.AnalyzedClass
1516
import xsbti.compile.{
1617
Changes,
1718
CompileAnalysis,
@@ -33,8 +34,6 @@ private[inc] abstract class IncrementalCommon(val log: sbt.util.Logger, options:
3334
val wrappedLog = new Incremental.PrefixingLogger("[inv] ")(log)
3435
def debug(s: => String) = if (options.relationsDebug) wrappedLog.debug(s) else ()
3536

36-
// TODO: the Analysis for the last successful compilation should get returned + Boolean indicating success
37-
// TODO: full external name changes, scopeInvalidations
3837
@tailrec final def cycle(invalidatedRaw: Set[String],
3938
modifiedSrcs: Set[File],
4039
allSources: Set[File],
@@ -76,14 +75,13 @@ private[inc] abstract class IncrementalCommon(val log: sbt.util.Logger, options:
7675

7776
debug("\nChanges:\n" + incChanges)
7877
val transitiveStep = options.transitiveStep
79-
val classToSourceMapper = new ClassToSourceMapper(previous.relations, current.relations)
8078
val incrementallyInvalidated = invalidateIncremental(
8179
current.relations,
82-
current.apis,
8380
incChanges,
8481
recompiledClasses,
8582
cycleNum >= transitiveStep,
86-
classToSourceMapper.isDefinedInScalaSrc)
83+
IncrementalCommon.comesFromScalaSource(previous.relations, Some(current.relations))
84+
)
8785
val allInvalidated =
8886
if (lookup.shouldDoIncrementalCompilation(incrementallyInvalidated, current))
8987
incrementallyInvalidated
@@ -260,7 +258,6 @@ private[inc] abstract class IncrementalCommon(val log: sbt.util.Logger, options:
260258
}
261259

262260
def invalidateIncremental(previous: Relations,
263-
apis: APIs,
264261
changes: APIChanges,
265262
recompiledClasses: Set[String],
266263
transitive: Boolean,
@@ -322,11 +319,11 @@ private[inc] abstract class IncrementalCommon(val log: sbt.util.Logger, options:
322319
val invalidatedClasses = removedClasses ++ dependentOnRemovedClasses ++ modifiedClasses
323320
val byProduct = changes.removedProducts.flatMap(previous.produced)
324321
val byBinaryDep = changes.binaryDeps.flatMap(previous.usesLibrary)
325-
val classToSrc = new ClassToSourceMapper(previous, previous)
326-
val byExtSrcDep = {
327-
//changes.external.modified.flatMap(previous.usesExternal) // ++ scopeInvalidations
328-
invalidateByAllExternal(previous, changes.external, classToSrc.isDefinedInScalaSrc)
329-
}
322+
val byExtSrcDep = invalidateByAllExternal(
323+
previous,
324+
changes.external,
325+
IncrementalCommon.comesFromScalaSource(previous)
326+
)
330327

331328
checkAbsolute(addedSrcs.toList)
332329

@@ -502,3 +499,22 @@ private[inc] abstract class IncrementalCommon(val log: sbt.util.Logger, options:
502499
xs.toSet
503500
}
504501
}
502+
503+
object IncrementalCommon {
504+
505+
/** Tell if given class names comes from a Scala source file or not by inspecting relations. */
506+
def comesFromScalaSource(
507+
previous: Relations,
508+
current: Option[Relations] = None
509+
)(className: String): Boolean = {
510+
val previousSourcesWithClassName = previous.classes.reverse(className)
511+
val newSourcesWithClassName = current.map(_.classes.reverse(className)).getOrElse(Set.empty)
512+
if (previousSourcesWithClassName.isEmpty && newSourcesWithClassName.isEmpty)
513+
sys.error(s"Fatal Zinc error: no entry for class $className in classes relation.")
514+
else {
515+
// Makes sure that the dependency doesn't possibly come from Java
516+
previousSourcesWithClassName.forall(src => APIUtil.isScalaSourceName(src.getName)) &&
517+
newSourcesWithClassName.forall(src => APIUtil.isScalaSourceName(src.getName))
518+
}
519+
}
520+
}

0 commit comments

Comments
 (0)