google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.34k stars 212 forks source link

hash: allow only strings, and use a deterministic algorithm #198

Closed alandonovan closed 5 years ago

alandonovan commented 5 years ago

Previously, hash would allow any operand defined as hashable by the spec, and would use (for strings at least) a fast hardware implementation that varies across process restarts.

alandonovan commented 5 years ago

@laurentlb -- this change brings the Go and Java impls closer, and fixes a bug in which the set of targets in a Bazel package would vary from one run to the next.

alandonovan commented 5 years ago

A question: should Starlark in Go attempt to generate the exact same hashes as Starlark-in-Java, which hashes the sequence of UTF-16 codes using a polynomial accumulator? Transcoding valid UTF-8 to 16 is not hard, but it does seem to be indulging bad habits of writing code that depends on hashing for its observed results. On the other hand, that is exactly what some users do.