Skip to content

Commit f628ce0

Browse files
committed
Relative source path in pickling
1 parent 8501978 commit f628ce0

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import util.Spans._
1919
class PositionPickler(
2020
pickler: TastyPickler,
2121
addrOfTree: PositionPickler.TreeToAddr,
22-
treeAnnots: untpd.MemberDef => List[tpd.Tree]) {
22+
treeAnnots: untpd.MemberDef => List[tpd.Tree])(using Context) {
2323

2424
import ast.tpd._
2525
val buf: TastyBuffer = new TastyBuffer(5000)
@@ -67,21 +67,10 @@ class PositionPickler(
6767
// specialization.
6868
}
6969

70-
def pickleSource(source: SourceFile): Unit = {
70+
def pickleSource(source: SourceFile)(using Context): Unit = {
7171
buf.writeInt(SOURCE)
72-
val pathName = source.path
73-
val pickledPath =
74-
val originalPath = java.nio.file.Paths.get(pathName.toString).normalize()
75-
if originalPath.isAbsolute then
76-
val path = originalPath.toAbsolutePath().normalize()
77-
val cwd = java.nio.file.Paths.get("").toAbsolutePath().normalize()
78-
try cwd.relativize(path)
79-
catch case _: IllegalArgumentException =>
80-
warnings += "Could not relativize path for pickling: " + originalPath
81-
originalPath
82-
else
83-
originalPath
84-
buf.writeInt(pickler.nameBuffer.nameIndex(pickledPath.toString.toTermName).index)
72+
val relativePath = SourceFile.relativePath(source)
73+
buf.writeInt(pickler.nameBuffer.nameIndex(relativePath.toTermName).index)
8574
}
8675

8776
/** True if x's position shouldn't be reconstructed automatically from its initial span
@@ -105,7 +94,7 @@ class PositionPickler(
10594
case _ => false
10695
}
10796

108-
def traverse(x: Any, current: SourceFile): Unit = x match {
97+
def traverse(x: Any, current: SourceFile)(using Context): Unit = x match {
10998
case x: untpd.Tree =>
11099
if (x.span.exists) {
111100
val addr = addrOfTree(x)

0 commit comments

Comments
 (0)