Stream: t-compiler/rust-analyzer

Topic: Design of eager macro expansion


Jonas Schievink [he/him] (Nov 30 2020 at 21:55, on Zulip):

In rustc, eager expansion is implemented with a single line of code:

let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();

In rust-analyzer, a comparatively huge amount of infrastructure seems to be responsible for handling eager macros. Is that a necessary consequence of doing it in a query-driven way, or is this complexity accidental and could be reduced?

Jonas Schievink [he/him] (Dec 01 2020 at 00:09, on Zulip):

Ah, just found this thread: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros

matklad (Dec 01 2020 at 14:21, on Zulip):

Yeah, it's true that, overall, "eager macros are tricky". Our current impl is not in cache for me though it's quite likely we can simplify it substantionally.

IIRC, we just encode the whole of macro argument into macro ID for eager expansion.

Last update: Jul 24 2021 at 19:45UTC