Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b6c232d

Browse files
authored
Encode path of class (#23503)
`TastyFileUtil.getClassName` encodes its path result so that `a.b` is not taken as two segments.
2 parents 2887c0a + e7db08a commit b6c232d

File tree

7 files changed

+45
-48
lines changed

7 files changed

+45
-48
lines changed

‎compiler/src/dotty/tools/dotc/core/Denotations.scala‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,9 +1310,9 @@ object Denotations {
13101310
}
13111311

13121312
/** The current denotation of the static reference given by path,
1313-
* or a MissingRef or NoQualifyingRef instance, if it does not exist.
1314-
* if generateStubs is set, generates stubs for missing top-level symbols
1315-
*/
1313+
* or a MissingRef or NoQualifyingRef instance, if it does not exist.
1314+
* if generateStubs is set, generates stubs for missing top-level symbols
1315+
*/
13161316
def staticRef(path: Name, generateStubs: Boolean = true, isPackage: Boolean = false)(using Context): Denotation = {
13171317
def select(prefix: Denotation, selector: Name): Denotation = {
13181318
val owner = prefix.disambiguate(_.info.isParameterless)

‎compiler/src/dotty/tools/dotc/core/Phases.scala‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,14 @@ object Phases {
505505
* Enrich crash messages.
506506
*/
507507
final def monitor(doing: String)(body: Context ?=> Unit)(using Context): Boolean =
508-
valunit=ctx.compilationUnit
509-
if ctx.run.enterUnit(unit) then
508+
ctx.run.enterUnit(ctx.compilationUnit)
509+
&& {
510510
try {body; true}
511511
catch case NonFatal(ex) if !ctx.run.enrichedErrorMessage =>
512-
report.echo(ctx.run.enrichErrorMessage(s"exception occurred while $doing$unit"))
512+
report.echo(ctx.run.enrichErrorMessage(s"exception occurred while $doing${ctx.compilationUnit}"))
513513
throw ex
514514
finally ctx.run.advanceUnit()
515-
else
516-
false
515+
}
517516

518517
inline def runSubPhase[T](id: Run.SubPhase)(inline body: (Run.SubPhase, Context) ?=> T)(using Context): T =
519518
given Run.SubPhase = id

‎compiler/src/dotty/tools/dotc/fromtasty/TastyFileUtil.scala‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object TastyFileUtil {
1515
* package foo
1616
* class Foo
1717
* ```
18-
* then `getClassName("./out/foo/Foo.tasty") returns `Some("./out")`
18+
* then `getClassPath("./out/foo/Foo.tasty") returns `Some("./out")`
1919
*/
2020
def getClassPath(file: AbstractFile, fromBestEffortTasty: Boolean = false): Option[String] =
2121
getClassName(file, fromBestEffortTasty).map { className =>
@@ -33,19 +33,16 @@ object TastyFileUtil {
3333
* ```
3434
* then `getClassName("./out/foo/Foo.tasty") returns `Some("foo.Foo")`
3535
*/
36-
def getClassName(file: AbstractFile, withBestEffortTasty: Boolean = false): Option[String] = {
36+
def getClassName(file: AbstractFile, withBestEffortTasty: Boolean = false): Option[String] =
3737
assert(file.exists)
3838
assert(file.hasTastyExtension || (withBestEffortTasty && file.hasBetastyExtension))
3939
val bytes = file.toByteArray
4040
val names = new TastyClassName(bytes, file.hasBetastyExtension).readName()
41-
names.map { case (packageName, className) =>
42-
val fullName = packageName match {
43-
case EMPTY_PACKAGE => s"${className.lastPart}"
44-
case _ => s"$packageName.${className.lastPart}"
45-
}
46-
fullName
47-
}
48-
}
41+
names.map: (packageName, className) =>
42+
if packageName == EMPTY_PACKAGE then
43+
s"${className.lastPart.encode}"
44+
else
45+
s"${packageName.encode}.${className.lastPart.encode}"
4946
}
5047

5148

‎compiler/test/dotc/neg-best-effort-unpickling.excludelist‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ i23402b.scala
2727

2828
# Unhandled TypeError exception
2929
i23504.scala
30+
31+
# owner of anon, where package object has funky name
32+
i20511-1.scala

‎compiler/test/dotty/tools/dotc/BestEffortOptionsTests.scala‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,42 @@ package dotty
22
package tools
33
package dotc
44

5-
import scala.concurrent.duration._
6-
import dotty.tools.vulpix._
7-
import org.junit.{ Test, AfterClass }
5+
import dotty.tools.vulpix.*
86
import reporting.TestReporter
9-
import java.io.{File => JFile}
107

8+
import scala.concurrent.duration.*
119
import scala.language.unsafeNulls
1210

11+
import java.io.{File => JFile}
12+
import org.junit.{AfterClass, Test}
13+
1314
class BestEffortOptionsTests {
14-
import ParallelTesting._
15-
import vulpix.TestConfiguration._
16-
import BestEffortOptionsTests._
17-
import CompilationTest.aggregateTests
15+
import ParallelTesting.*
16+
import vulpix.TestConfiguration.*
17+
import BestEffortOptionsTests.*
1818

1919
// Since TASTy and beTASTy files are read in a lazy manner (only when referenced by the source .scala file)
2020
// we test by using the "-from-tasty" option. This guarantees that the tasty files will be read
2121
// (and that the Best Effort TASTy reader will be tested), but we unfortunately skip the useful
2222
// interactions a tree derived from beTASTy could have with other frontend phases.
23-
@Test def negTestFromBestEffortTasty: Unit = {
23+
@Test def negTestFromBestEffortTasty: Unit =
2424
// Can be reproduced with
2525
// > sbt
26-
// > scalac --Ybest-effort -Xsemanticdb <source>
27-
// > scalac --from-tasty -Ywith-best-effort-tasty META_INF/best-effort/<betasty>
26+
// > scalac -Ybest-effort -Xsemanticdb <source>
27+
// > scalac -from-tasty -Ywith-best-effort-tasty META_INF/best-effort/<betasty>
2828

29-
implicitvaltestGroup: TestGroup = TestGroup("negTestFromBestEffortTasty")
29+
given TestGroup = TestGroup("negTestFromBestEffortTasty")
3030
compileBestEffortTastyInDir(s"tests${JFile.separator}neg", bestEffortBaselineOptions,
3131
picklingFilter = FileFilter.exclude(TestSources.negBestEffortPicklingExcludelisted),
3232
unpicklingFilter = FileFilter.exclude(TestSources.negBestEffortUnpicklingExcludelisted)
3333
).checkNoCrash()
34-
}
3534

3635
// Tests an actual use case of this compilation mode, where symbol definitions of the downstream
3736
// projects depend on the best effort tasty files generated with the Best Effort dir option
38-
@Test def bestEffortIntergrationTest: Unit = {
39-
implicitvaltestGroup: TestGroup = TestGroup("bestEffortIntegrationTests")
37+
@Test def bestEffortIntegrationTest: Unit =
38+
given TestGroup = TestGroup("bestEffortIntegrationTests")
4039
compileBestEffortIntegration(s"tests${JFile.separator}best-effort", bestEffortBaselineOptions)
4140
.noCrashWithCompilingDependencies()
42-
}
4341
}
4442

4543
object BestEffortOptionsTests extends ParallelTesting {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
def exampleMember = "hello, world"

‎scaladoc/src/scala/tasty/inspector/TastyInspector.scala‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scala.quoted.runtime.impl.QuotesImpl
1111
import dotty.tools.dotc.Compiler
1212
import dotty.tools.dotc.Driver
1313
import dotty.tools.dotc.Run
14-
import dotty.tools.dotc.core.Contexts.Context
14+
import dotty.tools.dotc.core.Contexts.{Context, ctx}
1515
import dotty.tools.dotc.core.Mode
1616
import dotty.tools.dotc.core.Phases.Phase
1717
import dotty.tools.dotc.fromtasty._
@@ -53,21 +53,19 @@ object ScaladocInternalTastyInspector:
5353
tastyFiles.foreach(checkFile(_, "tasty"))
5454
jars.foreach(checkFile(_, "jar"))
5555

56-
/**
57-
* Added for Scaladoc-only.
58-
* Meant to fix regressions introduces by the switch from old to new TastyInspector:
59-
* https://github.com/scala/scala3/issues/18231
60-
* https://github.com/scala/scala3/issues/20476
61-
* Stable TastyInspector API does not support passing compiler context.
62-
*/
56+
/** Added for Scaladoc-only.
57+
* Meant to fix regressions introduces by the switch from old to new TastyInspector:
58+
* - https://github.com/scala/scala3/issues/18231
59+
* - https://github.com/scala/scala3/issues/20476
60+
* Stable TastyInspector API does not support passing compiler context.
61+
*/
6362
def inspectAllTastyFilesInContext(tastyFiles: List[String], jars: List[String], dependenciesClasspath: List[String])(inspector: Inspector)(using Context): Boolean =
6463
checkFiles(tastyFiles, jars)
6564
val classes = tastyFiles ::: jars
66-
classes match
67-
case Nil => true
68-
case _ =>
69-
val reporter = inspectorDriver(inspector).process(inspectorArgs(dependenciesClasspath, classes), summon[Context])
70-
!reporter.hasErrors
65+
classes.isEmpty
66+
|| !inspectorDriver(inspector)
67+
.process(inspectorArgs(dependenciesClasspath, classes), ctx)
68+
.hasErrors
7169

7270
/** Load and process TASTy files using TASTy reflect
7371
*
@@ -90,7 +88,7 @@ object ScaladocInternalTastyInspector:
9088
override def phaseName: String = "tastyInspector"
9189

9290
override def runOn(units: List[CompilationUnit])(using ctx0: Context): List[CompilationUnit] =
93-
// NOTE: although this is a phase, do not expect this to be ran with an xsbti.CompileProgress
91+
// NOTE: although this is a phase, do not expect this to be run with an xsbti.CompileProgress
9492
val ctx = QuotesCache.init(ctx0.fresh)
9593
runOnImpl(units)(using ctx)
9694

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /