Skip to content

Commit a8f7075

Browse files
committed
Auto merge of rust-lang#80692 - Aaron1011:feature/query-result-debug, r=estebank
Enforce that query results implement Debug Currently, we require that query keys implement `Debug`, but we do not do the same for query values. This can make incremental compilation bugs difficult to debug - there isn't a good place to print out the result loaded from disk. This PR adds `Debug` bounds to several query-related functions, allowing us to debug-print the query value when an 'unstable fingerprint' error occurs. This required adding `#[derive(Debug)]` to a fairly large number of types - hopefully, this doesn't have much of an impact on compiler bootstrapping times.
2 parents ff6ee2a + 056fbbf commit a8f7075

File tree

23 files changed

+46
-34
lines changed

23 files changed

+46
-34
lines changed

compiler/rustc_attr/src/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,21 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
6666
}
6767
}
6868

69-
#[derive(Copy, Clone, PartialEq, Encodable, Decodable)]
69+
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug)]
7070
pub enum InlineAttr {
7171
None,
7272
Hint,
7373
Always,
7474
Never,
7575
}
7676

77-
#[derive(Clone, Encodable, Decodable)]
77+
#[derive(Clone, Encodable, Decodable, Debug)]
7878
pub enum InstructionSetAttr {
7979
ArmA32,
8080
ArmT32,
8181
}
8282

83-
#[derive(Clone, Encodable, Decodable)]
83+
#[derive(Clone, Encodable, Decodable, Debug)]
8484
pub enum OptimizeAttr {
8585
None,
8686
Speed,

compiler/rustc_data_structures/src/stable_hasher.rs

+1
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ pub fn hash_stable_hashmap<HCX, K, V, R, SK, F>(
552552

553553
/// A vector container that makes sure that its items are hashed in a stable
554554
/// order.
555+
#[derive(Debug)]
555556
pub struct StableVec<T>(Vec<T>);
556557

557558
impl<T> StableVec<T> {

compiler/rustc_data_structures/src/steal.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::sync::{MappedReadGuard, ReadGuard, RwLock};
2121
/// -- once the value is stolen -- it will never be read from again.
2222
//
2323
// FIXME(#41710): what is the best way to model linear queries?
24+
#[derive(Debug)]
2425
pub struct Steal<T> {
2526
value: RwLock<Option<T>>,
2627
}

compiler/rustc_feature/src/active.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ macro_rules! declare_features {
3636
),+];
3737

3838
/// A set of features to be used by later passes.
39-
#[derive(Clone, Default)]
39+
#[derive(Clone, Default, Debug)]
4040
pub struct Features {
4141
/// `#![feature]` attrs for language features, for error reporting.
4242
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,

compiler/rustc_hir/src/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ macro_rules! language_item_table {
6767
}
6868
}
6969

70-
#[derive(HashStable_Generic)]
70+
#[derive(HashStable_Generic, Debug)]
7171
pub struct LanguageItems {
7272
/// Mappings from lang items to their possibly found `DefId`s.
7373
/// The index corresponds to the order in `LangItem`.

compiler/rustc_middle/src/hir/map/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ fn is_body_owner<'hir>(node: Node<'hir>, hir_id: HirId) -> bool {
8585
}
8686
}
8787

88+
#[derive(Debug)]
8889
pub(super) struct HirOwnerData<'hir> {
8990
pub(super) signature: Option<&'hir Owner<'hir>>,
9091
pub(super) with_bodies: Option<&'hir mut OwnerNodes<'hir>>,
9192
}
9293

94+
#[derive(Debug)]
9395
pub struct IndexedHir<'hir> {
9496
/// The SVH of the local crate.
9597
pub crate_hash: Svh,

compiler/rustc_middle/src/hir/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_hir::*;
1717
use rustc_index::vec::IndexVec;
1818
use rustc_span::DUMMY_SP;
1919

20+
#[derive(Debug)]
2021
pub struct Owner<'tcx> {
2122
parent: HirId,
2223
node: Node<'tcx>,
@@ -32,12 +33,13 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
3233
}
3334
}
3435

35-
#[derive(Clone)]
36+
#[derive(Clone, Debug)]
3637
pub struct ParentedNode<'tcx> {
3738
parent: ItemLocalId,
3839
node: Node<'tcx>,
3940
}
4041

42+
#[derive(Debug)]
4143
pub struct OwnerNodes<'tcx> {
4244
hash: Fingerprint,
4345
nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,

compiler/rustc_middle/src/lint.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan};
1212
use rustc_span::{symbol, Span, Symbol, DUMMY_SP};
1313

1414
/// How a lint level was set.
15-
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
15+
#[derive(Clone, Copy, PartialEq, Eq, HashStable, Debug)]
1616
pub enum LintLevelSource {
1717
/// Lint is at the default level as declared
1818
/// in rustc or a plugin.
@@ -48,11 +48,13 @@ impl LintLevelSource {
4848
/// A tuple of a lint level and its source.
4949
pub type LevelAndSource = (Level, LintLevelSource);
5050

51+
#[derive(Debug)]
5152
pub struct LintLevelSets {
5253
pub list: Vec<LintSet>,
5354
pub lint_cap: Level,
5455
}
5556

57+
#[derive(Debug)]
5658
pub enum LintSet {
5759
CommandLine {
5860
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
@@ -139,6 +141,7 @@ impl LintLevelSets {
139141
}
140142
}
141143

144+
#[derive(Debug)]
142145
pub struct LintLevelMap {
143146
pub sets: LintLevelSets,
144147
pub id_to_set: FxHashMap<HirId, u32>,

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
33
use rustc_session::config::SanitizerSet;
44
use rustc_span::symbol::Symbol;
55

6-
#[derive(Clone, TyEncodable, TyDecodable, HashStable)]
6+
#[derive(Clone, TyEncodable, TyDecodable, HashStable, Debug)]
77
pub struct CodegenFnAttrs {
88
pub flags: CodegenFnAttrFlags,
99
/// Parsed representation of the `#[inline]` attribute

compiler/rustc_middle/src/middle/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub struct NativeLib {
9696
pub wasm_import_module: Option<Symbol>,
9797
}
9898

99-
#[derive(Clone, TyEncodable, TyDecodable, HashStable)]
99+
#[derive(Clone, TyEncodable, TyDecodable, HashStable, Debug)]
100100
pub struct ForeignModule {
101101
pub foreign_items: Vec<DefId>,
102102
pub def_id: DefId,

compiler/rustc_middle/src/middle/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod lib_features {
77
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
88
use rustc_span::symbol::Symbol;
99

10-
#[derive(HashStable)]
10+
#[derive(HashStable, Debug)]
1111
pub struct LibFeatures {
1212
// A map from feature to stabilisation version.
1313
pub stable: FxHashMap<Symbol, Symbol>,

compiler/rustc_middle/src/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub type ObjectLifetimeDefault = Set1<Region>;
6868

6969
/// Maps the id of each lifetime reference to the lifetime decl
7070
/// that it corresponds to.
71-
#[derive(Default, HashStable)]
71+
#[derive(Default, HashStable, Debug)]
7272
pub struct ResolveLifetimes {
7373
/// Maps from every use of a named (not anonymous) lifetime to a
7474
/// `Region` describing how that region is bound

compiler/rustc_middle/src/middle/stability.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl StabilityLevel {
3636
}
3737

3838
/// An entry in the `depr_map`.
39-
#[derive(Clone, HashStable)]
39+
#[derive(Clone, HashStable, Debug)]
4040
pub struct DeprecationEntry {
4141
/// The metadata of the attribute associated with this entry.
4242
pub attr: Deprecation,
@@ -63,7 +63,7 @@ impl DeprecationEntry {
6363
}
6464

6565
/// A stability index, giving the stability level for items and methods.
66-
#[derive(HashStable)]
66+
#[derive(HashStable, Debug)]
6767
pub struct Index<'tcx> {
6868
/// This is mostly a cache, except the stabilities of local items
6969
/// are filled by the annotator.

compiler/rustc_middle/src/mir/interpret/value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::ty::{ParamEnv, ScalarInt, Ty, TyCtxt};
1313
use super::{AllocId, Allocation, InterpResult, Pointer, PointerArithmetic};
1414

1515
/// Represents the result of const evaluation via the `eval_to_allocation` query.
16-
#[derive(Clone, HashStable, TyEncodable, TyDecodable)]
16+
#[derive(Clone, HashStable, TyEncodable, TyDecodable, Debug)]
1717
pub struct ConstAlloc<'tcx> {
1818
// the value lives here, at offset 0, and that allocation definitely is a `AllocKind::Memory`
1919
// (so you can use `AllocMap::unwrap_memory`).

compiler/rustc_middle/src/mir/mono.rs

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ impl<'tcx> fmt::Display for MonoItem<'tcx> {
216216
}
217217
}
218218

219+
#[derive(Debug)]
219220
pub struct CodegenUnit<'tcx> {
220221
/// A name for this CGU. Incremental compilation requires that
221222
/// name be unique amongst **all** crates. Therefore, it should

compiler/rustc_middle/src/mir/query.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::fmt::{self, Debug};
1717

1818
use super::{Field, SourceInfo};
1919

20-
#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable)]
20+
#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable, Debug)]
2121
pub enum UnsafetyViolationKind {
2222
/// Only permitted in regular `fn`s, prohibited in `const fn`s.
2323
General,
@@ -36,7 +36,7 @@ pub enum UnsafetyViolationKind {
3636
UnsafeFnBorrowPacked,
3737
}
3838

39-
#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable)]
39+
#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable, Debug)]
4040
pub enum UnsafetyViolationDetails {
4141
CallToUnsafeFunction,
4242
UseOfInlineAssembly,
@@ -121,15 +121,15 @@ impl UnsafetyViolationDetails {
121121
}
122122
}
123123

124-
#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable)]
124+
#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable, Debug)]
125125
pub struct UnsafetyViolation {
126126
pub source_info: SourceInfo,
127127
pub lint_root: hir::HirId,
128128
pub kind: UnsafetyViolationKind,
129129
pub details: UnsafetyViolationDetails,
130130
}
131131

132-
#[derive(Clone, TyEncodable, TyDecodable, HashStable)]
132+
#[derive(Clone, TyEncodable, TyDecodable, HashStable, Debug)]
133133
pub struct UnsafetyCheckResult {
134134
/// Violations that are propagated *upwards* from this function.
135135
pub violations: Lrc<[UnsafetyViolation]>,

compiler/rustc_middle/src/traits/specialization_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_span::symbol::Ident;
2323
/// parents of a given specializing impl, which is needed for extracting
2424
/// default items amongst other things. In the simple "chain" rule, every impl
2525
/// has at most one parent.
26-
#[derive(TyEncodable, TyDecodable, HashStable)]
26+
#[derive(TyEncodable, TyDecodable, HashStable, Debug)]
2727
pub struct Graph {
2828
/// All impls have a parent; the "root" impls have as their parent the `def_id`
2929
/// of the trait.
@@ -50,7 +50,7 @@ impl Graph {
5050

5151
/// Children of a given impl, grouped into blanket/non-blanket varieties as is
5252
/// done in `TraitDef`.
53-
#[derive(Default, TyEncodable, TyDecodable)]
53+
#[derive(Default, TyEncodable, TyDecodable, Debug)]
5454
pub struct Children {
5555
// Impls of a trait (or specializations of a given impl). To allow for
5656
// quicker lookup, the impls are indexed by a simplified version of their

compiler/rustc_middle/src/ty/inhabitedness/def_id_forest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use DefIdForest::*;
1818
/// We store the minimal set of `DefId`s required to represent the whole set. If A and B are
1919
/// `DefId`s in the `DefIdForest`, and A is a parent of B, then only A will be stored. When this is
2020
/// used with `type_uninhabited_from`, there will very rarely be more than one `DefId` stored.
21-
#[derive(Clone, HashStable)]
21+
#[derive(Clone, HashStable, Debug)]
2222
pub enum DefIdForest {
2323
Empty,
2424
Single(DefId),

compiler/rustc_middle/src/ty/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub struct ImplHeader<'tcx> {
185185
pub predicates: Vec<Predicate<'tcx>>,
186186
}
187187

188-
#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable)]
188+
#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable, Debug)]
189189
pub enum ImplPolarity {
190190
/// `impl Trait for Type`
191191
Positive,
@@ -435,7 +435,7 @@ pub enum Variance {
435435
/// HIR of every item in the local crate. Instead, use
436436
/// `tcx.variances_of()` to get the variance for a *particular*
437437
/// item.
438-
#[derive(HashStable)]
438+
#[derive(HashStable, Debug)]
439439
pub struct CrateVariancesMap<'tcx> {
440440
/// For each item with generics, maps to a vector of the variance
441441
/// of its generics. If an item has no generics, it will have no
@@ -1174,7 +1174,7 @@ pub enum PredicateKind<'tcx> {
11741174
/// HIR of every item in the local crate. Instead, use
11751175
/// `tcx.inferred_outlives_of()` to get the outlives for a *particular*
11761176
/// item.
1177-
#[derive(HashStable)]
1177+
#[derive(HashStable, Debug)]
11781178
pub struct CratePredicatesMap<'tcx> {
11791179
/// For each struct with outlive bounds, maps to a vector of the
11801180
/// predicate of its outlive bounds. If an item has no outlives
@@ -3107,7 +3107,7 @@ impl<'tcx> TyCtxt<'tcx> {
31073107
}
31083108
}
31093109

3110-
#[derive(Clone, HashStable)]
3110+
#[derive(Clone, HashStable, Debug)]
31113111
pub struct AdtSizedConstraint<'tcx>(pub &'tcx [Ty<'tcx>]);
31123112

31133113
/// Yields the parent function's `DefId` if `def_id` is an `impl Trait` definition.

compiler/rustc_middle/src/ty/trait_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub enum TraitSpecializationKind {
6363
AlwaysApplicable,
6464
}
6565

66-
#[derive(Default)]
66+
#[derive(Default, Debug)]
6767
pub struct TraitImpls {
6868
blanket_impls: Vec<DefId>,
6969
/// Impls indexed by their simplified self type, for fast lookup.

compiler/rustc_query_system/src/query/caches.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait CacheSelector<K, V> {
1515
}
1616

1717
pub trait QueryStorage: Default {
18-
type Value;
18+
type Value: Debug;
1919
type Stored: Clone;
2020

2121
/// Store a value without putting it in the cache.
@@ -75,7 +75,7 @@ impl<K, V> Default for DefaultCache<K, V> {
7575
}
7676
}
7777

78-
impl<K: Eq + Hash, V: Clone> QueryStorage for DefaultCache<K, V> {
78+
impl<K: Eq + Hash, V: Clone + Debug> QueryStorage for DefaultCache<K, V> {
7979
type Value = V;
8080
type Stored = V;
8181

@@ -89,7 +89,7 @@ impl<K: Eq + Hash, V: Clone> QueryStorage for DefaultCache<K, V> {
8989
impl<K, V> QueryCache for DefaultCache<K, V>
9090
where
9191
K: Eq + Hash + Clone + Debug,
92-
V: Clone,
92+
V: Clone + Debug,
9393
{
9494
type Key = K;
9595
type Sharded = FxHashMap<K, (V, DepNodeIndex)>;
@@ -156,7 +156,7 @@ impl<'tcx, K, V> Default for ArenaCache<'tcx, K, V> {
156156
}
157157
}
158158

159-
impl<'tcx, K: Eq + Hash, V: 'tcx> QueryStorage for ArenaCache<'tcx, K, V> {
159+
impl<'tcx, K: Eq + Hash, V: Debug + 'tcx> QueryStorage for ArenaCache<'tcx, K, V> {
160160
type Value = V;
161161
type Stored = &'tcx V;
162162

@@ -171,6 +171,7 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> QueryStorage for ArenaCache<'tcx, K, V> {
171171
impl<'tcx, K, V: 'tcx> QueryCache for ArenaCache<'tcx, K, V>
172172
where
173173
K: Eq + Hash + Clone + Debug,
174+
V: Debug,
174175
{
175176
type Key = K;
176177
type Sharded = FxHashMap<K, &'tcx (V, DepNodeIndex)>;

compiler/rustc_query_system/src/query/plumbing.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_errors::{Diagnostic, FatalError};
2020
use rustc_span::source_map::DUMMY_SP;
2121
use rustc_span::Span;
2222
use std::collections::hash_map::Entry;
23+
use std::fmt::Debug;
2324
use std::hash::{Hash, Hasher};
2425
use std::mem;
2526
use std::num::NonZeroU32;
@@ -478,7 +479,7 @@ where
478479
result
479480
}
480481

481-
fn load_from_disk_and_cache_in_memory<CTX, K, V>(
482+
fn load_from_disk_and_cache_in_memory<CTX, K, V: Debug>(
482483
tcx: CTX,
483484
key: K,
484485
prev_dep_node_index: SerializedDepNodeIndex,
@@ -539,7 +540,7 @@ where
539540

540541
#[inline(never)]
541542
#[cold]
542-
fn incremental_verify_ich<CTX, K, V>(
543+
fn incremental_verify_ich<CTX, K, V: Debug>(
543544
tcx: CTX,
544545
result: &V,
545546
dep_node: &DepNode<CTX::DepKind>,

compiler/rustc_session/src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl Default for TrimmedDefPaths {
361361
/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
362362
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
363363
/// dependency tracking for command-line arguments.
364-
#[derive(Clone, Hash)]
364+
#[derive(Clone, Hash, Debug)]
365365
pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);
366366

367367
impl_stable_hash_via_hash!(OutputTypes);
@@ -552,7 +552,7 @@ impl Input {
552552
}
553553
}
554554

555-
#[derive(Clone, Hash)]
555+
#[derive(Clone, Hash, Debug)]
556556
pub struct OutputFilenames {
557557
pub out_directory: PathBuf,
558558
filestem: String,

0 commit comments

Comments
 (0)