Skip to content

Commit

Permalink
Simplify findFailedProblems
Browse files Browse the repository at this point in the history
  • Loading branch information
jchyb committed May 20, 2024
1 parent 5c5cb23 commit 9cded83
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions backend/src/main/scala/bloop/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -368,23 +368,6 @@ object Compiler {
reporter.reportStartCompilation(previousProblems)
val fileManager = newFileManager

def findFailedProblems(fMaybe: Option[xsbti.CompileFailed]): List[ProblemPerPhase] = {
// We cannot guarantee reporter.problems == f.problems, so we aggregate them together
val reportedProblems = reporter.allProblemsPerPhase.toList
val rawProblemsFromReporter = reportedProblems.iterator.map(_.problem).toSet
val newProblems: List[ProblemPerPhase] = fMaybe
.map { f =>
f.problems()
.flatMap { p =>
if (rawProblemsFromReporter.contains(p)) Nil
else List(ProblemPerPhase(p, None))
}
.toList
}
.getOrElse(Nil)
reportedProblems ++ newProblems.toList
}

// Manually skip redundant best-effort compilations. This is necessary because compiler
// phases supplying the data needed to skip compilations in zinc remain unimplemented for now.
val noopBestEffortResult = compileInputs.previousCompilerResult match {
Expand Down Expand Up @@ -442,7 +425,6 @@ object Compiler {
compileInputs,
compileOut,
() => elapsed,
findFailedProblems,
reporter,
backgroundTasksWhenNewSuccessfulAnalysis,
allInvalidatedClassFilesForProject,
Expand Down Expand Up @@ -684,7 +666,6 @@ object Compiler {
compileInputs,
compileOut,
() => elapsed,
findFailedProblems,
reporter,
backgroundTasksWhenNewSuccessfulAnalysis,
allInvalidatedClassFilesForProject,
Expand All @@ -701,14 +682,7 @@ object Compiler {

cause match {
case f: xsbti.CompileFailed =>
// We cannot guarantee reporter.problems == f.problems, so we aggregate them together
val reportedProblems = reporter.allProblemsPerPhase.toList
val rawProblemsFromReporter = reportedProblems.iterator.map(_.problem).toSet
val newProblems = f.problems().flatMap { p =>
if (rawProblemsFromReporter.contains(p)) Nil
else List(ProblemPerPhase(p, None))
}
val failedProblems = reportedProblems ++ newProblems.toList
val failedProblems = findFailedProblems(reporter, Some(f))
val backgroundTasks =
toBackgroundTasks(backgroundTasksForFailedCompilation.toList)
Result.Failed(failedProblems, None, elapsed, backgroundTasks, None)
Expand All @@ -721,6 +695,26 @@ object Compiler {
}
}

def findFailedProblems(
reporter: ZincReporter,
compileFailedMaybe: Option[xsbti.CompileFailed]
): List[ProblemPerPhase] = {
// We cannot guarantee reporter.problems == f.problems, so we aggregate them together
val reportedProblems = reporter.allProblemsPerPhase.toList
val rawProblemsFromReporter = reportedProblems.iterator.map(_.problem).toSet
val newProblems: List[ProblemPerPhase] = compileFailedMaybe
.map { f =>
f.problems()
.flatMap { p =>
if (rawProblemsFromReporter.contains(p)) Nil
else List(ProblemPerPhase(p, None))
}
.toList
}
.getOrElse(Nil)
reportedProblems ++ newProblems.toList
}

def containsBestEffortFailure(cause: xsbti.CompileFailed) =
cause.problems().exists(_.message().contains("Unsuccessful best-effort compilation."))

Expand Down Expand Up @@ -823,7 +817,6 @@ object Compiler {
compileInputs: CompileInputs,
compileOut: CompileOutPaths,
elapsed: () => Long,
findFailedProblems: Option[xsbti.CompileFailed] => List[ProblemPerPhase],
reporter: ZincReporter,
backgroundTasksWhenNewSuccessfulAnalysis: mutable.ListBuffer[CompileBackgroundTasks.Sig],
allInvalidatedClassFilesForProject: mutable.HashSet[File],
Expand Down Expand Up @@ -940,7 +933,7 @@ object Compiler {
compileInputs.sources,
compileInputs.classpath
)
val failedProblems = findFailedProblems(errorCause)
val failedProblems = findFailedProblems(reporter, errorCause)
Result.Failed(
failedProblems,
None,
Expand Down

0 comments on commit 9cded83

Please sign in to comment.