Skip to content

Commit b6a6c47

Browse files
committed
Compute tasty UUID based on nameBuffer and sections hash.
1 parent c4d4ceb commit b6a6c47

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,13 @@ package tasty
66
import TastyFormat._
77
import collection.mutable
88
import TastyBuffer._
9-
import java.util.UUID
109
import core.Symbols.Symbol
1110
import ast.tpd
1211
import Decorators._
1312

1413
class TastyPickler {
1514

1615
private val sections = new mutable.ArrayBuffer[(NameRef, TastyBuffer)]
17-
private val uuid = UUID.fromString("3cee1b79-c03a-4125-b337-d067b5cb3a94") // TODO: use a hash of the tasty tree
18-
19-
private val headerBuffer = {
20-
val buf = new TastyBuffer(24)
21-
for (ch <- header) buf.writeByte(ch.toByte)
22-
buf.writeNat(MajorVersion)
23-
buf.writeNat(MinorVersion)
24-
buf.writeUncompressedLong(uuid.getMostSignificantBits)
25-
buf.writeUncompressedLong(uuid.getLeastSignificantBits)
26-
buf
27-
}
2816

2917
val nameBuffer = new NameBuffer
3018

@@ -36,6 +24,20 @@ class TastyPickler {
3624
buf.assemble()
3725
buf.length + natSize(buf.length)
3826
}
27+
28+
val uuidLow: Long = longHash(nameBuffer.bytes)
29+
val uuidHi: Long = sections.iterator.map(x => longHash(x._2.bytes)).fold(0L)(_ ^ _)
30+
31+
val headerBuffer = {
32+
val buf = new TastyBuffer(header.length + 24)
33+
for (ch <- header) buf.writeByte(ch.toByte)
34+
buf.writeNat(MajorVersion)
35+
buf.writeNat(MinorVersion)
36+
buf.writeUncompressedLong(uuidLow)
37+
buf.writeUncompressedLong(uuidHi)
38+
buf
39+
}
40+
3941
val totalSize =
4042
headerBuffer.length +
4143
lengthWithLength(nameBuffer) + {
@@ -69,4 +71,8 @@ class TastyPickler {
6971
var addrOfSym: Symbol => Option[Addr] = (_ => None)
7072

7173
val treePkl = new TreePickler(this)
74+
75+
private def longHash(arr: Array[Byte], i: Int = 0, acc: Long = 1): Long =
76+
if (i < arr.length) longHash(arr, i + 1, 31L * acc + arr(i)) else acc
77+
7278
}

0 commit comments

Comments
 (0)