track proc-macro expansions in the self-profiler
Use the proc-macro descr to track their individual expansions with self-profiling events. This will help diagnose performance issues with slow proc-macros.
This commit is contained in:
parent
f132bcf3bd
commit
9ac8d2fe4e
2 changed files with 24 additions and 10 deletions
|
@ -1047,6 +1047,12 @@ impl<'a> ExtCtxt<'a> {
|
||||||
self.current_expansion.id.expn_data().call_site
|
self.current_expansion.id.expn_data().call_site
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the current expansion kind's description.
|
||||||
|
pub(crate) fn expansion_descr(&self) -> String {
|
||||||
|
let expn_data = self.current_expansion.id.expn_data();
|
||||||
|
expn_data.kind.descr()
|
||||||
|
}
|
||||||
|
|
||||||
/// Equivalent of `Span::def_site` from the proc macro API,
|
/// Equivalent of `Span::def_site` from the proc macro API,
|
||||||
/// except that the location is taken from the span passed as an argument.
|
/// except that the location is taken from the span passed as an argument.
|
||||||
pub fn with_def_site_ctxt(&self, span: Span) -> Span {
|
pub fn with_def_site_ctxt(&self, span: Span) -> Span {
|
||||||
|
|
|
@ -24,6 +24,8 @@ impl base::ProcMacro for BangProcMacro {
|
||||||
span: Span,
|
span: Span,
|
||||||
input: TokenStream,
|
input: TokenStream,
|
||||||
) -> Result<TokenStream, ErrorGuaranteed> {
|
) -> Result<TokenStream, ErrorGuaranteed> {
|
||||||
|
let _timer =
|
||||||
|
ecx.sess.prof.generic_activity_with_arg("expand_proc_macro", ecx.expansion_descr());
|
||||||
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
|
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
|
||||||
let server = proc_macro_server::Rustc::new(ecx);
|
let server = proc_macro_server::Rustc::new(ecx);
|
||||||
self.client.run(&EXEC_STRATEGY, server, input, proc_macro_backtrace).map_err(|e| {
|
self.client.run(&EXEC_STRATEGY, server, input, proc_macro_backtrace).map_err(|e| {
|
||||||
|
@ -48,6 +50,8 @@ impl base::AttrProcMacro for AttrProcMacro {
|
||||||
annotation: TokenStream,
|
annotation: TokenStream,
|
||||||
annotated: TokenStream,
|
annotated: TokenStream,
|
||||||
) -> Result<TokenStream, ErrorGuaranteed> {
|
) -> Result<TokenStream, ErrorGuaranteed> {
|
||||||
|
let _timer =
|
||||||
|
ecx.sess.prof.generic_activity_with_arg("expand_proc_macro", ecx.expansion_descr());
|
||||||
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
|
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
|
||||||
let server = proc_macro_server::Rustc::new(ecx);
|
let server = proc_macro_server::Rustc::new(ecx);
|
||||||
self.client
|
self.client
|
||||||
|
@ -97,9 +101,12 @@ impl MultiItemModifier for ProcMacroDerive {
|
||||||
nt_to_tokenstream(&item, &ecx.sess.parse_sess, CanSynthesizeMissingTokens::No)
|
nt_to_tokenstream(&item, &ecx.sess.parse_sess, CanSynthesizeMissingTokens::No)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let stream = {
|
||||||
|
let _timer =
|
||||||
|
ecx.sess.prof.generic_activity_with_arg("expand_proc_macro", ecx.expansion_descr());
|
||||||
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
|
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
|
||||||
let server = proc_macro_server::Rustc::new(ecx);
|
let server = proc_macro_server::Rustc::new(ecx);
|
||||||
let stream = match self.client.run(&EXEC_STRATEGY, server, input, proc_macro_backtrace) {
|
match self.client.run(&EXEC_STRATEGY, server, input, proc_macro_backtrace) {
|
||||||
Ok(stream) => stream,
|
Ok(stream) => stream,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let mut err = ecx.struct_span_err(span, "proc-macro derive panicked");
|
let mut err = ecx.struct_span_err(span, "proc-macro derive panicked");
|
||||||
|
@ -109,6 +116,7 @@ impl MultiItemModifier for ProcMacroDerive {
|
||||||
err.emit();
|
err.emit();
|
||||||
return ExpandResult::Ready(vec![]);
|
return ExpandResult::Ready(vec![]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let error_count_before = ecx.sess.parse_sess.span_diagnostic.err_count();
|
let error_count_before = ecx.sess.parse_sess.span_diagnostic.err_count();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue