Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pushing towards basic schema completion #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 115 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,145 @@ path = "src/lib.rs"

[dependencies]
# core
bytes = { version = "1.2", features = ["serde"] }
cid = { version = "0.8", features = ["alloc", "std", "serde-codec"] }
# erased-serde = { version = "0.3", features = ["std"] }
# ipfs = { git = "https://github.com/ipfs-rust/rust-ipfs", branch = "master", optional = true }
arrayvec = { version = "0.7", default-features = false }
bytes = { version = "1.2", default-features = false, features = ["serde"] }
cid = { version = "0.8", default-features = false, features = ["serde-codec"] }
# digest = { version = "0.10", optional = true }
# erased-serde = { version = "0.3", default-features = false }
# TODO: optional? also not no_std
ipld-macros = { path = "./macros" }
ipld-macros-internals = { path = "./macros-internals" }
multibase = "0.9"
multihash = { version = "0.16", default-features = false, features = ["std"] }
serde = { version = "1.0", features = ["derive", "rc"] }
multibase = { version = "0.9", default-features = false }
# todo: allow for better customization of multihash
multihash = { version = "0.16", default-features = false, features = ["multihash-impl", "secure-hashes"] }
serde = { version = "1.0", default-features = false, features = ["derive", "rc"] }
# serde_repr = "0.1"
# TODO: not no_std
thiserror = "1.0"
unicode-normalization = "0.1"
unicode-normalization = { version = "0.1", default-features = false }

# codecs
serde_cbor = { version = "0.11", optional = true } # TODO: use ciborium or cbor4ii instead
serde_json = { version = "1.0", optional = true, features = ["float_roundtrip"] }
rkyv = { version = "*", default-features = false, optional = true }
serde_cbor = { version = "0.11", default-features = false, optional = true, features = ["tags"] }
# cbor4ii = { version = "0.2", optional = true, features = ["serde1", "use_std"] }
# serde_ipld_dagcbor = { version = "0.2", optional = true, features = ["std"] }
serde_json = { version = "1.0", default-features = false, optional = true, features = ["float_roundtrip", "unbounded_depth"] }
# simd-json = { version = "0.6", optional = true, features = ["serde_impl", "128bit"] }
# risc0-zeroio = { git = "https://github.com/risc0/risc0", default-features = false, optional = true }
# risc0-zeroio-derive = { git = "https://github.com/risc0/risc0", default-features = false, optional = true }

# compatibility with other libraries
im = { version = "*", default-features = false, optional = true }
indexmap = { version = "*", default-features = false, optional = true }
libp2p-core = { version = "0.38", optional = true }
multiaddr = { version = "0.17", default-features = false, optional = true }
# bigint
# ed25519, secp256k1, rsa, bls, recrypt
# time, ?half
# serdect
# radixdb = { version = "0.2", optional = true }
wnfs = { version = "*", default-features = false, optional = true }

# adls
crdts = { version = "7.2", default-features = false, optional = true }
# merkle-log = { version = "*", default-features = false, optional = true }
# vb_accumulator = { version = "*", default-features = false, optional = true }

# misc
anyhow = "1.0"
bitflags = "1.3"
cfg-if = "1"
# const-str = "0.3"
# const_format = "0.2"
delegate = { version = "0.8", optional = true }
core2 = { version = "0.4", default-features = false, optional = true }
delegate = { version = "0.8" }
# derive_builder = "0.11"
downcast-rs = "1.2"
# lexical, itoa = "1.0" dtoa?
paste = "1.0"
# ref-cast = "1.0"

[dev-dependencies]
criterion = "0.4"
proptest = "1.0"
# criterion = "0.4"
# proptest = "1.0"

[features]
default = ["multicodec"]
dag-cbor = ["serde_cbor/tags"]
dag-json = ["serde_json", "delegate"]
dag-pb = []
default = [
"std",
"multicodec",
# TODO: remove these
"dev",
"multiaddr",
]
alloc = [
"cid/alloc",
"multihash/alloc",
"serde/alloc",
"serde_cbor?/alloc",
"serde_json?/alloc",
]
std = [
"alloc",
"sync",
"arrayvec/std",
"bytes/std",
"cid/std",
"core2/std",
"multibase/std",
"multihash/std",
"serde/std",
"unicode-normalization/std",
# optional
"indexmap?/std",
"serde_cbor?/std",
"serde_json?/std",
]
sync = []
parallel = ["std"]
# activate dev docs
dev = [
"hamt",
"merkle-crdts",
]

# codecs
dag-cbor = ["dep:serde_cbor"]
# dag-cbor = ["cbor4ii", "delegate"]
# dag-cbor = ["serde_ipld_dagcbor", "delegate"]
dag-json = ["dep:serde_json"]
# dag-pb = []
# raw = []
# enables all available multicodecs
multicodec = ["dag-cbor", "dag-json", "dag-pb"]
multicodec = ["dag-cbor", "dag-json"]
# # enables simd-related implementations, including an alternate dag-json
# simd = ["dag-json", "simd-json"]

# compatibility with other libraries
crdts = ["dep:crdts", "std"]
# ecdsa = []
# dalek = []
indexmap = ["dep:indexmap"]
im = ["dep:im"]
libp2p = ["dep:libp2p-core"]
multiaddr = ["dep:multiaddr"]
# signature = []
wnfs = ["dep:wnfs"]

# adls
fbl = []
hamt = []
merkle-crdts = ["crdts"]
# merkle-log = ["dep:merkle-log"]
prolly-tree = []
# vb-collection = ["dep:vb_accumulator"]


[package.metadata.docs.rs]
features = ["multicodec", "std", "dev"]
rustdoc-args = ["--cfg", "docsrs"]

[workspace]
members = [
# "advanced-schemas",
# "codegen",
"macros",
"macros-hack",
"macros-internals",
# "sqlite",
]
exclude = [
"codec-fixtures/rust",
Expand All @@ -69,3 +159,4 @@ exclude = [
[patch.crates-io]
# cid = { path = "../rust-cid" }
# multihash = { path = "../rust-multihash" }
wnfs = { path = "vendor/wnfs/wnfs" }
14 changes: 0 additions & 14 deletions macros-hack/Cargo.toml

This file was deleted.

54 changes: 0 additions & 54 deletions macros-hack/src/lib.rs

This file was deleted.

7 changes: 3 additions & 4 deletions macros-internals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ version = "0.0.3"
authors = ["sunny-g <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bitflags = "1.3"
darling = "0.14"
derive_more = "0.99"
# impls = "1"
# juniper = { version = "0.14", optional = true }
# num-traits = "0.2"
proc-macro-crate = "1.1"
proc-macro-crate = "1.1" # todo: remove
proc-macro2 = "1.0"
quote = "1.0"
# static_assertions = "1.1.0"
Expand Down
10 changes: 6 additions & 4 deletions macros-internals/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub(crate) mod attr {
pub(crate) const IPLD_CRATE_NAME: &'static str = "ipld";
pub(crate) const ATTR: &'static str = "ipld_attr";

pub(crate) const INTERNAL: &'static str = "internal";
pub(crate) const TRY_FROM: &'static str = "try_from";
pub(crate) const WRAPPER: &'static str = "wrapper";
pub(crate) const SERDE: &'static str = "serde";
Expand Down Expand Up @@ -153,11 +152,14 @@ pub fn is_end(input: ParseStream) -> bool {
input.peek(Token![;])
}

/// Parses the ending semicolon, asserting that the token stream is empty.
/// Parses on optional ending semicolon, then assert that the token stream is
/// empty.
pub fn parse_end(input: ParseStream) -> ParseResult<()> {
input.parse::<Token![;]>()?;
if input.peek(Token![;]) {
input.parse::<Token![;]>()?;
}
if !input.is_empty() {
Err(input.error("must end IPLD schema definitions with a semicolon"))
Err(input.error("unexpected tokens at the end of the IPLD schema definition"))
} else {
Ok(())
}
Expand Down
9 changes: 3 additions & 6 deletions macros-internals/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
pub extern crate derive_more;
// #[macro_use]
// pub extern crate static_assertions;

pub mod common;
pub mod schema;
pub mod schema2;
pub mod selector;

pub use schema::SchemaDefinition;
pub use selector::{RootSelectorDefinition, SelectorDefinition};

/// Convenient re-exports for development.
pub mod dev {
pub use crate::common::*;
pub use crate::derive_newtype;
Expand All @@ -18,7 +16,6 @@ pub mod dev {
pub use crate::selector::*;
pub use crate::*;

pub use darling;
pub use derive_more;
// pub use static_assertions;
// pub use tylift;
}
50 changes: 24 additions & 26 deletions macros-internals/src/schema/compound/expand_list.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
use super::*;
use crate::dev::*;
use quote::quote;
use syn::{
braced, bracketed,
parse::{Parse, ParseStream, Result as ParseResult},
LitStr, Path, Token, Type,
};
use syn::Type;

impl ExpandBasicRepresentation for ListReprDefinition {
fn schema(&self, meta: &SchemaMeta) -> TokenStream {
let name_str = meta.name_str();
let (_, child_name) = self.child();
quote!(concat!("type ", #name_str, " [", #child_name, "]"))
}

fn define_type(&self, meta: &SchemaMeta) -> TokenStream {
let inner_ty = self.inner_ty();
derive_newtype!(@typedef_transparent self, meta => inner_ty)
derive_newtype!(@typedef self, meta => inner_ty)
}
fn derive_repr(&self, meta: &SchemaMeta) -> TokenStream {
let child_ty = self.child_ty();
expand::impl_repr(
meta,
quote! {
// const SCHEMA: &'static str = macros::concatcp!("type ", Self::NAME, " [", <#child_ty>::NAME, "]");
const DATA_MODEL_KIND: Kind = Kind::List;
const HAS_LINKS: bool = false;

// fn has_links(&self) -> bool {
// self.0.has_links()
// }
},
)
let inner_ty = self.inner_ty();
let consts = quote! {
const DATA_MODEL_KIND: Kind = Kind::List;
const SCHEMA_KIND: Kind = Kind::List;
const REPR_KIND: Kind = Kind::List;
};
derive_newtype!(@repr self, meta => inner_ty { consts })
}
fn derive_select(&self, meta: &SchemaMeta) -> TokenStream {
let inner_ty = self.inner_ty();
derive_newtype!(@select meta => inner_ty)
// quote!()
derive_newtype!(@select self, meta => inner_ty)
}
fn derive_conv(&self, meta: &SchemaMeta) -> TokenStream {
quote!()
derive_newtype!(@conv @has_constructor self, meta)
}
}

impl ListReprDefinition {
fn child_ty(&self) -> Type {
fn child(&self) -> (Type, TokenStream) {
match self {
Self::Basic { elem, nullable } if *nullable => Type::Verbatim(quote!(Option<#elem>)),
Self::Basic { elem, .. } => elem.clone(),
Self::Basic { elem, nullable } if *nullable => (
Type::Verbatim(quote!(Option<#elem>)),
quote!("nullable ", stringify!(#elem)),
),
Self::Basic { elem, .. } => (elem.clone(), quote!(stringify!(#elem))),
Self::Advanced(..) => unimplemented!(),
}
}
fn inner_ty(&self) -> Type {
let child_ty = self.child_ty();
let (child_ty, _) = self.child();
Type::Verbatim(quote!(List<#child_ty>))
}
}
Loading