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).
This commit is contained in:
Rich Kadel 2021-05-11 20:56:23 -07:00
parent 31f523ff94
commit aed8ef5a4d
5 changed files with 8 additions and 19 deletions

View File

@ -49,9 +49,9 @@ pub fn unused(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self {
} }
fn create(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, is_used: bool) -> Self { fn create(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, is_used: bool) -> Self {
let coverageinfo = tcx.coverageinfo(instance.def_id()); let coverageinfo = tcx.coverageinfo(instance.def);
debug!( debug!(
"FunctionCoverage::new(instance={:?}) has coverageinfo={:?}. is_used={}", "FunctionCoverage::create(instance={:?}) has coverageinfo={:?}. is_used={}",
instance, coverageinfo, is_used instance, coverageinfo, is_used
); );
Self { Self {

View File

@ -31,7 +31,7 @@ pub fn codegen_coverage(&self, bx: &mut Bx, coverage: Coverage, scope: SourceSco
bx.add_coverage_counter(instance, id, code_region); bx.add_coverage_counter(instance, id, code_region);
} }
let coverageinfo = bx.tcx().coverageinfo(instance.def_id()); let coverageinfo = bx.tcx().coverageinfo(instance.def);
let fn_name = bx.get_pgo_func_name_var(instance); let fn_name = bx.get_pgo_func_name_var(instance);
let hash = bx.const_u64(function_source_hash); let hash = bx.const_u64(function_source_hash);

View File

@ -335,10 +335,9 @@
/// Returns coverage summary info for a function, after executing the `InstrumentCoverage` /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
/// MIR pass (assuming the -Zinstrument-coverage option is enabled). /// MIR pass (assuming the -Zinstrument-coverage option is enabled).
query coverageinfo(key: DefId) -> mir::CoverageInfo { query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key) } desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
cache_on_disk_if { key.is_local() }
} }
/// Returns the name of the file that contains the function body, if instrumented for coverage. /// Returns the name of the file that contains the function body, if instrumented for coverage.

View File

@ -156,16 +156,6 @@ fn inject_counters(&'a mut self) {
let fn_sig_span = self.fn_sig_span; let fn_sig_span = self.fn_sig_span;
let body_span = self.body_span; let body_span = self.body_span;
<<<<<<< HEAD
debug!(
"instrumenting {:?}, fn sig span: {}, body span: {}",
def_id,
source_map.span_to_diagnostic_string(fn_sig_span),
source_map.span_to_diagnostic_string(body_span)
);
=======
>>>>>>> 476104d0f54 (Simplified body_span and filtered span code)
let mut graphviz_data = debug::GraphvizData::new(); let mut graphviz_data = debug::GraphvizData::new();
let mut debug_used_expressions = debug::UsedExpressions::new(); let mut debug_used_expressions = debug::UsedExpressions::new();
@ -572,7 +562,7 @@ fn get_body_span<'tcx>(
if expn_data.is_root() { if expn_data.is_root() {
break; break;
} }
if let ExpnKind::Macro{..} = expn_data.kind { if let ExpnKind::Macro { .. } = expn_data.kind {
body_span = expn_data.call_site; body_span = expn_data.call_site;
} else { } else {
break; break;

View File

@ -120,8 +120,8 @@ fn visit_coverage(&mut self, coverage: &Coverage) {
} }
} }
fn coverageinfo<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> CoverageInfo { fn coverageinfo<'tcx>(tcx: TyCtxt<'tcx>, instance_def: ty::InstanceDef<'tcx>) -> CoverageInfo {
let mir_body = mir_body(tcx, def_id); let mir_body = tcx.instance_mir(instance_def);
let mut coverage_visitor = CoverageVisitor { let mut coverage_visitor = CoverageVisitor {
// num_counters always has at least the `ZERO` counter. // num_counters always has at least the `ZERO` counter.