Skip to content

Commit 12e4605

Browse files
committed
Pickle comments positions
We're not reusing the PositionPickler for this task, because it is very tied to pickling the positions of `Tree`s, which `Comment`s are not. We simply pickle the coordinates of the comment, and reconstruct the position from the coordinates when unpickling.
1 parent a02f8ad commit 12e4605

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Option[Addr]
2323
buf.writeAddr(addr)
2424
buf.writeNat(length)
2525
buf.writeBytes(bytes, length)
26+
buf.writeLongInt(cmt.pos.coords)
2627
buf.writeByte(if (cmt.isExpanded) 1 else 0)
2728
case other =>
2829
()

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotty.tools.dotc.core.tasty
33
import dotty.tools.dotc.core.Comments.Comment
44
import dotty.tools.dotc.core.Symbols.Symbol
55
import dotty.tools.dotc.core.tasty.TastyBuffer.Addr
6-
import dotty.tools.dotc.util.Positions
6+
import dotty.tools.dotc.util.Positions.Position
77

88
import scala.collection.mutable.HashMap
99

@@ -19,9 +19,10 @@ class CommentUnpickler(reader: TastyReader) {
1919
val length = readNat()
2020
if (length > 0) {
2121
val bytes = readBytes(length)
22+
val position = new Position(readLongInt())
2223
val expanded = readByte() == 1
2324
val rawComment = new String(bytes, Charset.forName("UTF-8"))
24-
comments(addr) = Comment(Positions.NoPosition, rawComment, expanded = expanded)
25+
comments(addr) = Comment(position, rawComment, expanded = expanded)
2526
}
2627
}
2728
comments.toMap

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ Standard Section: "Positions" Assoc*
235235
236236
Standard Section: "Comments" Comment*
237237
238-
Comment = Length Bytes Byte // Raw comment's bytes encoded as UTF-8, plus a byte indicating
239-
// whether the comment is expanded (1) or not expanded (0)
238+
Comment = Length Bytes LongInt Byte // Raw comment's bytes encoded as UTF-8, followed by the comment's coordinates,
239+
// plus a byte indicating whether the comment is expanded (1) or not expanded (0)
240240
241241
242242
**************************************************************************************/

0 commit comments

Comments
 (0)