diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-11-16 10:05:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-16 10:05:03 +0100 |
| commit | 3c1ea047da61fd6b389849492bfcd362bbc6c0d1 (patch) | |
| tree | 431a1d357c1b212b3920f5bff36f85a66bf97caf /src | |
| parent | 387fa844bbcfa236b3ea192adc4196361d25677a (diff) | |
| parent | 824b307ff7e3e93f2a5d0d864e9161c3db12acfc (diff) | |
| download | rust-3c1ea047da61fd6b389849492bfcd362bbc6c0d1.tar.gz rust-3c1ea047da61fd6b389849492bfcd362bbc6c0d1.zip | |
Rollup merge of #45973 - arielb1:fast-path, r=estebank
avoid the pprust infrastructure in macro expansion This changes macro expansion to format the path of a macro directly instead of usng the pprust infrastructure. The pprust infrastructure tries to perform line-breaking in a slow fashion, which is undesired when formatting the path of a macro. This should to speed up expansion by a fair amount (I saw 20% on a profiler on `rustc_mir`, and 50% of the time marked as "expansion" in the profiler/time-passes is actually spent loading dependencies). r? @jseyfried
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 614c4a10e6d..491dbed01f1 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -29,6 +29,7 @@ use std_inject; use symbol::Symbol; use symbol::keywords; use syntax_pos::{Span, DUMMY_SP}; +use syntax_pos::hygiene::ExpnFormat; use tokenstream::{TokenStream, TokenTree}; use util::small_vector::SmallVector; use visit::Visitor; @@ -151,6 +152,26 @@ impl ExpansionKind { } } +fn macro_bang_format(path: &ast::Path) -> ExpnFormat { + // We don't want to format a path using pretty-printing, + // `format!("{}", path)`, because that tries to insert + // line-breaks and is slow. + let mut path_str = String::with_capacity(64); + for (i, segment) in path.segments.iter().enumerate() { + if i != 0 { + path_str.push_str("::"); + } + + if segment.identifier.name != keywords::CrateRoot.name() && + segment.identifier.name != keywords::DollarCrate.name() + { + path_str.push_str(&segment.identifier.name.as_str()) + } + } + + MacroBang(Symbol::intern(&path_str)) +} + pub struct Invocation { pub kind: InvocationKind, expansion_kind: ExpansionKind, @@ -517,7 +538,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { mark.set_expn_info(ExpnInfo { call_site: span, callee: NameAndSpan { - format: MacroBang(Symbol::intern(&format!("{}", path))), + format: macro_bang_format(path), span: def_site_span, allow_internal_unstable, allow_internal_unsafe, @@ -564,7 +585,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { invoc.expansion_data.mark.set_expn_info(ExpnInfo { call_site: span, callee: NameAndSpan { - format: MacroBang(Symbol::intern(&format!("{}", path))), + format: macro_bang_format(path), span: tt_span, allow_internal_unstable, allow_internal_unsafe: false, @@ -600,7 +621,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { invoc.expansion_data.mark.set_expn_info(ExpnInfo { call_site: span, callee: NameAndSpan { - format: MacroBang(Symbol::intern(&format!("{}", path))), + format: macro_bang_format(path), // FIXME procedural macros do not have proper span info // yet, when they do, we should use it here. span: None, |
