Skip to content

Commit 129db82

Browse files
committed
Remove the poll_list workarounds that are no longer needed.
1 parent 461e45c commit 129db82

File tree

5 files changed

+22
-318
lines changed

5 files changed

+22
-318
lines changed

crates/test-programs/command-tests/src/bin/stream_pollable_lifetimes.rs

+2-75
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ fn main() {
99
if args == &["correct"] {
1010
let stdin: streams::InputStream = stdin::get_stdin();
1111
let stdin_pollable = stdin.subscribe();
12-
let ready = poll_list(&[&stdin_pollable]);
12+
let ready = poll::poll_list(&[&stdin_pollable]);
1313
assert_eq!(ready, &[0]);
1414
drop(stdin_pollable);
1515
drop(stdin);
1616
} else if args == &["trap"] {
1717
let stdin: streams::InputStream = stdin::get_stdin();
1818
let stdin_pollable = stdin.subscribe();
19-
let ready = poll_list(&[&stdin_pollable]);
19+
let ready = poll::poll_list(&[&stdin_pollable]);
2020
assert_eq!(ready, &[0]);
2121
drop(stdin);
2222
unreachable!(
@@ -26,76 +26,3 @@ fn main() {
2626
panic!("bad value for args: expected `[\"correct\"]` or `[\"trap\"]`, got {args:?}")
2727
}
2828
}
29-
30-
/// FIXME: This is a copy of the `poll_list` bindings generated with a
31-
/// wit-bindgen with this fix:
32-
/// <https://github.com/bytecodealliance/wit-bindgen/pull/670>
33-
///
34-
/// One that PR is in a published release, delete this code and use the
35-
/// bindings.
36-
///
37-
/// Poll for completion on a set of pollables.
38-
///
39-
/// This function takes a list of pollables, which identify I/O sources of
40-
/// interest, and waits until one or more of the events is ready for I/O.
41-
///
42-
/// The result `list<u32>` contains one or more indices of handles in the
43-
/// argument list that is ready for I/O.
44-
///
45-
/// If the list contains more elements than can be indexed with a `u32`
46-
/// value, this function traps.
47-
///
48-
/// A timeout can be implemented by adding a pollable from the
49-
/// wasi-clocks API to the list.
50-
///
51-
/// This function does not return a `result`; polling in itself does not
52-
/// do any I/O so it doesn't fail. If any of the I/O sources identified by
53-
/// the pollables has an error, it is indicated by marking the source as
54-
/// being reaedy for I/O.
55-
pub fn poll_list(in_: &[&poll::Pollable]) -> wit_bindgen::rt::vec::Vec<u32> {
56-
#[allow(unused_imports)]
57-
use wit_bindgen::rt::{alloc, string::String, vec::Vec};
58-
unsafe {
59-
#[repr(align(4))]
60-
struct RetArea([u8; 8]);
61-
let mut ret_area = ::core::mem::MaybeUninit::<RetArea>::uninit();
62-
let vec0 = in_;
63-
let len0 = vec0.len() as i32;
64-
let layout0 = alloc::Layout::from_size_align_unchecked(vec0.len() * 4, 4);
65-
let result0 = if layout0.size() != 0 {
66-
let ptr = alloc::alloc(layout0);
67-
if ptr.is_null() {
68-
alloc::handle_alloc_error(layout0);
69-
}
70-
ptr
71-
} else {
72-
::core::ptr::null_mut()
73-
};
74-
for (i, e) in vec0.into_iter().enumerate() {
75-
let base = result0 as i32 + (i as i32) * 4;
76-
{
77-
*((base + 0) as *mut i32) = (e).handle() as i32;
78-
}
79-
}
80-
let ptr1 = ret_area.as_mut_ptr() as i32;
81-
#[cfg(target_arch = "wasm32")]
82-
#[link(wasm_import_module = "wasi:io/poll")]
83-
extern "C" {
84-
#[link_name = "poll-list"]
85-
fn wit_import(_: i32, _: i32, _: i32);
86-
}
87-
88-
#[cfg(not(target_arch = "wasm32"))]
89-
fn wit_import(_: i32, _: i32, _: i32) {
90-
unreachable!()
91-
}
92-
wit_import(result0 as i32, len0, ptr1);
93-
let l2 = *((ptr1 + 0) as *const i32);
94-
let l3 = *((ptr1 + 4) as *const i32);
95-
let len4 = l3 as usize;
96-
if layout0.size() != 0 {
97-
alloc::dealloc(result0, layout0);
98-
}
99-
Vec::from_raw_parts(l2 as *mut _, len4, len4)
100-
}
101-
}

crates/test-programs/reactor-tests/src/lib.rs

+2-75
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Guest for T {
3434
for s in STATE.iter() {
3535
let mut out = s.as_bytes();
3636
while !out.is_empty() {
37-
crate::poll_list(&[&pollable]);
37+
poll::poll_list(&[&pollable]);
3838
let n = match o.check_write() {
3939
Ok(n) => n,
4040
Err(_) => return Err(()),
@@ -53,7 +53,7 @@ impl Guest for T {
5353
Err(_) => return Err(()),
5454
}
5555

56-
crate::poll_list(&[&pollable]);
56+
poll::poll_list(&[&pollable]);
5757
match o.check_write() {
5858
Ok(_) => {}
5959
Err(_) => return Err(()),
@@ -66,76 +66,3 @@ impl Guest for T {
6666
format!("{stat:?}")
6767
}
6868
}
69-
70-
/// FIXME: This is a copy of the `poll_list` bindings generated with a
71-
/// wit-bindgen with this fix:
72-
/// <https://github.com/bytecodealliance/wit-bindgen/pull/670>
73-
///
74-
/// One that PR is in a published release, delete this code and use the
75-
/// bindings.
76-
///
77-
/// Poll for completion on a set of pollables.
78-
///
79-
/// This function takes a list of pollables, which identify I/O sources of
80-
/// interest, and waits until one or more of the events is ready for I/O.
81-
///
82-
/// The result `list<u32>` contains one or more indices of handles in the
83-
/// argument list that is ready for I/O.
84-
///
85-
/// If the list contains more elements than can be indexed with a `u32`
86-
/// value, this function traps.
87-
///
88-
/// A timeout can be implemented by adding a pollable from the
89-
/// wasi-clocks API to the list.
90-
///
91-
/// This function does not return a `result`; polling in itself does not
92-
/// do any I/O so it doesn't fail. If any of the I/O sources identified by
93-
/// the pollables has an error, it is indicated by marking the source as
94-
/// being reaedy for I/O.
95-
pub fn poll_list(in_: &[&poll::Pollable]) -> wit_bindgen::rt::vec::Vec<u32> {
96-
#[allow(unused_imports)]
97-
use wit_bindgen::rt::{alloc, string::String, vec::Vec};
98-
unsafe {
99-
#[repr(align(4))]
100-
struct RetArea([u8; 8]);
101-
let mut ret_area = ::core::mem::MaybeUninit::<RetArea>::uninit();
102-
let vec0 = in_;
103-
let len0 = vec0.len() as i32;
104-
let layout0 = alloc::Layout::from_size_align_unchecked(vec0.len() * 4, 4);
105-
let result0 = if layout0.size() != 0 {
106-
let ptr = alloc::alloc(layout0);
107-
if ptr.is_null() {
108-
alloc::handle_alloc_error(layout0);
109-
}
110-
ptr
111-
} else {
112-
::core::ptr::null_mut()
113-
};
114-
for (i, e) in vec0.into_iter().enumerate() {
115-
let base = result0 as i32 + (i as i32) * 4;
116-
{
117-
*((base + 0) as *mut i32) = (e).handle() as i32;
118-
}
119-
}
120-
let ptr1 = ret_area.as_mut_ptr() as i32;
121-
#[cfg(target_arch = "wasm32")]
122-
#[link(wasm_import_module = "wasi:io/poll")]
123-
extern "C" {
124-
#[link_name = "poll-list"]
125-
fn wit_import(_: i32, _: i32, _: i32);
126-
}
127-
128-
#[cfg(not(target_arch = "wasm32"))]
129-
fn wit_import(_: i32, _: i32, _: i32) {
130-
unreachable!()
131-
}
132-
wit_import(result0 as i32, len0, ptr1);
133-
let l2 = *((ptr1 + 0) as *const i32);
134-
let l3 = *((ptr1 + 4) as *const i32);
135-
let len4 = l3 as usize;
136-
if layout0.size() != 0 {
137-
alloc::dealloc(result0, layout0);
138-
}
139-
Vec::from_raw_parts(l2 as *mut _, len4, len4)
140-
}
141-
}

crates/test-programs/wasi-http-tests/src/lib.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,15 @@ pub async fn request(
7676
.map_err(|_| anyhow!("outgoing request write failed"))?;
7777

7878
if let Some(mut buf) = body {
79-
let request_body = http_types::outgoing_body_write(outgoing_body)
79+
let request_body = outgoing_body
80+
.write()
8081
.map_err(|_| anyhow!("outgoing request write failed"))?;
8182

82-
let pollable = streams::subscribe_to_output_stream(request_body);
83+
let pollable = request_body.subscribe();
8384
while !buf.is_empty() {
84-
test_programs::poll_list(&[pollable]);
85+
poll::poll_list(&[&pollable]);
8586

86-
let permit = match streams::check_write(request_body) {
87+
let permit = match request_body.check_write() {
8788
Ok(n) => n,
8889
Err(_) => anyhow::bail!("output stream error"),
8990
};
@@ -92,39 +93,37 @@ pub async fn request(
9293
let (chunk, rest) = buf.split_at(len);
9394
buf = rest;
9495

95-
match streams::write(request_body, chunk) {
96+
match request_body.write(chunk) {
9697
Err(_) => anyhow::bail!("output stream error"),
9798
_ => {}
9899
}
99100
}
100101

101-
match streams::flush(request_body) {
102+
match request_body.flush() {
102103
Err(_) => anyhow::bail!("output stream error"),
103104
_ => {}
104105
}
105106

106-
test_programs::poll_oneoff(&[pollable]);
107+
poll::poll_list(&[&pollable]);
107108

108-
match streams::check_write(request_body) {
109+
match request_body.check_write() {
109110
Ok(_) => {}
110111
Err(_) => anyhow::bail!("output stream error"),
111112
};
112-
113-
streams::drop_output_stream(request_body);
114113
}
115114

116115
let future_response = outgoing_handler::handle(request, None)?;
117116

118117
// TODO: The current implementation requires this drop after the request is sent.
119118
// The ownership semantics are unclear in wasi-http we should clarify exactly what is
120119
// supposed to happen here.
121-
http_types::drop_outgoing_body(outgoing_body);
120+
drop(outgoing_body);
122121

123122
let incoming_response = match http_types::future_incoming_response_get(future_response) {
124123
Some(result) => result.map_err(|_| anyhow!("incoming response errored"))?,
125124
None => {
126125
let pollable = http_types::listen_to_future_incoming_response(future_response);
127-
let _ = test_programs::poll_oneoff(&[pollable]);
126+
let _ = poll::poll_list(&[&pollable]);
128127
http_types::future_incoming_response_get(future_response)
129128
.expect("incoming response available")
130129
.map_err(|_| anyhow!("incoming response errored"))?
@@ -147,15 +146,16 @@ pub async fn request(
147146

148147
http_types::drop_incoming_response(incoming_response);
149148

150-
let input_stream = http_types::incoming_body_stream(incoming_body).unwrap();
151-
let input_stream_pollable = streams::subscribe_to_input_stream(input_stream);
149+
let input_stream = incoming_body.stream().unwrap();
150+
let input_stream_pollable = input_stream.subscribe();
152151

153152
let mut body = Vec::new();
154153
let mut eof = streams::StreamStatus::Open;
155154
while eof != streams::StreamStatus::Ended {
156-
poll::poll_oneoff(&[input_stream_pollable]);
155+
poll::poll_list(&[&input_stream_pollable]);
157156

158-
let (mut body_chunk, stream_status) = streams::read(input_stream, 1024 * 1024)
157+
let (mut body_chunk, stream_status) = input_stream
158+
.read(1024 * 1024)
159159
.map_err(|_| anyhow!("input_stream read failed"))?;
160160

161161
eof = stream_status;
@@ -165,10 +165,6 @@ pub async fn request(
165165
}
166166
}
167167

168-
poll::drop_pollable(input_stream_pollable);
169-
streams::drop_input_stream(input_stream);
170-
http_types::drop_incoming_body(incoming_body);
171-
172168
Ok(Response {
173169
status,
174170
headers,

crates/test-programs/wasi-sockets-tests/src/lib.rs

+1-74
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn write(output: &streams::OutputStream, mut bytes: &[u8]) -> (usize, stream
1111
let pollable = output.subscribe();
1212

1313
while !bytes.is_empty() {
14-
crate::poll_list(&[&pollable]);
14+
poll::poll_list(&[&pollable]);
1515

1616
let permit = match output.check_write() {
1717
Ok(n) => n,
@@ -116,76 +116,3 @@ pub fn example_body(net: tcp::Network, sock: tcp::TcpSocket, family: network::Ip
116116
// Check that we sent and recieved our message!
117117
assert_eq!(data, second_message); // Not guaranteed to work but should work in practice.
118118
}
119-
120-
/// FIXME: This is a copy of the `poll_list` bindings generated with a
121-
/// wit-bindgen with this fix:
122-
/// <https://github.com/bytecodealliance/wit-bindgen/pull/670>
123-
///
124-
/// One that PR is in a published release, delete this code and use the
125-
/// bindings.
126-
///
127-
/// Poll for completion on a set of pollables.
128-
///
129-
/// This function takes a list of pollables, which identify I/O sources of
130-
/// interest, and waits until one or more of the events is ready for I/O.
131-
///
132-
/// The result `list<u32>` contains one or more indices of handles in the
133-
/// argument list that is ready for I/O.
134-
///
135-
/// If the list contains more elements than can be indexed with a `u32`
136-
/// value, this function traps.
137-
///
138-
/// A timeout can be implemented by adding a pollable from the
139-
/// wasi-clocks API to the list.
140-
///
141-
/// This function does not return a `result`; polling in itself does not
142-
/// do any I/O so it doesn't fail. If any of the I/O sources identified by
143-
/// the pollables has an error, it is indicated by marking the source as
144-
/// being reaedy for I/O.
145-
pub fn poll_list(in_: &[&poll::Pollable]) -> wit_bindgen::rt::vec::Vec<u32> {
146-
#[allow(unused_imports)]
147-
use wit_bindgen::rt::{alloc, string::String, vec::Vec};
148-
unsafe {
149-
#[repr(align(4))]
150-
struct RetArea([u8; 8]);
151-
let mut ret_area = ::core::mem::MaybeUninit::<RetArea>::uninit();
152-
let vec0 = in_;
153-
let len0 = vec0.len() as i32;
154-
let layout0 = alloc::Layout::from_size_align_unchecked(vec0.len() * 4, 4);
155-
let result0 = if layout0.size() != 0 {
156-
let ptr = alloc::alloc(layout0);
157-
if ptr.is_null() {
158-
alloc::handle_alloc_error(layout0);
159-
}
160-
ptr
161-
} else {
162-
::core::ptr::null_mut()
163-
};
164-
for (i, e) in vec0.into_iter().enumerate() {
165-
let base = result0 as i32 + (i as i32) * 4;
166-
{
167-
*((base + 0) as *mut i32) = (e).handle() as i32;
168-
}
169-
}
170-
let ptr1 = ret_area.as_mut_ptr() as i32;
171-
#[cfg(target_arch = "wasm32")]
172-
#[link(wasm_import_module = "wasi:io/poll")]
173-
extern "C" {
174-
#[link_name = "poll-list"]
175-
fn wit_import(_: i32, _: i32, _: i32);
176-
}
177-
178-
#[cfg(not(target_arch = "wasm32"))]
179-
fn wit_import(_: i32, _: i32, _: i32) {
180-
unreachable!()
181-
}
182-
wit_import(result0 as i32, len0, ptr1);
183-
let l2 = *((ptr1 + 0) as *const i32);
184-
let l3 = *((ptr1 + 4) as *const i32);
185-
let len4 = l3 as usize;
186-
if layout0.size() != 0 {
187-
alloc::dealloc(result0, layout0);
188-
}
189-
Vec::from_raw_parts(l2 as *mut _, len4, len4)
190-
}
191-
}

0 commit comments

Comments
 (0)