Skip to content

Commit 954d880

Browse files
committed
Minor DCE from bytecodealliance#11986
Some follow-up work to delete more unnecessary parameter-passing.
1 parent b676f1e commit 954d880

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,6 @@ impl<D> StreamProducer<D> for bytes::BytesMut {
652652

653653
/// Represents the buffer for a host- or guest-initiated stream write.
654654
pub struct Source<'a, T> {
655-
instance: Option<Instance>,
656655
id: TableId<TransmitState>,
657656
host_buffer: Option<&'a mut dyn WriteBuffer<T>>,
658657
}
@@ -661,7 +660,6 @@ impl<'a, T> Source<'a, T> {
661660
/// Reborrow `self` so it can be used again later.
662661
pub fn reborrow(&mut self) -> Source<'_, T> {
663662
Source {
664-
instance: self.instance,
665663
id: self.id,
666664
host_buffer: self.host_buffer.as_deref_mut(),
667665
}
@@ -689,14 +687,14 @@ impl<'a, T> Source<'a, T> {
689687
address,
690688
count,
691689
options,
690+
instance,
692691
..
693692
} = &transmit.write
694693
else {
695694
unreachable!()
696695
};
697696

698-
let cx =
699-
&mut LiftContext::new(store.0.store_opaque_mut(), options, self.instance.unwrap());
697+
let cx = &mut LiftContext::new(store.0.store_opaque_mut(), options, instance);
700698
let ty = payload(ty, cx.types);
701699
let old_remaining = buffer.remaining_capacity();
702700
lift::<T, B>(
@@ -1837,9 +1835,7 @@ impl TableDebug for TransmitState {
18371835
}
18381836

18391837
type PollStream = Box<
1840-
dyn Fn(Option<Instance>) -> Pin<Box<dyn Future<Output = Result<StreamResult>> + Send + 'static>>
1841-
+ Send
1842-
+ Sync,
1838+
dyn Fn() -> Pin<Box<dyn Future<Output = Result<StreamResult>> + Send + 'static>> + Send + Sync,
18431839
>;
18441840

18451841
type TryInto = Box<dyn Fn(TypeId) -> Option<Box<dyn Any>> + Send + Sync>;
@@ -2217,7 +2213,7 @@ impl<T> StoreContextMut<'_, T> {
22172213
let mut dropped = false;
22182214
let produce = Box::new({
22192215
let producer = producer.clone();
2220-
move |_instance| {
2216+
move || {
22212217
let producer = producer.clone();
22222218
async move {
22232219
let (mut mine, mut buffer) = producer.lock().unwrap().take().unwrap();
@@ -2395,7 +2391,7 @@ impl<T> StoreContextMut<'_, T> {
23952391
let consumer = Arc::new(Mutex::new(Some(Box::pin(consumer))));
23962392
let consume_with_buffer = {
23972393
let consumer = consumer.clone();
2398-
async move |instance, mut host_buffer: Option<&mut dyn WriteBuffer<C::Item>>| {
2394+
async move |mut host_buffer: Option<&mut dyn WriteBuffer<C::Item>>| {
23992395
let mut mine = consumer.lock().unwrap().take().unwrap();
24002396

24012397
let host_buffer_remaining_before =
@@ -2413,7 +2409,6 @@ impl<T> StoreContextMut<'_, T> {
24132409
cx,
24142410
token.as_context_mut(store),
24152411
Source {
2416-
instance,
24172412
id,
24182413
host_buffer: host_buffer.as_deref_mut(),
24192414
},
@@ -2494,9 +2489,9 @@ impl<T> StoreContextMut<'_, T> {
24942489
};
24952490
let consume = {
24962491
let consume = consume_with_buffer.clone();
2497-
Box::new(move |instance| {
2492+
Box::new(move || {
24982493
let consume = consume.clone();
2499-
async move { consume(instance, None).await }.boxed()
2494+
async move { consume(None).await }.boxed()
25002495
})
25012496
};
25022497

@@ -2509,8 +2504,8 @@ impl<T> StoreContextMut<'_, T> {
25092504
cancel_waker: None,
25102505
};
25112506
}
2512-
&WriteState::GuestReady { instance, .. } => {
2513-
let future = consume(Some(instance));
2507+
&WriteState::GuestReady { .. } => {
2508+
let future = consume();
25142509
transmit.read = ReadState::HostReady {
25152510
consume,
25162511
guest_offset: 0,
@@ -2523,7 +2518,7 @@ impl<T> StoreContextMut<'_, T> {
25232518
let WriteState::HostReady { produce, .. } = mem::replace(
25242519
&mut transmit.write,
25252520
WriteState::HostReady {
2526-
produce: Box::new(|_| unreachable!()),
2521+
produce: Box::new(|| unreachable!()),
25272522
try_into: Box::new(|_| unreachable!()),
25282523
guest_offset: 0,
25292524
cancel: false,
@@ -2536,7 +2531,7 @@ impl<T> StoreContextMut<'_, T> {
25362531
transmit.read = ReadState::HostToHost {
25372532
accept: Box::new(move |input| {
25382533
let consume = consume_with_buffer.clone();
2539-
async move { consume(None, Some(input.get_mut::<C::Item>())).await }.boxed()
2534+
async move { consume(Some(input.get_mut::<C::Item>())).await }.boxed()
25402535
}),
25412536
buffer: Vec::new(),
25422537
limit: 0,
@@ -2553,7 +2548,7 @@ impl<T> StoreContextMut<'_, T> {
25532548
break Ok(());
25542549
}
25552550

2556-
match produce(None).await? {
2551+
match produce().await? {
25572552
StreamResult::Completed | StreamResult::Cancelled => {}
25582553
StreamResult::Dropped => break Ok(()),
25592554
}
@@ -2745,7 +2740,7 @@ impl Instance {
27452740
guest_offset: usize,
27462741
cancel: bool,
27472742
) -> Result<ReturnCode> {
2748-
let mut future = consume(Some(self));
2743+
let mut future = consume();
27492744
store.concurrent_state_mut().get_mut(transmit_id)?.read = ReadState::HostReady {
27502745
consume,
27512746
guest_offset,
@@ -2787,7 +2782,7 @@ impl Instance {
27872782
guest_offset: usize,
27882783
cancel: bool,
27892784
) -> Result<ReturnCode> {
2790-
let mut future = produce(Some(self));
2785+
let mut future = produce();
27912786
store.concurrent_state_mut().get_mut(transmit_id)?.write = WriteState::HostReady {
27922787
produce,
27932788
try_into,

0 commit comments

Comments
 (0)