clean up incremental debugging messages

This commit is contained in:
Mark Harrah 2011-05-29 19:17:31 -04:00
parent a94247d1b6
commit 437a3f7f50
4 changed files with 29 additions and 24 deletions

View File

@ -9,12 +9,12 @@ import java.io.File
object IncrementalCompile object IncrementalCompile
{ {
def apply(sources: Set[File], entry: String => Option[File], compile: (Set[File], xsbti.AnalysisCallback) => Unit, previous: Analysis, forEntry: File => Option[Analysis], outputPath: File): (Boolean, Analysis) = def apply(sources: Set[File], entry: String => Option[File], compile: (Set[File], xsbti.AnalysisCallback) => Unit, previous: Analysis, forEntry: File => Option[Analysis], outputPath: File, log: Logger): (Boolean, Analysis) =
{ {
val current = Stamps.initial(Stamp.exists, Stamp.hash, Stamp.lastModified) val current = Stamps.initial(Stamp.exists, Stamp.hash, Stamp.lastModified)
val internalMap = (f: File) => previous.relations.produced(f).headOption val internalMap = (f: File) => previous.relations.produced(f).headOption
val externalAPI = getExternalAPI(entry, forEntry) val externalAPI = getExternalAPI(entry, forEntry)
Incremental.compile(sources, entry, previous, current, forEntry, doCompile(compile, internalMap, externalAPI, current, outputPath)) Incremental.compile(sources, entry, previous, current, forEntry, doCompile(compile, internalMap, externalAPI, current, outputPath), log)
} }
def doCompile(compile: (Set[File], xsbti.AnalysisCallback) => Unit, internalMap: File => Option[File], externalAPI: (File, String) => Option[Source], current: ReadStamps, outputPath: File) = (srcs: Set[File]) => { def doCompile(compile: (Set[File], xsbti.AnalysisCallback) => Unit, internalMap: File => Option[File], externalAPI: (File, String) => Option[Source], current: ReadStamps, outputPath: File) = (srcs: Set[File]) => {
val callback = new AnalysisCallback(internalMap, externalAPI, current, outputPath) val callback = new AnalysisCallback(internalMap, externalAPI, current, outputPath)

View File

@ -12,19 +12,18 @@ import java.io.File
object Incremental object Incremental
{ {
def debug(s: => String) = if(java.lang.Boolean.getBoolean("xsbt.inc.debug")) println(s) else () def debug(s: => String) = if(java.lang.Boolean.getBoolean("xsbt.inc.debug")) println(s) else ()
def compile(sources: Set[File], entry: String => Option[File], previous: Analysis, current: ReadStamps, forEntry: File => Option[Analysis], doCompile: Set[File] => Analysis)(implicit equivS: Equiv[Stamp]): (Boolean, Analysis) = def compile(sources: Set[File], entry: String => Option[File], previous: Analysis, current: ReadStamps, forEntry: File => Option[Analysis], doCompile: Set[File] => Analysis, log: Logger)(implicit equivS: Equiv[Stamp]): (Boolean, Analysis) =
{ {
val initialChanges = changedInitial(entry, sources, previous, current, forEntry) val initialChanges = changedInitial(entry, sources, previous, current, forEntry)
debug("Initial changes: " + initialChanges) val initialInv = invalidateInitial(previous.relations, initialChanges, log)
val initialInv = invalidateInitial(previous.relations, initialChanges) log.debug("Initially invalidated: " + initialInv)
debug("Initially invalidated: " + initialInv) val analysis = cycle(initialInv, previous, doCompile, log)
val analysis = cycle(initialInv, previous, doCompile)
(!initialInv.isEmpty, analysis) (!initialInv.isEmpty, analysis)
} }
// TODO: the Analysis for the last successful compilation should get returned + Boolean indicating success // TODO: the Analysis for the last successful compilation should get returned + Boolean indicating success
// TODO: full external name changes, scopeInvalidations // TODO: full external name changes, scopeInvalidations
def cycle(invalidated: Set[File], previous: Analysis, doCompile: Set[File] => Analysis): Analysis = def cycle(invalidated: Set[File], previous: Analysis, doCompile: Set[File] => Analysis, log: Logger): Analysis =
if(invalidated.isEmpty) if(invalidated.isEmpty)
previous previous
else else
@ -37,9 +36,9 @@ object Incremental
debug("********* Merged: \n" + merged.relations + "\n*********") debug("********* Merged: \n" + merged.relations + "\n*********")
val incChanges = changedIncremental(invalidated, previous.apis.internalAPI _, merged.apis.internalAPI _) val incChanges = changedIncremental(invalidated, previous.apis.internalAPI _, merged.apis.internalAPI _)
debug("Changes:\n" + incChanges) debug("Changes:\n" + incChanges)
val incInv = invalidateIncremental(merged.relations, incChanges, invalidated) val incInv = invalidateIncremental(merged.relations, incChanges, invalidated, log)
debug("Incrementally invalidated: " + incInv) log.debug("Incrementally invalidated: " + incInv)
cycle(incInv, merged, doCompile) cycle(incInv, merged, doCompile, log)
} }
@ -84,9 +83,9 @@ object Incremental
val (changed, unmodified) = inBoth.partition(existingModified) val (changed, unmodified) = inBoth.partition(existingModified)
} }
def invalidateIncremental(previous: Relations, changes: APIChanges[File], recompiledSources: Set[File]): Set[File] = def invalidateIncremental(previous: Relations, changes: APIChanges[File], recompiledSources: Set[File], log: Logger): Set[File] =
{ {
val inv = invalidateTransitive(previous.usesInternalSrc _, changes.modified )// ++ scopeInvalidations(previous.extAPI _, changes.modified, changes.names) val inv = invalidateTransitive(previous.usesInternalSrc _, changes.modified, log)// ++ scopeInvalidations(previous.extAPI _, changes.modified, changes.names)
if((inv -- recompiledSources).isEmpty) Set.empty else inv if((inv -- recompiledSources).isEmpty) Set.empty else inv
} }
@ -96,26 +95,32 @@ object Incremental
(modified flatMap dependsOnSrc) -- modified (modified flatMap dependsOnSrc) -- modified
/** Invalidates transitive source dependencies including `modified`. It excludes any sources that were recompiled during the previous run.*/ /** Invalidates transitive source dependencies including `modified`. It excludes any sources that were recompiled during the previous run.*/
@tailrec def invalidateTransitive(dependsOnSrc: File => Set[File], modified: Set[File]): Set[File] = @tailrec def invalidateTransitive(dependsOnSrc: File => Set[File], modified: Set[File], log: Logger): Set[File] =
{ {
val newInv = invalidateDirect(dependsOnSrc, modified) val newInv = invalidateDirect(dependsOnSrc, modified)
debug("\tInvalidated direct: " + newInv) log.debug("\tInvalidated direct: " + newInv)
if(newInv.isEmpty) modified else invalidateTransitive(dependsOnSrc, modified ++ newInv) if(newInv.isEmpty) modified else invalidateTransitive(dependsOnSrc, modified ++ newInv, log)
} }
/** Invalidates sources based on initially detected 'changes' to the sources, products, and dependencies.*/ /** Invalidates sources based on initially detected 'changes' to the sources, products, and dependencies.*/
def invalidateInitial(previous: Relations, changes: InitialChanges): Set[File] = def invalidateInitial(previous: Relations, changes: InitialChanges, log: Logger): Set[File] =
{ {
val srcChanges = changes.internalSrc val srcChanges = changes.internalSrc
debug("Initial source changes: \n\tremoved:" + srcChanges.removed + "\n\tadded: " + srcChanges.added + "\n\tmodified: " + srcChanges.changed)
val srcDirect = srcChanges.removed ++ srcChanges.removed.flatMap(previous.usesInternalSrc) ++ srcChanges.added ++ srcChanges.changed val srcDirect = srcChanges.removed ++ srcChanges.removed.flatMap(previous.usesInternalSrc) ++ srcChanges.added ++ srcChanges.changed
debug("Initial source direct: " + srcDirect)
val byProduct = changes.removedProducts.flatMap(previous.produced) val byProduct = changes.removedProducts.flatMap(previous.produced)
debug("Initial by product: " + byProduct)
val byBinaryDep = changes.binaryDeps.flatMap(previous.usesBinary) val byBinaryDep = changes.binaryDeps.flatMap(previous.usesBinary)
debug("Initial by binary dep: " + byBinaryDep)
val byExtSrcDep = changes.external.modified.flatMap(previous.usesExternal) // ++ scopeInvalidations val byExtSrcDep = changes.external.modified.flatMap(previous.usesExternal) // ++ scopeInvalidations
debug("Initial by binary dep: " + byExtSrcDep) log.debug(
"\nInitial source changes: \n\tremoved:" + srcChanges.removed + "\n\tadded: " + srcChanges.added + "\n\tmodified: " + srcChanges.changed +
"\nRemoved products: " + changes.removedProducts +
"\nModified external sources: " + changes.external.modified +
"\nModified binary dependencies: " + changes.binaryDeps +
"\nInitial directly invalidated sources: " + srcDirect +
"\n\nSources indirectly invalidated by:" +
"\n\tproduct: " + byProduct +
"\n\tbinary dep: " + byBinaryDep +
"\n\texternal source: " + byExtSrcDep
)
srcDirect ++ byProduct ++ byBinaryDep ++ byExtSrcDep srcDirect ++ byProduct ++ byBinaryDep ++ byExtSrcDep
} }

View File

@ -83,7 +83,7 @@ class AggressiveCompile(cacheDirectory: File)
case Some(previous) if equiv.equiv(previous, currentSetup) => previousAnalysis case Some(previous) if equiv.equiv(previous, currentSetup) => previousAnalysis
case _ => Incremental.prune(sourcesSet, previousAnalysis) case _ => Incremental.prune(sourcesSet, previousAnalysis)
} }
IncrementalCompile(sourcesSet, entry, compile0, analysis, getAnalysis, outputDirectory) IncrementalCompile(sourcesSet, entry, compile0, analysis, getAnalysis, outputDirectory, log)
} }
private[this] def logInputs(log: Logger, javaCount: Int, scalaCount: Int) private[this] def logInputs(log: Logger, javaCount: Int, scalaCount: Int)
{ {

View File

@ -63,7 +63,7 @@ class XSbt(info: ProjectInfo) extends ParentProject(info) with NoCrossPaths
val compileInterfaceSub = project(compilePath / "interface", "Compiler Interface", new CompilerInterfaceProject(_), interfaceSub) val compileInterfaceSub = project(compilePath / "interface", "Compiler Interface", new CompilerInterfaceProject(_), interfaceSub)
// Implements the core functionality of detecting and propagating changes incrementally. // Implements the core functionality of detecting and propagating changes incrementally.
// Defines the data structures for representing file fingerprints and relationships and the overall source analysis // Defines the data structures for representing file fingerprints and relationships and the overall source analysis
val compileIncrementalSub = testedBase(compilePath / "inc", "Incremental Compiler", collectionSub, apiSub, ioSub) val compileIncrementalSub = testedBase(compilePath / "inc", "Incremental Compiler", collectionSub, apiSub, ioSub, logSub)
// Persists the incremental data structures using SBinary // Persists the incremental data structures using SBinary
val compilePersistSub = project(compilePath / "persist", "Persist", new PersistProject(_), compileIncrementalSub, apiSub) val compilePersistSub = project(compilePath / "persist", "Persist", new PersistProject(_), compileIncrementalSub, apiSub)
// sbt-side interface to compiler. Calls compiler-side interface reflectively // sbt-side interface to compiler. Calls compiler-side interface reflectively