Skip to content

Commit

Permalink
fix: Ensure all futures on the stack gets polled
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Oct 14, 2018
1 parent 514fd3b commit d5862e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion std/writer.glu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let { Identity } = import! std.identity
type Writer w a = { value : a, writer : w }

let functor : [Monoid w] -> Functor (Writer w) = {
map = \f m -> { value = f m.value, writer = m.writer },
map = \f m -> { value = f m.value, writer = m.writer }
}

let applicative : [Monoid w] -> Applicative (Writer w) = {
Expand Down
30 changes: 17 additions & 13 deletions vm/src/thread.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! The thread/vm type
use std::any::{Any, TypeId};
use std::cmp::Ordering;
use std::collections::VecDeque;
use std::fmt;
use std::mem;
use std::ops::{Add, Deref, DerefMut, Div, Mul, Sub};
Expand Down Expand Up @@ -339,7 +338,8 @@ impl<'b> Roots<'b> {
Roots {
vm: thread_ptr,
stack: &context.stack,
}.traverse(gc);
}
.traverse(gc);

Vec::push(&mut locks, (child_threads, context, thread_ptr));
}
Expand Down Expand Up @@ -1239,7 +1239,7 @@ pub struct Context {

/// Stack of polling functions used for extern functions returning futures
#[cfg_attr(feature = "serde_derive", serde(skip))]
poll_fns: VecDeque<PollFn>,
poll_fns: Vec<PollFn>,
}

impl Context {
Expand All @@ -1253,7 +1253,7 @@ impl Context {
previous_instruction_index: usize::max_value(),
},
max_stack_size: VmIndex::max_value(),
poll_fns: VecDeque::new(),
poll_fns: Vec::new(),
}
}

Expand All @@ -1269,7 +1269,8 @@ impl Context {
tag: tag,
elems: fields,
},
).map(ValueRepr::Data)
)
.map(ValueRepr::Data)
.map(Value::from)
}
pub fn slide(&mut self, fields: VmIndex) {
Expand All @@ -1292,7 +1293,8 @@ impl Context {
tag: tag,
elems: fields,
},
).map(ValueRepr::Data)
)
.map(ValueRepr::Data)
.map(Value::from)?
};
self.stack.push(value);
Expand Down Expand Up @@ -1365,7 +1367,7 @@ impl Context {
F: Future<Error = Error> + Send + 'static,
F::Item: Pushable<'vm>,
{
self.poll_fns.push_back(PollFn {
self.poll_fns.push(PollFn {
frame_index,
poll_fn: Box::new(move |vm| {
let value = try_ready!(future.poll());
Expand Down Expand Up @@ -1509,7 +1511,7 @@ impl<'b> OwnedContext<'b> {
return Ok(Async::Ready(Some(context)));
}
if ext.call_state == ExternCallState::Poll {
if let Some(frame_index) = context.poll_fns.front().map(|f| f.frame_index) {
if let Some(frame_index) = context.poll_fns.last().map(|f| f.frame_index) {
ext = ExternState::from_state(
context.stack.get_frames()[frame_index as usize].state,
);
Expand Down Expand Up @@ -1630,7 +1632,7 @@ impl<'b> OwnedContext<'b> {
}

ExternCallState::Poll => {
if let Some(mut poll_fn) = self.poll_fns.pop_front() {
if let Some(mut poll_fn) = self.poll_fns.pop() {
let frame_offset = poll_fn.frame_index as usize;

match self.stack.get_frames_mut()[frame_offset].state {
Expand All @@ -1654,7 +1656,7 @@ impl<'b> OwnedContext<'b> {
_ => unreachable!(),
}
// Restore `poll_fn` so it can be polled again
self.poll_fns.push_front(poll_fn);
self.poll_fns.push(poll_fn);
return Ok(Async::NotReady);
}
Err(err) => return Err(err),
Expand Down Expand Up @@ -1975,9 +1977,11 @@ impl<'b> ExecuteContext<'b> {
}
Split => {
match self.stack.pop().get_repr() {
Data(data) => for field in &data.fields {
self.stack.push(field);
},
Data(data) => {
for field in &data.fields {
self.stack.push(field);
}
}
// Zero argument variant
ValueRepr::Tag(_) => (),
_ => {
Expand Down

0 comments on commit d5862e1

Please sign in to comment.