News for hackers. Stuff that matters.
Re:Writing a website in Rust by kibwen on Saturday May 30, 2015 @03:32PM (#9631473)
I'm actually working right now on a `cargo check` command which only runs those phases of the compiler to do with typechecking, to accommodate workflows based around tweaking types and then running the compiler to check your work. Given that the vast majority of compilation time is currently based in code generation and linking, this should drastically improve usability for this sort of rapid-iteration, dynamic-language-style workflow. (Though also note that improving the speed of codegen and linking is an ongoing task as well.)
Re:Writing a website in Rust by mafribe on Sunday May 31, 2015 @03:19AM (#9633361)
This is a great idea. I wish other compilers would offer this feature (scalac is in dire need of such an option).

Does the Rust macro system require compile-time compilation before type-checking?

Re:Writing a website in Rust by Jweb_Guru on Sunday May 31, 2015 @09:50AM (#9634166)
Not really. Macro expansion occurs during its own phase of compilation (which, in my experience, is generally really fast).
Re:Writing a website in Rust by mafribe on Sunday May 31, 2015 @12:50PM (#9634692)
Macro expansion can lead to programs that don't typecheck, unless a very restrictive typing system is used (e.g. MetaML, MetaOcaml). I don't think Rust has such restrictions, therefore I assume that type-checking happens after macro expansion.
Re:Writing a website in Rust by Jweb_Guru on Sunday May 31, 2015 @12:58PM (#9634724)
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).
Re:Writing a website in Rust by mafribe on Sunday May 31, 2015 @02:16PM (#9634978)
So Rust macros don't offer full compile-time meta-programming?
Re:Writing a website in Rust by Jweb_Guru on Sunday May 31, 2015 @03:18PM (#9635194)
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.
Re:Writing a website in Rust by mafribe on Sunday May 31, 2015 @04:18PM (#9635382)
Who's working on this? I may have something to contribute in this direction.
Re:Writing a website in Rust by Manishearth on Monday June 01, 2015 @04:10AM (#9637283)
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.

Re:Writing a website in Rust by mafribe on Monday June 01, 2015 @06:18AM (#9637606)
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.

Re:Writing a website in Rust by Jweb_Guru on Sunday May 31, 2015 @06:04PM (#9635757)
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.