Skip to content

Commit da9130a

Browse files
committed
[derive] Start to move manually_traced macros over to proc_derive
Procedural macros are more flexible and will allow us to use a single macro for all our manually traced code. It should also help downstream crates start to utilize this.
1 parent e225f32 commit da9130a

File tree

7 files changed

+873
-261
lines changed

7 files changed

+873
-261
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ readme = "README.md"
1313
# Providing support for these important libraries,
1414
# gives zerogc 'batteries included' support.
1515
indexmap = { version = "1.6", optional = true }
16+
# Used for macros
17+
zerogc-derive = { version = "0.2.0-alpha.1" }
1618

1719
[workspace]
1820
members = ["libs/simple", "libs/derive", "libs/context"]

libs/derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ zerogc = { version = "0.2.0-alpha.1", path = "../.." }
1616

1717
[dependencies]
1818
# Proc macros
19-
syn = "1.0.55"
19+
syn = { version = "1.0.55", features = ["full", "extra-traits"] }
2020
quote = "1.0.8"
2121
proc-macro2 = "1"

libs/derive/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use std::collections::HashSet;
1212
use std::fmt::Display;
1313
use std::io::Write;
1414

15+
mod macros;
16+
1517
struct MutableFieldOpts {
1618
public: bool
1719
}
@@ -334,6 +336,22 @@ impl Parse for TypeAttrs {
334336
}
335337
}
336338

339+
#[proc_macro]
340+
pub fn unsafe_gc_impl(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
341+
let cloned_impl = input.clone();
342+
let parsed = parse_macro_input!(input as macros::MacroInput);
343+
let res = parsed.expand_output()
344+
.unwrap_or_else(|e| e.to_compile_error());
345+
debug_derive(
346+
"unsafe_gc_impl!",
347+
&"",
348+
&format_args!("#[unsafe_gc_impl {{ {} }}", cloned_impl),
349+
&res
350+
);
351+
res.into()
352+
}
353+
354+
337355
#[proc_macro_derive(Trace, attributes(zerogc))]
338356
pub fn derive_trace(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
339357
let input = parse_macro_input!(input as DeriveInput);

0 commit comments

Comments
 (0)