Skip to content

Commit d4687cd

Browse files
Kordyjananatoliykmetyuk
authored andcommitted
Add explanation to InlinedSourceMaps
1 parent b7e97d9 commit d4687cd

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

compiler/src/dotty/tools/backend/jvm/InlinedSourceMaps.scala

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,27 @@ import dotc.report
1111
import dotc.typer.Inliner.InliningPosition
1212
import collection.mutable
1313

14-
14+
/**
15+
* Tool for generating virtual lines for inlined calls and keeping track of them.
16+
17+
* How it works:
18+
* - For every inlined call it assumes that empty lines are appended to the source file. These
19+
* lines are not added anywhere in physical form. We only assume that they exist only to be used
20+
* by `LineNumberTable` and `SourceDebugExtension`. The number of these virtual lines is every
21+
* time equal to the size of line range of the expansion of inlined call.
22+
* - It generates SMAP (as defined by JSR-45) containing two strata. The first stratum (`Scala`)
23+
* is describing the mapping from the real source files to the real and virtual lines in our
24+
* assumed source. The second stratum (`ScalaDebug`) is mapping from virtual lines to
25+
* corresponding inlined calls.
26+
* - Generated SMAP is written to the bytecode in `SourceDebugExtension`
27+
* - During the generation of the bytecode backed is asking `InlinedSourceMap` about position of
28+
* all trees that have source different from the main source of given compilation unit.
29+
* The response to that request is number of the virtual line that is corresponding to particular
30+
* line from the other source.
31+
* - Debuggers can use information stored in `LineNumberTable` and `SourceDebugExtension` to
32+
* correctly guess which line of inlined method is currently executed. They can also construct
33+
* stack frames for inlined calls.
34+
**/
1535
object InlinedSourceMaps:
1636
private case class Request(targetPos: SourcePosition, origPos: SourcePosition, firstFakeLine: Int)
1737

0 commit comments

Comments
 (0)