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

[1.x] Local dependency invalidation improvement #1528

Open
wants to merge 1 commit into
base: 1.10.x
Choose a base branch
from
Open
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 @@ -98,7 +98,6 @@ private[inc] abstract class IncrementalCommon(
invalidatedSources,
classfileManager,
pruned,
previous,
classesToRecompile,
profiler.registerCycle(
invalidatedClasses,
Expand Down Expand Up @@ -149,11 +148,11 @@ private[inc] abstract class IncrementalCommon(
invalidatedSources: Set[VirtualFile],
classFileManager: XClassFileManager,
pruned: Analysis,
override val previousAnalysis: Analysis,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change relevant to the fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, my thinking was to clean up as this parameter that was not necessary and introduced the confusion by duplication of parameters previous in CycleState vs previousAnalysis here.

classesToRecompile: Set[String],
registerCycle: (Set[String], APIChanges, Set[String], Boolean) => Unit
) extends IncrementalCallback(classFileManager) {
override val isFullCompilation: Boolean = allSources.subsetOf(invalidatedSources)
override val previousAnalysis: Analysis = previous
override val previousAnalysisPruned: Analysis = pruned

override def mergeAndInvalidate(
Expand All @@ -165,10 +164,12 @@ private[inc] abstract class IncrementalCommon(
partialAnalysis.copy(compilations = pruned.compilations ++ partialAnalysis.compilations)
else pruned ++ partialAnalysis

// Represents classes detected as changed externally and internally (by a previous cycle)
// Represents all classes that were compiled as a result of external and internal invalidation (by a previous cycle)
// Maps the changed sources by the user to class names we can count as invalidated
val getClasses = (a: Analysis) => initialChangedSources.flatMap(a.relations.classNames)
val recompiledClasses = classesToRecompile ++ getClasses(previous) ++ getClasses(analysis)
val recompiledClasses = classesToRecompile ++
getClasses(previous) ++ getClasses(analysis) ++
invalidatedSources.flatMap(previous.relations.classNames)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense.


val newApiChanges =
detectAPIChanges(recompiledClasses, previous.apis.internalAPI, analysis.apis.internalAPI)
Expand Down Expand Up @@ -501,13 +502,14 @@ private[inc] abstract class IncrementalCommon(
Set.empty
} else {
if (invalidateTransitively) {
val firstClassTransitiveInvalidation = includeTransitiveInitialInvalidations(
initial,
IncrementalCommon.transitiveDeps(initial, log)(dependsOnClass),
dependsOnClass
)
// NOTE: As member reference relations do not include local relations, this invalidation will fully propagate
// thus we can't rely solely on `firstClassTransitiveInvalidation`. Better bet is to try to find transitive
// dependencies from result of `firstClassInvalidation`
val firstClassTransitiveInvalidation =
IncrementalCommon.transitiveDeps(firstClassInvalidation, log)(dependsOnClass)
log.debug("Invalidate by brute force:\n\t" + firstClassTransitiveInvalidation)
firstClassTransitiveInvalidation ++ secondClassInvalidation ++ thirdClassInvalidation ++ recompiledClasses
firstClassInvalidation ++ firstClassTransitiveInvalidation ++ secondClassInvalidation ++
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think of it, it may actually be enough to have
firstClassTransitiveInvalidation ++ secondClassInvalidation ++ thirdClassInvalidation ++ recompiledClasses as firstClassTransitiveInvalidations is now computed from firstClassInvalidation

thirdClassInvalidation ++ recompiledClasses
} else {
firstClassInvalidation ++ secondClassInvalidation ++ thirdClassInvalidation
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ trait Relations {
private[inc] def externalDependencies: ExternalDependencies

/**
* The class dependency relation between classes introduced by member reference.
* The class dependency relation between classes introduced by member reference excluding local references
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Zinc, the term local often means within the same subproject, i.e. local-to-Analysis, so "excluding same-source references" might be less ambiguous.

*
* NOTE: All inheritance dependencies are included in this relation because in order to
* inherit from a member you have to refer to it. If you check documentation of `inheritance`
* you'll see that there's small oddity related to traits being the first parent of a
* class/trait that results in additional parents being introduced due to normalization.
* This relation properly accounts for that so the invariant that `memberRef` is a superset
*
* Because `inheritance` includes local relations, `memberRef` is not a superset of `inheritance`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

* of `inheritance` is preserved.
*/
private[inc] def memberRef: ClassDependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait A {
def buildNonemptyObjects(a: Int): Int = a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Main extends App {
val x: C = new C { }
val z: Int = x.x
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait C extends B {
def x = something
}
trait B extends A {
def something = buildNonemptyObjects(5)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trait A {
// change return type Int => String
def buildNonemptyObjects(a: Int): String = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait A {
def buildNonemptyObjects(a: Int): Int = a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transitiveStep = 3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transitiveStep = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
##################### FAILURE ############################
# clean build that compiles with transitiveStep = 1
> compile

# incremental build that should fail with transitiveStep = 1
$ copy-file changes/A.scala A.scala
-> compile

##################### FAILURE ############################

# rerun the test with transitiveStep = 3
> clean
$ copy-file changes/OriginalA.scala A.scala
$ copy-file changes/incOptions.properties incOptions.properties

# clean build that compiles with transitiveStep = 3
> compile

# incremental build that should fail with transitiveStep = 3
$ copy-file changes/A.scala A.scala
-> compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object A {
def buildNonemptyObjects(a: Int): Int = a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Main extends App {
val z: Int = C.x
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object C {
def x = B.something
}

object B {
def something = A.buildNonemptyObjects(5)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object A {
// change return type Int => String
def buildNonemptyObjects(a: Int): String = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object A {
def buildNonemptyObjects(a: Int): Int = a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object A {
// add default param
def buildNonemptyObjects(a: Int, b: Int = 5): Int = a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transitiveStep = 3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transitiveStep = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
##################### SUCCESS ############################
# clean build that compiles with transitiveStep = 1
> compile

# incremental build that should work with transitiveStep = 1
$ copy-file changes/WorkingA.scala A.scala
> compile
# > checkIterations 2 this is not yet working, but it should be 2

##################### FAILURE ############################

# clean build that compiles with transitiveStep = 1
> clean
$ copy-file changes/OriginalA.scala A.scala
> compile

# incremental build that should fail with transitiveStep = 1
$ copy-file changes/A.scala A.scala
-> compile

##################### FAILURE ############################

# rerun the test with transitiveStep = 3
> clean
$ copy-file changes/OriginalA.scala A.scala
$ copy-file changes/incOptions.properties incOptions.properties

# clean build that compiles with transitiveStep = 3
> compile

# incremental build that should fail with transitiveStep = 3
$ copy-file changes/A.scala A.scala
-> compile
Loading