Skip to content

Commit

Permalink
refactor: Don't enter context if not caching (don't need it then)
Browse files Browse the repository at this point in the history
  • Loading branch information
futile committed Dec 28, 2024
1 parent 00cff94 commit 441c4ab
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,25 @@ impl MultiItemModifier for DeriveProcMacro {

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

assert_eq!(invoc_expn_data.call_site, span);

let res = crate::derive_macro_expansion::enter_context((ecx, self.client), move || {
let key = (invoc_id, proc_macro_crate_hash, input);
// FIXME(pr-time): Is this the correct way to check for incremental compilation (as
// well)?
if tcx.sess.opts.incremental.is_some()
&& tcx.sess.opts.unstable_opts.cache_proc_macros
{
tcx.derive_macro_expansion(key).cloned()
} else {
crate::derive_macro_expansion::provide_derive_macro_expansion(tcx, key).cloned()
}
});
let key = (invoc_id, proc_macro_crate_hash, input);

res
if tcx.sess.opts.incremental.is_some() && tcx.sess.opts.unstable_opts.cache_proc_macros
{
crate::derive_macro_expansion::enter_context((ecx, self.client), move || {
// FIXME(pr-time): Is this the correct way to check for incremental compilation (as
// well)?
tcx.derive_macro_expansion(key).cloned()
})
} else {
crate::derive_macro_expansion::provide_derive_macro_expansion(tcx, key).cloned()
}
});
let Ok(output) = res else {
// error will already have been emitted
Expand Down

0 comments on commit 441c4ab

Please sign in to comment.