Skip to content

Commit aed8ef5

Browse files
committed
coverageinfo query needs to use the same MIR as codegen
I ran into an error trying to fix dead block coverage and realized the `coverageinfo` query is getting a different MIR compared to the codegenned MIR, which can sometimes be a problem during mapgen. I changed that query to use the `InstandeDef` (which includes the generic parameter substitutions, prosibly specific to const params) instead of the `DefId` (without unknown/default const substitutions).
1 parent 31f523f commit aed8ef5

File tree

5 files changed

+8
-19
lines changed

5 files changed

+8
-19
lines changed

compiler/rustc_codegen_ssa/src/coverageinfo/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ impl<'tcx> FunctionCoverage<'tcx> {
4949
}
5050

5151
fn create(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, is_used: bool) -> Self {
52-
let coverageinfo = tcx.coverageinfo(instance.def_id());
52+
let coverageinfo = tcx.coverageinfo(instance.def);
5353
debug!(
54-
"FunctionCoverage::new(instance={:?}) has coverageinfo={:?}. is_used={}",
54+
"FunctionCoverage::create(instance={:?}) has coverageinfo={:?}. is_used={}",
5555
instance, coverageinfo, is_used
5656
);
5757
Self {

compiler/rustc_codegen_ssa/src/mir/coverageinfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3131
bx.add_coverage_counter(instance, id, code_region);
3232
}
3333

34-
let coverageinfo = bx.tcx().coverageinfo(instance.def_id());
34+
let coverageinfo = bx.tcx().coverageinfo(instance.def);
3535

3636
let fn_name = bx.get_pgo_func_name_var(instance);
3737
let hash = bx.const_u64(function_source_hash);

compiler/rustc_middle/src/query/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,9 @@ rustc_queries! {
335335

336336
/// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
337337
/// MIR pass (assuming the -Zinstrument-coverage option is enabled).
338-
query coverageinfo(key: DefId) -> mir::CoverageInfo {
339-
desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key) }
338+
query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
339+
desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
340340
storage(ArenaCacheSelector<'tcx>)
341-
cache_on_disk_if { key.is_local() }
342341
}
343342

344343
/// Returns the name of the file that contains the function body, if instrumented for coverage.

compiler/rustc_mir/src/transform/coverage/mod.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,6 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
156156
let fn_sig_span = self.fn_sig_span;
157157
let body_span = self.body_span;
158158

159-
<<<<<<< HEAD
160-
debug!(
161-
"instrumenting {:?}, fn sig span: {}, body span: {}",
162-
def_id,
163-
source_map.span_to_diagnostic_string(fn_sig_span),
164-
source_map.span_to_diagnostic_string(body_span)
165-
);
166-
167-
=======
168-
>>>>>>> 476104d0f54 (Simplified body_span and filtered span code)
169159
let mut graphviz_data = debug::GraphvizData::new();
170160
let mut debug_used_expressions = debug::UsedExpressions::new();
171161

@@ -572,7 +562,7 @@ fn get_body_span<'tcx>(
572562
if expn_data.is_root() {
573563
break;
574564
}
575-
if let ExpnKind::Macro{..} = expn_data.kind {
565+
if let ExpnKind::Macro { .. } = expn_data.kind {
576566
body_span = expn_data.call_site;
577567
} else {
578568
break;

compiler/rustc_mir/src/transform/coverage/query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ impl CoverageVisitor {
120120
}
121121
}
122122

123-
fn coverageinfo<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> CoverageInfo {
124-
let mir_body = mir_body(tcx, def_id);
123+
fn coverageinfo<'tcx>(tcx: TyCtxt<'tcx>, instance_def: ty::InstanceDef<'tcx>) -> CoverageInfo {
124+
let mir_body = tcx.instance_mir(instance_def);
125125

126126
let mut coverage_visitor = CoverageVisitor {
127127
// num_counters always has at least the `ZERO` counter.

0 commit comments

Comments
 (0)