Skip to content

Commit 05781ca

Browse files
committed
Apply review remarks
1 parent 1fc1766 commit 05781ca

7 files changed

Lines changed: 40 additions & 78 deletions

File tree

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,18 +3348,8 @@ impl UseTree {
33483348
/// Distinguishes between `Attribute`s that decorate items and Attributes that
33493349
/// are contained as statements within items. These two cases need to be
33503350
/// distinguished for pretty-printing.
3351-
#[derive(
3352-
Clone,
3353-
PartialEq,
3354-
Eq,
3355-
Encodable,
3356-
Decodable,
3357-
Hash,
3358-
Debug,
3359-
Copy,
3360-
HashStable_Generic,
3361-
Walkable
3362-
)]
3351+
#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)]
3352+
#[derive(Encodable, Decodable, HashStable_Generic, Walkable)]
33633353
pub enum AttrStyle {
33643354
Outer,
33653355
Inner,

compiler/rustc_expand/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub mod module;
2929
#[allow(rustc::untranslatable_diagnostic)]
3030
pub mod proc_macro;
3131

32-
pub fn provide(providers: &mut rustc_middle::util::Providers) {
32+
pub fn provide(providers: &mut rustc_middle::query::Providers) {
3333
providers.derive_macro_expansion = proc_macro::provide_derive_macro_expansion;
3434
}
3535

compiler/rustc_expand/src/proc_macro.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ impl MultiItemModifier for DeriveProcMacro {
139139
&& ecx.sess.opts.unstable_opts.cache_proc_macros
140140
{
141141
ty::tls::with(|tcx| {
142-
let input = tcx.arena.alloc(input) as &TokenStream;
143-
let key = (invoc_id, input);
142+
let input = &*tcx.arena.alloc(input);
143+
let key: (LocalExpnId, &TokenStream) = (invoc_id, input);
144144

145145
QueryDeriveExpandCtx::enter(ecx, self.client, move || {
146146
tcx.derive_macro_expansion(key).cloned()
@@ -196,8 +196,7 @@ pub(super) fn provide_derive_macro_expansion<'tcx>(
196196
let _ = tcx.crate_hash(invoc_id.expn_data().macro_def_id.unwrap().krate);
197197

198198
QueryDeriveExpandCtx::with(|ecx, client| {
199-
expand_derive_macro(invoc_id, input.clone(), ecx, client)
200-
.map(|ts| tcx.arena.alloc(ts) as &TokenStream)
199+
expand_derive_macro(invoc_id, input.clone(), ecx, client).map(|ts| &*tcx.arena.alloc(ts))
201200
})
202201
}
203202

@@ -209,11 +208,11 @@ fn expand_derive_macro(
209208
ecx: &mut ExtCtxt<'_>,
210209
client: DeriveClient,
211210
) -> Result<TokenStream, ()> {
212-
let invoc_expn_data = invoc_id.expn_data();
213-
let span = invoc_expn_data.call_site;
214-
let event_arg = invoc_expn_data.kind.descr();
215211
let _timer =
216212
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
213+
let invoc_expn_data = invoc_id.expn_data();
214+
let span = invoc_expn_data.call_site;
215+
let event_arg = invoc_expn_data.kind.descr();
217216
recorder.record_arg_with_span(ecx.sess.source_map(), event_arg.clone(), span);
218217
});
219218

@@ -224,6 +223,8 @@ fn expand_derive_macro(
224223
match client.run(&strategy, server, input, proc_macro_backtrace) {
225224
Ok(stream) => Ok(stream),
226225
Err(e) => {
226+
let invoc_expn_data = invoc_id.expn_data();
227+
let span = invoc_expn_data.call_site;
227228
ecx.dcx().emit_err({
228229
errors::ProcMacroDerivePanicked {
229230
span,

compiler/rustc_incremental/src/persist/dirty_clean.rs

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ use rustc_hir::def_id::LocalDefId;
2626
use rustc_hir::{
2727
Attribute, ImplItemKind, ItemKind as HirItem, Node as HirNode, TraitItemKind, intravisit,
2828
};
29-
use rustc_middle::dep_graph::{DepKind, DepNode, DepNodeExt, dep_kind_from_label, label_strs};
29+
use rustc_middle::dep_graph::{DepNode, DepNodeExt, dep_kind_from_label, label_strs};
3030
use rustc_middle::hir::nested_filter;
3131
use rustc_middle::ty::TyCtxt;
32-
use rustc_span::def_id::DefPathHash;
3332
use rustc_span::{Span, Symbol, sym};
3433
use thin_vec::ThinVec;
3534
use tracing::debug;
@@ -358,29 +357,6 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
358357
}
359358
}
360359

361-
fn assert_loaded_from_disk(&self, item_span: Span, dep_item: DepItem) {
362-
debug!("assert_loaded_from_disk({:?})", dep_item);
363-
364-
match dep_item {
365-
DepItem::DepNode(dep_node) => {
366-
if !self.tcx.dep_graph.debug_was_loaded_from_disk(dep_node) {
367-
let dep_node_str = self.dep_node_str(&dep_node);
368-
self.tcx.dcx().emit_err(errors::NotLoaded {
369-
span: item_span,
370-
dep_node_str: &dep_node_str,
371-
});
372-
}
373-
}
374-
DepItem::DepKind { kind, label } => {
375-
if !self.tcx.dep_graph.debug_dep_kind_was_loaded_from_disk(kind) {
376-
self.tcx
377-
.dcx()
378-
.emit_err(errors::NotLoaded { span: item_span, dep_node_str: &label });
379-
}
380-
}
381-
}
382-
}
383-
384360
fn check_item(&mut self, item_id: LocalDefId) {
385361
let item_span = self.tcx.def_span(item_id.to_def_id());
386362
let def_path_hash = self.tcx.def_path_hash(item_id.to_def_id());
@@ -398,34 +374,32 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
398374
self.assert_dirty(item_span, dep_node);
399375
}
400376
for label in assertion.loaded_from_disk.items().into_sorted_stable_ord() {
401-
let dep_item = resolve_dep_item(self.tcx, label, def_path_hash);
402-
self.assert_loaded_from_disk(item_span, dep_item);
377+
let dep_kind = dep_kind_from_label(label);
378+
match DepNode::from_label_string(self.tcx, label, def_path_hash) {
379+
Ok(dep_node) => {
380+
if !self.tcx.dep_graph.debug_was_loaded_from_disk(dep_node) {
381+
let dep_node_str = self.dep_node_str(&dep_node);
382+
self.tcx.dcx().emit_err(errors::NotLoaded {
383+
span: item_span,
384+
dep_node_str: &dep_node_str,
385+
});
386+
}
387+
}
388+
// Opaque/unit hash, we only know the dep kind
389+
Err(()) => {
390+
if !self.tcx.dep_graph.debug_dep_kind_was_loaded_from_disk(dep_kind) {
391+
self.tcx.dcx().emit_err(errors::NotLoaded {
392+
span: item_span,
393+
dep_node_str: &label,
394+
});
395+
}
396+
}
397+
}
403398
}
404399
}
405400
}
406401
}
407402

408-
/// Represents a query that we want to test for dirtiness.
409-
#[derive(Debug)]
410-
enum DepItem {
411-
/// We have a DepNode for this query.
412-
DepNode(DepNode),
413-
/// This query has an opaque or a unit hash fingerprint, so we cannot resolve a DepNode for it.
414-
/// We thus only store the DepKind, so that we can check if *any* query with the given label
415-
/// was executed, regardless of its query arguments.
416-
DepKind { kind: DepKind, label: String },
417-
}
418-
419-
fn resolve_dep_item(tcx: TyCtxt<'_>, label: &str, def_path_hash: DefPathHash) -> DepItem {
420-
let dep_kind = dep_kind_from_label(label).unwrap(); // Ensure that the query label is known
421-
422-
match DepNode::from_label_string(tcx, label, def_path_hash) {
423-
Ok(dep_node) => DepItem::DepNode(dep_node),
424-
// Opaque/unit hash, we only know the dep kind
425-
Err(()) => DepItem::DepKind { kind: dep_kind, label: label.to_owned() },
426-
}
427-
}
428-
429403
/// Given a `#[rustc_clean]` attribute, scan for a `cfg="foo"` attribute and check whether we have
430404
/// a cfg flag called `foo`.
431405
fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ impl DepNodeExt for DepNode {
176176
}
177177
}
178178

179-
/// Maps a query label to its DepKind, if it exists.
180-
pub fn dep_kind_from_label(label: &str) -> Option<DepKind> {
181-
dep_kind_from_label_string(label).ok()
179+
/// Maps a query label to its DepKind. Panics if a query with the given label does not exist.
180+
pub fn dep_kind_from_label(label: &str) -> DepKind {
181+
dep_kind_from_label_string(label)
182+
.unwrap_or_else(|_| panic!("Query label {label} does not exist"))
182183
}
183184

184185
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for () {

tests/incremental/derive_macro_expansion/auxiliary/derive_nothing.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
//@ force-host
2-
//@ no-prefer-dynamic
3-
4-
#![crate_type = "proc-macro"]
5-
61
extern crate proc_macro;
72
use proc_macro::TokenStream;
83

tests/incremental/derive_macro_expansion/proc_macro_unchanged.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// This test tests that derive-macro execution is cached.
1+
// This test tests that derive proc macro execution is cached.
22

3-
//@ aux-build:derive_nothing.rs
3+
//@ proc-macro:derive_nothing.rs
44
//@ revisions:rpass1 rpass2
55
//@ compile-flags: -Zquery-dep-graph -Zcache-proc-macros
6+
//@ ignore-backends: gcc
67

78
#![feature(rustc_attrs)]
89

0 commit comments

Comments
 (0)