Skip to content

Backport "Encode path of class" to 3.3 LTS #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: backport-lts-3.3-23365
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 7 additions & 10 deletions compiler/src/dotty/tools/dotc/fromtasty/TastyFileUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -32,19 +32,16 @@ object TastyFileUtil {
* ```
* then `getClassName("./out/foo/Foo.tasty") returns `Some("foo.Foo")`
*/
def getClassName(file: AbstractFile): Option[String] = {
def getClassName(file: AbstractFile): Option[String] =
assert(file.exists)
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}"
}


2 changes: 2 additions & 0 deletions scaladoc-testcases/src/tests/encoded.name.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

def exampleMember = "hello, world"
4 changes: 2 additions & 2 deletions scaladoc/src/scala/tasty/inspector/TastyInspector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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)

Expand Down