Skip to content

Commit

Permalink
Revert "Fix scaladoc TastyInspector regressions (#21716)"
Browse files Browse the repository at this point in the history
This reverts commit 21a7cbd.
  • Loading branch information
hamzaremmal authored Oct 9, 2024
1 parent 3408ed7 commit b3fe9bb
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 57 deletions.
9 changes: 0 additions & 9 deletions sbt-test/sbt-dotty/scaladoc-regressions/build.sbt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions sbt-test/sbt-dotty/scaladoc-regressions/test

This file was deleted.

4 changes: 2 additions & 2 deletions scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package tasty
import java.util.regex.Pattern

import scala.util.{Try, Success, Failure}
import scala.tasty.inspector.{ScaladocInternalTastyInspector, Inspector, Tasty}
import scala.tasty.inspector.{TastyInspector, Inspector, Tasty}
import scala.quoted._

import dotty.tools.dotc
Expand Down Expand Up @@ -160,7 +160,7 @@ object ScaladocTastyInspector:
report.error("File extension is not `tasty` or `jar`: " + invalidPath)

if tastyPaths.nonEmpty then
ScaladocInternalTastyInspector.inspectAllTastyFilesInContext(tastyPaths, jarPaths, classpath)(inspector)(using ctx.compilerContext)
TastyInspector.inspectAllTastyFiles(tastyPaths, jarPaths, classpath)(inspector)

val all = inspector.topLevels.result()
all.groupBy(_._1).map { case (pckName, members) =>
Expand Down
43 changes: 11 additions & 32 deletions scaladoc/src/scala/tasty/inspector/TastyInspector.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Renamed copy of tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala
// Copy of tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala
// FIXME remove this copy of the file
// Since copying, an inspectAllTastyFilesInContext method was added for scaladoc only
// to fix regressions introduced by the switch from old to a new TastyInspector

package scala.tasty.inspector

Expand All @@ -23,7 +21,7 @@ import dotty.tools.dotc.report

import java.io.File.pathSeparator

object ScaladocInternalTastyInspector:
object TastyInspector:

/** Load and process TASTy files using TASTy reflect
*
Expand All @@ -43,32 +41,6 @@ object ScaladocInternalTastyInspector:
def inspectTastyFilesInJar(jar: String)(inspector: Inspector): Boolean =
inspectAllTastyFiles(Nil, List(jar), Nil)(inspector)

private def checkFiles(tastyFiles: List[String], jars: List[String]): Unit =
def checkFile(fileName: String, ext: String): Unit =
val file = dotty.tools.io.Path(fileName)
if !file.ext.toLowerCase.equalsIgnoreCase(ext) then
throw new IllegalArgumentException(s"File extension is not `.$ext`: $file")
else if !file.exists then
throw new IllegalArgumentException(s"File not found: ${file.toAbsolute}")
tastyFiles.foreach(checkFile(_, "tasty"))
jars.foreach(checkFile(_, "jar"))

/**
* Added for Scaladoc-only.
* Meant to fix regressions introduces by the switch from old to new TastyInspector:
* https://github.com/scala/scala3/issues/18231
* https://github.com/scala/scala3/issues/20476
* Stable TastyInspector API does not support passing compiler context.
*/
def inspectAllTastyFilesInContext(tastyFiles: List[String], jars: List[String], dependenciesClasspath: List[String])(inspector: Inspector)(using Context): Boolean =
checkFiles(tastyFiles, jars)
val classes = tastyFiles ::: jars
classes match
case Nil => true
case _ =>
val reporter = inspectorDriver(inspector).process(inspectorArgs(dependenciesClasspath, classes), summon[Context])
!reporter.hasErrors

/** Load and process TASTy files using TASTy reflect
*
* @param tastyFiles List of paths of `.tasty` files
Expand All @@ -78,7 +50,14 @@ object ScaladocInternalTastyInspector:
* @return boolean value indicating whether the process succeeded
*/
def inspectAllTastyFiles(tastyFiles: List[String], jars: List[String], dependenciesClasspath: List[String])(inspector: Inspector): Boolean =
checkFiles(tastyFiles, jars)
def checkFile(fileName: String, ext: String): Unit =
val file = dotty.tools.io.Path(fileName)
if !file.ext.toLowerCase.equalsIgnoreCase(ext) then
throw new IllegalArgumentException(s"File extension is not `.$ext`: $file")
else if !file.exists then
throw new IllegalArgumentException(s"File not found: ${file.toAbsolute}")
tastyFiles.foreach(checkFile(_, "tasty"))
jars.foreach(checkFile(_, "jar"))
val files = tastyFiles ::: jars
inspectFiles(dependenciesClasspath, files)(inspector)

Expand Down Expand Up @@ -145,4 +124,4 @@ object ScaladocInternalTastyInspector:
end inspectFiles


end ScaladocInternalTastyInspector
end TastyInspector
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class LinkWarningsTest extends ScaladocTest("noLinkWarnings"):

override def runTest = afterRendering {
val diagnostics = summon[DocContext].compilerContext.reportedDiagnostics
val filteredWarnings = diagnostics.warningMsgs.filter(_ != "1 warning found")
assertEquals("There should be exactly one warning", 1, filteredWarnings.size)
assertEquals("There should be exactly one warning", 1, diagnostics.warningMsgs.size)
assertNoErrors(diagnostics)
}

0 comments on commit b3fe9bb

Please sign in to comment.