Skip to content

Commit dcba1d8

Browse files
committed
Debug hooks for capture set inference
Allows us to diagnose when a specific variable is created or obtains new elements.
1 parent c07f6fa commit dcba1d8

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

compiler/src/dotty/tools/dotc/cc/Capability.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ object Capabilities:
168168
case _ => false
169169

170170
/** Is this fresh cap at the right level to be able to subsume `ref`?
171+
* Only outer freshes can be subsumed.
171172
*/
172173
def acceptsLevelOf(ref: Capability)(using Context): Boolean =
173174
if ccConfig.useFreshLevels && !CCState.collapseFresh then

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,13 @@ sealed abstract class CaptureSet extends Showable:
394394
if mappedElems == elems then this
395395
else Const(mappedElems)
396396
else if ccState.mapFutureElems then
397-
def unfused = BiMapped(asVar, tm, mappedElems)
397+
def unfused =
398+
if debugVars then
399+
try BiMapped(asVar, tm, mappedElems)
400+
catch case ex: AssertionError =>
401+
println(i"error while mapping $this")
402+
throw ex
403+
else BiMapped(asVar, tm, mappedElems)
398404
this match
399405
case self: BiMapped => self.bimap.fuse(tm) match
400406
case Some(fused: BiTypeMap) => BiMapped(self.source, fused, mappedElems)
@@ -652,8 +658,12 @@ object CaptureSet:
652658
override def toString = "<fluid>"
653659
end Fluid
654660

661+
/** If true emit info when var with id debugTarget is created or gets a new element */
662+
inline val debugVars = false
663+
inline val debugTarget = 22
664+
655665
/** The subclass of captureset variables with given initial elements */
656-
class Var(initialOwner: Symbol = NoSymbol, initialElems: Refs = emptyRefs, val level: Level = undefinedLevel, underBox: Boolean = false)(using @constructorOnly ictx: Context) extends CaptureSet:
666+
class Var(initialOwner: Symbol = NoSymbol, initialElems: Refs = emptyRefs, val level: Level = undefinedLevel, underBox: Boolean = false)(using /*@constructorOnly*/ ictx: Context) extends CaptureSet:
657667

658668
override def owner = initialOwner
659669

@@ -678,8 +688,14 @@ object CaptureSet:
678688
/** The elements currently known to be in the set */
679689
protected var myElems: Refs = initialElems
680690

691+
if debugVars && id == debugTarget then
692+
println(i"###INIT ELEMS of $id to $initialElems")
693+
681694
def elems: Refs = myElems
682-
def elems_=(refs: Refs): Unit = myElems = refs
695+
def elems_=(refs: Refs): Unit =
696+
if debugVars && id == debugTarget then
697+
println(i"###SET ELEMS of $id to $refs")
698+
myElems = refs
683699

684700
/** The sets currently known to be dependent sets (i.e. new additions to this set
685701
* are propagated to these dependent sets.)
@@ -762,6 +778,8 @@ object CaptureSet:
762778

763779
protected def includeElem(elem: Capability)(using Context): Unit =
764780
if !elems.contains(elem) then
781+
if debugVars && id == debugTarget then
782+
println(i"###INCLUDE $elem in $this")
765783
elems += elem
766784
TypeComparer.logUndoAction: () =>
767785
elems -= elem

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,15 @@ class PlainPrinter(_ctx: Context) extends Printer {
172172
then cs.toString
173173
else if cs == CaptureSet.Fluid then "<fluid>"
174174
else
175+
val idTxt = Str(s"#${cs.asVar.id}").provided(showUniqueIds && !cs.isConst)
175176
val core: Text =
176-
if !cs.isConst && cs.elems.isEmpty then cs.asVar.repr.show
177+
if !cs.isConst && cs.elems.isEmpty
178+
then cs.asVar.repr.show ~ idTxt
177179
else
178180
Str("'").provided(ccVerbose && !cs.isConst)
179181
~ "{" ~ Text(cs.processElems(_.toList.map(toTextCapability)), ", ") ~ "}"
180182
~ Str(".reader").provided(ccVerbose && cs.mutability == Mutability.Reader)
181-
~ Str(s"#${cs.asVar.id}").provided(showUniqueIds && !cs.isConst)
183+
~ idTxt
182184
core ~ cs.optionalInfo
183185

184186
private def toTextRetainedElem(ref: Type): Text = ref match

0 commit comments

Comments
 (0)