Skip to content

Backport sourcelinks fixes #13274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ class TreeUnpickler(reader: TastyReader,
if (path.nonEmpty) {
val sourceFile = ctx.getSource(path)
posUnpicklerOpt match
case Some(posUnpickler) =>
case Some(posUnpickler) if !sourceFile.initizlized =>
sourceFile.setLineIndicesFromLineSizes(posUnpickler.lineSizes)
case _ =>
pickling.println(i"source change at $addr: $path")
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/util/SourceFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
if lineIndicesCache eq null then
lineIndicesCache = calculateLineIndicesFromContents()
lineIndicesCache

def initizlized = lineIndicesCache != null

def setLineIndicesFromLineSizes(sizes: Array[Int]): Unit =
val lines = sizes.length
val indices = new Array[Int](lines + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ class RemoteLinksTest:
def runTest =
assertTrue(mtslAll.nonEmpty)
val mtsl = randomGenerator.shuffle(mtslAll).take(80) // take 80 random entries
val pageToMtsl: Map[String, List[(String, String)]] = mtsl.groupMap(_._2.split("#L").head)(v => (v._1, v._2.split("#L").last))
pageToMtsl.foreach { case (link, members) =>
val pageToMtsl: Map[String, List[(String, Int)]] =
mtsl.groupMap(_._2.split("#L").head)(v => (v._1, v._2.split("#L").last.toInt))
pageToMtsl.toSeq.sortBy(_._1).foreach { case (link, members) =>
try
val doc = getDocumentFromUrl(link)
println(s"Checking $link")
members.foreach { case (member, expectedLine) =>
if !member.startsWith("given_") then // TODO: handle synthetic givens, for now we disable them from testing
val toLine = expectedLine + 3
val memberToMatch = member.replace("`", "")
val lineCorrectlyDefined = (expectedLine.toInt until toLine.toInt).exists{ line =>
val lineCorrectlyDefined = (expectedLine until toLine).exists{ line =>
val loc = doc.select(s"#LC$line").text

loc.contains(memberToMatch)
Expand Down