Skip to content

Fix #12352: replace Mode.ReadComments with -Yread-comments #12372

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

Merged
merged 3 commits into from
May 17, 2021
Merged
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Driver {
Positioned.init(using ictx)

inContext(ictx) {
if !ctx.settings.YdropComments.value || ctx.mode.is(Mode.ReadComments) then
if !ctx.settings.YdropComments.value || ctx.settings.YreadComments.value then
ictx.setProperty(ContextDoc, new ContextDocstrings)
val fileNamesOrNone = command.checkUsage(summary, sourcesRequired)(using ctx.settings)(using ctx.settingsState)
fileNamesOrNone.map { fileNames =>
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ trait AllScalaSettings extends CommonScalaSettings { self: Settings.SettingGroup
val YcheckReentrant: Setting[Boolean] = BooleanSetting("-Ycheck-reentrant", "Check that compiled program does not contain vars that can be accessed from a global root.")
val YdropComments: Setting[Boolean] = BooleanSetting("-Ydrop-docs", "Drop documentation when scanning source files.", aliases = List("-Ydrop-comments"))
val YcookComments: Setting[Boolean] = BooleanSetting("-Ycook-docs", "Cook the documentation (type check `@usecase`, etc.)", aliases = List("-Ycook-comments"))
val YreadComments: Setting[Boolean] = BooleanSetting("-Yread-docs", "Read documentation from tasty.")
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.")
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.")
val YcheckAllPatmat: Setting[Boolean] = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm).")
Expand Down
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Mode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ object Mode {
/** We are typing the body of an inline method */
val InlineableBody: Mode = newMode(21, "InlineableBody")

/** Read comments from definitions when unpickling from TASTY */
val ReadComments: Mode = newMode(22, "ReadComments")

/** We are synthesizing the receiver of an extension method */
val SynthesizeExtMethodReceiver: Mode = newMode(23, "SynthesizeExtMethodReceiver")

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ class TreeUnpickler(reader: TastyReader,
if (!sym.isType) // Only terms might have leaky aliases, see the documentation of `checkNoPrivateLeaks`
sym.info = ta.avoidPrivateLeaks(sym)

if (ctx.mode.is(Mode.ReadComments)) {
assert(ctx.docCtx.isDefined, "Mode is `ReadComments`, but no `docCtx` is set.")
if (ctx.settings.YreadComments.value) {
assert(ctx.docCtx.isDefined, "`-Yread-docs` enabled, but no `docCtx` is set.")
commentUnpicklerOpt.foreach { commentUnpickler =>
val comment = commentUnpickler.commentAt(start)
ctx.docCtx.get.addDocstring(tree.symbol, comment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import scala.quoted.runtime.impl.QuotesImpl
class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver {

private val myInitCtx: Context = {
val rootCtx = initCtx.fresh.addMode(Mode.Interactive | Mode.ReadPositions | Mode.ReadComments)
val rootCtx = initCtx.fresh.addMode(Mode.Interactive | Mode.ReadPositions)
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
rootCtx.setSetting(rootCtx.settings.YretainTrees, true)
rootCtx.setSetting(rootCtx.settings.fromTasty, true)
val ctx = setup(settings.toArray :+ "dummy.scala", rootCtx).get._2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
override def sourcesRequired: Boolean = false

private val myInitCtx: Context = {
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive).addMode(Mode.ReadComments)
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive)
rootCtx.setSetting(rootCtx.settings.YretainTrees, true)
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
val ctx = setup(settings.toArray, rootCtx) match
case Some((_, ctx)) => ctx
case None => rootCtx
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ class Pickler extends Phase {
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
val result = super.runOn(units)
if ctx.settings.YtestPickler.value then
val ctx2 = ctx.fresh.setSetting(ctx.settings.YreadComments, true)
testUnpickler(
using ctx.fresh
using ctx2
.setPeriod(Period(ctx.runId + 1, FirstPhaseId))
.setReporter(new ThrowingReporter(ctx.reporter))
.addMode(Mode.ReadPositions)
.addMode(Mode.ReadComments)
.addMode(Mode.PrintShowExceptions))
result
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ class ReplDriver(settings: Array[String],

/** Create a fresh and initialized context with IDE mode enabled */
private def initialCtx = {
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions | Mode.Interactive | Mode.ReadComments)
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions | Mode.Interactive)
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
setup(settings, rootCtx) match
case Some((files, ictx)) =>
shouldStart = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class BootstrappedOnlyCompilationTests {
aggregateTests(
compileFilesInDir("tests/run-macros", defaultOptions.and("-Xcheck-macros")),
compileFilesInDir("tests/run-custom-args/Yretain-trees", defaultOptions and "-Yretain-trees"),
compileFilesInDir("tests/run-custom-args/Yread-comments", defaultOptions and "-Yread-docs"),
compileFilesInDir("tests/run-custom-args/run-macros-erased", defaultOptions.and("-language:experimental.erasedDefinitions").and("-Xcheck-macros")),
)
}.checkRuns()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ class CommentPicklingTest {
}

private class UnpicklingDriver extends Driver {
override def initCtx = super.initCtx.addMode(Mode.ReadComments)
override def initCtx =
val ctx = super.initCtx.fresh
ctx.setSetting(ctx.settings.YreadComments, true)
ctx

def unpickle[T](args: Array[String], files: List[File])(fn: (List[tpd.Tree], Context) => T): T = {
implicit val ctx: Context = setup(args, initCtx).map(_._2).getOrElse(initCtx)
ctx.initialize()
Expand Down
5 changes: 4 additions & 1 deletion scaladoc/src/scala/tasty/inspector/OldTastyInspector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ trait OldTastyInspector:

override def newRun(implicit ctx: Context): Run =
reset()
new TASTYRun(this, ctx.fresh.addMode(Mode.ReadPositions).addMode(Mode.ReadComments))
val ctx2 = ctx.fresh
.addMode(Mode.ReadPositions)
.setSetting(ctx.settings.YreadComments, true)
new TASTYRun(this, ctx2)

new InspectorDriver

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ object TastyInspector:

override def newRun(implicit ctx: Context): Run =
reset()
new TASTYRun(this, ctx.fresh.addMode(Mode.ReadPositions).addMode(Mode.ReadComments))
val ctx2 = ctx.fresh
.addMode(Mode.ReadPositions)
.setSetting(ctx.settings.YreadComments, true)
new TASTYRun(this, ctx2)

new InspectorDriver

Expand Down
11 changes: 11 additions & 0 deletions tests/run-custom-args/Yread-comments/i12351/GetDocString_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scala.quoted.*

/** HELLO */
case class Data(test: Boolean)

inline def getDocString[T]: Option[String] = ${ getDocStringImpl[T] }

private def getDocStringImpl[T : Type](using Quotes): Expr[Option[String]] = {
import quotes.reflect.*
Expr(TypeRepr.of[T].typeSymbol.docstring)
}
4 changes: 4 additions & 0 deletions tests/run-custom-args/Yread-comments/i12351/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@main def Test(): Unit = {
println(getDocString[Data])
assert(getDocString[Data].nonEmpty)
}
8 changes: 8 additions & 0 deletions tests/run-custom-args/Yread-comments/i12352/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.quoted.*

inline def getDocString[T]: Option[String] = ${ getDocStringImpl[T] }

private def getDocStringImpl[T : Type](using Quotes): Expr[Option[String]] = {
import quotes.reflect.*
Expr(TypeRepr.of[T].typeSymbol.docstring)
}
5 changes: 5 additions & 0 deletions tests/run-custom-args/Yread-comments/i12352/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@main def Test(): Unit = {
val res = getDocString[scala.quoted.Quotes]
println(res)
assert(res.nonEmpty)
}