Skip to content

Commit

Permalink
Fix scaladoc TastyInspector regressions
Browse files Browse the repository at this point in the history
Adds an inspectAllTastyFilesInContext method in scaladoc-only version of
TastyInspector.
  • Loading branch information
jchyb committed Oct 7, 2024
1 parent a672e05 commit 513664a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 9 deletions.
9 changes: 9 additions & 0 deletions sbt-test/sbt-dotty/scaladoc-regressions/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ThisBuild / scalaVersion := sys.props("plugin.scalaVersion")

lazy val i20476 = project
.in(file("i20476"))
.enablePlugins(ScalaJSPlugin)

lazy val i18231 = project
.in(file("i18231"))
.settings(scalacOptions += "-release:8")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Foo {
@Deprecated
def foo(): Unit = ???
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package demo

import scala.scalajs.js

def bar: js.Promise[Int] = js.Promise.resolve(()).`then`(_ => 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % sys.props("plugin.scalaJSVersion"))
2 changes: 2 additions & 0 deletions sbt-test/sbt-dotty/scaladoc-regressions/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> i18231/doc
> i20476/doc
2 changes: 1 addition & 1 deletion scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ object ScaladocTastyInspector:
report.error("File extension is not `tasty` or `jar`: " + invalidPath)

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

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

package scala.tasty.inspector

Expand Down Expand Up @@ -41,6 +43,32 @@ object TastyInspector:
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 @@ -50,14 +78,7 @@ object TastyInspector:
* @return boolean value indicating whether the process succeeded
*/
def inspectAllTastyFiles(tastyFiles: List[String], jars: List[String], dependenciesClasspath: List[String])(inspector: Inspector): Boolean =
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"))
checkFiles(tastyFiles, jars)
val files = tastyFiles ::: jars
inspectFiles(dependenciesClasspath, files)(inspector)

Expand Down

0 comments on commit 513664a

Please sign in to comment.