Skip to content

Commit 5220403

Browse files
committed
Add some comments and rename the option to -Zcache-derive-macros
1 parent 71969a5 commit 5220403

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ impl<H: std::hash::Hasher> SpanEncoder for HashEncoder<H> {
650650
}
651651
}
652652

653+
/// TokenStream needs to be hashable because it is used as a query key for caching derive macro
654+
/// expansions.
653655
impl Hash for TokenStream {
654656
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
655657
Encodable::encode(self, &mut HashEncoder { hasher: state });

compiler/rustc_expand/src/proc_macro.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ impl MultiItemModifier for DeriveProcMacro {
145145

146146
// FIXME(pr-time): Is this the correct way to check for incremental compilation (as
147147
// well as for `cache_proc_macros`)?
148-
if tcx.sess.opts.incremental.is_some() && tcx.sess.opts.unstable_opts.cache_proc_macros
148+
if tcx.sess.opts.incremental.is_some()
149+
&& tcx.sess.opts.unstable_opts.cache_derive_macros
149150
{
150151
// FIXME(pr-time): Just using the crate hash to notice when the proc-macro code has
151152
// changed. How to *correctly* depend on exactly the macro definition?
@@ -197,6 +198,7 @@ impl MultiItemModifier for DeriveProcMacro {
197198
}
198199
}
199200

201+
/// Provide a query for computing the output of a derive macro.
200202
pub(super) fn provide_derive_macro_expansion<'tcx>(
201203
tcx: TyCtxt<'tcx>,
202204
key: (LocalExpnId, Svh, &'tcx TokenStream),

compiler/rustc_middle/src/query/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,14 @@ pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
165165
// Queries marked with `fatal_cycle` do not need the latter implementation,
166166
// as they will raise an fatal error on query cycles instead.
167167
rustc_queries! {
168+
/// Caches the expansion of a derive proc macro, e.g. `#[derive(Serialize)]`.
169+
/// The key is:
170+
/// - A unique key corresponding to the invocation of a macro.
171+
/// - Strict Version Hash of a crate.
172+
/// - Token stream which serves as an input to the macro.
173+
///
174+
/// The output is the token stream generated by the proc macro.
168175
query derive_macro_expansion(key: (LocalExpnId, Svh, &'tcx TokenStream)) -> Result<&'tcx TokenStream, ()> {
169-
// eval_always
170-
// no_hash
171176
desc { "expanding a derive (proc) macro" }
172177
cache_on_disk_if { true }
173178
}

tests/incremental/derive_macro_expansion/proc_macro_unchanged.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@
88

99
//@ aux-build:derive_nothing.rs
1010
//@ revisions:cfail1 cfail2
11-
//@ compile-flags: -Z query-dep-graph -Zcache-proc-macros=true
11+
//@ compile-flags: -Z query-dep-graph -Zcache-derive-macros=true
1212
//@ build-pass
1313

1414
#![feature(rustc_attrs)]
1515
#![feature(stmt_expr_attributes)]
1616
#![allow(dead_code)]
1717
#![crate_type = "rlib"]
18-
19-
#![rustc_partition_codegened(module="proc_macro_unchanged-foo", cfg="cfail1")]
18+
#![rustc_partition_codegened(module = "proc_macro_unchanged-foo", cfg = "cfail1")]
2019
// #![rustc_partition_codegened(module="proc_macro_unchanged-foo", cfg="cfail2")]
2120

2221
// `foo::nothing_mod` is created by the derive macro and doesn't change
23-
// BUG: this yields the same result with `-Zcache-proc-macros=false` (i.e., uncached),
22+
// BUG: this yields the same result with `-Zcache-derive-macros=false` (i.e., uncached),
2423
// not sure how to do this correctly.
25-
#![rustc_partition_reused(module="proc_macro_unchanged-foo-nothing_mod", cfg="cfail2")]
24+
#![rustc_partition_reused(module = "proc_macro_unchanged-foo-nothing_mod", cfg = "cfail2")]
2625

27-
#[macro_use]
28-
extern crate derive_nothing;
26+
#[macro_use]
27+
extern crate derive_nothing;
2928

3029
pub mod foo {
3130
#[derive(Nothing)]

0 commit comments

Comments
 (0)