Skip to content

Commit 18b0230

Browse files
committed
Keep comments by default, add -Ydrop-comments
This commit removes `-Ykeep-comments` and adds a new `-Ydrop-comments` flag. `-Ydrop-comments` is used to prevent the parser from keeping the comments, and defaults to `false`.
1 parent b1d0445 commit 18b0230

File tree

8 files changed

+5
-9
lines changed

8 files changed

+5
-9
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ class Driver extends DotClass {
4444

4545
/**
4646
* Should the `ContextDocstrings` be set for this context? The `ContextDocstrings` is used
47-
* to store doc comments when `-Ykeep-comments` is set, or when TASTY is configured to
47+
* to store doc comments unless `-Ydrop-comments` is set, or when TASTY is configured to
4848
* unpickle the doc comments.
4949
*/
5050
protected def shouldAddDocContext(implicit ctx: Context): Boolean = {
51-
ctx.settings.YkeepComments.value || ctx.mode.is(Mode.ReadComments)
51+
!ctx.settings.YdropComments.value || ctx.mode.is(Mode.ReadComments)
5252
}
5353

5454
def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ScalaSettings extends Settings.SettingGroup {
116116
val YshowPrintErrors = BooleanSetting("-Yshow-print-errors", "don't suppress exceptions thrown during tree printing.")
117117
val YtestPickler = BooleanSetting("-Ytest-pickler", "self-test for pickling functionality; should be used with -Ystop-after:pickler")
118118
val YcheckReentrant = BooleanSetting("-Ycheck-reentrant", "check that compiled program does not contain vars that can be accessed from a global root.")
119-
val YkeepComments = BooleanSetting("-Ykeep-comments", "Keep comments when scanning source files.")
119+
val YdropComments = BooleanSetting("-Ydrop-comments", "Drop comments when scanning source files.")
120120
val YcookComments = BooleanSetting("-Ycook-comments", "Cook the comments (type check `@usecase`, etc.)")
121121
val YforceSbtPhases = 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.")
122122
val YdumpSbtInc = 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/parsing/Scanners.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ object Scanners {
172172
}
173173

174174
class Scanner(source: SourceFile, override val startFrom: Offset = 0)(implicit ctx: Context) extends ScannerCommon(source)(ctx) {
175-
val keepComments = ctx.settings.YkeepComments.value
175+
val keepComments = !ctx.settings.YdropComments.value
176176

177177
/** All doc comments kept by their end position in a `Map` */
178178
private[this] var docstringMap: SortedMap[Int, Comment] = SortedMap.empty

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Pickler extends Phase {
6060
if (tree.pos.exists)
6161
new PositionPickler(pickler, treePkl.buf.addrOfTree).picklePositions(tree :: Nil)
6262

63-
if (ctx.settings.YkeepComments.value)
63+
if (!ctx.settings.YdropComments.value)
6464
new CommentPickler(pickler, treePkl.buf.addrOfTree).pickleComment(tree)
6565

6666
// other pickle sections go here.

compiler/test/dotty/tools/dotc/parsing/DocstringTest.scala

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import ast.Trees._
66
import core.Contexts.Context
77

88
trait DocstringTest extends DottyTest {
9-
ctx = ctx.fresh.setSetting(ctx.settings.YkeepComments, true)
109

1110
def checkDocString(actual: Option[String], expected: String): Unit = actual match {
1211
case Some(str) =>

doc-tool/src/dotty/tools/dottydoc/DocDriver.scala

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class DocDriver extends Driver {
2222
val summary = CompilerCommand.distill(args)(ctx)
2323

2424
ctx.setSettings(summary.sstate)
25-
ctx.setSetting(ctx.settings.YkeepComments, true)
2625
ctx.setSetting(ctx.settings.YcookComments, true)
2726
ctx.setSetting(ctx.settings.YnoInline, true)
2827
ctx.setProperty(ContextDoc, new ContextDottydoc)

doc-tool/test/DottyDocTest.scala

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ trait DottyDocTest extends MessageRendering {
2323
import base.settings._
2424
val ctx = base.initialCtx.fresh
2525
ctx.setSetting(ctx.settings.language, List("Scala2"))
26-
ctx.setSetting(ctx.settings.YkeepComments, true)
2726
ctx.setSetting(ctx.settings.YcookComments, true)
2827
ctx.setSetting(ctx.settings.YnoInline, true)
2928
ctx.setSetting(ctx.settings.wikiSyntax, true)

doc-tool/test/MarkdownTests.scala

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class MarkdownTests extends DottyDocTest {
1515
import base.settings._
1616
val ctx = base.initialCtx.fresh
1717
ctx.setSetting(ctx.settings.language, List("Scala2"))
18-
ctx.setSetting(ctx.settings.YkeepComments, true)
1918
ctx.setSetting(ctx.settings.YnoInline, true)
2019
// No wiki syntax!
2120
ctx.setSetting(ctx.settings.wikiSyntax, false)

0 commit comments

Comments
 (0)