@@ -6,25 +6,13 @@ package tasty
66import TastyFormat ._
77import collection .mutable
88import TastyBuffer ._
9- import java .util .UUID
109import core .Symbols .Symbol
1110import ast .tpd
1211import Decorators ._
1312
1413class 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