Skip to content

Commit be15785

Browse files
committed
feat: Add -Zcache-all-derive-macros to use/bypass cache
1 parent 6ef439a commit be15785

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

compiler/rustc_expand/src/proc_macro.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ impl MultiItemModifier for DeriveProcMacro {
147147
assert_eq!(invoc_id.expn_data().call_site, span);
148148

149149
let res = crate::derive_macro_expansion::enter_context((ecx, self.client), move || {
150-
let res =
151-
tcx.derive_macro_expansion((invoc_id, proc_macro_crate_hash, input)).cloned();
152-
res
150+
let key = (invoc_id, proc_macro_crate_hash, input);
151+
if tcx.sess.opts.unstable_opts.cache_all_derive_macros {
152+
tcx.derive_macro_expansion(key).cloned()
153+
} else {
154+
crate::derive_macro_expansion::provide_derive_macro_expansion(tcx, key).cloned()
155+
}
153156
});
154157

155158
res

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,8 @@ options! {
16371637
"emit noalias metadata for box (default: yes)"),
16381638
branch_protection: Option<BranchProtection> = (None, parse_branch_protection, [TRACKED],
16391639
"set options for branch target identification and pointer authentication on AArch64"),
1640+
cache_all_derive_macros: bool = (false, parse_bool, [UNTRACKED],
1641+
"cache the results of ALL derive macro invocations (potentially unsound!) (default: no)"),
16401642
cf_protection: CFProtection = (CFProtection::None, parse_cfprotection, [TRACKED],
16411643
"instrument control-flow architecture protection"),
16421644
check_cfg_all_expected: bool = (false, parse_bool, [UNTRACKED],

0 commit comments

Comments
 (0)