Skip to content

Add -Ydebug-tree-with-id n #6363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import config.CompilerCommand
import core.Comments.{ContextDoc, ContextDocstrings}
import core.Contexts.{Context, ContextBase}
import core.{MacroClassLoader, Mode, TypeError}
import dotty.tools.dotc.ast.Positioned
import reporting._

import scala.util.control.NonFatal
Expand Down Expand Up @@ -55,6 +56,7 @@ class Driver {
val summary = CompilerCommand.distill(args)(ctx)
ctx.setSettings(summary.sstate)
MacroClassLoader.init(ctx)
Positioned.updateDebugPos(ctx)

if (!ctx.settings.YdropComments.value(ctx) || ctx.mode.is(Mode.ReadComments)) {
ctx.setProperty(ContextDoc, new ContextDocstrings)
Expand Down
21 changes: 16 additions & 5 deletions compiler/src/dotty/tools/dotc/ast/Positioned.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
*/
def uniqueId: Int = myUniqueId

private def uniqueId_=(id: Int): Unit = {
// FOR DEBUGGING
// assert(id != 2523, this)
// if (id == 1234) new Throwable().printStackTrace()

def uniqueId_=(id: Int): Unit = {
if (Positioned.debugId == id) {
def printTrace() = {
val stack = Thread.currentThread().getStackTrace().map("> " + _)
System.err.println(stack.mkString(s"> Debug tree (id=${Positioned.debugId}) creation \n> $this\n", "\n", "\n"))
}
printTrace()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the logic abstracted into a method instead of inlining it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uniqueId_= is probably a hot path as each tree creation will have a call to it. I put the code contained in this debug branch to make the bytecode of uniqueId_= smaller and probably simple to optimize from the JVM perspective.

}
myUniqueId = id
}

Expand Down Expand Up @@ -229,3 +232,11 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
throw ex
}
}

object Positioned {
@sharable private[Positioned] var debugId = Int.MinValue

def updateDebugPos(implicit ctx: Context): Unit = {
debugId = ctx.settings.YdebugTreeWithId.value
}
}
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ScalaSettings extends Settings.SettingGroup {
val YdebugMissingRefs: Setting[Boolean] = BooleanSetting("-Ydebug-missing-refs", "Print a stacktrace when a required symbol is missing")
val YdebugNames: Setting[Boolean] = BooleanSetting("-Ydebug-names", "Show internal representation of names")
val YdebugPos: Setting[Boolean] = BooleanSetting("-Ydebug-pos", "Show full source positions including spans")
val YdebugTreeWithId: Setting[Int] = IntSetting("-Ydebug-tree-with-id", "Print the stack trace when the tree with the given id is created", Int.MinValue)
val YtermConflict: Setting[String] = ChoiceSetting("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error")
val Ylog: Setting[List[String]] = PhasesSetting("-Ylog", "Log operations during")
val YemitTastyInClass: Setting[Boolean] = BooleanSetting("-Yemit-tasty-in-class", "Generate tasty in the .class file and add an empty *.hasTasty file.")
Expand Down