Skip to content

Commit 00218e8

Browse files
authored
Merge pull request #12372 from dotty-staging/fix-12352
Fix #12352: replace Mode.ReadComments with -Yread-comments
2 parents 2abba6a + 237569b commit 00218e8

File tree

16 files changed

+54
-14
lines changed

16 files changed

+54
-14
lines changed

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Driver {
8282
Positioned.init(using ictx)
8383

8484
inContext(ictx) {
85-
if !ctx.settings.YdropComments.value || ctx.mode.is(Mode.ReadComments) then
85+
if !ctx.settings.YdropComments.value || ctx.settings.YreadComments.value then
8686
ictx.setProperty(ContextDoc, new ContextDocstrings)
8787
val fileNamesOrNone = command.checkUsage(summary, sourcesRequired)(using ctx.settings)(using ctx.settingsState)
8888
fileNamesOrNone.map { fileNames =>

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ trait AllScalaSettings extends CommonScalaSettings { self: Settings.SettingGroup
179179
val YcheckReentrant: Setting[Boolean] = BooleanSetting("-Ycheck-reentrant", "Check that compiled program does not contain vars that can be accessed from a global root.")
180180
val YdropComments: Setting[Boolean] = BooleanSetting("-Ydrop-docs", "Drop documentation when scanning source files.", aliases = List("-Ydrop-comments"))
181181
val YcookComments: Setting[Boolean] = BooleanSetting("-Ycook-docs", "Cook the documentation (type check `@usecase`, etc.)", aliases = List("-Ycook-comments"))
182+
val YreadComments: Setting[Boolean] = BooleanSetting("-Yread-docs", "Read documentation from tasty.")
182183
val YforceSbtPhases: Setting[Boolean] = BooleanSetting("-Yforce-sbt-phases", "Run the phases used by sbt for incremental compilation (ExtractDependencies and ExtractAPI) even if the compiler is ran outside of sbt, for debugging.")
183184
val YdumpSbtInc: Setting[Boolean] = BooleanSetting("-Ydump-sbt-inc", "For every compiled foo.scala, output the API representation and dependencies used for sbt incremental compilation in foo.inc, implies -Yforce-sbt-phases.")
184185
val YcheckAllPatmat: Setting[Boolean] = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm).")

compiler/src/dotty/tools/dotc/core/Mode.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ object Mode {
102102
/** We are typing the body of an inline method */
103103
val InlineableBody: Mode = newMode(21, "InlineableBody")
104104

105-
/** Read comments from definitions when unpickling from TASTY */
106-
val ReadComments: Mode = newMode(22, "ReadComments")
107-
108105
/** We are synthesizing the receiver of an extension method */
109106
val SynthesizeExtMethodReceiver: Mode = newMode(23, "SynthesizeExtMethodReceiver")
110107

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,8 @@ class TreeUnpickler(reader: TastyReader,
884884
if (!sym.isType) // Only terms might have leaky aliases, see the documentation of `checkNoPrivateLeaks`
885885
sym.info = ta.avoidPrivateLeaks(sym)
886886

887-
if (ctx.mode.is(Mode.ReadComments)) {
888-
assert(ctx.docCtx.isDefined, "Mode is `ReadComments`, but no `docCtx` is set.")
887+
if (ctx.settings.YreadComments.value) {
888+
assert(ctx.docCtx.isDefined, "`-Yread-docs` enabled, but no `docCtx` is set.")
889889
commentUnpicklerOpt.foreach { commentUnpickler =>
890890
val comment = commentUnpickler.commentAt(start)
891891
ctx.docCtx.get.addDocstring(tree.symbol, comment)

compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import scala.quoted.runtime.impl.QuotesImpl
1616
class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver {
1717

1818
private val myInitCtx: Context = {
19-
val rootCtx = initCtx.fresh.addMode(Mode.Interactive | Mode.ReadPositions | Mode.ReadComments)
19+
val rootCtx = initCtx.fresh.addMode(Mode.Interactive | Mode.ReadPositions)
20+
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
2021
rootCtx.setSetting(rootCtx.settings.YretainTrees, true)
2122
rootCtx.setSetting(rootCtx.settings.fromTasty, true)
2223
val ctx = setup(settings.toArray :+ "dummy.scala", rootCtx).get._2

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
2929
override def sourcesRequired: Boolean = false
3030

3131
private val myInitCtx: Context = {
32-
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive).addMode(Mode.ReadComments)
32+
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive)
3333
rootCtx.setSetting(rootCtx.settings.YretainTrees, true)
3434
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
35+
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
3536
val ctx = setup(settings.toArray, rootCtx) match
3637
case Some((_, ctx)) => ctx
3738
case None => rootCtx

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ class Pickler extends Phase {
110110
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
111111
val result = super.runOn(units)
112112
if ctx.settings.YtestPickler.value then
113+
val ctx2 = ctx.fresh.setSetting(ctx.settings.YreadComments, true)
113114
testUnpickler(
114-
using ctx.fresh
115+
using ctx2
115116
.setPeriod(Period(ctx.runId + 1, FirstPhaseId))
116117
.setReporter(new ThrowingReporter(ctx.reporter))
117118
.addMode(Mode.ReadPositions)
118-
.addMode(Mode.ReadComments)
119119
.addMode(Mode.PrintShowExceptions))
120120
result
121121
}

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ class ReplDriver(settings: Array[String],
6666

6767
/** Create a fresh and initialized context with IDE mode enabled */
6868
private def initialCtx = {
69-
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions | Mode.Interactive | Mode.ReadComments)
69+
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions | Mode.Interactive)
7070
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
71+
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
7172
setup(settings, rootCtx) match
7273
case Some((files, ictx)) =>
7374
shouldStart = true

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class BootstrappedOnlyCompilationTests {
118118
aggregateTests(
119119
compileFilesInDir("tests/run-macros", defaultOptions.and("-Xcheck-macros")),
120120
compileFilesInDir("tests/run-custom-args/Yretain-trees", defaultOptions and "-Yretain-trees"),
121+
compileFilesInDir("tests/run-custom-args/Yread-comments", defaultOptions and "-Yread-docs"),
121122
compileFilesInDir("tests/run-custom-args/run-macros-erased", defaultOptions.and("-language:experimental.erasedDefinitions").and("-Xcheck-macros")),
122123
)
123124
}.checkRuns()

compiler/test/dotty/tools/dotc/core/tasty/CommentPicklingTest.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ class CommentPicklingTest {
105105
}
106106

107107
private class UnpicklingDriver extends Driver {
108-
override def initCtx = super.initCtx.addMode(Mode.ReadComments)
108+
override def initCtx =
109+
val ctx = super.initCtx.fresh
110+
ctx.setSetting(ctx.settings.YreadComments, true)
111+
ctx
112+
109113
def unpickle[T](args: Array[String], files: List[File])(fn: (List[tpd.Tree], Context) => T): T = {
110114
implicit val ctx: Context = setup(args, initCtx).map(_._2).getOrElse(initCtx)
111115
ctx.initialize()

scaladoc/src/scala/tasty/inspector/OldTastyInspector.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ trait OldTastyInspector:
110110

111111
override def newRun(implicit ctx: Context): Run =
112112
reset()
113-
new TASTYRun(this, ctx.fresh.addMode(Mode.ReadPositions).addMode(Mode.ReadComments))
113+
val ctx2 = ctx.fresh
114+
.addMode(Mode.ReadPositions)
115+
.setSetting(ctx.settings.YreadComments, true)
116+
new TASTYRun(this, ctx2)
114117

115118
new InspectorDriver
116119

tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ object TastyInspector:
8686

8787
override def newRun(implicit ctx: Context): Run =
8888
reset()
89-
new TASTYRun(this, ctx.fresh.addMode(Mode.ReadPositions).addMode(Mode.ReadComments))
89+
val ctx2 = ctx.fresh
90+
.addMode(Mode.ReadPositions)
91+
.setSetting(ctx.settings.YreadComments, true)
92+
new TASTYRun(this, ctx2)
9093

9194
new InspectorDriver
9295

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.quoted.*
2+
3+
/** HELLO */
4+
case class Data(test: Boolean)
5+
6+
inline def getDocString[T]: Option[String] = ${ getDocStringImpl[T] }
7+
8+
private def getDocStringImpl[T : Type](using Quotes): Expr[Option[String]] = {
9+
import quotes.reflect.*
10+
Expr(TypeRepr.of[T].typeSymbol.docstring)
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@main def Test(): Unit = {
2+
println(getDocString[Data])
3+
assert(getDocString[Data].nonEmpty)
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted.*
2+
3+
inline def getDocString[T]: Option[String] = ${ getDocStringImpl[T] }
4+
5+
private def getDocStringImpl[T : Type](using Quotes): Expr[Option[String]] = {
6+
import quotes.reflect.*
7+
Expr(TypeRepr.of[T].typeSymbol.docstring)
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@main def Test(): Unit = {
2+
val res = getDocString[scala.quoted.Quotes]
3+
println(res)
4+
assert(res.nonEmpty)
5+
}

0 commit comments

Comments
 (0)