-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Avoid some allocations in the macro parser #37318
Conversation
This avoids ~800,000 allocations in html5ever.
This avoids ~800,000 allocations in html5ever.
r? @nrc |
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
@eddyb tells me the 3rd commit is bogus, because those failure messages are not just used in panics. |
r = me for the first two commits, but I agree with @eddyb that the third is a non-starter. Not sure how much he explained, but the parser used to use panic to give errors. That behaviour is mostly gone, but there are a few remnants left such as the macro parser, so this is an error message that is user facing whenever a macro doesn't apply. |
f6135f0
to
76622eb
Compare
@nrc: Thank you for the fast response. I've updated to fix the third commit. I had to use the turbofish in multiple calls like this |
/// Fatal error (malformed macro?). Abort compilation. | ||
Error(syntax_pos::Span, String) | ||
} | ||
|
||
impl<T> ParseResult<T> { | ||
pub fn msg(tok: Option<Token>) -> String { |
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.
can you make this a method on &self
rather than a static method? That should avoid the turbo fish.
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.
Can't because it needs to be used in several places, without a ParseResult
around.
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.
Then I would just make it a top-level function (with a more descriptive name), rather than a method
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.
Indeed, I suggested failure_message
on IRC (with that same descriptivity goal).
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.
That's difficult, because the self
is gone by the time the method is called in some cases. I'll make it a top-level fn instead.
@@ -227,7 +231,11 @@ pub fn compile(sess: &ParseSess, def: &ast::MacroDef) -> SyntaxExtension { | |||
|
|||
let argument_map = match parse(sess, &Vec::new(), arg_reader, &argument_gram) { | |||
Success(m) => m, | |||
Failure(sp, str) | Error(sp, str) => { | |||
Failure(sp, tok) => { | |||
let str = ParseResult::<i32>::msg(tok); |
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: str is a bad name because it is a very common type, so the code is a little jarring.
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.
I'll use s
.
76622eb
to
3e662d1
Compare
All comments addressed! |
@nnethercote There's still the matter of using |
This lets us delay creation of failure messages until they are needed, which avoids ~1.6M allocations in html5ever.
3e662d1
to
b817cf8
Compare
Oh, that was a comment on IRC and I missed it. Thanks for the suggestion, I've updated again. |
@bors r=nrc,eddyb |
📌 Commit b817cf8 has been approved by |
…ddyb Avoid some allocations in the macro parser These three commits reduce the number of heap allocations done when compiling rustc-benchmarks/html5ever-2016-08-25 by 20%, from 16.5M to 13.3M. This speeds up (debug) compilation of it with a stage1 compiler by about 7%.
⌛ Testing commit b817cf8 with merge a117bba... |
Avoid some allocations in the macro parser These three commits reduce the number of heap allocations done when compiling rustc-benchmarks/html5ever-2016-08-25 by 20%, from 16.5M to 13.3M. This speeds up (debug) compilation of it with a stage1 compiler by about 7%.
These three commits reduce the number of heap allocations done when compiling rustc-benchmarks/html5ever-2016-08-25 by 20%, from 16.5M to 13.3M. This speeds up (debug) compilation of it with a stage1 compiler by about 7%.