From d7a1aceaf7a4b377b293a55ffc049ccc49645e62 Mon Sep 17 00:00:00 2001 From: friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Sat, 25 Nov 2023 18:16:10 -0800 Subject: [PATCH] Use the most up-to-date analysis for binary source lookup 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 --- .../scala/sbt/internal/inc/Incremental.scala | 24 ++++++------------- .../source-dependencies/empty-package/test | 8 ++++++- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/internal/zinc-core/src/main/scala/sbt/internal/inc/Incremental.scala b/internal/zinc-core/src/main/scala/sbt/internal/inc/Incremental.scala index 853e7e4207..ef511be607 100644 --- a/internal/zinc-core/src/main/scala/sbt/internal/inc/Incremental.scala +++ b/internal/zinc-core/src/main/scala/sbt/internal/inc/Incremental.scala @@ -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 => @@ -183,8 +179,6 @@ object Incremental { runProfiler.timeCompilation(startTime, System.nanoTime() - startTime) }, new AnalysisCallback.Builder( - internalBinaryToSourceClassName, - internalSourceToClassNamesMap, lookup.lookupAnalyzedClass(_, _), currentStamper, options, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/zinc/src/sbt-test/source-dependencies/empty-package/test b/zinc/src/sbt-test/source-dependencies/empty-package/test index 718e7f1259..8ba3b31bf5 100644 --- a/zinc/src/sbt-test/source-dependencies/empty-package/test +++ b/zinc/src/sbt-test/source-dependencies/empty-package/test @@ -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