Make sure that calls to Fingerprint::combine do not undermine collision safety #44337
Labels
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Fingerprint::combine
is not a cryptographic hash, so when we use it we might lose the "cryptographic" guarantee of collision safety. Potentially even worse,Fingerprint::combine
is associative:Fingerprint::combine(Fingerprint::combine(a, b), c) = Fingerprint::combine(a, Fingerprint::combine(b, c))
, and that might cause "algebraic" collisions in some cases.For example:
rust/src/librustc/dep_graph/dep_node.rs
Line 595 in 2f1ef9e
rust/src/librustc/dep_graph/dep_node.rs
Lines 614 to 623 in 2f1ef9e
And another case added by my PR:
https://github.com/arielb1/rust/blob/d14ed92f6b5aa23fd06f8affe4554f2c370bc79d/src/librustc/dep_graph/dep_node.rs#L647-L657
I believe the only requirement for
DepNode
is that the map fromQueryKey -> (DepKind, Fingerprint)
is injective. It might be a good idea to have a good sense of the requirements there to avoid accidental collisions.The text was updated successfully, but these errors were encountered: