Skip to content

Commit 1c235fa

Browse files
Merge pull request #6718 from dotty-staging/debug-pickling
Add pickling crash debug guide when developing macros
2 parents 0a67182 + 5e98568 commit 1c235fa

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ class TreePickler(pickler: TastyPickler) {
695695

696696
def pickle(trees: List[Tree])(implicit ctx: Context): Unit = {
697697
trees.foreach(tree => if (!tree.isEmpty) pickleTree(tree))
698-
def missing = forwardSymRefs.keysIterator.map(_.showLocated).toList
698+
def missing = forwardSymRefs.keysIterator.map(sym => sym.showLocated + "(line " + sym.sourcePos.line + ")").toList
699699
assert(forwardSymRefs.isEmpty, i"unresolved symbols: $missing%, % when pickling ${ctx.source}")
700700
}
701701

docs/docs/internals/debug-macros.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,36 @@ If the position is in the compiler, then either report a compiler bug or
3030
fix the problem with `.withSpan(tree.span)`. The following fix is an example:
3131

3232
- https://github.com/lampepfl/dotty/pull/6581
33+
34+
## unresolved symbols in pickling
35+
36+
Here is the usually stacktrace for unresolved symbols in pickling:
37+
38+
```
39+
[error] java.lang.AssertionError: assertion failed: unresolved symbols: value pos (line 5565) when pickling scalatest/scalatest-test.dotty/target/scala-0.17/src_managed/test/org/scalatest/AssertionsSpec.scala
40+
[error] at dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
41+
[error] at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:699)
42+
[error] at dotty.tools.dotc.transform.Pickler.run$$anonfun$10$$anonfun$8(Pickler.scala:60)
43+
[error] at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
44+
[error] at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
45+
[error] at scala.collection.immutable.List.foreach(List.scala:392)
46+
[error] at dotty.tools.dotc.transform.Pickler.run$$anonfun$2(Pickler.scala:83)
47+
[error] at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
48+
[error] at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
49+
[error] at scala.collection.immutable.List.foreach(List.scala:392)
50+
[error] at dotty.tools.dotc.transform.Pickler.run(Pickler.scala:83)
51+
[error] at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:316)
52+
[error] at scala.collection.immutable.List.map(List.scala:286)
53+
[error] at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:318)
54+
[error] at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:87)
55+
```
56+
57+
From the stack trace, we know `pos` at line 5565 cannot be resolved. For the
58+
compiler, it means that the name `pos` (usually a local name, but could also be
59+
a class member) is used in the code but its definition cannot be found.
60+
61+
A possible cause of the problem is that the macro implementation accidentally
62+
dropped the definition of the referenced name.
63+
64+
If you are confident that the macro implementation is correct, then it might be
65+
a bug of the compiler. Try to minimize the code and report a compiler bug.

0 commit comments

Comments
 (0)