[rust-dev] Compile-time function evaluation in Rust

Steven Fackler sfackler at gmail.com
Wed Jan 29 08:56:53 PST 2014


The rough idea that pcwalton, acrichto and I were talking about when I was
working on the procedural macro stuff was to split compilation into two
phases. The first phase would produce a library that the compiler would
load for the second phase. The procedural macro PR added the `phase`
attribute which is currently only used with `extern mod` statements but
could be extended to functions and whatever else:

#[phase(syntax)]
fn ctfe_function() -> int {
    10
}

static FOO: int = ctfe_function();

Steven Fackler


On Wed, Jan 29, 2014 at 11:44 AM, Niko Matsakis <niko at alum.mit.edu> wrote:

> On Tue, Jan 28, 2014 at 07:01:44PM -0500, comex wrote:
> > Actually, Rust already has procedural macros as of recently.  I was
> > wondering whether that could be combined with the proposed new system.
>
> I haven't looked in detail at the procedural macro support that was
> recently added, but off hand I think I favor that approach. That is,
> I'd rather compile a Rust module, link it dynamically, and run it as
> normal, versus defining some subset of Rust that the compiler can
> execute. The latter seems like it'll be difficult to define,
> implement, and understand. Our experience with effect systems and
> purity has not been particularly good, and I think staged compilation
> is easier to explain and free from the twin hazards of "this library
> function is pure but not marked pure" (when using explicit
> declaration) or "this library function is accidentally pure" (when
> using inference).
>
>
> Niko
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140129/a90897b4/attachment-0001.html>


More information about the Rust-dev mailing list