-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathlib.rs
More file actions
57 lines (46 loc) · 1.64 KB
/
lib.rs
File metadata and controls
57 lines (46 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Procedural macros for Feldera tuple types and `IsNone`.
//!
//! The `declare_tuple!` macro decides which layout to use based on tuple size
//! and the active storage format rules.
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};
mod tuples;
/// Parses input of the form: `declare_tuple!(Tup1<T0>);`
/// and generates dbsp tuple structs.
#[proc_macro]
pub fn declare_tuple(input: TokenStream) -> TokenStream {
let tuple = parse_macro_input!(input as tuples::TupleDef);
let expanded = tuples::declare_tuple_impl(tuple);
if std::env::var_os("FELDERA_DEV_MACROS_DUMP").is_some() {
let parsed_file: syn::File = syn::parse2(expanded.clone()).expect("Failed to parse output");
let formatted = prettyplease::unparse(&parsed_file);
eprintln!("{}", formatted);
}
expanded.into()
}
#[proc_macro_derive(IsNone)]
pub fn derive_not_none(item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as DeriveInput);
let ident = input.ident;
let generics = input.generics;
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
let expanded = quote! {
impl #impl_generics ::dbsp::utils::IsNone for #ident #ty_generics #where_clause {
type Inner = Self;
#[inline]
fn is_none(&self) -> bool {
false
}
#[inline]
fn unwrap_or_self(&self) -> &Self::Inner {
self
}
#[inline]
fn from_inner(inner: Self::Inner) -> Self {
inner
}
}
};
TokenStream::from(expanded)
}