Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade: tokio 1.0 #8779

Merged
merged 22 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
674 changes: 237 additions & 437 deletions Cargo.lock

Large diffs are not rendered by default.

49 changes: 24 additions & 25 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ path = "main.rs"
name = "denort"
path = "main_runtime.rs"


[[bench]]
name = "deno_bench"
harness = false
Expand All @@ -29,12 +28,12 @@ deno_core = { path = "../core", version = "0.75.0" }
deno_fetch = { path = "../op_crates/fetch", version = "0.18.0" }
deno_web = { path = "../op_crates/web", version = "0.26.0" }
deno_websocket = { path = "../op_crates/websocket", version = "0.1.0" }
regex = "1.3.9"
regex = "1.4.3"
serde = { version = "1.0.116", features = ["derive"] }

[target.'cfg(windows)'.build-dependencies]
winres = "0.1.11"
winapi = "0.3.9"
winres = "0.1.11"

[dependencies]
deno_core = { path = "../core", version = "0.75.0" }
Expand All @@ -43,54 +42,54 @@ deno_lint = "0.2.15"
deno_runtime = { path = "../runtime", version = "0.5.0" }

atty = "0.2.14"
base64 = "0.12.3"
byteorder = "1.3.4"
base64 = "0.13.0"
byteorder = "1.4.2"
clap = "2.33.3"
dissimilar = "1.0.2"
dprint-plugin-typescript = "0.38.1"
encoding_rs = "0.8.24"
env_logger = "0.7.1"
filetime = "0.2.12"
http = "0.2.1"
indexmap = "1.6.0"
jsonc-parser = "0.14.0"
encoding_rs = "0.8.26"
env_logger = "0.8.2"
filetime = "0.2.13"
http = "0.2.3"
indexmap = "1.6.1"
jsonc-parser = "0.15.1"
lazy_static = "1.4.0"
libc = "0.2.77"
log = { version = "0.4.11", features = ["serde"] }
lspower = "0.1.0"
notify = "5.0.0-pre.3"
libc = "0.2.82"
log = { version = "0.4.13", features = ["serde"] }
lspower = "0.3.0"
notify = "5.0.0-pre.4"
percent-encoding = "2.1.0"
regex = "1.3.9"
regex = "1.4.3"
ring = "0.16.19"
rustyline = { version = "7.1.0", default-features = false }
rustyline-derive = "0.4.0"
semver-parser = "0.9.0"
semver-parser = "0.10.2"
serde = { version = "1.0.116", features = ["derive"] }
shell-escape = "0.1.5"
sourcemap = "6.0.1"
swc_bundler = "0.19.2"
swc_common = { version = "0.10.8", features = ["sourcemap"] }
swc_ecmascript = { version = "0.17.1", features = ["codegen", "dep_graph", "parser", "proposal", "react", "transforms", "typescript", "visit"] }
tempfile = "3.1.0"
termcolor = "1.1.0"
tokio = { version = "0.2.22", features = ["full"] }
tokio-rustls = "0.14.1"
uuid = { version = "0.8.1", features = ["v4"] }
termcolor = "1.1.2"
tokio = { version = "1.0.1", features = ["full"] }
tokio-rustls = "0.22.0"
uuid = { version = "0.8.2", features = ["v4"] }
walkdir = "2.3.1"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] }
fwdansi = "1.1.0"
winapi = { version = "0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] }

[target.'cfg(unix)'.dependencies]
nix = "0.19.0"
nix = "0.19.1"

[dev-dependencies]
# Used in benchmark
chrono = "0.4.15"
chrono = "0.4.19"
os_pipe = "0.9.2"
test_util = { path = "../test_util" }
tower-test = "0.3.0"
tower-test = "0.4.0"

[target.'cfg(unix)'.dev-dependencies]
exec = "0.3.1" # Used in test_raw_tty
Expand Down
10 changes: 5 additions & 5 deletions cli/file_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use tokio::select;
use tokio::time::{delay_for, Delay};
use tokio::time::sleep;

const DEBOUNCE_INTERVAL_MS: Duration = Duration::from_millis(200);

type FileWatcherFuture<T> = Pin<Box<dyn Future<Output = T>>>;

struct Debounce {
delay: Delay,
sleep: Pin<Box<dyn Future<Output = ()>>>,
event_detected: Arc<AtomicBool>,
}

impl Debounce {
fn new() -> Self {
Self {
delay: delay_for(DEBOUNCE_INTERVAL_MS),
sleep: sleep(DEBOUNCE_INTERVAL_MS).boxed_local(),
event_detected: Arc::new(AtomicBool::new(false)),
}
}
Expand All @@ -52,9 +52,9 @@ impl Stream for Debounce {
inner.event_detected.store(false, Ordering::Relaxed);
Poll::Ready(Some(()))
} else {
match inner.delay.poll_unpin(cx) {
match inner.sleep.poll_unpin(cx) {
Poll::Ready(_) => {
inner.delay = delay_for(DEBOUNCE_INTERVAL_MS);
inner.sleep = sleep(DEBOUNCE_INTERVAL_MS).boxed_local();
Poll::Pending
}
Poll::Pending => Poll::Pending,
Expand Down
3 changes: 2 additions & 1 deletion cli/lsp/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ pub fn server_capabilities(
color_provider: None,
execute_command_provider: None,
call_hierarchy_provider: None,
on_type_rename_provider: None,
semantic_highlighting: None,
semantic_tokens_provider: None,
workspace: None,
experimental: None,
linked_editing_range_provider: None,
moniker_provider: None,
}
}
3 changes: 2 additions & 1 deletion cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl TsServer {
// the language server...
let mut ts_runtime = start(false).expect("could not start tsc");

let mut runtime = create_basic_runtime();
let runtime = create_basic_runtime();
runtime.block_on(async {
while let Some((req, state_snapshot, tx)) = rx.recv().await {
let value = request(&mut ts_runtime, state_snapshot, req);
Expand Down Expand Up @@ -482,6 +482,7 @@ impl RenameLocations {
}

Ok(lsp_types::WorkspaceEdit {
change_annotations: None,
changes: None,
document_changes: Some(lsp_types::DocumentChanges::Edits(
text_document_edit_map.values().cloned().collect(),
Expand Down
7 changes: 3 additions & 4 deletions cli/tokio_util.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

pub fn create_basic_runtime() -> tokio::runtime::Runtime {
tokio::runtime::Builder::new()
.basic_scheduler()
tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
// This limits the number of threads for blocking operations (like for
// synchronous fs ops) or CPU bound tasks like when we run dprint in
// parallel for deno fmt.
// The default value is 512, which is an unhelpfully large thread pool. We
// don't ever want to have more than a couple dozen threads.
.max_threads(32)
.max_blocking_threads(32)
.build()
.unwrap()
}
Expand All @@ -20,6 +19,6 @@ pub fn run_basic<F, R>(future: F) -> R
where
F: std::future::Future<Output = R>,
{
let mut rt = create_basic_runtime();
let rt = create_basic_runtime();
rt.block_on(future)
}
5 changes: 3 additions & 2 deletions cli/tools/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::colors;
use crate::media_type::MediaType;
use crate::program_state::ProgramState;
use deno_core::error::AnyError;
use deno_core::futures::FutureExt;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_runtime::inspector::InspectorSession;
Expand Down Expand Up @@ -277,7 +278,7 @@ async fn post_message_and_poll(
// A zero delay is long enough to yield the thread in order to prevent the loop from
// running hot for messages that are taking longer to resolve like for example an
// evaluation of top level await.
tokio::time::delay_for(tokio::time::Duration::from_millis(0)).await;
tokio::time::sleep(tokio::time::Duration::from_millis(0)).await;
}
}
}
Expand Down Expand Up @@ -305,7 +306,7 @@ async fn read_line_and_poll(
// Because an inspector websocket client may choose to connect at anytime when we have an
// inspector server we need to keep polling the worker to pick up new connections.
let mut timeout =
tokio::time::delay_for(tokio::time::Duration::from_millis(100));
tokio::time::sleep(tokio::time::Duration::from_millis(100)).boxed_local();

tokio::select! {
result = &mut line => {
Expand Down
22 changes: 11 additions & 11 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ repository = "https://github.com/denoland/deno"
path = "lib.rs"

[dependencies]
anyhow = "1.0.32"
futures = "0.3.8"
indexmap = "1.6.0"
anyhow = "1.0.38"
futures = "0.3.9"
indexmap = "1.6.1"
lazy_static = "1.4.0"
libc = "0.2.77"
log = "0.4.11"
libc = "0.2.82"
log = "0.4.13"
pin-project = "1.0.4"
rusty_v8 = "0.15.0"
serde_json = { version = "1.0", features = ["preserve_order"] }
serde = { version = "1.0", features = ["derive"] }
smallvec = "1.4.2"
url = { version = "2.2", features = ["serde"] }
pin-project = "1.0.2"
serde = { version = "1.0.116", features = ["derive"] }
serde_json = { version = "1.0.61", features = ["preserve_order"] }
smallvec = "1.6.1"
url = { version = "2.2.0", features = ["serde"] }

[[example]]
name = "http_bench_bin_ops"
Expand All @@ -36,4 +36,4 @@ path = "examples/http_bench_json_ops.rs"

# These dependencies are only used for the 'http_bench_*_ops' examples.
[dev-dependencies]
tokio = { version = "0.3.5", features = ["full"] }
tokio = { version = "1.0.1", features = ["full"] }
9 changes: 5 additions & 4 deletions op_crates/fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ repository = "https://github.com/denoland/deno"
path = "lib.rs"

[dependencies]
bytes = "1.0.1"
deno_core = { version = "0.75.0", path = "../../core" }

bytes = "0.5.6"
reqwest = { version = "0.10.8", default-features = false, features = ["rustls-tls", "stream", "gzip", "brotli"] }
reqwest = { version = "0.11.0", default-features = false, features = ["rustls-tls", "stream", "gzip", "brotli"] }
serde = { version = "1.0.116", features = ["derive"] }
tokio = { version = "0.2.22", features = ["full"] }
tokio = { version = "1.0.1", features = ["full"] }
tokio-stream = "0.1.1"
tokio-util = "0.6.0"
13 changes: 7 additions & 6 deletions op_crates/fetch/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelFuture;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::JsRuntime;
use deno_core::OpState;
use deno_core::RcRef;
Expand All @@ -38,10 +39,10 @@ use std::io::Read;
use std::path::PathBuf;
use std::pin::Pin;
use std::rc::Rc;
use tokio::io::stream_reader;
use tokio::io::AsyncReadExt;
use tokio::io::StreamReader;
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use tokio_util::io::StreamReader;

pub use reqwest; // Re-export reqwest

Expand Down Expand Up @@ -157,7 +158,7 @@ where
0 => {
// If no body is passed, we return a writer for streaming the body.
let (tx, rx) = mpsc::channel::<std::io::Result<Vec<u8>>>(1);
request = request.body(Body::wrap_stream(rx));
request = request.body(Body::wrap_stream(ReceiverStream::new(rx)));

let request_body_rid =
state.resource_table.add(FetchRequestBodyResource {
Expand Down Expand Up @@ -247,7 +248,7 @@ pub async fn op_fetch_send(
let stream: BytesStream = Box::pin(res.bytes_stream().map(|r| {
r.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))
}));
let stream_reader = stream_reader(stream);
let stream_reader = StreamReader::new(stream);
let rid = state
.borrow_mut()
.resource_table
Expand Down Expand Up @@ -288,7 +289,7 @@ pub async fn op_fetch_request_write(
.resource_table
.get::<FetchRequestBodyResource>(rid as u32)
.ok_or_else(bad_resource_id)?;
let mut body = RcRef::map(&resource, |r| &r.body).borrow_mut().await;
let body = RcRef::map(&resource, |r| &r.body).borrow_mut().await;
let cancel = RcRef::map(resource, |r| &r.cancel);
body.send(Ok(buf)).or_cancel(cancel).await??;

Expand Down Expand Up @@ -321,7 +322,7 @@ pub async fn op_fetch_response_read(
let mut reader = RcRef::map(&resource, |r| &r.reader).borrow_mut().await;
let cancel = RcRef::map(resource, |r| &r.cancel);
let mut buf = data[0].clone();
let read = reader.read(&mut buf).or_cancel(cancel).await??;
let read = reader.read(&mut buf).try_or_cancel(cancel).await?;
Ok(json!({ "read": read }))
}

Expand Down
2 changes: 1 addition & 1 deletion op_crates/web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ idna = "0.2.0"
serde = { version = "1.0.116", features = ["derive"] }

[dev-dependencies]
futures = "0.3.8"
futures = "0.3.9"
12 changes: 6 additions & 6 deletions op_crates/websocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ path = "lib.rs"

[dependencies]
deno_core = { version = "0.75.0", path = "../../core" }
http = "0.2.1"
tokio = { version = "0.2.22", features = ["full"] }
tokio-rustls = "0.14.1"
tokio-tungstenite = "0.11.0"
http = "0.2.3"
serde = { version = "1.0.116", features = ["derive"] }
webpki = "0.21.3"
webpki-roots = "=0.19.0" # Pinned to v0.19.0 to match 'reqwest'.
tokio = { version = "1.0.1", features = ["full"] }
tokio-rustls = "0.22.0"
tokio-tungstenite = "0.13.0"
webpki = "0.21.4"
webpki-roots = "0.21.0"
Loading