Use memoized hashes when hashing Fingerprint.
authorGeoffry Song <goffrie@dropbox.com>
Fri, 22 Sep 2017 06:04:17 +0000 (23:04 -0700)
committerGeoffry Song <goffrie@dropbox.com>
Fri, 22 Sep 2017 06:05:12 +0000 (23:05 -0700)
The recursive hashing of dependencies can cause exponential blowup. We
already have a memoized hash available, so use that, Merkle-tree-style.

src/cargo/ops/cargo_rustc/fingerprint.rs

index 38cef8f1c34ff7d4d2c788f034a7cc39f2135dd0..e4d2dd1245c8e79aee07cf4ce01bfa057b61bc36 100644 (file)
@@ -297,7 +297,14 @@ impl hash::Hash for Fingerprint {
             memoized_hash: _,
             ref rustflags,
         } = *self;
-        (rustc, features, target, profile, deps, local, rustflags).hash(h)
+        (rustc, features, target, profile, local, rustflags).hash(h);
+
+        h.write_usize(deps.len());
+        for &(ref name, ref fingerprint) in deps {
+            name.hash(h);
+            // use memoized dep hashes to avoid exponential blowup
+            h.write_u64(Fingerprint::hash(fingerprint));
+        }
     }
 }