Skip to content

Commit

Permalink
bump v0.0.30
Browse files Browse the repository at this point in the history
  • Loading branch information
memoryleak47 committed Nov 22, 2024
1 parent a40cb14 commit aa7f053
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "slotted-egraphs"
version = "0.0.29"
version = "0.0.30"
edition = "2021"
description = "E-Graphs with name binding"
license = "Apache-2.0 OR MIT"
Expand All @@ -15,7 +15,7 @@ trace = ["tracing/max_level_trace", "tracing/release_max_level_trace", "tracing"
features = ["explanations"]

[dependencies]
slotted-egraphs-derive = "=0.0.3"
slotted-egraphs-derive = "=0.0.30"
fnv = "1.0.7"
tracing = { version = "0.1", features = ["attributes"], optional = true }
symbol_table = { version = "0.3", features = ["global"] }
Expand Down
2 changes: 1 addition & 1 deletion slotted-egraphs-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "slotted-egraphs-derive"
description = "proc macros to implement slotted Languages"
version = "0.0.3"
version = "0.0.30"
edition = "2021"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/memoryleak47/slotted-egraphs/"
Expand Down
92 changes: 83 additions & 9 deletions slotted-egraphs-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pub fn define_language(input: TokenStream1) -> TokenStream1 {
let all_slot_occurrences_mut_arms: Vec<TokenStream2> = ie.variants.iter().map(|x| produce_all_slot_occurrences_mut(&name, x)).collect();
let public_slot_occurrences_mut_arms: Vec<TokenStream2> = ie.variants.iter().map(|x| produce_public_slot_occurrences_mut(&name, x)).collect();
let applied_id_occurrences_mut_arms: Vec<TokenStream2> = ie.variants.iter().map(|x| produce_applied_id_occurrences_mut(&name, x)).collect();

let all_slot_occurrences_arms: Vec<TokenStream2> = ie.variants.iter().map(|x| produce_all_slot_occurrences(&name, x)).collect();
let public_slot_occurrences_arms: Vec<TokenStream2> = ie.variants.iter().map(|x| produce_public_slot_occurrences(&name, x)).collect();
let applied_id_occurrences_arms: Vec<TokenStream2> = ie.variants.iter().map(|x| produce_applied_id_occurrences(&name, x)).collect();

let to_syntax_arms: Vec<TokenStream2> = ie.variants.iter().zip(&str_names).map(|(x, n)| produce_to_syntax(&name, &n, x)).collect();
let from_syntax_arms1: Vec<TokenStream2> = ie.variants.iter().zip(&str_names).filter_map(|(x, n)| produce_from_syntax1(&name, &n, x)).collect();
let from_syntax_arms2: Vec<TokenStream2> = ie.variants.iter().zip(&str_names).filter_map(|(x, n)| produce_from_syntax2(&name, &n, x)).collect();
Expand All @@ -28,6 +33,7 @@ pub fn define_language(input: TokenStream1) -> TokenStream1 {
#ie

impl Language for #name {
// mut:
fn all_slot_occurrences_mut(&mut self) -> Vec<&mut Slot> {
match self {
#(#all_slot_occurrences_mut_arms),*
Expand All @@ -44,6 +50,25 @@ pub fn define_language(input: TokenStream1) -> TokenStream1 {
}
}


// immut:
fn all_slot_occurrences(&self) -> Vec<Slot> {
match self {
#(#all_slot_occurrences_arms),*
}
}
fn public_slot_occurrences(&self) -> Vec<Slot> {
match self {
#(#public_slot_occurrences_arms),*
}
}
fn applied_id_occurrences(&self) -> Vec<&AppliedId> {
match self {
#(#applied_id_occurrences_arms),*
}
}

// syntax:
fn to_syntax(&self) -> Vec<SyntaxElem> {
match self {
#(#to_syntax_arms),*
Expand Down Expand Up @@ -71,11 +96,11 @@ fn produce_all_slot_occurrences_mut(name: &Ident, v: &Variant) -> TokenStream2 {
let fields: Vec<Ident> = (0..n).map(|x| Ident::new(&format!("a{x}"), proc_macro2::Span::call_site())).collect();
quote! {
#name::#variant_name(#(#fields),*) => {
let mut out: Vec<&mut Slot> = Vec::new();
let out = std::iter::empty();
#(
out.extend(#fields .all_slot_occurrences_iter_mut());
let out = out.chain(#fields .all_slot_occurrences_iter_mut());
)*
out
out.collect()
}
}
}
Expand All @@ -86,11 +111,11 @@ fn produce_public_slot_occurrences_mut(name: &Ident, v: &Variant) -> TokenStream
let fields: Vec<Ident> = (0..n).map(|x| Ident::new(&format!("a{x}"), proc_macro2::Span::call_site())).collect();
quote! {
#name::#variant_name(#(#fields),*) => {
let mut out: Vec<&mut Slot> = Vec::new();
let out = std::iter::empty();
#(
out.extend(#fields .public_slot_occurrences_iter_mut());
let out = out.chain(#fields .public_slot_occurrences_iter_mut());
)*
out
out.collect()
}
}
}
Expand All @@ -101,15 +126,64 @@ fn produce_applied_id_occurrences_mut(name: &Ident, v: &Variant) -> TokenStream2
let fields: Vec<Ident> = (0..n).map(|x| Ident::new(&format!("a{x}"), proc_macro2::Span::call_site())).collect();
quote! {
#name::#variant_name(#(#fields),*) => {
let mut out: Vec<&mut AppliedId> = Vec::new();
let out = std::iter::empty();
#(
out.extend(#fields .applied_id_occurrences_iter_mut());
let out = out.chain(#fields .applied_id_occurrences_iter_mut());
)*
out
out.collect()
}
}
}


// immut:
fn produce_all_slot_occurrences(name: &Ident, v: &Variant) -> TokenStream2 {
let variant_name = &v.ident;
let n = v.fields.len();
let fields: Vec<Ident> = (0..n).map(|x| Ident::new(&format!("a{x}"), proc_macro2::Span::call_site())).collect();
quote! {
#name::#variant_name(#(#fields),*) => {
let out = std::iter::empty();
#(
let out = out.chain(#fields .all_slot_occurrences_iter().copied());
)*
out.collect()
}
}
}

fn produce_public_slot_occurrences(name: &Ident, v: &Variant) -> TokenStream2 {
let variant_name = &v.ident;
let n = v.fields.len();
let fields: Vec<Ident> = (0..n).map(|x| Ident::new(&format!("a{x}"), proc_macro2::Span::call_site())).collect();
quote! {
#name::#variant_name(#(#fields),*) => {
let out = std::iter::empty();
#(
let out = out.chain(#fields .public_slot_occurrences_iter().copied());
)*
out.collect()
}
}
}

fn produce_applied_id_occurrences(name: &Ident, v: &Variant) -> TokenStream2 {
let variant_name = &v.ident;
let n = v.fields.len();
let fields: Vec<Ident> = (0..n).map(|x| Ident::new(&format!("a{x}"), proc_macro2::Span::call_site())).collect();
quote! {
#name::#variant_name(#(#fields),*) => {
let out = std::iter::empty();
#(
let out = out.chain(#fields .applied_id_occurrences_iter());
)*
out.collect()
}
}
}


// syntax:
fn produce_to_syntax(name: &Ident, e: &Option<Expr>, v: &Variant) -> TokenStream2 {
let variant_name = &v.ident;

Expand Down
25 changes: 9 additions & 16 deletions src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ pub trait Language: Debug + Clone + Hash + Eq {
/// List the mutable references to all child [AppliedId]s in your E-Node, in the order of occurrence.
fn applied_id_occurrences_mut(&mut self) -> Vec<&mut AppliedId>;


fn all_slot_occurrences(&self) -> Vec<Slot>;
fn public_slot_occurrences(&self) -> Vec<Slot>;
fn applied_id_occurrences(&self) -> Vec<&AppliedId>;

/// This function will be used to display your E-Node.
fn to_syntax(&self) -> Vec<SyntaxElem>;

Expand Down Expand Up @@ -185,24 +190,12 @@ pub trait Language: Debug + Clone + Hash + Eq {
out
}

#[doc(hidden)]
fn all_slot_occurrences(&self) -> Vec<Slot> {
self.clone().all_slot_occurrences_mut().into_iter().map(|x| x.clone()).collect()
}

#[doc(hidden)]
fn public_slot_occurrences(&self) -> Vec<Slot> {
self.clone().public_slot_occurrences_mut().into_iter().map(|x| x.clone()).collect()
}

#[doc(hidden)]
fn applied_id_occurrences(&self) -> Vec<AppliedId> {
self.clone().applied_id_occurrences_mut().into_iter().map(|x| x.clone()).collect()
}

#[doc(hidden)]
fn private_slot_occurrences(&self) -> Vec<Slot> {
self.clone().private_slot_occurrences_mut().into_iter().map(|x| x.clone()).collect()
let public = self.public_slot_occurrences();
let mut out = self.all_slot_occurrences();
out.retain(|x| !public.contains(x));
out
}

#[doc(hidden)]
Expand Down

0 comments on commit aa7f053

Please sign in to comment.