diff options
author | Nadrieril | 2020-04-06 11:48:28 +0100 |
---|---|---|
committer | GitHub | 2020-04-06 11:48:28 +0100 |
commit | d35cb130d80d628807a4247ddf84a8d0230c87ab (patch) | |
tree | b99dadebeab8094c129cc5d872cfd561f9aa78f3 /dhall/src/syntax | |
parent | 4290615769fc26c5e4b70843e7fbfddf6359af41 (diff) | |
parent | 12b81d55e1343fc30138d1a13cd48fa2e05744df (diff) |
Merge pull request #158 from Nadrieril/hash
Implement semantic hashing (but no caching yet)
Diffstat (limited to 'dhall/src/syntax')
-rw-r--r-- | dhall/src/syntax/ast/expr.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs index 6ba6649..9e935dc 100644 --- a/dhall/src/syntax/ast/expr.rs +++ b/dhall/src/syntax/ast/expr.rs @@ -1,5 +1,6 @@ use std::collections::BTreeMap; +use crate::error::Error; use crate::semantics::Universe; use crate::syntax::map::{DupTreeMap, DupTreeSet}; use crate::syntax::visitor; @@ -255,6 +256,13 @@ impl Expr { span, } } + + // Compute the sha256 hash of the binary form of the expression. + pub fn hash(&self) -> Result<Box<[u8]>, Error> { + use sha2::Digest; + let data = binary::encode(self)?; + Ok(sha2::Sha256::digest(&data).as_slice().into()) + } } // Empty enum to indicate that no error can occur |