From 73e7c3e5602920fb4ac304d11341abdfeab556c3 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Wed, 6 Mar 2024 00:05:42 -0800 Subject: [PATCH] Attempt order invariance --- packages/interpreter/build.rs | 17 +++++++++-------- packages/interpreter/src/js/hash.txt | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/interpreter/build.rs b/packages/interpreter/build.rs index 753e774e1..619273eed 100644 --- a/packages/interpreter/build.rs +++ b/packages/interpreter/build.rs @@ -1,6 +1,6 @@ use std::{ fs::read_to_string, - hash::{DefaultHasher, Hash, Hasher}, + hash::{DefaultHasher, Hasher}, process::Command, }; @@ -16,8 +16,6 @@ fn main() { if contents.trim() == hash.to_string() { return; } - - panic!("Hashes don't match {} != {}", contents, hash.to_string()); } // Otherwise, generate the bindings and write the new hash to disk @@ -30,8 +28,8 @@ fn main() { } /// Hashes the contents of a directory -fn hash_dir(dir: &str) -> u64 { - let mut hasher = DefaultHasher::new(); +fn hash_dir(dir: &str) -> u128 { + let mut out = 0_128; for entry in std::fs::read_dir(dir).unwrap() { let entry = entry.unwrap(); @@ -45,11 +43,14 @@ fn hash_dir(dir: &str) -> u64 { continue; } - let contents = std::fs::read(&path).unwrap(); - contents.hash(&mut hasher); + // Hash the contents of the file and then add it to the overall hash + // This makes us order invariant + let mut hasher = DefaultHasher::new(); + hasher.write(&std::fs::read(&path).unwrap()); + out += hasher.finish() as u128; } - hasher.finish() + out } // okay...... so tsc might fail if the user doesn't have it installed diff --git a/packages/interpreter/src/js/hash.txt b/packages/interpreter/src/js/hash.txt index 4ab3240ae..623ff5f16 100644 --- a/packages/interpreter/src/js/hash.txt +++ b/packages/interpreter/src/js/hash.txt @@ -1 +1 @@ -6653358969285642234 \ No newline at end of file +63611502429846612446 \ No newline at end of file