Skip to content

Experimental: Add Derive Proc-Macro Caching #129102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eccec74
deps(rustc_expand): Add `rustc_middle` as a dep
futile Aug 11, 2024
e0fe67e
refactor(rustc_expand): Take &SyntaxExtension instead of only &*Kind
futile Aug 11, 2024
7081090
wip: So yeah, tests pass, but still `eval_always` (not far from disk …
futile Aug 12, 2024
377075a
fix: Prevent double-enter with same `&mut ExtCtxt` (which would be UB)
futile Aug 12, 2024
fdc7d63
chore: Remove old `allow`
futile Aug 12, 2024
efb8f71
chore: Remove unneeded code, adapt TODOs for pr-time
futile Aug 12, 2024
9175ccc
wip(test): Run with `-- --nocapture --verbose` and `invoked` should n…
futile Aug 12, 2024
b92601a
wip: Activate, test (and fix) on_disk caching for proc-macro expansions!
futile Aug 12, 2024
f9ec979
chore: Adjust timing outputs
futile Aug 12, 2024
f0e0006
feat: Add `-Zcache-all-derive-macros` to use/bypass cache
futile Aug 12, 2024
74b9365
wip: try also hashing query output
futile Aug 12, 2024
df518db
prepare for PR (tidy should pass, caching=yes by default for rustc-perf)
futile Aug 14, 2024
12c6d3e
wip: Undo unnecessary refactoring
futile Aug 19, 2024
5439803
rebase + fix unreachable pub-items, inline some CONTEXT-things
futile Sep 9, 2024
8610ec6
fix: comment + unused warning
futile Nov 16, 2024
1bad277
style: move import to correct place
futile Nov 16, 2024
bc58b22
chore: remove old comment
futile Nov 16, 2024
3e5e84b
don't flatten proc macro output, let's see how it goes
futile Nov 16, 2024
4652473
only retrieve expn_data once
futile Nov 16, 2024
1cd9a4f
fix: Ensure incremental compilation is also enabled
futile Dec 8, 2024
db56376
refactor!: Rename `cache-all-derive-macros` option to `cache-proc-mac…
futile Dec 28, 2024
70460d4
nit: remove comment
futile Dec 28, 2024
9352678
refactor: Require `ecx` less
futile Dec 28, 2024
6a62f9b
refactor: Only call invoc_id.expn_data() once, inline some `res`
futile Dec 28, 2024
4a3ed82
refactor: Don't enter context if not caching (don't need it then)
futile Dec 28, 2024
26cf691
refactor: Move derive_macro_expansion.rs to end of proc_macro.rs
futile Dec 28, 2024
39002fb
fix: Make non-context expansion actually work
futile Dec 28, 2024
0e125a5
fix: Build was broken, probably should squash all commits now or sth.
futile Mar 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Don't enter context if not caching (don't need it then)
futile committed Mar 28, 2025

Verified

This commit was signed with the committer’s verified signature.
wilfwilson Wilf Wilson
commit 4a3ed82a619fee0e0ee196b6d79cf82d1ef928d4
28 changes: 13 additions & 15 deletions compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
@@ -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
// 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
{
crate::derive_macro_expansion::enter_context((ecx, self.client), move || {
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