diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index 2c87672cf..8b0cfd036 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -630,7 +630,9 @@ fn add_main_fingerprint(cf: &mut CompileForm, forms: &[Rc]) { nl: cf.loc(), name: b"main".to_vec(), kind: Some(IncludeProcessType::Compiled), - fingerprint: sha256tree(form_list), + fingerprint: sha256tree(form_list) + .try_into() + .expect("sha256tree digest is 32 bytes"), }); } diff --git a/src/compiler/comptypes.rs b/src/compiler/comptypes.rs index a3fe5fdd2..a31b1e32c 100644 --- a/src/compiler/comptypes.rs +++ b/src/compiler/comptypes.rs @@ -848,8 +848,8 @@ pub struct IncludeDesc { /// Kind of inclusion. Determines whether dependencies are recursed and /// what operation is performed on the retrieved clvm form. pub kind: Option, - /// Fingerprint of input - pub fingerprint: Vec, + /// Fingerprint of input (SHA-256 tree hash of file bytes when known; otherwise zero). + pub fingerprint: [u8; 32], } impl IncludeDesc { diff --git a/src/compiler/diskcache.rs b/src/compiler/diskcache.rs index 0b07c5b4a..e10f3c02b 100644 --- a/src/compiler/diskcache.rs +++ b/src/compiler/diskcache.rs @@ -7,7 +7,7 @@ use crate::compiler::sexp::decode_string; fn cache_key(cf: &CompileForm) -> String { let mut include_fingerprints = Vec::new(); for include in cf.include_forms.iter() { - include_fingerprints.append(&mut include.fingerprint.clone()); + include_fingerprints.extend_from_slice(&include.fingerprint); } hex::encode(sha256tree_from_atom(&include_fingerprints)) } diff --git a/src/compiler/preprocessor/mod.rs b/src/compiler/preprocessor/mod.rs index 6d7352cf8..6fe71a337 100644 --- a/src/compiler/preprocessor/mod.rs +++ b/src/compiler/preprocessor/mod.rs @@ -636,7 +636,9 @@ impl Preprocessor { self.opts.read_new_file(self.opts.filename(), filename_clsp) { // Hash newly read input. - let content_hash = sha256tree_from_atom(&content); + let content_hash: [u8; 32] = sha256tree_from_atom(&content) + .try_into() + .expect("sha256tree_from_atom digest is 32 bytes"); includes.push(IncludeDesc { kw: kw.clone(), nl: nl.clone(), @@ -668,7 +670,9 @@ impl Preprocessor { nl: nl.clone(), name: full_name.as_bytes().to_vec(), kind: Some(IncludeProcessType::Module(Box::new(kind.clone()))), - fingerprint: sha256tree_from_atom(&content), + fingerprint: sha256tree_from_atom(&content) + .try_into() + .expect("sha256tree_from_atom digest is 32 bytes"), }); Ok(res) @@ -805,7 +809,9 @@ impl Preprocessor { let (full_name, content) = self.opts.read_new_file(self.opts.filename(), name_string)?; // Hash newly read input. - let content_hash = sha256tree_from_atom(&content); + let content_hash: [u8; 32] = sha256tree_from_atom(&content) + .try_into() + .expect("sha256tree_from_atom digest is 32 bytes"); includes.push(IncludeDesc { name: full_name.as_bytes().to_vec(), fingerprint: content_hash, @@ -1116,7 +1122,7 @@ impl Preprocessor { nl: import.nl.clone(), name: fname.clone(), kind: Some(mod_kind.clone()), - fingerprint: Vec::new(), + fingerprint: [0u8; 32], }), mod_kind, fname.clone(), @@ -1180,7 +1186,7 @@ impl Preprocessor { nl: nl.clone(), name: fname.clone(), kind: None, - fingerprint: Vec::new(), + fingerprint: [0u8; 32], }))); } @@ -1217,7 +1223,7 @@ impl Preprocessor { nl: nl.clone(), kind: Some(IncludeProcessType::Hex), name: fname.clone(), - fingerprint: Vec::new(), + fingerprint: [0u8; 32], }), IncludeProcessType::Hex, name.clone(), @@ -1229,7 +1235,7 @@ impl Preprocessor { nl: nl.clone(), kind: Some(IncludeProcessType::Bin), name: fname.clone(), - fingerprint: Vec::new(), + fingerprint: [0u8; 32], }), IncludeProcessType::Bin, name.clone(), @@ -1241,7 +1247,7 @@ impl Preprocessor { nl: nl.clone(), kind: Some(IncludeProcessType::SExpression), name: fname.clone(), - fingerprint: Vec::new(), + fingerprint: [0u8; 32], }), IncludeProcessType::SExpression, name.clone(), @@ -1274,7 +1280,7 @@ impl Preprocessor { nl: nl.clone(), kind: Some(IncludeProcessType::Compiled), name: fname.clone(), - fingerprint: Vec::new(), + fingerprint: [0u8; 32], }), IncludeProcessType::Compiled, name.clone(),