From b57e8249e61d08f3260ca25527a3c97f560cb143 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Thu, 24 May 2018 07:20:21 +0200 Subject: [PATCH] Add `-Ycook-comments` to cook comments This commit adds the `-Ycook-comments` option that will enable cooking of the comments (type checking of `@usecase` in docstrings, expansion of `@define` and `@inheritdoc`, etc.) There are two reasons for introducing this configuration option: - Cooking the comments slows the compilation down in cases where we are not interested in cooking them. - Cooking the comments breaks `-Ycheck`, which prevents us from enabling `-Ykeep-comments` by default. --- compiler/src/dotty/tools/dotc/config/ScalaSettings.scala | 1 + compiler/src/dotty/tools/dotc/typer/Typer.scala | 6 ++++-- doc-tool/src/dotty/tools/dottydoc/DocDriver.scala | 1 + doc-tool/test/DottyDocTest.scala | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 8b39883d51c0..7430d41ed453 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -117,6 +117,7 @@ class ScalaSettings extends Settings.SettingGroup { 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 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.") val YcheckAllPatmat = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm)") diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index ef714f516ccb..f9c7fdaeef7b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1527,8 +1527,10 @@ class Typer extends Namer if (!ctx.isAfterTyper) cls.setNoInitsFlags((NoInitsInterface /: body1) ((fs, stat) => fs & defKind(stat))) - // Expand comments and type usecases - cookComments(body1.map(_.symbol), self1.symbol)(ctx.localContext(cdef, cls).setNewScope) + // Expand comments and type usecases if `-Ycook-comments` is set. + if (ctx.settings.YcookComments.value) { + cookComments(body1.map(_.symbol), self1.symbol)(ctx.localContext(cdef, cls).setNewScope) + } checkNoDoubleDeclaration(cls) val impl1 = cpy.Template(impl)(constr1, parents1, self1, body1) diff --git a/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala b/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala index ad114f9a2e19..42eaea8a259b 100644 --- a/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala +++ b/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala @@ -23,6 +23,7 @@ class DocDriver extends Driver { 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) diff --git a/doc-tool/test/DottyDocTest.scala b/doc-tool/test/DottyDocTest.scala index 1d1df4128d18..365acc171356 100644 --- a/doc-tool/test/DottyDocTest.scala +++ b/doc-tool/test/DottyDocTest.scala @@ -24,6 +24,7 @@ trait DottyDocTest extends MessageRendering { 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.YnoInline, true) ctx.setSetting(ctx.settings.wikiSyntax, true) ctx.setProperty(ContextDoc, new ContextDottydoc)