Skip to content

Commit c3bfe48

Browse files
committed
Add documentation to debug missing position crash
Previously we just print the stacktrace, which is not helpful for complex projects, as the console will be flooded with other noisy messages.
1 parent 9413cc0 commit c3bfe48

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
2424
def uniqueId: Int = myUniqueId
2525

2626
def uniqueId_=(id: Int): Unit = {
27-
if (Positioned.debugId == id) {
28-
def printTrace() = {
29-
val stack = Thread.currentThread().getStackTrace().map("> " + _)
30-
System.err.println(stack.mkString(s"> Debug tree (id=${Positioned.debugId}) creation \n> $this\n", "\n", "\n"))
31-
}
32-
printTrace()
33-
}
27+
if (Positioned.debugId == id) ???
3428
myUniqueId = id
3529
}
3630

docs/docs/internals/debug-macros.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
layout: doc-page
3+
title: "Debug Macros"
4+
---
5+
6+
Complex macros may break invariants of the compiler, which leads to compiler crashes.
7+
Here we lists common compiler crashes and how to deal with them.
8+
9+
## position not set
10+
11+
For this problem, here is the log that is usually shown:
12+
13+
```
14+
[error] assertion failed: position not set for org.scalactic.anyvals.PosZInt.+$extension3(SizeParam.this.minSize)(
15+
[error] org.scalactic.anyvals.PosZInt.widenToInt(SizeParam.this.sizeRange)
16+
[error] ) # 2326942 of class dotty.tools.dotc.ast.Trees$Apply in library/src-bootstrapped/scala/tasty/reflect/utils/TreeUtils.scala
17+
```
18+
19+
To debug why the position is not set, note the tree id `2326942`, and enable
20+
the following compiler option:
21+
22+
```
23+
-Ydebug-tree-with-id 2326942
24+
```
25+
26+
With the option above, the compiler will crash when the tree is created. From
27+
the stack trace, we will be able to figure out where the tree is created.
28+
29+
If the position is in the compiler, then either report a compiler bug or
30+
fix the problem with `.withSpan(tree.span)`. The following fix is an example:
31+
32+
- https://github.com/lampepfl/dotty/pull/6581
33+

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ sidebar:
183183
url: docs/internals/type-system.html
184184
- title: "Dotty Internals 1: Trees & Symbols (Meeting Notes)"
185185
url: docs/internals/dotty-internals-1-notes.html
186+
- title: Debug Macros
187+
url: docs/internals/debug-macros.html
186188
- title: Resources
187189
subsection:
188190
- title: Talks

0 commit comments

Comments
 (0)