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

Encode parent trait private members in extraHash to propagate TraitPrivateMembersModified across external dependency #1289

Merged
merged 2 commits into from
Nov 28, 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 @@ -82,6 +82,8 @@ object Incremental {

def previousAnalysisPruned: Analysis

def previousAnalysis: Analysis

/**
* @return true when the compilation cycle is compiling all the sources; false, otherwise.
*/
Expand Down Expand Up @@ -885,7 +887,18 @@ private final class AnalysisCallback(
case d @ (DefinitionType.ClassDef | DefinitionType.Trait) =>
val extraApiHash = {
if (d != DefinitionType.Trait) apiHash
else HashAPI(_.hashAPI(classApi), includePrivateDefsInTrait = true)
else {
val currentExtraHash = HashAPI(_.hashAPI(classApi), includePrivateDefsInTrait = true)
incHandlerOpt match {
case Some(handler) =>
val analysis = handler.previousAnalysis
val parents = analysis.relations.inheritance.external.forward(className)
val parentsAPI = parents.map(analysis.apis.externalAPI)
val parentsHashes = parentsAPI.map(_.extraHash())
parentsHashes.fold(currentExtraHash)(_ ^ _)
case None => currentExtraHash
}
}
}

classApis(className) = ApiInfo(apiHash, extraApiHash, savedClassApi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private[inc] abstract class IncrementalCommon(
invalidatedSources,
classfileManager,
pruned,
previous,
classesToRecompile,
profiler.registerCycle(
invalidatedClasses,
Expand Down Expand Up @@ -148,6 +149,7 @@ private[inc] abstract class IncrementalCommon(
invalidatedSources: Set[VirtualFile],
classFileManager: XClassFileManager,
pruned: Analysis,
override val previousAnalysis: Analysis,
classesToRecompile: Set[String],
registerCycle: (Set[String], APIChanges, Set[String], Boolean) => Unit
) extends IncrementalCallback(classFileManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ case class ProjectStructure(
compile(i).map { analysis =>
discoverMainClasses(Some(analysis.apis)) match {
case Seq(mainClassName) =>
val cp = ((i.si.allJars.map(_.toPath) :+ classesDir) ++ outputJar).map(_.toAbsolutePath)
val jars = i.si.allJars.map(_.toPath)
val cp = (jars ++ (unmanagedJars :+ output) ++ internalClasspath).map(_.toAbsolutePath)
val loader = ClasspathUtil.makeLoader(cp, i.si, baseDirectory)
val buffer = new ByteArrayOutputStream(8192)
val oldOut = System.out
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package a

trait A {
private val a1: String = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package a

trait A {
private val a2: String = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package b

trait B extends a.A
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"projects": [
{"name": "main", "dependsOn": ["a", "b","c"], "scalaVersion": "2.13.12"},
{"name": "c", "dependsOn": ["a","b"], "scalaVersion": "2.13.12"},
{"name": "b", "dependsOn": ["a"], "scalaVersion": "2.13.12"},
{"name": "a", "scalaVersion": "2.13.12"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package c

class C extends b.B
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Main extends App {
val impl = new c.C()
println("OK")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> main/run
$ copy-file a/changes/A.scala a/A.scala
> main/run