Skip to content

Commit b1380ed

Browse files
committed
Fix #12352: replace Mode.ReadComments with -YreadComments
1 parent 782f57e commit b1380ed

File tree

11 files changed

+25
-14
lines changed

11 files changed

+25
-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
@@ -178,6 +178,7 @@ class ScalaSettings extends Settings.SettingGroup with CommonScalaSettings {
178178
val YtestPickler: Setting[Boolean] = BooleanSetting("-Ytest-pickler", "Self-test for pickling functionality; should be used with -Ystop-after:pickler.")
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-comments", "Drop comments when scanning source files.")
181+
val YreadComments: Setting[Boolean] = BooleanSetting("-Yread-comments", "Read comments from tasty.")
181182
val YcookComments: Setting[Boolean] = BooleanSetting("-Ycook-comments", "Cook the comments (type check `@usecase`, etc.)")
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.")

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
@@ -885,8 +885,8 @@ class TreeUnpickler(reader: TastyReader,
885885
if (!sym.isType) // Only terms might have leaky aliases, see the documentation of `checkNoPrivateLeaks`
886886
sym.info = ta.avoidPrivateLeaks(sym)
887887

888-
if (ctx.mode.is(Mode.ReadComments)) {
889-
assert(ctx.docCtx.isDefined, "Mode is `ReadComments`, but no `docCtx` is set.")
888+
if (ctx.settings.YreadComments.value) {
889+
assert(ctx.docCtx.isDefined, "`-YreadComments` enabled, but no `docCtx` is set.")
890890
commentUnpicklerOpt.foreach { commentUnpickler =>
891891
val comment = commentUnpickler.commentAt(start)
892892
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/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
110+
ctx.setSetting(rootCtx.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

0 commit comments

Comments
 (0)