Skip to content

Commit 1521576

Browse files
authored
Merge pull request #6363 from dotty-staging/add-tree-id-debug-setting
Add `-Ydebug-tree-with-id n`
2 parents 93aba3f + 5bb1ee3 commit 1521576

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import config.CompilerCommand
77
import core.Comments.{ContextDoc, ContextDocstrings}
88
import core.Contexts.{Context, ContextBase}
99
import core.{MacroClassLoader, Mode, TypeError}
10+
import dotty.tools.dotc.ast.Positioned
1011
import reporting._
1112

1213
import scala.util.control.NonFatal
@@ -55,6 +56,7 @@ class Driver {
5556
val summary = CompilerCommand.distill(args)(ctx)
5657
ctx.setSettings(summary.sstate)
5758
MacroClassLoader.init(ctx)
59+
Positioned.updateDebugPos(ctx)
5860

5961
if (!ctx.settings.YdropComments.value(ctx) || ctx.mode.is(Mode.ReadComments)) {
6062
ctx.setProperty(ContextDoc, new ContextDocstrings)

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
2323
*/
2424
def uniqueId: Int = myUniqueId
2525

26-
private def uniqueId_=(id: Int): Unit = {
27-
// FOR DEBUGGING
28-
// assert(id != 2523, this)
29-
// if (id == 1234) new Throwable().printStackTrace()
30-
26+
def uniqueId_=(id: Int): Unit = {
27+
if (Positioned.debugId == id) {
28+
def printTrace() = {
29+
val stack = Thread.currentThread().getStackTrace().map("> " + _)
30+
System.err.println(stack.mkString(s"> Debug tree (id=${Positioned.debugId}) creation \n> $this\n", "\n", "\n"))
31+
}
32+
printTrace()
33+
}
3134
myUniqueId = id
3235
}
3336

@@ -229,3 +232,11 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
229232
throw ex
230233
}
231234
}
235+
236+
object Positioned {
237+
@sharable private[Positioned] var debugId = Int.MinValue
238+
239+
def updateDebugPos(implicit ctx: Context): Unit = {
240+
debugId = ctx.settings.YdebugTreeWithId.value
241+
}
242+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class ScalaSettings extends Settings.SettingGroup {
102102
val YdebugMissingRefs: Setting[Boolean] = BooleanSetting("-Ydebug-missing-refs", "Print a stacktrace when a required symbol is missing")
103103
val YdebugNames: Setting[Boolean] = BooleanSetting("-Ydebug-names", "Show internal representation of names")
104104
val YdebugPos: Setting[Boolean] = BooleanSetting("-Ydebug-pos", "Show full source positions including spans")
105+
val YdebugTreeWithId: Setting[Int] = IntSetting("-Ydebug-tree-with-id", "Print the stack trace when the tree with the given id is created", Int.MinValue)
105106
val YtermConflict: Setting[String] = ChoiceSetting("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error")
106107
val Ylog: Setting[List[String]] = PhasesSetting("-Ylog", "Log operations during")
107108
val YemitTastyInClass: Setting[Boolean] = BooleanSetting("-Yemit-tasty-in-class", "Generate tasty in the .class file and add an empty *.hasTasty file.")

0 commit comments

Comments
 (0)