Skip to content

Commit f049d5d

Browse files
committed
Remove an unnecessary use of with_session_globals.
We can easily pass in the source map.
1 parent c1d3610 commit f049d5d

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

compiler/rustc_expand/src/proc_macro.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl base::BangProcMacro for BangProcMacro {
5454
) -> Result<TokenStream, ErrorGuaranteed> {
5555
let _timer =
5656
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
57-
recorder.record_arg_with_span(ecx.expansion_descr(), span);
57+
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
5858
});
5959

6060
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
@@ -85,7 +85,7 @@ impl base::AttrProcMacro for AttrProcMacro {
8585
) -> Result<TokenStream, ErrorGuaranteed> {
8686
let _timer =
8787
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
88-
recorder.record_arg_with_span(ecx.expansion_descr(), span);
88+
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
8989
});
9090

9191
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
@@ -134,7 +134,11 @@ impl MultiItemModifier for DeriveProcMacro {
134134
let stream = {
135135
let _timer =
136136
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
137-
recorder.record_arg_with_span(ecx.expansion_descr(), span);
137+
recorder.record_arg_with_span(
138+
ecx.sess.source_map(),
139+
ecx.expansion_descr(),
140+
span,
141+
);
138142
});
139143
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
140144
let strategy = exec_strategy(ecx);

compiler/rustc_span/src/profiling.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::source_map::SourceMap;
2+
13
use std::borrow::Borrow;
24

35
use rustc_data_structures::profiling::EventArgRecorder;
@@ -11,25 +13,17 @@ pub trait SpannedEventArgRecorder {
1113
///
1214
/// Note: when self-profiling with costly event arguments, at least one argument
1315
/// needs to be recorded. A panic will be triggered if that doesn't happen.
14-
fn record_arg_with_span<A>(&mut self, event_arg: A, span: crate::Span)
16+
fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
1517
where
1618
A: Borrow<str> + Into<String>;
1719
}
1820

1921
impl SpannedEventArgRecorder for EventArgRecorder<'_> {
20-
fn record_arg_with_span<A>(&mut self, event_arg: A, span: crate::Span)
22+
fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
2123
where
2224
A: Borrow<str> + Into<String>,
2325
{
2426
self.record_arg(event_arg);
25-
26-
let span_arg = crate::with_session_globals(|session_globals| {
27-
if let Some(source_map) = &*session_globals.source_map.borrow() {
28-
source_map.span_to_embeddable_string(span)
29-
} else {
30-
format!("{span:?}")
31-
}
32-
});
33-
self.record_arg(span_arg);
27+
self.record_arg(source_map.span_to_embeddable_string(span));
3428
}
3529
}

0 commit comments

Comments
 (0)