Skip to content

Commit 19fdbc4

Browse files
authored
Unrolled build for rust-lang#131802
Rollup merge of rust-lang#131802 - compiler-errors:fnonce-coverage, r=Zalathar Dont ICE when computing coverage of synthetic async closure body I'm not totally certain if this is *right*, but at least it doesn't ICE. The issue is that we end up generating two MIR bodies for each async closure, since the `FnOnce` and `Fn`/`FnMut` implementations have different borrowing behavior of their captured variables. They should ideally both contribute to the coverage, since those MIR bodies are (*to the user*) the same code and should have no behavioral differences. This PR at least suppresses the ICEs, and then I guess worst case we can fix this the right way later. r? Zalathar or re-roll Fixes rust-lang#131190
2 parents acfdb8d + cdbf28a commit 19fdbc4

File tree

7 files changed

+102
-19
lines changed

7 files changed

+102
-19
lines changed

compiler/rustc_middle/src/query/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ rustc_queries! {
570570
/// either `#[coverage(on)]` or no coverage attribute was found.
571571
query coverage_attr_on(key: LocalDefId) -> bool {
572572
desc { |tcx| "checking for `#[coverage(..)]` on `{}`", tcx.def_path_str(key) }
573+
feedable
573574
}
574575

575576
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
223223

224224
// Inherited from the by-ref coroutine.
225225
body_def.codegen_fn_attrs(tcx.codegen_fn_attrs(coroutine_def_id).clone());
226+
body_def.coverage_attr_on(tcx.coverage_attr_on(coroutine_def_id));
226227
body_def.constness(tcx.constness(coroutine_def_id));
227228
body_def.coroutine_kind(tcx.coroutine_kind(coroutine_def_id));
228229
body_def.def_ident_span(tcx.def_ident_span(coroutine_def_id));

compiler/rustc_mir_transform/src/coverage/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
524524
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
525525
// to HIR for it.
526526

527+
// HACK: For synthetic MIR bodies (async closures), use the def id of the HIR body.
528+
if tcx.is_synthetic_mir(def_id) {
529+
return extract_hir_info(tcx, tcx.local_parent(def_id));
530+
}
531+
527532
let hir_node = tcx.hir_node_by_def_id(def_id);
528533
let fn_body_id = hir_node.body_id().expect("HIR node is a function with body");
529534
let hir_body = tcx.hir().body(fn_body_id);

tests/coverage/async_closure.cov-map

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Function name: async_closure::call_once::<async_closure::main::{closure#0}>
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 07, 01, 00, 2c]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 0
6+
Number of file 0 mappings: 1
7+
- Code(Counter(0)) at (prev + 7, 1) to (start + 0, 44)
8+
Highest counter ID seen: c0
9+
10+
Function name: async_closure::call_once::<async_closure::main::{closure#0}>::{closure#0}
11+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 07, 2c, 01, 0e, 05, 02, 01, 00, 02]
12+
Number of files: 1
13+
- file 0 => global file 1
14+
Number of expressions: 0
15+
Number of file 0 mappings: 2
16+
- Code(Counter(0)) at (prev + 7, 44) to (start + 1, 14)
17+
- Code(Counter(1)) at (prev + 2, 1) to (start + 0, 2)
18+
Highest counter ID seen: c1
19+
20+
Function name: async_closure::main
21+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 0b, 01, 01, 16, 01, 02, 05, 02, 02]
22+
Number of files: 1
23+
- file 0 => global file 1
24+
Number of expressions: 0
25+
Number of file 0 mappings: 2
26+
- Code(Counter(0)) at (prev + 11, 1) to (start + 1, 22)
27+
- Code(Counter(0)) at (prev + 2, 5) to (start + 2, 2)
28+
Highest counter ID seen: c0
29+
30+
Function name: async_closure::main::{closure#0}
31+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0c, 23, 00, 24]
32+
Number of files: 1
33+
- file 0 => global file 1
34+
Number of expressions: 0
35+
Number of file 0 mappings: 1
36+
- Code(Counter(0)) at (prev + 12, 35) to (start + 0, 36)
37+
Highest counter ID seen: c0
38+
39+
Function name: async_closure::main::{closure#0}::{closure#0}::<i16>
40+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0c, 22, 00, 24]
41+
Number of files: 1
42+
- file 0 => global file 1
43+
Number of expressions: 0
44+
Number of file 0 mappings: 1
45+
- Code(Counter(0)) at (prev + 12, 34) to (start + 0, 36)
46+
Highest counter ID seen: c0
47+
48+
Function name: async_closure::main::{closure#0}::{closure#1}::<i32>
49+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0c, 23, 00, 24]
50+
Number of files: 1
51+
- file 0 => global file 1
52+
Number of expressions: 0
53+
Number of file 0 mappings: 1
54+
- Code(Counter(0)) at (prev + 12, 35) to (start + 0, 36)
55+
Highest counter ID seen: c0
56+

tests/coverage/async_closure.coverage

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
LL| |#![feature(async_closure)]
2+
LL| |//@ edition: 2021
3+
LL| |
4+
LL| |//@ aux-build: executor.rs
5+
LL| |extern crate executor;
6+
LL| |
7+
LL| 1|async fn call_once(f: impl async FnOnce()) {
8+
LL| 1| f().await;
9+
LL| 1|}
10+
LL| |
11+
LL| 1|pub fn main() {
12+
LL| 2| let async_closure = async || {};
13+
^1
14+
------------------
15+
| async_closure::main::{closure#0}:
16+
| LL| 1| let async_closure = async || {};
17+
------------------
18+
| async_closure::main::{closure#0}::{closure#1}::<i32>:
19+
| LL| 1| let async_closure = async || {};
20+
------------------
21+
LL| 1| executor::block_on(async_closure());
22+
LL| 1| executor::block_on(call_once(async_closure));
23+
LL| 1|}
24+

tests/coverage/async_closure.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(async_closure)]
2+
//@ edition: 2021
3+
4+
//@ aux-build: executor.rs
5+
extern crate executor;
6+
7+
async fn call_once(f: impl async FnOnce()) {
8+
f().await;
9+
}
10+
11+
pub fn main() {
12+
let async_closure = async || {};
13+
executor::block_on(async_closure());
14+
executor::block_on(call_once(async_closure));
15+
}

tests/crashes/131190.rs

-19
This file was deleted.

0 commit comments

Comments
 (0)