Skip to content

Commit 7a1b2f5

Browse files
committed
feat: Add -Zcache-all-derive-macros to use/bypass cache
1 parent 075853d commit 7a1b2f5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

compiler/rustc_expand/src/proc_macro.rs

Lines changed: 6 additions & 3 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,8 @@ options! {
16971697
"emit noalias metadata for box (default: yes)"),
16981698
branch_protection: Option<BranchProtection> = (None, parse_branch_protection, [TRACKED],
16991699
"set options for branch target identification and pointer authentication on AArch64"),
1700+
cache_all_derive_macros: bool = (false, parse_bool, [UNTRACKED],
1701+
"cache the results of ALL derive macro invocations (potentially unsound!) (default: no)"),
17001702
cf_protection: CFProtection = (CFProtection::None, parse_cfprotection, [TRACKED],
17011703
"instrument control-flow architecture protection"),
17021704
check_cfg_all_expected: bool = (false, parse_bool, [UNTRACKED],

0 commit comments

Comments
 (0)