Skip to content

Commit 5bb27fd

Browse files
committed
-Vcyclic to trace locked symbols
1 parent 0637b15 commit 5bb27fd

File tree

7 files changed

+38
-7
lines changed

7 files changed

+38
-7
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
9090

9191
override def settings = currentSettings
9292

93+
override def isSymbolLockTracingEnabled = settings.cyclic
94+
9395
private[this] var currentReporter: FilteringReporter = null
9496
locally { reporter = reporter0 }
9597

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett
563563
*/
564564
val Vhelp = BooleanSetting("-V", "Print a synopsis of verbose options.")
565565
val browse = PhasesSetting("-Vbrowse", "Browse the abstract syntax tree after") withAbbreviation "-Ybrowse"
566+
val cyclic = BooleanSetting("-Vcyclic", "Debug cyclic reference error.")
566567
val debug = BooleanSetting("-Vdebug", "Increase the quantity of debugging output.") withAbbreviation "-Ydebug" withPostSetHook (s => if (s.value) StatisticsStatics.enableDebugAndDeoptimize())
567568
val YdebugTasty = BooleanSetting("-Vdebug-tasty", "Increase the quantity of debugging output when unpickling tasty.") withAbbreviation "-Ydebug-tasty"
568569
val VdebugTypeError = BooleanSetting("-Vdebug-type-error", "Print the stack trace when any error is caught.") withAbbreviation "-Ydebug-type-error"

src/reflect/scala/reflect/internal/SymbolTable.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ abstract class SymbolTable extends macros.Universe
9595

9696
def settings: MutableSettings
9797

98+
def isSymbolLockTracingEnabled: Boolean = isDeveloper
99+
98100
/** Override with final implementation for inlining. */
99101
def debuglog(msg: => String): Unit = if (settings.isDebug) log(msg)
100102

src/reflect/scala/reflect/internal/Symbols.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
4545
def lockedCount_=(i: Int) = _lockedCount = i
4646

4747
private[this] val _lockingTrace = Stack.empty[Symbol]
48-
48+
private[this] val lockTracing: Boolean = self.isSymbolLockTracingEnabled
4949

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

569569
// Lock a symbol, using the handler if the recursion depth becomes too great.
570570
private[scala] def lock(handler: => Unit): Boolean = {
571-
_lockingTrace.push(this)
571+
if (lockTracing) _lockingTrace.push(this)
572572
if ((_rawflags & LOCKED) != 0L) {
573573
if (settings.Yrecursion.value != 0) {
574574
recursionTable.get(this) match {
@@ -598,7 +598,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
598598
private[scala] def unlock(): Unit =
599599
if ((_rawflags & LOCKED) != 0L) {
600600
_rawflags &= ~LOCKED
601-
if (!_lockingTrace.isEmpty)
601+
if (lockTracing && !_lockingTrace.isEmpty)
602602
_lockingTrace.remove(idx = 0, count = 1)
603603
if (settings.Yrecursion.value != 0)
604604
recursionTable -= this
@@ -1563,12 +1563,16 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
15631563
if ((_rawflags & LOCKED) != 0L) { // rolled out once for performance
15641564
lock {
15651565
setInfo(ErrorType)
1566-
val trace = _lockingTrace.toList
1567-
_lockingTrace.clear()
1566+
val trace =
1567+
if (lockTracing) {
1568+
val t = _lockingTrace.toList
1569+
_lockingTrace.clear()
1570+
t
1571+
} else Nil
15681572
throw CyclicReference(this, tp, trace)
15691573
}
15701574
} else {
1571-
_lockingTrace.push(this)
1575+
if (lockTracing) _lockingTrace.push(this)
15721576
_rawflags |= LOCKED
15731577
}
15741578
val current = phase

test/files/neg/t7808.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
//> using options -Vcyclic
22
class C {
33
type OI = Option[Int]
44
def f(z: OI, ls: List[OI], rs: List[OI]): (List[OI], List[OI]) = {

test/files/neg/t7808b.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
t7808b.scala:5: error: recursive value x$1 needs type
2+
val (ls, rs) = z match {
3+
^
4+
1 error

test/files/neg/t7808b.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
class C {
3+
type OI = Option[Int]
4+
def f(z: OI, ls: List[OI], rs: List[OI]): (List[OI], List[OI]) = {
5+
val (ls, rs) = z match {
6+
case Some(_) => (z::ls, rs)
7+
case _ => (ls, z::rs)
8+
}
9+
(ls, rs)
10+
}
11+
}
12+
13+
/*
14+
t7808.scala:5: error: recursive value x$1 needs type
15+
val (ls, rs) = z match {
16+
^
17+
1 error
18+
*/

0 commit comments

Comments
 (0)