@@ -220,7 +220,7 @@ impl GotocCtx<'_> {
220220pub mod rustc_smir {
221221 use crate :: codegen_cprover_gotoc:: codegen:: source_region:: { SourceRegion , make_source_region} ;
222222 use crate :: stable_mir:: CrateDef ;
223- use rustc_middle:: mir:: coverage:: CovTerm ;
223+ use rustc_middle:: mir:: coverage:: BasicCoverageBlock ;
224224 use rustc_middle:: mir:: coverage:: MappingKind :: Code ;
225225 use rustc_middle:: ty:: TyCtxt ;
226226 use rustc_smir:: rustc_internal;
@@ -236,16 +236,16 @@ pub mod rustc_smir {
236236 coverage_opaque : & CoverageOpaque ,
237237 instance : Instance ,
238238 ) -> Option < ( SourceRegion , Filename ) > {
239- let cov_term = parse_coverage_opaque ( coverage_opaque) ;
240- region_from_coverage ( tcx, cov_term , instance)
239+ let bcb = parse_coverage_opaque ( coverage_opaque) ;
240+ region_from_coverage ( tcx, bcb , instance)
241241 }
242242
243- /// Retrieves the `SourceRegion` associated with a `CovTerm ` object.
243+ /// Retrieves the `SourceRegion` associated with a `BasicCoverageBlock ` object.
244244 ///
245245 /// Note: This function could be in the internal `rustc` impl for `Coverage`.
246246 pub fn region_from_coverage (
247247 tcx : TyCtxt < ' _ > ,
248- coverage : CovTerm ,
248+ coverage : BasicCoverageBlock ,
249249 instance : Instance ,
250250 ) -> Option < ( SourceRegion , Filename ) > {
251251 // We need to pull the coverage info from the internal MIR instance.
@@ -257,10 +257,10 @@ pub mod rustc_smir {
257257 if let Some ( cov_info) = & body. function_coverage_info {
258258 // Iterate over the coverage mappings and match with the coverage term.
259259 for mapping in & cov_info. mappings {
260- let Code ( term ) = mapping. kind else { unreachable ! ( ) } ;
260+ let Code { bcb } = mapping. kind else { unreachable ! ( ) } ;
261261 let source_map = tcx. sess . source_map ( ) ;
262262 let file = source_map. lookup_source_file ( cov_info. body_span . lo ( ) ) ;
263- if term == coverage {
263+ if bcb == coverage {
264264 return Some ( (
265265 make_source_region ( source_map, cov_info, & file, mapping. span ) . unwrap ( ) ,
266266 rustc_internal:: stable ( cov_info. body_span ) . get_filename ( ) ,
@@ -271,25 +271,17 @@ pub mod rustc_smir {
271271 None
272272 }
273273
274- /// Parse a `CoverageOpaque` item and return the corresponding `CovTerm`:
275- /// <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/coverage/enum.CovTerm.html>
276- ///
277- /// At present, a `CovTerm` can be one of the following:
278- /// - `CounterIncrement(<num>)`: A physical counter.
279- /// - `ExpressionUsed(<num>)`: An expression-based counter.
280- /// - `Zero`: A counter with a constant zero value.
281- fn parse_coverage_opaque ( coverage_opaque : & Opaque ) -> CovTerm {
274+ /// Parse a `CoverageOpaque` item and return the corresponding `BasicCoverageBlock`:
275+ fn parse_coverage_opaque ( coverage_opaque : & Opaque ) -> BasicCoverageBlock {
282276 let coverage_str = coverage_opaque. to_string ( ) ;
283- if let Some ( rest) = coverage_str. strip_prefix ( "CounterIncrement(" ) {
284- let ( num_str, _rest) = rest. split_once ( ')' ) . unwrap ( ) ;
285- let num = num_str. parse :: < u32 > ( ) . unwrap ( ) ;
286- CovTerm :: Counter ( num. into ( ) )
287- } else if let Some ( rest) = coverage_str. strip_prefix ( "ExpressionUsed(" ) {
277+ if let Some ( rest) = coverage_str. strip_prefix ( "VirtualCounter(bcb" ) {
288278 let ( num_str, _rest) = rest. split_once ( ')' ) . unwrap ( ) ;
289279 let num = num_str. parse :: < u32 > ( ) . unwrap ( ) ;
290- CovTerm :: Expression ( num. into ( ) )
280+ BasicCoverageBlock :: from_u32 ( num)
291281 } else {
292- CovTerm :: Zero
282+ // When the coverage statement is injected into mir_body, it always has the form CoverageKind::VirtualCounter { bcb }
283+ // https://github.com/rust-lang/rust/pull/136053/files#diff-c99ec9a281dce4a381fa7e11cf2d04f55dba5573d1d14389d47929fe0a154d24R209-R212
284+ unreachable ! ( ) ;
293285 }
294286 }
295287}
0 commit comments