diff --git a/Cargo.lock b/Cargo.lock index 295c72ca2..68ed66bba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1184,7 +1184,6 @@ dependencies = [ "fe-common2", "fe-hir", "fe-hir-analysis", - "fe-macros", "salsa 0.18.0", ] @@ -1197,7 +1196,6 @@ dependencies = [ "derive_more", "dot2 1.0.0", "fe-common2", - "fe-macros", "fe-parser2", "num-bigint", "num-traits", @@ -1221,7 +1219,6 @@ dependencies = [ "fe-common2", "fe-compiler-test-utils", "fe-hir", - "fe-macros", "if_chain", "itertools", "num-bigint", @@ -1239,16 +1236,6 @@ dependencies = [ "smol_str", ] -[[package]] -name = "fe-macros" -version = "0.26.0" -dependencies = [ - "glob", - "proc-macro2", - "quote", - "syn 2.0.68", -] - [[package]] name = "fe-mir" version = "0.26.0" diff --git a/crates/driver2/Cargo.toml b/crates/driver2/Cargo.toml index d00d446b9..0af1b159f 100644 --- a/crates/driver2/Cargo.toml +++ b/crates/driver2/Cargo.toml @@ -15,7 +15,6 @@ codespan-reporting = "0.11" hir = { path = "../hir", package = "fe-hir" } common = { path = "../common2", package = "fe-common2" } -macros = { path = "../macros", package = "fe-macros" } hir-analysis = { path = "../hir-analysis", package = "fe-hir-analysis" } camino = "1.1.4" clap = { version = "4.3", features = ["derive"] } diff --git a/crates/hir-analysis/Cargo.toml b/crates/hir-analysis/Cargo.toml index 80c199011..19f87542d 100644 --- a/crates/hir-analysis/Cargo.toml +++ b/crates/hir-analysis/Cargo.toml @@ -22,7 +22,6 @@ bitflags = "2.5" cranelift-entity = "0.91" hir = { path = "../hir", package = "fe-hir" } common = { path = "../common2", package = "fe-common2" } -macros = { path = "../macros", package = "fe-macros" } [dev-dependencies] codespan-reporting = "0.11" diff --git a/crates/hir/Cargo.toml b/crates/hir/Cargo.toml index e59353501..7846c3752 100644 --- a/crates/hir/Cargo.toml +++ b/crates/hir/Cargo.toml @@ -21,4 +21,3 @@ dot2 = "1.0" common = { path = "../common2", package = "fe-common2" } parser = { path = "../parser2", package = "fe-parser2" } -macros = { path = "../macros", package = "fe-macros" } diff --git a/crates/macros/Cargo.toml b/crates/macros/Cargo.toml deleted file mode 100644 index a8e8ec1c8..000000000 --- a/crates/macros/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "fe-macros" -authors = ["The Fe Project Developers"] -version = "0.26.0" -edition = "2021" -license = "Apache-2.0" -repository = "https://github.com/ethereum/fe" -description = "Provides procudural macros for Fe lang." - -[lib] -proc-macro = true - -[dependencies] -syn = { version = "2.0", features = ["full"] } -proc-macro2 = "1.0" -quote = "1.0" -glob = "0.3" diff --git a/crates/macros/src/kw.rs b/crates/macros/src/kw.rs deleted file mode 100644 index 518e30211..000000000 --- a/crates/macros/src/kw.rs +++ /dev/null @@ -1,111 +0,0 @@ -use std::collections::HashSet; - -use proc_macro2::TokenStream; -use quote::quote; - -use super::{Error, Result}; - -pub(super) fn define_keywords(attrs: proc_macro::TokenStream) -> Result { - let args = syn::parse::(attrs)?; - - let definer = KeywordDefiner { args }; - Ok(definer.build().into()) -} - -struct KeywordDefiner { - args: Args, -} - -impl KeywordDefiner { - fn build(self) -> TokenStream { - let keywords = self.define_keywords(); - let prefill_method = self.define_prefill_method(); - quote! { - #keywords - #prefill_method - } - } - - fn define_keywords(&self) -> TokenStream { - let mut stream = vec![]; - for (i, (kw, _)) in self.args.0.iter().enumerate() { - let ident_id = Self::ident_id(i); - stream.push(quote!( - pub const #kw: crate::hir_def::ident::IdentId = #ident_id; - )) - } - - quote! { - #(#stream)* - } - } - - fn define_prefill_method(&self) -> TokenStream { - let mut prefills = vec![]; - for (kw, kw_str) in self.args.0.iter() { - let kw_str = kw_str.value(); - prefills.push(quote!( - let generated_kw = crate::hir_def::ident::IdentId::new(db, #kw_str.to_string()); - assert_eq!(generated_kw, #kw); - )); - } - - quote! { - impl<'db> crate::hir_def::ident::IdentId<'db> { - pub fn prefill(db: &dyn crate::HirDb) { - #(#prefills)* - } - } - } - } - - fn ident_id(index: usize) -> TokenStream { - quote! { - crate::hir_def::ident::IdentId(::salsa::Id::from_u32((#index) as u32)) - } - } -} - -struct Args(Vec<(syn::Ident, syn::LitStr)>); -impl syn::parse::Parse for Args { - fn parse(input: syn::parse::ParseStream) -> Result { - let mut seen_kws = HashSet::new(); - let mut seen_kw_str = HashSet::new(); - let mut kws = vec![]; - - while !input.is_empty() { - let keyword; - syn::parenthesized!(keyword in input); - let kw = keyword.parse::()?; - keyword.parse::()?; - let kw_str = keyword.parse::()?; - - if !seen_kws.insert(kw.to_string()) { - return Err(Error::new_spanned( - kw.clone(), - format!("duplicated keyword `{kw}"), - )); - } - if !seen_kw_str.insert(kw_str.value()) { - return Err(Error::new_spanned( - kw_str.clone(), - format!("duplicated keyword string `{}`", kw_str.value()), - )); - } - kws.push((kw, kw_str)); - - if input.parse::().is_err() { - break; - } - } - - if !input.is_empty() { - return Err(Error::new_spanned( - input.parse::()?, - "unexpected token", - )); - } - - Ok(Args(kws)) - } -} diff --git a/crates/macros/src/lib.rs b/crates/macros/src/lib.rs deleted file mode 100644 index e8894e362..000000000 --- a/crates/macros/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -mod kw; - -#[proc_macro] -pub fn define_keywords(attrs: proc_macro::TokenStream) -> proc_macro::TokenStream { - match kw::define_keywords(attrs) { - Ok(tokens) => tokens, - Err(e) => e.to_compile_error().into(), - } -} - -type Error = syn::Error; -type Result = syn::Result;