Skip to content

Commit 21e90d8

Browse files
committed
Add -Yprintpos-syms to print the position of symbols
And add it to the set of options passed to the pickling tests so that we can start checking that symbol positions are properly pickled and unpickled.
1 parent d2d2d8f commit 21e90d8

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class ScalaSettings extends Settings.SettingGroup {
9696
val YdetailedStats = BooleanSetting("-Ydetailed-stats", "show detailed internal compiler stats (needs Stats.enabled to be set to true).")
9797
val Yheartbeat = BooleanSetting("-Ydetailed-stats", "show heartbeat stack trace of compiler operations (needs Stats.enabled to be set to true).")
9898
val YprintPos = BooleanSetting("-Yprint-pos", "show tree positions.")
99+
val YprintPosSyms = BooleanSetting("-Yprint-pos-syms", "show symbol definitions positions.")
99100
val YnoDeepSubtypes = BooleanSetting("-Yno-deep-subtypes", "throw an exception on deep subtyping call stacks.")
100101
val YnoPatmatOpt = BooleanSetting("-Yno-patmat-opt", "disable all pattern matching optimizations.")
101102
val YplainPrinter = BooleanSetting("-Yplain-printer", "Pretty-print using a plain printer.")

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Trees._
1313
import TypeApplications._
1414
import Decorators._
1515
import config.Config
16+
import util.Positions._
1617
import transform.SymUtils._
1718
import scala.annotation.switch
1819
import language.implicitConversions
@@ -630,14 +631,18 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
630631
else if (tree.isType && !homogenizedView)
631632
txt = toText(tp)
632633
}
633-
if (printPos && !suppressPositions) {
634-
// add positions
635-
val pos =
636-
if (homogenizedView && !tree.isInstanceOf[MemberDef]) tree.pos.toSynthetic
637-
else tree.pos
638-
val clsStr = ""//if (tree.isType) tree.getClass.toString else ""
639-
txt = (txt ~ "@" ~ pos.toString ~ clsStr).close
640-
}
634+
if (!suppressPositions) {
635+
if (printPos) {
636+
val pos =
637+
if (homogenizedView && !tree.isInstanceOf[MemberDef]) tree.pos.toSynthetic
638+
else tree.pos
639+
val clsStr = ""//if (tree.isType) tree.getClass.toString else ""
640+
txt = (txt ~ "@" ~ pos.toString ~ clsStr).close
641+
}
642+
if (ctx.settings.YprintPosSyms.value && tree.isDef)
643+
txt = (txt ~
644+
s"@@(${tree.symbol.name}=" ~ tree.symbol.pos.toString ~ ")").close
645+
}
641646
if (ctx.settings.YshowTreeIds.value)
642647
txt = (txt ~ "#" ~ tree.uniqueId.toString).close
643648
tree match {

compiler/test/dotc/tests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class tests extends CompilerTest {
7373
else List("-Ycheck:tailrec,resolveSuper,mixin,elimStaticThis,labelDef,simplify")
7474
} ++ checkOptions ++ classPath
7575

76-
val testPickling = List("-Xprint-types", "-Ytest-pickler", "-Ystop-after:pickler", "-Yprint-pos")
76+
val testPickling = List("-Xprint-types", "-Ytest-pickler", "-Ystop-after:pickler", "-Yprint-pos", "-Yprint-pos-syms")
7777

7878
val twice = List("#runs", "2")
7979
val staleSymbolError: List[String] = List()

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ object TestConfiguration {
5454
val picklingOptions = defaultUnoptimised and (
5555
"-Xprint-types",
5656
"-Ytest-pickler",
57-
"-Yprint-pos"
57+
"-Yprint-pos",
58+
"-Yprint-pos-syms"
5859
)
5960
val scala2Mode = defaultOptions and "-language:Scala2"
6061
val explicitUTF8 = defaultOptions and ("-encoding", "UTF8")

0 commit comments

Comments
 (0)