-
Notifications
You must be signed in to change notification settings - Fork 71
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
Procedural macros design document #1109
Conversation
5ee682d
to
c54c604
Compare
48cbcb2
to
ba702c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see any major issues
af1e183
to
2bb66a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, really good job 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't understand anything beforehand, now I understand something, thanks and good job!
59a1055
to
61f42ec
Compare
Looks great, amazing unlock for customization and abstraction in projects!
#[derive(ToValue)]
struct Input {
value: felt252,
} // Let's say something similar to that.
#[derive_macro(ToValue)]
pub fn to_value(token_stream: TokenStream) -> ProcMacroResult {
// only access the struct Input.
ProcMacroResult::Leave
} Is it considerable to give more context to the macro? I'm imagining some scenario where for instance the full path of the module in which the macro is executed, the crate id or even the file name could be useful. Or is this something not available at the time the macro is being called? Awesome job on that guys, keen to contribute on that and see it evolve! 🚀 |
61f42ec
to
c0c8a81
Compare
c0c8a81
to
8022889
Compare
Thanks for feedback @glihm !
😍
Yes, it will be possible! Possibly not from the day one, but not long after it.
As of the design, the On the other hand, the current design proposes running procedural macro's only on simple and explicit request from the user made in the Cairo code, for instance by adding the |
8022889
to
20bc7a3
Compare
20bc7a3
to
d04abd4
Compare
Hi everyone! |
I've read through the doc. The whole apparatus seems very well though through as far as I can tell. Sadly, I haven't written a Rust macro in my life, but I have a couple of (potentially dumb, please bear with me) questions based on what I'd like to do with macros.
#[derive(Packing(v0))]
struct Values {
a: u64,
b: u8,
c: u16,
d: u128
} The idea is that this macro would expand into a full implementation of
struct Storage {
#[getter]
foo: u64,
#[getter]
bar: LegacyMap<ContractAddress, u128>
#[getter]
#[setter(guard=only_admin)]
baz: ContractAddress
} that would expand into sth like fn get_foo(self: @ContractState) -> u64 {
self.foo.read()
}
fn get_bar(self: @ContractState, value: ContractAddress) -> u128 {
self.bar.read(value)
}
fn get_baz(self: @ContractState) -> ContractAddress {
self.baz.read()
}
fn set_baz(ref self: ContractState, new_value: ContractAddress) {
assert_only_admin();
self.baz.write(new_value);
} Will it be possible to have macros "stacked" like the Also note that while this example looks cool, it complicates writing the
#[starknet::contract]
mod C {
/// ....
#[abi(embed_v0)]
impl Foo of super::IFoo<ContractState> {
/// ...
#[non_reentrant]
fn do_stuff_with_callback(ref self: ContractState) {
/// ...
}
}
} Now in this case, say the macro has a dependency on OZ's cairo-contracts, so it pulls in the reentrancy guard component. Can the
|
Hi @milancermak ! This are all really great questions! Thanks for your input. I don’t think I will exhaust all of these topics with my response, but I will try to give my thoughts right away. Please note, that the design doc in review is the first attempt at bringing said functionality to Cairo, so we intentionally want to keep things simple. Some topics mentioned here should ultimately become separate issues and be discussed as such. By question number:
|
I would like to extend my thanks to everyone engaged in review and comments of this document. 😍 😍 😍 |
No description provided.