Skip to content

Commit

Permalink
Keep comments by default, add -Ydrop-comments
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Duhemm committed Jun 11, 2018
1 parent afbc23f commit deb9dc8
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class Driver extends DotClass {

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

def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ScalaSettings extends Settings.SettingGroup {
val YshowPrintErrors = BooleanSetting("-Yshow-print-errors", "don't suppress exceptions thrown during tree printing.")
val YtestPickler = BooleanSetting("-Ytest-pickler", "self-test for pickling functionality; should be used with -Ystop-after:pickler")
val YcheckReentrant = BooleanSetting("-Ycheck-reentrant", "check that compiled program does not contain vars that can be accessed from a global root.")
val YkeepComments = BooleanSetting("-Ykeep-comments", "Keep comments when scanning source files.")
val YdropComments = BooleanSetting("-Ydrop-comments", "Drop comments when scanning source files.")
val YcookComments = BooleanSetting("-Ycook-comments", "Cook the comments (type check `@usecase`, etc.)")
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.")
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.")
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ object Scanners {
}

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

/** All doc comments kept by their end position in a `Map` */
private[this] var docstringMap: SortedMap[Int, Comment] = SortedMap.empty
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Pickler extends Phase {
if (tree.pos.exists)
new PositionPickler(pickler, treePkl.buf.addrOfTree).picklePositions(tree :: Nil)

if (ctx.settings.YkeepComments.value)
if (!ctx.settings.YdropComments.value)
new CommentPickler(pickler, treePkl.buf.addrOfTree).pickleComment(tree)

// other pickle sections go here.
Expand Down
1 change: 0 additions & 1 deletion compiler/test/dotty/tools/dotc/parsing/DocstringTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ast.Trees._
import core.Contexts.Context

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

def checkDocString(actual: Option[String], expected: String): Unit = actual match {
case Some(str) =>
Expand Down
1 change: 0 additions & 1 deletion doc-tool/src/dotty/tools/dottydoc/DocDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class DocDriver extends Driver {
val summary = CompilerCommand.distill(args)(ctx)

ctx.setSettings(summary.sstate)
ctx.setSetting(ctx.settings.YkeepComments, true)
ctx.setSetting(ctx.settings.YcookComments, true)
ctx.setSetting(ctx.settings.YnoInline, true)
ctx.setProperty(ContextDoc, new ContextDottydoc)
Expand Down
1 change: 0 additions & 1 deletion doc-tool/test/DottyDocTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ trait DottyDocTest extends MessageRendering {
import base.settings._
val ctx = base.initialCtx.fresh
ctx.setSetting(ctx.settings.language, List("Scala2"))
ctx.setSetting(ctx.settings.YkeepComments, true)
ctx.setSetting(ctx.settings.YcookComments, true)
ctx.setSetting(ctx.settings.Ycheck, "all" :: Nil)
ctx.setSetting(ctx.settings.YnoInline, true)
Expand Down
1 change: 0 additions & 1 deletion doc-tool/test/MarkdownTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class MarkdownTests extends DottyDocTest {
import base.settings._
val ctx = base.initialCtx.fresh
ctx.setSetting(ctx.settings.language, List("Scala2"))
ctx.setSetting(ctx.settings.YkeepComments, true)
ctx.setSetting(ctx.settings.YnoInline, true)
ctx.setSetting(ctx.settings.Ycheck, "all" :: Nil)
// No wiki syntax!
Expand Down

0 comments on commit deb9dc8

Please sign in to comment.