Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 6b6ade7

Browse files
committed
Simplify some generics in type signatures
Much of this is relic of historic designs and no longer needed, so try to clean up some things here and there.
1 parent 4cd979b commit 6b6ade7

8 files changed

Lines changed: 39 additions & 53 deletions

File tree

crates/misc/component-async-tests/src/resource_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl bindings::local::local::resource_stream::HostConcurrent for Ctx {
6565

6666
let (tx, rx) = accessor.with(|mut view| {
6767
let instance = view.instance();
68-
instance.stream::<_, _, Option<_>, _, _>(&mut view)
68+
instance.stream::<_, _, Option<_>>(&mut view)
6969
})?;
7070
accessor.spawn(Task { tx, count });
7171
Ok(rx.into())

crates/misc/component-async-tests/tests/scenario/streams.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,46 +46,46 @@ pub async fn async_watch_streams() -> Result<()> {
4646
let instance = linker.instantiate_async(&mut store, &component).await?;
4747

4848
// Test watching and then dropping the read end of a stream.
49-
let (tx, rx) = instance.stream::<u8, Option<_>, Option<_>, _, _>(&mut store)?;
49+
let (tx, rx) = instance.stream::<u8, Option<_>, Option<_>>(&mut store)?;
5050
let watch = tx.watch_reader().0;
5151
drop(rx);
5252
instance.run(&mut store, watch).await?;
5353

5454
// Test dropping and then watching the read end of a stream.
55-
let (tx, rx) = instance.stream::<u8, Option<_>, Option<_>, _, _>(&mut store)?;
55+
let (tx, rx) = instance.stream::<u8, Option<_>, Option<_>>(&mut store)?;
5656
drop(rx);
5757
instance.run(&mut store, tx.watch_reader().0).await?;
5858

5959
// Test watching and then dropping the write end of a stream.
60-
let (tx, rx) = instance.stream::<u8, Option<_>, Option<_>, _, _>(&mut store)?;
60+
let (tx, rx) = instance.stream::<u8, Option<_>, Option<_>>(&mut store)?;
6161
let watch = rx.watch_writer().0;
6262
drop(tx);
6363
instance.run(&mut store, watch).await?;
6464

6565
// Test dropping and then watching the write end of a stream.
66-
let (tx, rx) = instance.stream::<u8, Option<_>, Option<_>, _, _>(&mut store)?;
66+
let (tx, rx) = instance.stream::<u8, Option<_>, Option<_>>(&mut store)?;
6767
drop(tx);
6868
instance.run(&mut store, rx.watch_writer().0).await?;
6969

7070
// Test watching and then dropping the read end of a future.
71-
let (tx, rx) = instance.future::<u8, _, _>(|| 42, &mut store)?;
71+
let (tx, rx) = instance.future::<u8>(|| 42, &mut store)?;
7272
let watch = tx.watch_reader().0;
7373
drop(rx);
7474
instance.run(&mut store, watch).await?;
7575

7676
// Test dropping and then watching the read end of a future.
77-
let (tx, rx) = instance.future::<u8, _, _>(|| 42, &mut store)?;
77+
let (tx, rx) = instance.future::<u8>(|| 42, &mut store)?;
7878
drop(rx);
7979
instance.run(&mut store, tx.watch_reader().0).await?;
8080

8181
// Test watching and then dropping the write end of a future.
82-
let (tx, rx) = instance.future::<u8, _, _>(|| 42, &mut store)?;
82+
let (tx, rx) = instance.future::<u8>(|| 42, &mut store)?;
8383
let watch = rx.watch_writer().0;
8484
drop(tx);
8585
instance.run(&mut store, watch).await?;
8686

8787
// Test dropping and then watching the write end of a future.
88-
let (tx, rx) = instance.future::<u8, _, _>(|| 42, &mut store)?;
88+
let (tx, rx) = instance.future::<u8>(|| 42, &mut store)?;
8989
drop(tx);
9090
instance.run(&mut store, rx.watch_writer().0).await?;
9191

@@ -293,7 +293,7 @@ pub async fn test_closed_streams(watch: bool) -> Result<()> {
293293

294294
// Next, test stream host->guest
295295
{
296-
let (tx, rx) = instance.stream::<_, _, Vec<_>, _, _>(&mut store)?;
296+
let (tx, rx) = instance.stream::<_, _, Vec<_>>(&mut store)?;
297297

298298
let mut futures = FuturesUnordered::new();
299299
futures.push(

crates/misc/component-async-tests/tests/scenario/transmit.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,8 @@ async fn test_transmit_with<Test: TransmitTest + 'static>(component: &str) -> Re
358358
ReadNone(Option<StreamReader<Option<String>>>),
359359
}
360360

361-
let (control_tx, control_rx) = instance.stream::<_, _, Option<_>, _, _>(&mut store)?;
362-
let (caller_stream_tx, caller_stream_rx) =
363-
instance.stream::<_, _, Option<_>, _, _>(&mut store)?;
361+
let (control_tx, control_rx) = instance.stream::<_, _, Option<_>>(&mut store)?;
362+
let (caller_stream_tx, caller_stream_rx) = instance.stream::<_, _, Option<_>>(&mut store)?;
364363
let (caller_future1_tx, caller_future1_rx) = instance.future(|| unreachable!(), &mut store)?;
365364
let (_caller_future2_tx, caller_future2_rx) = instance.future(|| unreachable!(), &mut store)?;
366365

crates/wasi-http/src/p3/host/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ where
790790
store.with(|mut view| {
791791
let instance = view.instance();
792792
let (contents_tx, contents_rx) = instance
793-
.stream::<_, _, Vec<_>, _, _>(&mut view)
793+
.stream::<_, _, Vec<_>>(&mut view)
794794
.context("failed to create stream")?;
795795
let (trailers_tx, trailers_rx) = instance
796796
.future(|| Ok(None), &mut view)
@@ -1107,7 +1107,7 @@ where
11071107
store.with(|mut view| {
11081108
let instance = view.instance();
11091109
let (contents_tx, contents_rx) = instance
1110-
.stream::<_, _, Vec<_>, _, _>(&mut view)
1110+
.stream::<_, _, Vec<_>>(&mut view)
11111111
.context("failed to create stream")?;
11121112
let (trailers_tx, trailers_rx) = instance
11131113
.future(|| Ok(None), &mut view)

crates/wasi/src/p3/cli/host.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ where
171171
store.with(|mut view| {
172172
let instance = view.instance();
173173
let (tx, rx) = instance
174-
.stream::<_, _, Vec<_>, _, _>(&mut view)
174+
.stream::<_, _, Vec<_>>(&mut view)
175175
.context("failed to create stream")?;
176176
let stdin = view.get().cli().stdin.reader();
177177
view.spawn(InputTask { input: stdin, tx });

crates/wasi/src/p3/filesystem/host.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ where
6161
store.with(|mut view| {
6262
let instance = view.instance();
6363
let (data_tx, data_rx) = instance
64-
.stream::<_, _, Vec<_>, _, _>(&mut view)
64+
.stream::<_, _, Vec<_>>(&mut view)
6565
.context("failed to create stream")?;
6666
let (res_tx, res_rx) = instance
6767
.future(|| unreachable!(), &mut view)
@@ -150,7 +150,7 @@ where
150150
) -> wasmtime::Result<Result<(), ErrorCode>> {
151151
let mut buf = Vec::with_capacity(8096);
152152
let (fd, fut) = store.with(|mut view| {
153-
let data = data.into_reader::<Vec<u8>, _, _>(&mut view);
153+
let data = data.into_reader::<Vec<u8>>(&mut view);
154154
let fut = data.read(buf);
155155
let fd = get_descriptor(view.get().table(), &fd)?.clone();
156156
anyhow::Ok((fd.clone(), fut))
@@ -198,7 +198,7 @@ where
198198
) -> wasmtime::Result<Result<(), ErrorCode>> {
199199
let mut buf = Vec::with_capacity(8096);
200200
let (fd, fut) = store.with(|mut view| {
201-
let data = data.into_reader::<Vec<u8>, _, _>(&mut view);
201+
let data = data.into_reader::<Vec<u8>>(&mut view);
202202
let fut = data.read(buf);
203203
let fd = get_descriptor(view.get().table(), &fd)?.clone();
204204
anyhow::Ok((fd, fut))
@@ -318,7 +318,7 @@ where
318318
store.with(|mut view| {
319319
let instance = view.instance();
320320
let (data_tx, data_rx) = instance
321-
.stream::<_, _, Vec<_>, _, _>(&mut view)
321+
.stream::<_, _, Vec<_>>(&mut view)
322322
.context("failed to create stream")?;
323323
let (res_tx, res_rx) = instance
324324
.future(|| unreachable!(), &mut view)

crates/wasi/src/p3/sockets/host/types/tcp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ where
289289
};
290290
let instance = view.instance();
291291
let (tx, rx) = instance
292-
.stream::<_, _, Vec<_>, _, _>(&mut view)
292+
.stream::<_, _, Vec<_>>(&mut view)
293293
.context("failed to create stream")?;
294294
let &TcpSocket {
295295
listen_backlog_size,
@@ -379,7 +379,7 @@ where
379379
) -> wasmtime::Result<Result<(), ErrorCode>> {
380380
let mut buf = Vec::with_capacity(8096);
381381
let (stream, fut) = match store.with(|mut view| {
382-
let data = data.into_reader::<Vec<u8>, _, _>(&mut view);
382+
let data = data.into_reader::<Vec<u8>>(&mut view);
383383
let fut = data.read(buf);
384384
let mut binding = view.get();
385385
let sock = get_socket(binding.table(), &socket)?;
@@ -440,7 +440,7 @@ where
440440
store.with(|mut view| {
441441
let instance = view.instance();
442442
let (data_tx, data_rx) = instance
443-
.stream::<_, _, Vec<_>, _, _>(&mut view)
443+
.stream::<_, _, Vec<_>>(&mut view)
444444
.context("failed to create stream")?;
445445
let (res_tx, res_rx) = instance
446446
.future(|| unreachable!(), &mut view)

crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,14 @@ impl<T> HostFuture<T> {
605605
}
606606

607607
/// Convert this object into a [`FutureReader`].
608-
pub fn into_reader<U: 'static, S: AsContextMut<Data = U>>(self, mut store: S) -> FutureReader<T>
608+
pub fn into_reader(self, mut store: impl AsContextMut) -> FutureReader<T>
609609
where
610610
T: func::Lower + func::Lift + Send + Sync + 'static,
611611
{
612612
FutureReader {
613613
instance: self.instance,
614614
rep: self.rep,
615-
tx: Some(self.instance.start_read_event_loop::<_, _, U>(
615+
tx: Some(self.instance.start_read_event_loop(
616616
store.as_context_mut(),
617617
self.rep,
618618
TransmitKind::Future,
@@ -984,18 +984,15 @@ impl<T> HostStream<T> {
984984
}
985985

986986
/// Convert this object into a [`StreamReader`].
987-
pub fn into_reader<B, U: 'static, S: AsContextMut<Data = U>>(
988-
self,
989-
mut store: S,
990-
) -> StreamReader<B>
987+
pub fn into_reader<B>(self, mut store: impl AsContextMut) -> StreamReader<B>
991988
where
992989
T: func::Lower + func::Lift + Send + 'static,
993990
B: ReadBuffer<T>,
994991
{
995992
StreamReader {
996993
instance: self.instance,
997994
rep: self.rep,
998-
tx: Some(self.instance.start_read_event_loop::<_, _, U>(
995+
tx: Some(self.instance.start_read_event_loop(
999996
store.as_context_mut(),
1000997
self.rep,
1001998
TransmitKind::Stream,
@@ -1233,7 +1230,7 @@ impl ErrorContext {
12331230
}
12341231

12351232
/// Attempt to convert the specified [`Val`] to a `ErrorContext`.
1236-
pub fn from_val<U, S: AsContextMut<Data = U>>(_: S, value: &Val) -> Result<Self> {
1233+
pub fn from_val(_: impl AsContextMut, value: &Val) -> Result<Self> {
12371234
let Val::ErrorContext(ErrorContextAny(rep)) = value else {
12381235
bail!("expected `error-context`; got `{}`", value.desc());
12391236
};
@@ -1516,22 +1513,18 @@ impl Instance {
15161513
/// If there's no plausible default value, and you're sure
15171514
/// `FutureWriter::write` will be called, you can consider passing `||
15181515
/// unreachable!()` as the `default` parameter.
1519-
pub fn future<
1520-
T: func::Lower + func::Lift + Send + Sync + 'static,
1521-
U: 'static,
1522-
S: AsContextMut<Data = U>,
1523-
>(
1516+
pub fn future<T: func::Lower + func::Lift + Send + Sync + 'static>(
15241517
self,
15251518
default: fn() -> T,
1526-
mut store: S,
1519+
mut store: impl AsContextMut,
15271520
) -> Result<(FutureWriter<T>, FutureReader<T>)> {
15281521
let mut store = store.as_context_mut();
15291522
let (write, read) = self.concurrent_state_mut(store.0).new_transmit()?;
15301523

15311524
Ok((
15321525
FutureWriter::new(
15331526
default,
1534-
Some(self.start_write_event_loop::<_, _, U>(
1527+
Some(self.start_write_event_loop(
15351528
store.as_context_mut(),
15361529
write.rep(),
15371530
TransmitKind::Future,
@@ -1540,7 +1533,7 @@ impl Instance {
15401533
),
15411534
FutureReader::new(
15421535
read.rep(),
1543-
Some(self.start_read_event_loop::<_, _, U>(
1536+
Some(self.start_read_event_loop(
15441537
store.as_context_mut(),
15451538
read.rep(),
15461539
TransmitKind::Future,
@@ -1556,18 +1549,16 @@ impl Instance {
15561549
T: func::Lower + func::Lift + Send + 'static,
15571550
W: WriteBuffer<T>,
15581551
R: ReadBuffer<T>,
1559-
U: 'static,
1560-
S: AsContextMut<Data = U>,
15611552
>(
15621553
self,
1563-
mut store: S,
1554+
mut store: impl AsContextMut,
15641555
) -> Result<(StreamWriter<W>, StreamReader<R>)> {
15651556
let mut store = store.as_context_mut();
15661557
let (write, read) = self.concurrent_state_mut(store.0).new_transmit()?;
15671558

15681559
Ok((
15691560
StreamWriter::new(
1570-
Some(self.start_write_event_loop::<_, _, U>(
1561+
Some(self.start_write_event_loop(
15711562
store.as_context_mut(),
15721563
write.rep(),
15731564
TransmitKind::Stream,
@@ -1576,7 +1567,7 @@ impl Instance {
15761567
),
15771568
StreamReader::new(
15781569
read.rep(),
1579-
Some(self.start_read_event_loop::<_, _, U>(
1570+
Some(self.start_read_event_loop(
15801571
store.as_context_mut(),
15811572
read.rep(),
15821573
TransmitKind::Stream,
@@ -1598,7 +1589,7 @@ impl Instance {
15981589
fn start_write_event_loop<
15991590
T: func::Lower + func::Lift + Send + 'static,
16001591
B: WriteBuffer<T>,
1601-
U: 'static,
1592+
U,
16021593
>(
16031594
self,
16041595
mut store: StoreContextMut<U>,
@@ -1668,11 +1659,7 @@ impl Instance {
16681659

16691660
/// Same as `Self::start_write_event_loop`, but for the read end of a stream
16701661
/// or future.
1671-
fn start_read_event_loop<
1672-
T: func::Lower + func::Lift + Send + 'static,
1673-
B: ReadBuffer<T>,
1674-
U: 'static,
1675-
>(
1662+
fn start_read_event_loop<T: func::Lower + func::Lift + Send + 'static, B: ReadBuffer<T>, U>(
16761663
self,
16771664
mut store: StoreContextMut<U>,
16781665
rep: u32,
@@ -1748,7 +1735,7 @@ impl Instance {
17481735
/// * `post_write` - Whether the transmit should be dropped after write, possibly with an error context
17491736
/// * `tx` - Oneshot channel to notify when operation completes (or drop on error)
17501737
/// * `kind` - whether this is a stream or a future
1751-
fn host_write<T: func::Lower + Send + 'static, B: WriteBuffer<T>, U: 'static>(
1738+
fn host_write<T: func::Lower + Send + 'static, B: WriteBuffer<T>, U>(
17521739
self,
17531740
mut store: StoreContextMut<U>,
17541741
transmit_rep: u32,
@@ -1871,7 +1858,7 @@ impl Instance {
18711858
/// * `buffer` - Buffer to receive values
18721859
/// * `tx` - Oneshot channel to notify when operation completes (or drop on error)
18731860
/// * `kind` - whether this is a stream or a future
1874-
fn host_read<T: func::Lift + Send + 'static, B: ReadBuffer<T>, U: 'static>(
1861+
fn host_read<T: func::Lift + Send + 'static, B: ReadBuffer<T>, U>(
18751862
self,
18761863
mut store: StoreContextMut<U>,
18771864
rep: u32,
@@ -2792,7 +2779,7 @@ impl Instance {
27922779
///
27932780
/// SAFETY: `memory` and `realloc` must be valid pointers to their
27942781
/// respective guest entities.
2795-
pub(super) unsafe fn error_context_debug_message<T: 'static>(
2782+
pub(super) unsafe fn error_context_debug_message<T>(
27962783
self,
27972784
store: StoreContextMut<T>,
27982785
memory: *mut VMMemoryDefinition,

0 commit comments

Comments
 (0)