Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It does, but what I was getting at was that full compilation doesn't need to occur first. Macro expansion is one of the very first phases of compilation (and doesn't have access to typechecking information, incidentally).


So Rust macros don't offer full compile-time meta-programming?


Not in Rust 1.0. In the nightlies there are syntax extensions available that give you more power, but those are likely to see significant revisions before they're available in a stable version since they're a major backwards compatibility hazard.


Who's working on this? I may have something to contribute in this direction.


Not something being actively worked on, but I and some others care about it.

Rust macro-esque things are of three types:

- Macro by Example (MBE): These are easily defined by the user via `macro_rules!`, which can match on their input and expand to some output at compile time. These don't need to be defined as a plugin; you can define a macro directly in your code.

- tokentree expansion plugins: These take in a token tree, run arbitrary code, and output an AST (syntax tree) node. Ish.

- AST expansion plugin: These take in the parsed AST, run arbitrary code, and output another AST to replace or augment it.

There also is support for custom lints and llvm passes.

All of this is at compile time.


I'm not sure what a token tree is. Usually compilers feed a token list to the parser, which then generates an AST. The AST is what compile-time meta-programming such as macro expansion works on.

In fully-blown compile-time meta-programming systems such as Converge or Template Haskell, the "AST expansion plugin" can and typically does itself invoke the compiler to compile arbitrary code which in turn outputs a new AST for further compilation.

I'm not fully sure what macro-by-example is.


I'm not sure who specifically is working on improving the macro system, but it's definitely something that's been prioritized. My primary recommendation for contacting the relevant people would be either the Rust internals forums (https://internals.rust-lang.org) or the #rust-internals channel on irc.mozilla.org.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: