-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial support for a new formatting syntax #8245
Conversation
@@ -0,0 +1,901 @@ | |||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: what does ct
mean in the file name? Maybe change to something more descriptive.
From looking at this it looks like the format string verified at compile time but parsed at runtime. That seems strange: is it due to internalization concerns? I would hope that for perf there is at least eventually an option to turn off runtime parsing. |
Good news! For the following benchmark: extern mod extra;
use extra::test::BenchHarness;
#[bench]
fn fmt(b: &mut BenchHarness) {
do b.iter {
do 100.times {
fmt!("aasd f df %d awe", 4);
}
}
}
#[bench]
fn ifmt(b: &mut BenchHarness) {
do b.iter {
do 100.times {
ifmt!("aasd f df {:d} awe", 4);
}
}
} I get the results:
Here's a summary:
On the side I also change:
I'm still fixing up a few bugs here and there, but this has the bulk of everything. |
All bugs should be fixed now, everything should be good to go |
Here's some numbers about code size generated from the new formatting syntax. This program was compiled #[inline(never)]
#[no_mangle]
fn fmtarg0() -> ~str {
fmt!("Hello world for the 4th time again!")
}
#[inline(never)]
#[no_mangle]
fn ifmtarg0() -> ~str {
ifmt!("Hello world for the 4th time again!")
}
#[inline(never)]
#[no_mangle]
fn fmtarg1() -> ~str {
fmt!("Hello %s for the 4th time again!", "world")
}
#[inline(never)]
#[no_mangle]
fn ifmtarg1() -> ~str {
ifmt!("Hello {:s} for the 4th time again!", "world")
}
#[inline(never)]
#[no_mangle]
fn fmtarg2() -> ~str {
fmt!("Hello %s for the %dth time again!", "world", 4)
}
#[inline(never)]
#[no_mangle]
fn ifmtarg2() -> ~str {
ifmt!("Hello {:s} for the {:d}th time again!", "world", 4)
}
#[inline(never)]
#[no_mangle]
fn fmtarg3() -> ~str {
fmt!("Hello %s for the %dth time %s!", "world", 4, "again")
}
#[inline(never)]
#[no_mangle]
fn ifmtarg3() -> ~str {
ifmt!("Hello {:s} for the {:d}th time {:s}!", "world", 4, "again")
}
fn main() {
} And I got this data:
The first number for |
Closing; in my rollup |
Backing out of my rollup |
The new macro is available under the name ifmt! (only an intermediate name)
This is a reopening of #8182, although this removes any abuse of the compiler internals. Now it's just a pure syntax extension (hard coded what the attribute names are).
This is a reopening of #8182, although this removes any abuse of the compiler internals. Now it's just a pure syntax extension (hard coded what the attribute names are).