Skip to content

Commit b9a6f19

Browse files
authored
Rollup merge of #118969 - Zalathar:waker-noop, r=compiler-errors
coverage: Use `Waker::noop` in async tests Inspired by #118948. --- `@rustbot` label +A-code-coverage
2 parents 2f8867e + 5764ccc commit b9a6f19

9 files changed

+135
-354
lines changed

tests/coverage/async.cov-map

+50-102
Large diffs are not rendered by default.

tests/coverage/async.coverage

+17-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |#![feature(noop_waker)]
13
LL| |#![allow(unused_assignments, dead_code)]
2-
LL| |
3-
LL| |// compile-flags: --edition=2018 -C opt-level=1
4+
LL| |// edition: 2018
5+
LL| |// compile-flags: -Copt-level=1
46
LL| |
57
LL| 1|async fn c(x: u8) -> u8 {
68
LL| 1| if x == 8 {
@@ -108,32 +110,21 @@
108110
LL| 1|}
109111
LL| |
110112
LL| |mod executor {
111-
LL| | use core::{
112-
LL| | future::Future,
113-
LL| | pin::Pin,
114-
LL| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
115-
LL| | };
116-
LL| |
117-
LL| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output {
118-
LL| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) };
119-
LL| 1| use std::hint::unreachable_unchecked;
120-
LL| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new(
121-
LL| 1| |_| unsafe { unreachable_unchecked() }, // clone
122-
^0
123-
LL| 1| |_| unsafe { unreachable_unchecked() }, // wake
124-
^0
125-
LL| 1| |_| unsafe { unreachable_unchecked() }, // wake_by_ref
126-
^0
127-
LL| 1| |_| (),
128-
LL| 1| );
129-
LL| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
130-
LL| 1| let mut context = Context::from_waker(&waker);
113+
LL| | use core::future::Future;
114+
LL| | use core::pin::pin;
115+
LL| | use core::task::{Context, Poll, Waker};
116+
LL| |
117+
LL| | #[coverage(off)]
118+
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
119+
LL| | let mut future = pin!(future);
120+
LL| | let waker = Waker::noop();
121+
LL| | let mut context = Context::from_waker(&waker);
131122
LL| |
132123
LL| | loop {
133-
LL| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
134-
LL| 1| break val;
135-
LL| 0| }
124+
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
125+
LL| | break val;
126+
LL| | }
136127
LL| | }
137-
LL| 1| }
128+
LL| | }
138129
LL| |}
139130

tests/coverage/async.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
#![feature(coverage_attribute)]
2+
#![feature(noop_waker)]
13
#![allow(unused_assignments, dead_code)]
2-
3-
// compile-flags: --edition=2018 -C opt-level=1
4+
// edition: 2018
5+
// compile-flags: -Copt-level=1
46

57
async fn c(x: u8) -> u8 {
68
if x == 8 {
@@ -101,22 +103,14 @@ fn main() {
101103
}
102104

103105
mod executor {
104-
use core::{
105-
future::Future,
106-
pin::Pin,
107-
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
108-
};
106+
use core::future::Future;
107+
use core::pin::pin;
108+
use core::task::{Context, Poll, Waker};
109109

110+
#[coverage(off)]
110111
pub fn block_on<F: Future>(mut future: F) -> F::Output {
111-
let mut future = unsafe { Pin::new_unchecked(&mut future) };
112-
use std::hint::unreachable_unchecked;
113-
static VTABLE: RawWakerVTable = RawWakerVTable::new(
114-
|_| unsafe { unreachable_unchecked() }, // clone
115-
|_| unsafe { unreachable_unchecked() }, // wake
116-
|_| unsafe { unreachable_unchecked() }, // wake_by_ref
117-
|_| (),
118-
);
119-
let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
112+
let mut future = pin!(future);
113+
let waker = Waker::noop();
120114
let mut context = Context::from_waker(&waker);
121115

122116
loop {

tests/coverage/async2.cov-map

+12-84
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,58 @@
11
Function name: async2::async_func
2-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0b, 01, 00, 17]
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0d, 01, 00, 17]
33
Number of files: 1
44
- file 0 => global file 1
55
Number of expressions: 0
66
Number of file 0 mappings: 1
7-
- Code(Counter(0)) at (prev + 11, 1) to (start + 0, 23)
7+
- Code(Counter(0)) at (prev + 13, 1) to (start + 0, 23)
88

99
Function name: async2::async_func::{closure#0}
10-
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 0b, 17, 03, 09, 05, 03, 0a, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02]
10+
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 0d, 17, 03, 09, 05, 03, 0a, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02]
1111
Number of files: 1
1212
- file 0 => global file 1
1313
Number of expressions: 2
1414
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
1515
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
1616
Number of file 0 mappings: 4
17-
- Code(Counter(0)) at (prev + 11, 23) to (start + 3, 9)
17+
- Code(Counter(0)) at (prev + 13, 23) to (start + 3, 9)
1818
- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6)
1919
- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7)
2020
= (c0 - c1)
2121
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
2222
= (c1 + (c0 - c1))
2323

2424
Function name: async2::async_func_just_println
25-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 01, 00, 24]
25+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 15, 01, 00, 24]
2626
Number of files: 1
2727
- file 0 => global file 1
2828
Number of expressions: 0
2929
Number of file 0 mappings: 1
30-
- Code(Counter(0)) at (prev + 19, 1) to (start + 0, 36)
30+
- Code(Counter(0)) at (prev + 21, 1) to (start + 0, 36)
3131

3232
Function name: async2::async_func_just_println::{closure#0}
33-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 24, 02, 02]
33+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 15, 24, 02, 02]
3434
Number of files: 1
3535
- file 0 => global file 1
3636
Number of expressions: 0
3737
Number of file 0 mappings: 1
38-
- Code(Counter(0)) at (prev + 19, 36) to (start + 2, 2)
39-
40-
Function name: async2::executor::block_on::<async2::async_func::{closure#0}>
41-
Raw bytes (40): 0x[01, 01, 03, 0b, 05, 01, 05, 01, 05, 06, 01, 27, 05, 0a, 36, 02, 0d, 20, 00, 23, 0b, 00, 27, 00, 49, 02, 01, 17, 00, 1a, 05, 01, 0e, 00, 0f, 02, 02, 05, 00, 06]
42-
Number of files: 1
43-
- file 0 => global file 1
44-
Number of expressions: 3
45-
- expression 0 operands: lhs = Expression(2, Add), rhs = Counter(1)
46-
- expression 1 operands: lhs = Counter(0), rhs = Counter(1)
47-
- expression 2 operands: lhs = Counter(0), rhs = Counter(1)
48-
Number of file 0 mappings: 6
49-
- Code(Counter(0)) at (prev + 39, 5) to (start + 10, 54)
50-
- Code(Expression(0, Sub)) at (prev + 13, 32) to (start + 0, 35)
51-
= ((c0 + c1) - c1)
52-
- Code(Expression(2, Add)) at (prev + 0, 39) to (start + 0, 73)
53-
= (c0 + c1)
54-
- Code(Expression(0, Sub)) at (prev + 1, 23) to (start + 0, 26)
55-
= ((c0 + c1) - c1)
56-
- Code(Counter(1)) at (prev + 1, 14) to (start + 0, 15)
57-
- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 0, 6)
58-
= ((c0 + c1) - c1)
59-
60-
Function name: async2::executor::block_on::<async2::async_func_just_println::{closure#0}>
61-
Raw bytes (40): 0x[01, 01, 03, 0b, 05, 01, 05, 01, 05, 06, 01, 27, 05, 0a, 36, 02, 0d, 20, 00, 23, 0b, 00, 27, 00, 49, 02, 01, 17, 00, 1a, 05, 01, 0e, 00, 0f, 02, 02, 05, 00, 06]
62-
Number of files: 1
63-
- file 0 => global file 1
64-
Number of expressions: 3
65-
- expression 0 operands: lhs = Expression(2, Add), rhs = Counter(1)
66-
- expression 1 operands: lhs = Counter(0), rhs = Counter(1)
67-
- expression 2 operands: lhs = Counter(0), rhs = Counter(1)
68-
Number of file 0 mappings: 6
69-
- Code(Counter(0)) at (prev + 39, 5) to (start + 10, 54)
70-
- Code(Expression(0, Sub)) at (prev + 13, 32) to (start + 0, 35)
71-
= ((c0 + c1) - c1)
72-
- Code(Expression(2, Add)) at (prev + 0, 39) to (start + 0, 73)
73-
= (c0 + c1)
74-
- Code(Expression(0, Sub)) at (prev + 1, 23) to (start + 0, 26)
75-
= ((c0 + c1) - c1)
76-
- Code(Counter(1)) at (prev + 1, 14) to (start + 0, 15)
77-
- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 0, 6)
78-
= ((c0 + c1) - c1)
79-
80-
Function name: async2::executor::block_on::VTABLE::{closure#0}
81-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2b, 11, 00, 31]
82-
Number of files: 1
83-
- file 0 => global file 1
84-
Number of expressions: 0
85-
Number of file 0 mappings: 1
86-
- Code(Counter(0)) at (prev + 43, 17) to (start + 0, 49)
87-
88-
Function name: async2::executor::block_on::VTABLE::{closure#1}
89-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2c, 11, 00, 31]
90-
Number of files: 1
91-
- file 0 => global file 1
92-
Number of expressions: 0
93-
Number of file 0 mappings: 1
94-
- Code(Counter(0)) at (prev + 44, 17) to (start + 0, 49)
95-
96-
Function name: async2::executor::block_on::VTABLE::{closure#2}
97-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2d, 11, 00, 31]
98-
Number of files: 1
99-
- file 0 => global file 1
100-
Number of expressions: 0
101-
Number of file 0 mappings: 1
102-
- Code(Counter(0)) at (prev + 45, 17) to (start + 0, 49)
103-
104-
Function name: async2::executor::block_on::VTABLE::{closure#3}
105-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2e, 11, 00, 13]
106-
Number of files: 1
107-
- file 0 => global file 1
108-
Number of expressions: 0
109-
Number of file 0 mappings: 1
110-
- Code(Counter(0)) at (prev + 46, 17) to (start + 0, 19)
38+
- Code(Counter(0)) at (prev + 21, 36) to (start + 2, 2)
11139

11240
Function name: async2::main
113-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 17, 01, 07, 02]
41+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 19, 01, 07, 02]
11442
Number of files: 1
11543
- file 0 => global file 1
11644
Number of expressions: 0
11745
Number of file 0 mappings: 1
118-
- Code(Counter(0)) at (prev + 23, 1) to (start + 7, 2)
46+
- Code(Counter(0)) at (prev + 25, 1) to (start + 7, 2)
11947

12048
Function name: async2::non_async_func
121-
Raw bytes (26): 0x[01, 01, 01, 05, 00, 04, 01, 03, 01, 03, 09, 05, 03, 0a, 02, 06, 00, 02, 06, 00, 07, 03, 01, 01, 00, 02]
49+
Raw bytes (26): 0x[01, 01, 01, 05, 00, 04, 01, 05, 01, 03, 09, 05, 03, 0a, 02, 06, 00, 02, 06, 00, 07, 03, 01, 01, 00, 02]
12250
Number of files: 1
12351
- file 0 => global file 1
12452
Number of expressions: 1
12553
- expression 0 operands: lhs = Counter(1), rhs = Zero
12654
Number of file 0 mappings: 4
127-
- Code(Counter(0)) at (prev + 3, 1) to (start + 3, 9)
55+
- Code(Counter(0)) at (prev + 5, 1) to (start + 3, 9)
12856
- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6)
12957
- Code(Zero) at (prev + 2, 6) to (start + 0, 7)
13058
- Code(Expression(0, Add)) at (prev + 1, 1) to (start + 0, 2)

tests/coverage/async2.coverage

+15-65
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
LL| |// compile-flags: --edition=2018
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |#![feature(noop_waker)]
3+
LL| |// edition: 2018
24
LL| |
35
LL| 1|fn non_async_func() {
46
LL| 1| println!("non_async_func was covered");
@@ -32,73 +34,21 @@
3234
LL| 1|}
3335
LL| |
3436
LL| |mod executor {
35-
LL| | use core::{
36-
LL| | future::Future,
37-
LL| | pin::Pin,
38-
LL| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
39-
LL| | };
37+
LL| | use core::future::Future;
38+
LL| | use core::pin::pin;
39+
LL| | use core::task::{Context, Poll, Waker};
4040
LL| |
41-
LL| 2| pub fn block_on<F: Future>(mut future: F) -> F::Output {
42-
LL| 2| let mut future = unsafe { Pin::new_unchecked(&mut future) };
43-
LL| 2| use std::hint::unreachable_unchecked;
44-
LL| 2| static VTABLE: RawWakerVTable = RawWakerVTable::new(
45-
LL| 2| |_| unsafe { unreachable_unchecked() }, // clone
46-
^0
47-
LL| 2| |_| unsafe { unreachable_unchecked() }, // wake
48-
^0
49-
LL| 2| |_| unsafe { unreachable_unchecked() }, // wake_by_ref
50-
^0
51-
LL| 2| |_| (),
52-
LL| 2| );
53-
LL| 2| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
54-
LL| 2| let mut context = Context::from_waker(&waker);
41+
LL| | #[coverage(off)]
42+
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
43+
LL| | let mut future = pin!(future);
44+
LL| | let waker = Waker::noop();
45+
LL| | let mut context = Context::from_waker(&waker);
5546
LL| |
5647
LL| | loop {
57-
LL| 2| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
58-
LL| 2| break val;
59-
LL| 0| }
48+
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
49+
LL| | break val;
50+
LL| | }
6051
LL| | }
61-
LL| 2| }
62-
------------------
63-
| async2::executor::block_on::<async2::async_func::{closure#0}>:
64-
| LL| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output {
65-
| LL| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) };
66-
| LL| 1| use std::hint::unreachable_unchecked;
67-
| LL| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new(
68-
| LL| 1| |_| unsafe { unreachable_unchecked() }, // clone
69-
| LL| 1| |_| unsafe { unreachable_unchecked() }, // wake
70-
| LL| 1| |_| unsafe { unreachable_unchecked() }, // wake_by_ref
71-
| LL| 1| |_| (),
72-
| LL| 1| );
73-
| LL| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
74-
| LL| 1| let mut context = Context::from_waker(&waker);
75-
| LL| |
76-
| LL| | loop {
77-
| LL| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
78-
| LL| 1| break val;
79-
| LL| 0| }
80-
| LL| | }
81-
| LL| 1| }
82-
------------------
83-
| async2::executor::block_on::<async2::async_func_just_println::{closure#0}>:
84-
| LL| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output {
85-
| LL| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) };
86-
| LL| 1| use std::hint::unreachable_unchecked;
87-
| LL| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new(
88-
| LL| 1| |_| unsafe { unreachable_unchecked() }, // clone
89-
| LL| 1| |_| unsafe { unreachable_unchecked() }, // wake
90-
| LL| 1| |_| unsafe { unreachable_unchecked() }, // wake_by_ref
91-
| LL| 1| |_| (),
92-
| LL| 1| );
93-
| LL| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
94-
| LL| 1| let mut context = Context::from_waker(&waker);
95-
| LL| |
96-
| LL| | loop {
97-
| LL| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
98-
| LL| 1| break val;
99-
| LL| 0| }
100-
| LL| | }
101-
| LL| 1| }
102-
------------------
52+
LL| | }
10353
LL| |}
10454

tests/coverage/async2.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// compile-flags: --edition=2018
1+
#![feature(coverage_attribute)]
2+
#![feature(noop_waker)]
3+
// edition: 2018
24

35
fn non_async_func() {
46
println!("non_async_func was covered");
@@ -30,22 +32,14 @@ fn main() {
3032
}
3133

3234
mod executor {
33-
use core::{
34-
future::Future,
35-
pin::Pin,
36-
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
37-
};
35+
use core::future::Future;
36+
use core::pin::pin;
37+
use core::task::{Context, Poll, Waker};
3838

39+
#[coverage(off)]
3940
pub fn block_on<F: Future>(mut future: F) -> F::Output {
40-
let mut future = unsafe { Pin::new_unchecked(&mut future) };
41-
use std::hint::unreachable_unchecked;
42-
static VTABLE: RawWakerVTable = RawWakerVTable::new(
43-
|_| unsafe { unreachable_unchecked() }, // clone
44-
|_| unsafe { unreachable_unchecked() }, // wake
45-
|_| unsafe { unreachable_unchecked() }, // wake_by_ref
46-
|_| (),
47-
);
48-
let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
41+
let mut future = pin!(future);
42+
let waker = Waker::noop();
4943
let mut context = Context::from_waker(&waker);
5044

5145
loop {

0 commit comments

Comments
 (0)