Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
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. |
|
@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 { |
nrc
Oct 21, 2016
Member
can you make this a method on &self rather than a static method? That should avoid the turbo fish.
can you make this a method on &self rather than a static method? That should avoid the turbo fish.
eddyb
Oct 21, 2016
Member
Can't because it needs to be used in several places, without a ParseResult around.
Can't because it needs to be used in several places, without a ParseResult around.
nrc
Oct 21, 2016
Member
Then I would just make it a top-level function (with a more descriptive name), rather than a method
Then I would just make it a top-level function (with a more descriptive name), rather than a method
eddyb
Oct 21, 2016
Member
Indeed, I suggested failure_message on IRC (with that same descriptivity goal).
Indeed, I suggested failure_message on IRC (with that same descriptivity goal).
nnethercote
Oct 21, 2016
Author
Contributor
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.
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); | |||
nrc
Oct 21, 2016
Member
nit: str is a bad name because it is a very common type, so the code is a little jarring.
nit: str is a bad name because it is a very common type, so the code is a little jarring.
nnethercote
Oct 21, 2016
Author
Contributor
I'll use s.
I'll use s.
|
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.
Oh, that was a comment on IRC and I missed it. Thanks for the suggestion, I've updated again. |
|
@bors r=nrc,eddyb |
|
|
…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%.
…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%.
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%.