From 513664a570cd49d161dbbff2bb2bf48e2528dc6a Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Mon, 7 Oct 2024 16:16:32 +0200 Subject: [PATCH 1/4] Fix scaladoc TastyInspector regressions Adds an inspectAllTastyFilesInContext method in scaladoc-only version of TastyInspector. --- .../sbt-dotty/scaladoc-regressions/build.sbt | 9 +++++ .../i18231/src/main/scala/main.scala | 4 ++ .../i20476/src/main/scala/main.scala | 5 +++ .../scaladoc-regressions/project/plugins.sbt | 1 + sbt-test/sbt-dotty/scaladoc-regressions/test | 2 + .../tools/scaladoc/tasty/TastyParser.scala | 2 +- .../tasty/inspector/TastyInspector.scala | 37 +++++++++++++++---- 7 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 sbt-test/sbt-dotty/scaladoc-regressions/build.sbt create mode 100644 sbt-test/sbt-dotty/scaladoc-regressions/i18231/src/main/scala/main.scala create mode 100644 sbt-test/sbt-dotty/scaladoc-regressions/i20476/src/main/scala/main.scala create mode 100644 sbt-test/sbt-dotty/scaladoc-regressions/project/plugins.sbt create mode 100644 sbt-test/sbt-dotty/scaladoc-regressions/test diff --git a/sbt-test/sbt-dotty/scaladoc-regressions/build.sbt b/sbt-test/sbt-dotty/scaladoc-regressions/build.sbt new file mode 100644 index 000000000000..bfdadb5ee038 --- /dev/null +++ b/sbt-test/sbt-dotty/scaladoc-regressions/build.sbt @@ -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") diff --git a/sbt-test/sbt-dotty/scaladoc-regressions/i18231/src/main/scala/main.scala b/sbt-test/sbt-dotty/scaladoc-regressions/i18231/src/main/scala/main.scala new file mode 100644 index 000000000000..82788aa829f0 --- /dev/null +++ b/sbt-test/sbt-dotty/scaladoc-regressions/i18231/src/main/scala/main.scala @@ -0,0 +1,4 @@ +object Foo { + @Deprecated + def foo(): Unit = ??? +} diff --git a/sbt-test/sbt-dotty/scaladoc-regressions/i20476/src/main/scala/main.scala b/sbt-test/sbt-dotty/scaladoc-regressions/i20476/src/main/scala/main.scala new file mode 100644 index 000000000000..31eb78c816cd --- /dev/null +++ b/sbt-test/sbt-dotty/scaladoc-regressions/i20476/src/main/scala/main.scala @@ -0,0 +1,5 @@ +package demo + +import scala.scalajs.js + +def bar: js.Promise[Int] = js.Promise.resolve(()).`then`(_ => 1) diff --git a/sbt-test/sbt-dotty/scaladoc-regressions/project/plugins.sbt b/sbt-test/sbt-dotty/scaladoc-regressions/project/plugins.sbt new file mode 100644 index 000000000000..b9ebfd07bf1f --- /dev/null +++ b/sbt-test/sbt-dotty/scaladoc-regressions/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("org.scala-js" % "sbt-scalajs" % sys.props("plugin.scalaJSVersion")) diff --git a/sbt-test/sbt-dotty/scaladoc-regressions/test b/sbt-test/sbt-dotty/scaladoc-regressions/test new file mode 100644 index 000000000000..816c0be96141 --- /dev/null +++ b/sbt-test/sbt-dotty/scaladoc-regressions/test @@ -0,0 +1,2 @@ +> i18231/doc +> i20476/doc diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala index f55451fdc636..ebd5311a4e33 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala @@ -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) => diff --git a/scaladoc/src/scala/tasty/inspector/TastyInspector.scala b/scaladoc/src/scala/tasty/inspector/TastyInspector.scala index 906578c9d405..b08b4dde1278 100644 --- a/scaladoc/src/scala/tasty/inspector/TastyInspector.scala +++ b/scaladoc/src/scala/tasty/inspector/TastyInspector.scala @@ -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 @@ -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 @@ -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) From 09a99e73c98915910d89f1aed1401ace6078f149 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Mon, 7 Oct 2024 18:47:26 +0200 Subject: [PATCH 2/4] Adjust LinkWarningTest to not count the aggregate warning --- .../tools/scaladoc/no-link-warnings/LinkWarningTest.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala b/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala index 1d140315cc10..bcaee696b65c 100644 --- a/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala +++ b/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala @@ -14,6 +14,7 @@ class LinkWarningsTest extends ScaladocTest("noLinkWarnings"): override def runTest = afterRendering { val diagnostics = summon[DocContext].compilerContext.reportedDiagnostics - assertEquals("There should be exactly one warning", 1, diagnostics.warningMsgs.size) + val filteredWarnings = diagnostics.warningMsgs.filter(_ != "1 warning found") + assertEquals("There should be exactly one warning", 1, filteredWarnings.size) assertNoErrors(diagnostics) } From 682c8b473c1531c4892fd1cebf6840667a614473 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Mon, 7 Oct 2024 23:02:42 +0200 Subject: [PATCH 3/4] rename scaladoc TastyInspector to avoid classpath issues --- scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala | 4 ++-- scaladoc/src/scala/tasty/inspector/TastyInspector.scala | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala index ebd5311a4e33..1a8337e0c6b7 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala @@ -5,7 +5,7 @@ package tasty import java.util.regex.Pattern import scala.util.{Try, Success, Failure} -import scala.tasty.inspector.{TastyInspector, Inspector, Tasty} +import scala.tasty.inspector.{ScaladocInternalTastyInspector, Inspector, Tasty} import scala.quoted._ import dotty.tools.dotc @@ -160,7 +160,7 @@ object ScaladocTastyInspector: report.error("File extension is not `tasty` or `jar`: " + invalidPath) if tastyPaths.nonEmpty then - TastyInspector.inspectAllTastyFilesInContext(tastyPaths, jarPaths, classpath)(inspector)(using ctx.compilerContext) + ScaladocInternalTastyInspector.inspectAllTastyFilesInContext(tastyPaths, jarPaths, classpath)(inspector)(using ctx.compilerContext) val all = inspector.topLevels.result() all.groupBy(_._1).map { case (pckName, members) => diff --git a/scaladoc/src/scala/tasty/inspector/TastyInspector.scala b/scaladoc/src/scala/tasty/inspector/TastyInspector.scala index b08b4dde1278..d4f97d5dd377 100644 --- a/scaladoc/src/scala/tasty/inspector/TastyInspector.scala +++ b/scaladoc/src/scala/tasty/inspector/TastyInspector.scala @@ -1,4 +1,4 @@ -// Copy of tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala +// Renamed 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 @@ -23,7 +23,7 @@ import dotty.tools.dotc.report import java.io.File.pathSeparator -object TastyInspector: +object ScaladocInternalTastyInspector: /** Load and process TASTy files using TASTy reflect * @@ -145,4 +145,4 @@ object TastyInspector: end inspectFiles -end TastyInspector +end ScaladocInternalTastyInspector From 73b8f8a405db2f0afcf476ff2f8cae45f9f12b88 Mon Sep 17 00:00:00 2001 From: Jan Chyb <48855024+jchyb@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:49:27 +0200 Subject: [PATCH 4/4] Fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MikoĊ‚aj Fornal <24961583+Florian3k@users.noreply.github.com> --- scaladoc/src/scala/tasty/inspector/TastyInspector.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scaladoc/src/scala/tasty/inspector/TastyInspector.scala b/scaladoc/src/scala/tasty/inspector/TastyInspector.scala index d4f97d5dd377..190be6a588a1 100644 --- a/scaladoc/src/scala/tasty/inspector/TastyInspector.scala +++ b/scaladoc/src/scala/tasty/inspector/TastyInspector.scala @@ -1,6 +1,6 @@ // Renamed 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 +// 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