Skip to content

Commit 8a6e06f

Browse files
committed
Exclude mir::coverage types from TypeFoldable/TypeVisitable
These types are unlikely to ever contain type information in the foreseeable future, so excluding them from TypeFoldable/TypeVisitable avoids some unhelpful derive boilerplate.
1 parent 1c9837d commit 8a6e06f

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

compiler/rustc_middle/src/mir/coverage.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Formatter};
44

55
use rustc_index::IndexVec;
66
use rustc_index::bit_set::DenseBitSet;
7-
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
7+
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
88
use rustc_span::Span;
99

1010
rustc_index::newtype_index! {
@@ -72,7 +72,7 @@ impl ConditionId {
7272
/// Enum that can hold a constant zero value, the ID of an physical coverage
7373
/// counter, or the ID of a coverage-counter expression.
7474
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
75-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
75+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
7676
pub enum CovTerm {
7777
Zero,
7878
Counter(CounterId),
@@ -89,7 +89,7 @@ impl Debug for CovTerm {
8989
}
9090
}
9191

92-
#[derive(Clone, PartialEq, TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
92+
#[derive(Clone, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
9393
pub enum CoverageKind {
9494
/// Marks a span that might otherwise not be represented in MIR, so that
9595
/// coverage instrumentation can associate it with its enclosing block/BCB.
@@ -151,7 +151,7 @@ impl Debug for CoverageKind {
151151
}
152152

153153
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
154-
#[derive(TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)]
154+
#[derive(TyEncodable, TyDecodable)]
155155
pub enum Op {
156156
Subtract,
157157
Add,
@@ -168,15 +168,15 @@ impl Op {
168168
}
169169

170170
#[derive(Clone, Debug, PartialEq, Eq)]
171-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
171+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
172172
pub struct Expression {
173173
pub lhs: CovTerm,
174174
pub op: Op,
175175
pub rhs: CovTerm,
176176
}
177177

178178
#[derive(Clone, Debug)]
179-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
179+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
180180
pub enum MappingKind {
181181
/// Associates a normal region of code with a counter/expression/zero.
182182
Code(CovTerm),
@@ -208,7 +208,7 @@ impl MappingKind {
208208
}
209209

210210
#[derive(Clone, Debug)]
211-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
211+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
212212
pub struct Mapping {
213213
pub kind: MappingKind,
214214
pub span: Span,
@@ -218,7 +218,7 @@ pub struct Mapping {
218218
/// to be used in conjunction with the individual coverage statements injected
219219
/// into the function's basic blocks.
220220
#[derive(Clone, Debug)]
221-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
221+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
222222
pub struct FunctionCoverageInfo {
223223
pub function_source_hash: u64,
224224
pub body_span: Span,
@@ -238,7 +238,7 @@ pub struct FunctionCoverageInfo {
238238
/// ("Hi" indicates that this is "high-level" information collected at the
239239
/// THIR/MIR boundary, before the MIR-based coverage instrumentation pass.)
240240
#[derive(Clone, Debug)]
241-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
241+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
242242
pub struct CoverageInfoHi {
243243
/// 1 more than the highest-numbered [`CoverageKind::BlockMarker`] that was
244244
/// injected into the MIR body. This makes it possible to allocate per-ID
@@ -252,23 +252,23 @@ pub struct CoverageInfoHi {
252252
}
253253

254254
#[derive(Clone, Debug)]
255-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
255+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
256256
pub struct BranchSpan {
257257
pub span: Span,
258258
pub true_marker: BlockMarkerId,
259259
pub false_marker: BlockMarkerId,
260260
}
261261

262262
#[derive(Copy, Clone, Debug)]
263-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
263+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
264264
pub struct ConditionInfo {
265265
pub condition_id: ConditionId,
266266
pub true_next_id: Option<ConditionId>,
267267
pub false_next_id: Option<ConditionId>,
268268
}
269269

270270
#[derive(Clone, Debug)]
271-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
271+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
272272
pub struct MCDCBranchSpan {
273273
pub span: Span,
274274
pub condition_info: ConditionInfo,
@@ -277,14 +277,14 @@ pub struct MCDCBranchSpan {
277277
}
278278

279279
#[derive(Copy, Clone, Debug)]
280-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
280+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
281281
pub struct DecisionInfo {
282282
pub bitmap_idx: u32,
283283
pub num_conditions: u16,
284284
}
285285

286286
#[derive(Clone, Debug)]
287-
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
287+
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
288288
pub struct MCDCDecisionSpan {
289289
pub span: Span,
290290
pub end_markers: Vec<BlockMarkerId>,

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ pub struct Body<'tcx> {
358358
///
359359
/// Only present if coverage is enabled and this function is eligible.
360360
/// Boxed to limit space overhead in non-coverage builds.
361+
#[type_foldable(identity)]
362+
#[type_visitable(ignore)]
361363
pub coverage_info_hi: Option<Box<coverage::CoverageInfoHi>>,
362364

363365
/// Per-function coverage information added by the `InstrumentCoverage`
@@ -366,6 +368,8 @@ pub struct Body<'tcx> {
366368
///
367369
/// If `-Cinstrument-coverage` is not active, or if an individual function
368370
/// is not eligible for coverage, then this should always be `None`.
371+
#[type_foldable(identity)]
372+
#[type_visitable(ignore)]
369373
pub function_coverage_info: Option<Box<coverage::FunctionCoverageInfo>>,
370374
}
371375

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,14 @@ pub enum StatementKind<'tcx> {
417417
///
418418
/// Interpreters and codegen backends that don't support coverage instrumentation
419419
/// can usually treat this as a no-op.
420-
Coverage(CoverageKind),
420+
Coverage(
421+
// Coverage statements are unlikely to ever contain type information in
422+
// the foreseeable future, so excluding them from TypeFoldable/TypeVisitable
423+
// avoids some unhelpful derive boilerplate.
424+
#[type_foldable(identity)]
425+
#[type_visitable(ignore)]
426+
CoverageKind,
427+
),
421428

422429
/// Denotes a call to an intrinsic that does not require an unwind path and always returns.
423430
/// This avoids adding a new block and a terminator for simple intrinsics.

0 commit comments

Comments
 (0)