From 093d5b2d5ea6b082929a249bacb95356c77a4f1e Mon Sep 17 00:00:00 2001 From: Arturo Castro Date: Mon, 23 Nov 2020 19:44:35 +0100 Subject: [PATCH 1/2] use MaybeUninit instead of uninitialized Latest versions of rust will panic when trying to leave an uninitialized SerializedValue from mem::uninitialized which was breaking the js! macro --- src/webcore/serialization.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/webcore/serialization.rs b/src/webcore/serialization.rs index 4f97d058..e05c9790 100644 --- a/src/webcore/serialization.rs +++ b/src/webcore/serialization.rs @@ -412,8 +412,9 @@ macro_rules! untagged_boilerplate { #[inline] fn from( untagged: $untagged_type ) -> Self { unsafe { - let mut value: SerializedValue = mem::uninitialized(); - *(&mut value as *mut SerializedValue as *mut $untagged_type) = untagged; + let mut value = mem::MaybeUninit::::uninit(); + *(value.as_mut_ptr() as *mut $untagged_type) = untagged; + let mut value = value.assume_init(); value.tag = $tag; value } From 24cdc7507d243438b56c374f9a03f3ee9e35894b Mon Sep 17 00:00:00 2001 From: Arturo Castro Date: Fri, 18 Dec 2020 16:58:38 +0100 Subject: [PATCH 2/2] ported to use stable futures --- Cargo.toml | 10 +++++----- src/webcore/executor.rs | 22 +++++++++------------- src/webcore/promise_future.rs | 4 ++-- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9da1da98..77159405 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,10 +17,10 @@ build = "build.rs" discard = "1.0.3" serde = { version = "1", optional = true } serde_json = { version = "1", optional = true } -futures-core-preview = { version = "0.3.0-alpha.15", optional = true } -futures-channel-preview = { version = "0.3.0-alpha.15", optional = true } -futures-util-preview = { version = "0.3.0-alpha.15", optional = true } -futures-executor-preview = { version = "0.3.0-alpha.15", optional = true } +futures-core = { version = "0.3.8", optional = true } +futures-channel = { version = "0.3.8", optional = true } +futures-util = { version = "0.3.8", optional = true } +futures-executor = { version = "0.3.8", optional = true } stdweb-derive = { version = "= 0.5.3", path = "stdweb-derive" } stdweb-internal-macros = { version = "= 0.2.9", path = "stdweb-internal-macros" } @@ -44,7 +44,7 @@ rustc_version = "0.2" default = ["serde", "serde_json"] nightly = [] web_test = [] -futures-support = ["futures-core-preview", "futures-channel-preview", "futures-util-preview", "futures-executor-preview"] +futures-support = ["futures-core", "futures-channel", "futures-util", "futures-executor"] experimental_features_which_may_break_on_minor_version_bumps = ["futures-support"] "docs-rs" = [] diff --git a/src/webcore/executor.rs b/src/webcore/executor.rs index 77ba6c5d..c366c741 100644 --- a/src/webcore/executor.rs +++ b/src/webcore/executor.rs @@ -5,10 +5,9 @@ // TODO: verify that this works correctly with pinned futures // TODO: use FuturesUnordered (similar to LocalPool) -use futures_core::future::{FutureObj, LocalFutureObj}; use futures_executor::enter; -use futures_core::task::{Spawn, SpawnError}; -use futures_util::task::{self, ArcWake}; +use futures_util::future::LocalFutureObj; +use futures_util::task::{self, ArcWake, LocalSpawn, SpawnError}; use std::future::Future; use std::task::{Poll, Context}; use std::pin::Pin; @@ -28,12 +27,9 @@ const INITIAL_QUEUE_CAPACITY: usize = 10; // Iterations to wait before allowing the queue to shrink const QUEUE_SHRINK_DELAY: usize = 10; - -pub(crate) type BoxedFuture = LocalFutureObj< 'static, () >; - #[derive(Debug)] struct TaskInner { - future: BoxedFuture, + future: LocalFutureObj<'static, ()>, executor: EventLoopExecutor, } @@ -50,7 +46,7 @@ unsafe impl Send for Task {} unsafe impl Sync for Task {} impl Task { - fn new( executor: EventLoopExecutor, future: BoxedFuture ) -> Arc< Self > { + fn new( executor: EventLoopExecutor, future: LocalFutureObj<'static, ()> ) -> Arc< Self > { Arc::new( Self { is_queued: Cell::new( true ), inner: RefCell::new( TaskInner { @@ -315,21 +311,21 @@ impl EventLoopExecutor { } #[inline] - fn spawn_local( &self, future: BoxedFuture ) { + fn spawn_local( &self, future: LocalFutureObj<'static, ()> ) { self.0.push_task( Task::new( self.clone(), future ) ); } } -impl Spawn for EventLoopExecutor { +impl LocalSpawn for EventLoopExecutor { #[inline] - fn spawn_obj( &mut self, future: FutureObj< 'static, () > ) -> Result< (), SpawnError > { - self.spawn_local( future.into() ); + fn spawn_local_obj( &self, future: LocalFutureObj< 'static, () > ) -> Result< (), SpawnError > { + self.spawn_local( future ); Ok( () ) } } -pub(crate) fn spawn_local( future: BoxedFuture ) { +pub(crate) fn spawn_local( future: LocalFutureObj<'static, ()> ) { thread_local! { static EVENT_LOOP: EventLoopExecutor = EventLoopExecutor::new(); } diff --git a/src/webcore/promise_future.rs b/src/webcore/promise_future.rs index d562eec9..6770737f 100644 --- a/src/webcore/promise_future.rs +++ b/src/webcore/promise_future.rs @@ -110,9 +110,9 @@ use super::promise::{Promise, DoneHandle}; /// } /// ``` #[inline] -pub fn spawn_local< F >( future: F ) where F: Future< Output = () > + 'static { +pub fn spawn_local< F >( future: F ) where F: Future< Output = () > + 'static{ // TODO does this need to use PinBox instead ? - let future: executor::BoxedFuture = Box::new( future ).into(); + let future = Box::new( future ).into(); executor::spawn_local( future ); }