Skip to content

Commit 738df13

Browse files
committed
Auto merge of #115093 - Zalathar:smir-coverage, r=cjgillot,oli-obk
Treat `StatementKind::Coverage` as completely opaque for SMIR purposes Coverage statements in MIR are heavily tied to internal details of the coverage implementation that are likely to change, and are unlikely to be useful to third-party tools for the foreseeable future.
2 parents b60f7b5 + 1fac8a0 commit 738df13

File tree

2 files changed

+5
-94
lines changed

2 files changed

+5
-94
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+1-55
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::stable_mir::ty::{
1515
};
1616
use crate::stable_mir::{self, Context};
1717
use rustc_hir as hir;
18-
use rustc_middle::mir::coverage::CodeRegion;
1918
use rustc_middle::mir::interpret::alloc_range;
2019
use rustc_middle::mir::{self, ConstantKind};
2120
use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
@@ -192,10 +191,7 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
192191
variance: variance.stable(tables),
193192
}
194193
}
195-
Coverage(coverage) => stable_mir::mir::Statement::Coverage(stable_mir::mir::Coverage {
196-
kind: coverage.kind.stable(tables),
197-
code_region: coverage.code_region.as_ref().map(|reg| reg.stable(tables)),
198-
}),
194+
Coverage(coverage) => stable_mir::mir::Statement::Coverage(opaque(coverage)),
199195
Intrinsic(intrinstic) => {
200196
stable_mir::mir::Statement::Intrinsic(intrinstic.stable(tables))
201197
}
@@ -496,30 +492,6 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> {
496492
}
497493
}
498494

499-
impl<'tcx> Stable<'tcx> for mir::coverage::CoverageKind {
500-
type T = stable_mir::mir::CoverageKind;
501-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
502-
use rustc_middle::mir::coverage::CoverageKind;
503-
match self {
504-
CoverageKind::Counter { function_source_hash, id } => {
505-
stable_mir::mir::CoverageKind::Counter {
506-
function_source_hash: *function_source_hash as usize,
507-
id: opaque(id),
508-
}
509-
}
510-
CoverageKind::Expression { id, lhs, op, rhs } => {
511-
stable_mir::mir::CoverageKind::Expression {
512-
id: opaque(id),
513-
lhs: opaque(lhs),
514-
op: op.stable(tables),
515-
rhs: opaque(rhs),
516-
}
517-
}
518-
CoverageKind::Unreachable => stable_mir::mir::CoverageKind::Unreachable,
519-
}
520-
}
521-
}
522-
523495
impl<'tcx> Stable<'tcx> for mir::UserTypeProjection {
524496
type T = stable_mir::mir::UserTypeProjection;
525497

@@ -528,18 +500,6 @@ impl<'tcx> Stable<'tcx> for mir::UserTypeProjection {
528500
}
529501
}
530502

531-
impl<'tcx> Stable<'tcx> for mir::coverage::Op {
532-
type T = stable_mir::mir::Op;
533-
534-
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
535-
use rustc_middle::mir::coverage::Op::*;
536-
match self {
537-
Subtract => stable_mir::mir::Op::Subtract,
538-
Add => stable_mir::mir::Op::Add,
539-
}
540-
}
541-
}
542-
543503
impl<'tcx> Stable<'tcx> for mir::Local {
544504
type T = stable_mir::mir::Local;
545505
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
@@ -586,20 +546,6 @@ impl<'tcx> Stable<'tcx> for ty::UserTypeAnnotationIndex {
586546
}
587547
}
588548

589-
impl<'tcx> Stable<'tcx> for CodeRegion {
590-
type T = stable_mir::mir::CodeRegion;
591-
592-
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
593-
stable_mir::mir::CodeRegion {
594-
file_name: self.file_name.as_str().to_string(),
595-
start_line: self.start_line as usize,
596-
start_col: self.start_col as usize,
597-
end_line: self.end_line as usize,
598-
end_col: self.end_col as usize,
599-
}
600-
}
601-
}
602-
603549
impl<'tcx> Stable<'tcx> for mir::UnwindAction {
604550
type T = stable_mir::mir::UnwindAction;
605551
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {

compiler/rustc_smir/src/stable_mir/mir/body.rs

+4-39
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ pub enum AsyncGeneratorKind {
135135
}
136136

137137
pub(crate) type LocalDefId = Opaque;
138-
pub(crate) type CounterValueReference = Opaque;
139-
pub(crate) type InjectedExpressionId = Opaque;
140-
pub(crate) type ExpressionOperandId = Opaque;
138+
/// [`rustc_middle::mir::Coverage`] is heavily tied to internal details of the
139+
/// coverage implementation that are likely to change, and are unlikely to be
140+
/// useful to third-party tools for the foreseeable future.
141+
pub(crate) type Coverage = Opaque;
141142

142143
/// The FakeReadCause describes the type of pattern why a FakeRead statement exists.
143144
#[derive(Clone, Debug)]
@@ -166,42 +167,6 @@ pub enum Variance {
166167
Bivariant,
167168
}
168169

169-
#[derive(Clone, Debug)]
170-
pub enum Op {
171-
Subtract,
172-
Add,
173-
}
174-
175-
#[derive(Clone, Debug)]
176-
pub enum CoverageKind {
177-
Counter {
178-
function_source_hash: usize,
179-
id: CounterValueReference,
180-
},
181-
Expression {
182-
id: InjectedExpressionId,
183-
lhs: ExpressionOperandId,
184-
op: Op,
185-
rhs: ExpressionOperandId,
186-
},
187-
Unreachable,
188-
}
189-
190-
#[derive(Clone, Debug)]
191-
pub struct CodeRegion {
192-
pub file_name: String,
193-
pub start_line: usize,
194-
pub start_col: usize,
195-
pub end_line: usize,
196-
pub end_col: usize,
197-
}
198-
199-
#[derive(Clone, Debug)]
200-
pub struct Coverage {
201-
pub kind: CoverageKind,
202-
pub code_region: Option<CodeRegion>,
203-
}
204-
205170
#[derive(Clone, Debug)]
206171
pub struct CopyNonOverlapping {
207172
pub src: Operand,

0 commit comments

Comments
 (0)