Skip to content

Commit

Permalink
-Vcyclic to trace locked symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Mar 16, 2024
1 parent 0637b15 commit 5bb27fd
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/compiler/scala/tools/nsc/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class Global(var currentSettings: Settings, reporter0: Reporter)

override def settings = currentSettings

override def isSymbolLockTracingEnabled = settings.cyclic

private[this] var currentReporter: FilteringReporter = null
locally { reporter = reporter0 }

Expand Down
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett
*/
val Vhelp = BooleanSetting("-V", "Print a synopsis of verbose options.")
val browse = PhasesSetting("-Vbrowse", "Browse the abstract syntax tree after") withAbbreviation "-Ybrowse"
val cyclic = BooleanSetting("-Vcyclic", "Debug cyclic reference error.")
val debug = BooleanSetting("-Vdebug", "Increase the quantity of debugging output.") withAbbreviation "-Ydebug" withPostSetHook (s => if (s.value) StatisticsStatics.enableDebugAndDeoptimize())
val YdebugTasty = BooleanSetting("-Vdebug-tasty", "Increase the quantity of debugging output when unpickling tasty.") withAbbreviation "-Ydebug-tasty"
val VdebugTypeError = BooleanSetting("-Vdebug-type-error", "Print the stack trace when any error is caught.") withAbbreviation "-Ydebug-type-error"
Expand Down
2 changes: 2 additions & 0 deletions src/reflect/scala/reflect/internal/SymbolTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ abstract class SymbolTable extends macros.Universe

def settings: MutableSettings

def isSymbolLockTracingEnabled: Boolean = isDeveloper

/** Override with final implementation for inlining. */
def debuglog(msg: => String): Unit = if (settings.isDebug) log(msg)

Expand Down
16 changes: 10 additions & 6 deletions src/reflect/scala/reflect/internal/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def lockedCount_=(i: Int) = _lockedCount = i

private[this] val _lockingTrace = Stack.empty[Symbol]

private[this] val lockTracing: Boolean = self.isSymbolLockTracingEnabled

@deprecated("Global existential IDs no longer used", "2.12.1")
private[this] var existentialIds = 0
Expand Down Expand Up @@ -568,7 +568,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>

// Lock a symbol, using the handler if the recursion depth becomes too great.
private[scala] def lock(handler: => Unit): Boolean = {
_lockingTrace.push(this)
if (lockTracing) _lockingTrace.push(this)
if ((_rawflags & LOCKED) != 0L) {
if (settings.Yrecursion.value != 0) {
recursionTable.get(this) match {
Expand Down Expand Up @@ -598,7 +598,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
private[scala] def unlock(): Unit =
if ((_rawflags & LOCKED) != 0L) {
_rawflags &= ~LOCKED
if (!_lockingTrace.isEmpty)
if (lockTracing && !_lockingTrace.isEmpty)
_lockingTrace.remove(idx = 0, count = 1)
if (settings.Yrecursion.value != 0)
recursionTable -= this
Expand Down Expand Up @@ -1563,12 +1563,16 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
if ((_rawflags & LOCKED) != 0L) { // rolled out once for performance
lock {
setInfo(ErrorType)
val trace = _lockingTrace.toList
_lockingTrace.clear()
val trace =
if (lockTracing) {
val t = _lockingTrace.toList
_lockingTrace.clear()
t
} else Nil
throw CyclicReference(this, tp, trace)
}
} else {
_lockingTrace.push(this)
if (lockTracing) _lockingTrace.push(this)
_rawflags |= LOCKED
}
val current = phase
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/t7808.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

//> using options -Vcyclic
class C {
type OI = Option[Int]
def f(z: OI, ls: List[OI], rs: List[OI]): (List[OI], List[OI]) = {
Expand Down
4 changes: 4 additions & 0 deletions test/files/neg/t7808b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
t7808b.scala:5: error: recursive value x$1 needs type
val (ls, rs) = z match {
^
1 error
18 changes: 18 additions & 0 deletions test/files/neg/t7808b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

class C {
type OI = Option[Int]
def f(z: OI, ls: List[OI], rs: List[OI]): (List[OI], List[OI]) = {
val (ls, rs) = z match {
case Some(_) => (z::ls, rs)
case _ => (ls, z::rs)
}
(ls, rs)
}
}

/*
t7808.scala:5: error: recursive value x$1 needs type
val (ls, rs) = z match {
^
1 error
*/

0 comments on commit 5bb27fd

Please sign in to comment.