Publish ssz_types (and deps) to crates.io (#468)

* Rename `hashing` crate to `eth2_hashing`

* Add license, desc to eth2_hashing Cargo.toml

* Remove merkle root from eth2 hashing

* Remove old benches folder (zombied from old branch)

* Add docs to eth2_hashing

* Prepare tree_hash for publishing on crates.io

* Update deps to use crates.io instead of paths

* Update all crates to pull ssz from crates.io

* Remove cached_tree_hash, add patches to manifest

* Fix compile error in benches

* Remove unused code

* Fix fake_crypto compile error
This commit is contained in:
Paul Hauner
2019-08-08 11:39:47 +10:00
committed by GitHub
parent 88e89f9ab2
commit 8cfa36fedd
87 changed files with 205 additions and 2643 deletions

View File

@@ -1,17 +1,14 @@
[package]
name = "tree_hash_derive"
version = "0.1.0"
version = "0.2.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
description = "Procedural derive macros for SSZ tree hashing."
description = "Procedural derive macros to accompany the tree_hash crate."
license = "Apache-2.0"
[lib]
proc-macro = true
[dev-dependencies]
tree_hash = { path = "../tree_hash" }
cached_tree_hash = { path = "../cached_tree_hash" }
[dependencies]
syn = "0.15"
quote = "0.6"

View File

@@ -37,81 +37,6 @@ fn should_skip_hashing(field: &syn::Field) -> bool {
.any(|attr| attr.into_token_stream().to_string() == "# [ tree_hash ( skip_hashing ) ]")
}
/// Implements `tree_hash::CachedTreeHash` for some `struct`.
///
/// Fields are hashed in the order they are defined.
#[proc_macro_derive(CachedTreeHash, attributes(tree_hash))]
pub fn subtree_derive(input: TokenStream) -> TokenStream {
let item = parse_macro_input!(input as DeriveInput);
let (impl_generics, ty_generics, where_clause) = &item.generics.split_for_impl();
let name = &item.ident;
let struct_data = match &item.data {
syn::Data::Struct(s) => s,
_ => panic!("tree_hash_derive only supports structs."),
};
let idents_a = get_hashable_named_field_idents(&struct_data);
let idents_b = idents_a.clone();
let idents_c = idents_a.clone();
let output = quote! {
impl #impl_generics cached_tree_hash::CachedTreeHash for #name #ty_generics #where_clause {
fn new_tree_hash_cache(&self, depth: usize) -> Result<cached_tree_hash::TreeHashCache, cached_tree_hash::Error> {
let tree = cached_tree_hash::TreeHashCache::from_subtrees(
self,
vec![
#(
self.#idents_a.new_tree_hash_cache(depth)?,
)*
],
depth
)?;
Ok(tree)
}
fn num_tree_hash_cache_chunks(&self) -> usize {
cached_tree_hash::BTreeOverlay::new(self, 0, 0).num_chunks()
}
fn tree_hash_cache_schema(&self, depth: usize) -> cached_tree_hash::BTreeSchema {
let mut lengths = vec![];
#(
lengths.push(self.#idents_b.num_tree_hash_cache_chunks());
)*
cached_tree_hash::BTreeSchema::from_lengths(depth, lengths)
}
fn update_tree_hash_cache(&self, cache: &mut cached_tree_hash::TreeHashCache) -> Result<(), cached_tree_hash::Error> {
let overlay = cached_tree_hash::BTreeOverlay::new(self, cache.chunk_index, 0);
// Skip the chunk index to the first leaf node of this struct.
cache.chunk_index = overlay.first_leaf_node();
// Skip the overlay index to the first leaf node of this struct.
// cache.overlay_index += 1;
// Recurse into the struct items, updating their caches.
#(
self.#idents_c.update_tree_hash_cache(cache)?;
)*
// Iterate through the internal nodes, updating them if their children have changed.
cache.update_internal_nodes(&overlay)?;
cache.chunk_index = overlay.next_node();
Ok(())
}
}
};
output.into()
}
/// Implements `tree_hash::TreeHash` for some `struct`.
///
/// Fields are hashed in the order they are defined.