Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the most up-to-date analysis for binary to source class name lookup #1287

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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