Crate local state for procedural macros?
I'm tinkering a bit with procedural macros and encountered a problem that can be solved by keeping state in between proc macro invocations. Example from my real application: assume my `proc-macro` crate exposes two macros: `config! {}` and `do_it {}`. The user of my lib is supposed to call `config! {}` only once, but may call `do_it! {}` multiple times. But `do_it!{}` needs data from the `config!{}` invocation. Another example: we want to write a `macro_unique_id!()` macro returning a `u64` by counting internally. --- How am I supposed to solve those problems? I know that somewhat-global state is usually bad. But I do see applications for crate-local state for proc macros.
Posted by LukasKalbertodt on Aug 22, 2017, 12:34 PM
Tags
Related issues
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
Crate local state for procedural macros?
I'm tinkering a bit with procedural macros and encountered a problem that can be solved by keeping state in between proc macro invocations. Example from my real application: assume my `proc-macro` crate exposes two macros: `config! {}` and `do_it {}`. The user of my lib is supposed to call `config! {}` only once, but may call `do_it! {}` multiple times. But `do_it!{}` needs data from the `config!{}` invocation. Another example: we want to write a `macro_unique_id!()` macro returning a `u64` by counting internally. --- How am I supposed to solve those problems? I know that somewhat-global state is usually bad. But I do see applications for crate-local state for proc macros.
Comments (0)
No comments yet. Start the discussion.