From e84a4e4960f3dbe3a11ced7643ef949e2c4eea8f Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 26 Jun 2025 07:33:39 -0700 Subject: [PATCH 1/3] Encode path of class --- .../src/dotty/tools/dotc/core/Denotations.scala | 6 +++--- compiler/src/dotty/tools/dotc/core/Phases.scala | 9 ++++----- .../tools/dotc/fromtasty/TastyFileUtil.scala | 15 ++++++--------- scaladoc-testcases/src/tests/encoded.name.scala | 2 ++ .../scala/tasty/inspector/TastyInspector.scala | 4 ++-- 5 files changed, 17 insertions(+), 19 deletions(-) create mode 100644 scaladoc-testcases/src/tests/encoded.name.scala diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 84ef94687b13..fdf6bf265096 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1299,9 +1299,9 @@ object Denotations { } /** The current denotation of the static reference given by path, - * or a MissingRef or NoQualifyingRef instance, if it does not exist. - * if generateStubs is set, generates stubs for missing top-level symbols - */ + * or a MissingRef or NoQualifyingRef instance, if it does not exist. + * if generateStubs is set, generates stubs for missing top-level symbols + */ def staticRef(path: Name, generateStubs: Boolean = true, isPackage: Boolean = false)(using Context): Denotation = { def select(prefix: Denotation, selector: Name): Denotation = { val owner = prefix.disambiguate(_.info.isParameterless) diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index 603328d18d44..dba638ca13d6 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -462,15 +462,14 @@ object Phases { * Enrich crash messages. */ final def monitor(doing: String)(body: Context ?=> Unit)(using Context): Boolean = - val unit = ctx.compilationUnit - if ctx.run.enterUnit(unit) then + ctx.run.enterUnit(ctx.compilationUnit) + && { try {body; true} catch case NonFatal(ex) if !ctx.run.enrichedErrorMessage => - report.echo(ctx.run.enrichErrorMessage(s"exception occurred while $doing $unit")) + report.echo(ctx.run.enrichErrorMessage(s"exception occurred while $doing ${ctx.compilationUnit}")) throw ex finally ctx.run.advanceUnit() - else - false + } inline def runSubPhase[T](id: Run.SubPhase)(inline body: (Run.SubPhase, Context) ?=> T)(using Context): T = given Run.SubPhase = id diff --git a/compiler/src/dotty/tools/dotc/fromtasty/TastyFileUtil.scala b/compiler/src/dotty/tools/dotc/fromtasty/TastyFileUtil.scala index bc04cc648a65..9bd3016de1f5 100644 --- a/compiler/src/dotty/tools/dotc/fromtasty/TastyFileUtil.scala +++ b/compiler/src/dotty/tools/dotc/fromtasty/TastyFileUtil.scala @@ -15,7 +15,7 @@ object TastyFileUtil { * package foo * class Foo * ``` - * then `getClassName("./out/foo/Foo.tasty") returns `Some("./out")` + * then `getClassPath("./out/foo/Foo.tasty") returns `Some("./out")` */ def getClassPath(file: AbstractFile): Option[String] = getClassName(file).map { className => @@ -37,14 +37,11 @@ object TastyFileUtil { assert(file.extension == "tasty") val bytes = file.toByteArray val names = new TastyClassName(bytes).readName() - names.map { case (packageName, className) => - val fullName = packageName match { - case EMPTY_PACKAGE => s"${className.lastPart}" - case _ => s"$packageName.${className.lastPart}" - } - fullName - } - } + names.map: (packageName, className) => + if packageName == EMPTY_PACKAGE then + s"${className.lastPart.encode}" + else + s"${packageName.encode}.${className.lastPart.encode}" } diff --git a/scaladoc-testcases/src/tests/encoded.name.scala b/scaladoc-testcases/src/tests/encoded.name.scala new file mode 100644 index 000000000000..d47bf83bfe15 --- /dev/null +++ b/scaladoc-testcases/src/tests/encoded.name.scala @@ -0,0 +1,2 @@ + +def exampleMember = "hello, world" diff --git a/scaladoc/src/scala/tasty/inspector/TastyInspector.scala b/scaladoc/src/scala/tasty/inspector/TastyInspector.scala index 14e5f019b433..47501521d612 100644 --- a/scaladoc/src/scala/tasty/inspector/TastyInspector.scala +++ b/scaladoc/src/scala/tasty/inspector/TastyInspector.scala @@ -9,7 +9,7 @@ import scala.quoted.runtime.impl.QuotesImpl import dotty.tools.dotc.Compiler import dotty.tools.dotc.Driver import dotty.tools.dotc.Run -import dotty.tools.dotc.core.Contexts.Context +import dotty.tools.dotc.core.Contexts.{Context, ctx} import dotty.tools.dotc.core.Mode import dotty.tools.dotc.core.Phases.Phase import dotty.tools.dotc.fromtasty._ @@ -69,7 +69,7 @@ object TastyInspector: override def phaseName: String = "tastyInspector" override def runOn(units: List[CompilationUnit])(using ctx0: Context): List[CompilationUnit] = - // NOTE: although this is a phase, do not expect this to be ran with an xsbti.CompileProgress + // NOTE: although this is a phase, do not expect this to be run with an xsbti.CompileProgress val ctx = QuotesCache.init(ctx0.fresh) runOnImpl(units)(using ctx) From 800ab5a16e1e866d6e9a58eab783c559ea0b2f12 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 28 Jul 2025 16:53:39 +0200 Subject: [PATCH 2/3] Encode path of class [Cherry-picked 7b42ed8853d127dbfed870d82829cfb422024331][modified] From bb6e368cf6b6e0daed799e4a1f9d657504793a38 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 28 Jul 2025 16:54:10 +0200 Subject: [PATCH 3/3] Best effort failure excluded [Cherry-picked e7db08ad692c9a4ccafeaad8b19367b0feaca78a][modified]