Skip to content

Commit

Permalink
Use the most up-to-date analysis for binary source lookup
Browse files Browse the repository at this point in the history
Remove internalBinaryToSourceClassName altogether

Remove internalSourceToClassNamesMap too

Strengthen empty-package test

Call checkDependencies properly

It seems that in other exams, a previous compile immediately before is required

Strengthened empty-package properly, along with comments explaining why it is being done
  • Loading branch information
Friendseeker committed Dec 6, 2023
1 parent ead41be commit d7a1ace
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ object Incremental {
log.debug(s"[zinc] IncrementalCompile -----------")
val previous = previous0 match { case a: Analysis => a }
val currentStamper = Stamps.initial(stamper)
val internalBinaryToSourceClassName = (binaryClassName: String) =>
previous.relations.productClassName.reverse(binaryClassName).headOption
val internalSourceToClassNamesMap: VirtualFile => Set[String] = (f: VirtualFile) =>
previous.relations.classNames(f)

val earlyJar = extractEarlyJar(earlyOutput)
val pickleJarPair = earlyJar.map { p =>
Expand Down Expand Up @@ -183,8 +179,6 @@ object Incremental {
runProfiler.timeCompilation(startTime, System.nanoTime() - startTime)
},
new AnalysisCallback.Builder(
internalBinaryToSourceClassName,
internalSourceToClassNamesMap,
lookup.lookupAnalyzedClass(_, _),
currentStamper,
options,
Expand Down Expand Up @@ -250,13 +244,7 @@ object Incremental {
log.debug("[zinc] compileAllJava")
val previous = previous0 match { case a: Analysis => a }
val currentStamper = Stamps.initial(stamper)
val internalBinaryToSourceClassName = (binaryClassName: String) =>
previous.relations.productClassName.reverse(binaryClassName).headOption
val internalSourceToClassNamesMap: VirtualFile => Set[String] =
(f: VirtualFile) => previous.relations.classNames(f)
val builder = new AnalysisCallback.Builder(
internalBinaryToSourceClassName,
internalSourceToClassNamesMap,
lookup.lookupAnalyzedClass(_, _),
currentStamper,
options,
Expand Down Expand Up @@ -537,8 +525,6 @@ private object AnalysisCallback {

/** Allow creating new callback instance to be used in each compile iteration */
class Builder(
internalBinaryToSourceClassName: String => Option[String],
internalSourceToClassNamesMap: VirtualFile => Set[String],
externalAPI: (String, Option[VirtualFileRef]) => Option[AnalyzedClass],
stampReader: ReadStamps,
options: IncOptions,
Expand All @@ -560,9 +546,14 @@ private object AnalysisCallback {
def build(): AnalysisCallback = buildImpl(None)

private def buildImpl(incHandlerOpt: Option[Incremental.IncrementalCallback]) = {
val previousAnalysisOpt = incHandlerOpt.map(_.previousAnalysisPruned)
val binaryToSourceLookup: String => Option[String] = previousAnalysisOpt match {
case Some(analysis) => (binaryClassName: String) =>
analysis.relations.productClassName.reverse(binaryClassName).headOption
case None => _ => None
}
new AnalysisCallback(
internalBinaryToSourceClassName,
internalSourceToClassNamesMap,
binaryToSourceLookup,
externalAPI,
stampReader,
options,
Expand All @@ -585,7 +576,6 @@ private object AnalysisCallback {

private final class AnalysisCallback(
internalBinaryToSourceClassName: String => Option[String],
internalSourceToClassNamesMap: VirtualFile => Set[String],
externalAPI: (String, Option[VirtualFileRef]) => Option[AnalyzedClass],
stampReader: ReadStamps,
options: IncOptions,
Expand Down
8 changes: 7 additions & 1 deletion zinc/src/sbt-test/source-dependencies/empty-package/test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ $ copy-file changes/Use.scala Use.scala
> compile

$ copy-file changes/Define2.scala Define.scala
> compile

# We usually call `compile` right before a checkDependencies call
# However, as per https://github.com/sbt/zinc/pull/1287#issue-2010864729
# The check would be too late to catch the missing dependency between a.Use and pkgName.Test
# As invalidateInitial introduces library dependency between a.Use and pkgName.Test

> checkDependencies a.Use: pkgName.Test

$ delete Define.scala
-> compile
Expand Down

0 comments on commit d7a1ace

Please sign in to comment.