Skip to content

Commit 4a3ed82

Browse files
committed
refactor: Don't enter context if not caching (don't need it then)
1 parent 6a62f9b commit 4a3ed82

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

compiler/rustc_expand/src/proc_macro.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,25 @@ impl MultiItemModifier for DeriveProcMacro {
141141

142142
// FIXME(pr-time): Just using the crate hash to notice when the proc-macro code has
143143
// changed. How to *correctly* depend on exactly the macro definition?
144-
// I.e., depending on the crate hash is just a HACK (and leaves garbage in the
145-
// incremental compilation dir).
144+
// I.e., depending on the crate hash is just a HACK, and ideally the dependency would be
145+
// more narrow.
146146
let macro_def_id = invoc_expn_data.macro_def_id.unwrap();
147147
let proc_macro_crate_hash = tcx.crate_hash(macro_def_id.krate);
148148

149149
assert_eq!(invoc_expn_data.call_site, span);
150150

151-
let res = crate::derive_macro_expansion::enter_context((ecx, self.client), move || {
152-
let key = (invoc_id, proc_macro_crate_hash, input);
153-
// FIXME(pr-time): Is this the correct way to check for incremental compilation (as
154-
// well)?
155-
if tcx.sess.opts.incremental.is_some()
156-
&& tcx.sess.opts.unstable_opts.cache_proc_macros
157-
{
158-
tcx.derive_macro_expansion(key).cloned()
159-
} else {
160-
crate::derive_macro_expansion::provide_derive_macro_expansion(tcx, key).cloned()
161-
}
162-
});
151+
let key = (invoc_id, proc_macro_crate_hash, input);
163152

164-
res
153+
// FIXME(pr-time): Is this the correct way to check for incremental compilation (as
154+
// well)?
155+
if tcx.sess.opts.incremental.is_some() && tcx.sess.opts.unstable_opts.cache_proc_macros
156+
{
157+
crate::derive_macro_expansion::enter_context((ecx, self.client), move || {
158+
tcx.derive_macro_expansion(key).cloned()
159+
})
160+
} else {
161+
crate::derive_macro_expansion::provide_derive_macro_expansion(tcx, key).cloned()
162+
}
165163
});
166164
let Ok(output) = res else {
167165
// error will already have been emitted

0 commit comments

Comments
 (0)