Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 581415c

Browse files
committed
Auto merge of #1713 - rust-lang:tokio-02, r=Xanewok
Use Tokio 0.2 Helps with #1695 and #1693 (still needs a bump to Tokio 1.0)
2 parents 36f4a9e + 36a75ae commit 581415c

File tree

10 files changed

+347
-538
lines changed

10 files changed

+347
-538
lines changed

Cargo.lock

+220-417
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+6-9
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ cargo = { git = "https://github.com/rust-lang/cargo", rev = "329895f5b52a358e5d9
3434
cargo_metadata = "0.8"
3535
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "7ea7cd165ad6705603852771bf82cc2fd6560db5", optional = true }
3636
env_logger = "0.7"
37-
futures = { version = "0.1", optional = true }
3837
home = "0.5.1"
3938
itertools = "0.8"
40-
jsonrpc-core = "14"
39+
jsonrpc-core = "17"
4140
lsp-types = { version = "0.60", features = ["proposed"] }
4241
lazy_static = "1"
4342
log = "0.4"
@@ -51,7 +50,6 @@ serde = "1.0"
5150
serde_json = "1.0"
5251
serde_derive = "1.0"
5352
serde_ignored = "0.1"
54-
tokio = { version = "0.1", optional = true }
5553
url = "2"
5654
walkdir = "2"
5755
regex = "1"
@@ -68,16 +66,15 @@ rustc-workspace-hack = "1.0.0"
6866
[dev-dependencies]
6967
difference = "2"
7068
tempfile = "3"
71-
lsp-codec = "0.1.2"
72-
tokio = "0.1"
73-
futures = "0.1"
74-
tokio-process = "0.2"
75-
tokio-timer = "0.2"
69+
lsp-codec = "0.2"
70+
tokio = { version = "0.2", default-features = false, features = ["rt-core", "time", "io-util", "process", "rt-util"] }
71+
tokio-util = { version = "0.3", default-features = false, features = ["codec"] }
72+
futures = "0.3"
7673

7774
[build-dependencies]
7875
rustc_tools_util = "0.2"
7976

8077
[features]
8178
clippy = ["clippy_lints", "rls-rustc/clippy"]
82-
ipc = ["tokio", "futures", "rls-rustc/ipc", "rls-ipc/server"]
79+
ipc = ["rls-rustc/ipc", "rls-ipc/server"]
8380
default = ["ipc"]

rls-ipc/Cargo.toml

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ repository = "https://github.com/rust-lang/rls"
99
categories = ["development-tools"]
1010

1111
[dependencies]
12-
jsonrpc-core = "14"
13-
jsonrpc-core-client = "14"
14-
jsonrpc-derive = "14"
15-
# Pin 14.0.3 to use single parity-tokio-ipc version (0.2)
16-
jsonrpc-ipc-server = { version = "=14.0.3", optional = true }
12+
jsonrpc-core = "17"
13+
jsonrpc-core-client = "17"
14+
jsonrpc-derive = "17"
15+
jsonrpc-ipc-server = { version = "17", optional = true }
1716
rls-data = "0.19"
1817
serde = { version = "1.0", features = ["derive"] }
1918

rls-rustc/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ env_logger = "0.7"
1313
log = "0.4"
1414
rand = "0.7"
1515
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "d236b30a1d638340aad8345fa2946cfe9543dcf0", optional = true }
16-
tokio = { version = "0.1", optional = true }
17-
futures = { version = "0.1", optional = true }
16+
tokio = { version = "0.2", optional = true }
17+
futures = { version = "0.3", optional = true }
1818
serde = { version = "1", features = ["derive"], optional = true }
1919
rls-data = { version = "0.19", optional = true }
2020
rls-ipc = { path = "../rls-ipc", optional = true }

rls-rustc/src/ipc.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::collections::{HashMap, HashSet};
2+
use std::future::Future;
23
use std::io;
34
use std::path::{Path, PathBuf};
45

5-
use futures::Future;
6-
76
use rls_ipc::client::{Client as JointClient, RpcChannel, RpcError};
87
use rls_ipc::rpc::callbacks::Client as CallbacksClient;
98
use rls_ipc::rpc::file_loader::Client as FileLoaderClient;
@@ -30,13 +29,11 @@ impl IpcFileLoader {
3029

3130
impl rustc_span::source_map::FileLoader for IpcFileLoader {
3231
fn file_exists(&self, path: &Path) -> bool {
33-
self.0.file_exists(path.to_owned()).wait().unwrap()
32+
futures::executor::block_on(self.0.file_exists(path.to_owned())).unwrap()
3433
}
3534

3635
fn read_file(&self, path: &Path) -> io::Result<String> {
37-
self.0
38-
.read_file(path.to_owned())
39-
.wait()
36+
futures::executor::block_on(self.0.read_file(path.to_owned()))
4037
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e)))
4138
}
4239
}
@@ -48,14 +45,14 @@ impl IpcCallbacks {
4845
pub fn complete_analysis(
4946
&self,
5047
analysis: rls_data::Analysis,
51-
) -> impl Future<Item = (), Error = RpcError> {
48+
) -> impl Future<Output = Result<(), RpcError>> {
5249
self.0.complete_analysis(analysis)
5350
}
5451

5552
pub fn input_files(
5653
&self,
5754
input_files: HashMap<PathBuf, HashSet<rls_ipc::rpc::Crate>>,
58-
) -> impl Future<Item = (), Error = RpcError> {
55+
) -> impl Future<Output = Result<(), RpcError>> {
5956
self.0.input_files(input_files)
6057
}
6158
}

rls-rustc/src/lib.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ pub fn run() -> Result<(), ()> {
3434
#[cfg(feature = "ipc")]
3535
let (mut shim_calls, file_loader) = match std::env::var("RLS_IPC_ENDPOINT").ok() {
3636
Some(endpoint) => {
37-
#[allow(deprecated)] // Windows doesn't work with lazily-bound reactors
38-
let reactor = rt.reactor().clone();
39-
let connection =
40-
ipc::connect(endpoint, &reactor).expect("Couldn't connect to IPC endpoint");
41-
let client: ipc::Client =
42-
rt.block_on(connection).expect("Couldn't connect to IPC endpoint");
37+
let client: ipc::Client = rt
38+
.block_on(async { ipc::connect(endpoint).await })
39+
.expect("Couldn't connect to IPC endpoint");
4340
let (file_loader, callbacks) = client.split();
4441

4542
(
@@ -113,7 +110,6 @@ impl Callbacks for ShimCalls {
113110
) -> Compilation {
114111
use rustc_session::config::Input;
115112

116-
use futures::future::Future;
117113
use rls_ipc::rpc::{Crate, Edition};
118114
use std::collections::{HashMap, HashSet};
119115

@@ -149,7 +145,7 @@ impl Callbacks for ShimCalls {
149145
input_files.entry(file).or_default().insert(krate.clone());
150146
}
151147

152-
if let Err(e) = callbacks.input_files(input_files).wait() {
148+
if let Err(e) = futures::executor::block_on(callbacks.input_files(input_files)) {
153149
log::error!("Can't send input files as part of a compilation callback: {:?}", e);
154150
}
155151

@@ -162,8 +158,6 @@ impl Callbacks for ShimCalls {
162158
compiler: &interface::Compiler,
163159
queries: &'tcx Queries<'tcx>,
164160
) -> Compilation {
165-
use futures::future::Future;
166-
167161
let callbacks = match self.callbacks.as_ref() {
168162
Some(callbacks) => callbacks,
169163
None => return Compilation::Continue,
@@ -196,7 +190,9 @@ impl Callbacks for ShimCalls {
196190
CallbackHandler {
197191
callback: &mut |a| {
198192
let analysis = unsafe { ::std::mem::transmute(a.clone()) };
199-
if let Err(e) = callbacks.complete_analysis(analysis).wait() {
193+
if let Err(e) =
194+
futures::executor::block_on(callbacks.complete_analysis(analysis))
195+
{
200196
log::error!(
201197
"Can't send analysis as part of a compilation callback: {:?}",
202198
e

rls/src/build/ipc.rs

-6
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ pub fn start_with_handler(io: IoHandler) -> Result<Server, ()> {
5757
let endpoint_path = endpoint_path.clone();
5858
move || {
5959
log::trace!("Attempting to spin up IPC server at {}", endpoint_path);
60-
let runtime = tokio::runtime::Builder::new().core_threads(1).build().unwrap();
61-
#[allow(deprecated)] // Windows won't work with lazily bound reactor
62-
let (reactor, executor) = (runtime.reactor(), runtime.executor());
63-
6460
let server = ServerBuilder::new(io)
65-
.event_loop_executor(executor)
66-
.event_loop_reactor(reactor.clone())
6761
.start(&endpoint_path)
6862
.map_err(|_| log::warn!("Couldn't open socket"))
6963
.unwrap();

tests/client.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::fs;
22
use std::path::Path;
3-
use std::time::{Duration, Instant};
3+
use std::time::Duration;
44

5-
use futures::future::Future;
5+
use futures::future;
66
use lsp_types::{notification::*, request::*, *};
77
use serde::de::Deserialize;
88
use serde_json::json;
@@ -245,7 +245,8 @@ fn client_changing_workspace_lib_retains_diagnostics() {
245245

246246
let lib = rls.future_diagnostics("library/src/lib.rs");
247247
let bin = rls.future_diagnostics("binary/src/main.rs");
248-
let (lib, bin) = rls.block_on(lib.join(bin)).unwrap();
248+
let (lib, bin) = rls.block_on(future::join(lib, bin)).unwrap();
249+
let (lib, bin) = (lib.unwrap(), bin.unwrap());
249250

250251
assert!(lib.diagnostics.iter().any(|m| m.message.contains("unused variable: `test_val`")));
251252
assert!(lib.diagnostics.iter().any(|m| m.message.contains("unused variable: `unused`")));
@@ -268,7 +269,8 @@ fn client_changing_workspace_lib_retains_diagnostics() {
268269

269270
let lib = rls.future_diagnostics("library/src/lib.rs");
270271
let bin = rls.future_diagnostics("binary/src/main.rs");
271-
let (lib, bin) = rls.block_on(lib.join(bin)).unwrap();
272+
let (lib, bin) = rls.block_on(future::join(lib, bin)).unwrap();
273+
let (lib, bin) = (lib.unwrap(), bin.unwrap());
272274

273275
// lib unit tests have compile errors
274276
assert!(lib.diagnostics.iter().any(|m| m.message.contains("unused variable: `unused`")));
@@ -293,7 +295,8 @@ fn client_changing_workspace_lib_retains_diagnostics() {
293295

294296
let lib = rls.future_diagnostics("library/src/lib.rs");
295297
let bin = rls.future_diagnostics("binary/src/main.rs");
296-
let (lib, bin) = rls.block_on(lib.join(bin)).unwrap();
298+
let (lib, bin) = rls.block_on(future::join(lib, bin)).unwrap();
299+
let (lib, bin) = (lib.unwrap(), bin.unwrap());
297300

298301
assert!(lib.diagnostics.iter().any(|m| m.message.contains("unused variable: `test_val`")));
299302
assert!(lib.diagnostics.iter().any(|m| m.message.contains("unused variable: `unused`")));
@@ -349,6 +352,7 @@ fn client_implicit_workspace_pick_up_lib_changes() {
349352

350353
let bin = rls.future_diagnostics("src/main.rs");
351354
let bin = rls.block_on(bin).unwrap();
355+
let bin = bin.unwrap();
352356
assert!(bin.diagnostics[0].message.contains("unused variable: `val`"));
353357

354358
rls.notify::<DidChangeTextDocument>(DidChangeTextDocumentParams {
@@ -369,6 +373,7 @@ fn client_implicit_workspace_pick_up_lib_changes() {
369373
// bin depending on lib picks up type mismatch
370374
let bin = rls.future_diagnostics("src/main.rs");
371375
let bin = rls.block_on(bin).unwrap();
376+
let bin = bin.unwrap();
372377
assert!(bin.diagnostics[0].message.contains("cannot find function `foo`"));
373378

374379
rls.notify::<DidChangeTextDocument>(DidChangeTextDocumentParams {
@@ -388,6 +393,7 @@ fn client_implicit_workspace_pick_up_lib_changes() {
388393

389394
let bin = rls.future_diagnostics("src/main.rs");
390395
let bin = rls.block_on(bin).unwrap();
396+
let bin = bin.unwrap();
391397
assert!(bin.diagnostics[0].message.contains("unused variable: `val`"));
392398
}
393399

@@ -1971,7 +1977,7 @@ fn client_omit_init_build() {
19711977
// We need to assert that no other messages are received after a short
19721978
// period of time (e.g. no build progress messages).
19731979
std::thread::sleep(std::time::Duration::from_secs(1));
1974-
rls.block_on(response).unwrap();
1980+
rls.block_on(response).unwrap().unwrap();
19751981

19761982
assert_eq!(rls.messages().iter().count(), 1);
19771983
}
@@ -2141,8 +2147,7 @@ fn client_fail_uninitialized_request() {
21412147
},
21422148
);
21432149

2144-
let delay = tokio_timer::Delay::new(Instant::now() + Duration::from_secs(1));
2145-
rls.block_on(delay).unwrap();
2150+
rls.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await }).unwrap();
21462151

21472152
let err = jsonrpc_core::Failure::deserialize(rls.messages().last().unwrap()).unwrap();
21482153
assert_eq!(err.id, jsonrpc_core::Id::Num(ID));

tests/support/client/child_process.rs

+29-23
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,61 @@
1-
use std::io::{Read, Write};
1+
use std::io;
2+
use std::pin::Pin;
23
use std::process::{Command, Stdio};
34
use std::rc::Rc;
5+
use std::task::{Context, Poll};
46

5-
use futures::Poll;
67
use tokio::io::{AsyncRead, AsyncWrite};
7-
use tokio_process::{Child, CommandExt};
88

99
pub struct ChildProcess {
10-
stdin: tokio_process::ChildStdin,
11-
stdout: tokio_process::ChildStdout,
12-
child: Rc<tokio_process::Child>,
10+
stdin: tokio::process::ChildStdin,
11+
stdout: tokio::process::ChildStdout,
12+
child: Rc<tokio::process::Child>,
1313
}
1414

15-
impl Read for ChildProcess {
16-
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
17-
Read::read(&mut self.stdout, buf)
15+
impl AsyncRead for ChildProcess {
16+
fn poll_read(
17+
mut self: Pin<&mut Self>,
18+
cx: &mut Context<'_>,
19+
buf: &mut [u8],
20+
) -> Poll<io::Result<usize>> {
21+
Pin::new(&mut self.stdout).poll_read(cx, buf)
1822
}
1923
}
2024

21-
impl Write for ChildProcess {
22-
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
23-
Write::write(&mut self.stdin, buf)
25+
impl AsyncWrite for ChildProcess {
26+
fn poll_write(
27+
mut self: Pin<&mut Self>,
28+
cx: &mut Context<'_>,
29+
buf: &[u8],
30+
) -> Poll<io::Result<usize>> {
31+
Pin::new(&mut self.stdin).poll_write(cx, buf)
2432
}
25-
fn flush(&mut self) -> std::io::Result<()> {
26-
Write::flush(&mut self.stdin)
33+
34+
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
35+
Pin::new(&mut self.stdin).poll_flush(cx)
2736
}
28-
}
2937

30-
impl AsyncRead for ChildProcess {}
31-
impl AsyncWrite for ChildProcess {
32-
fn shutdown(&mut self) -> Poll<(), std::io::Error> {
33-
AsyncWrite::shutdown(&mut self.stdin)
38+
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
39+
Pin::new(&mut self.stdin).poll_shutdown(cx)
3440
}
3541
}
3642

3743
impl ChildProcess {
3844
pub fn spawn_from_command(mut cmd: Command) -> Result<ChildProcess, std::io::Error> {
3945
cmd.stdin(Stdio::piped());
4046
cmd.stdout(Stdio::piped());
41-
let mut child = cmd.spawn_async()?;
47+
let mut child = tokio::process::Command::from(cmd).spawn().expect("to async spawn process");
4248

4349
Ok(ChildProcess {
44-
stdout: child.stdout().take().unwrap(),
45-
stdin: child.stdin().take().unwrap(),
50+
stdout: child.stdout.take().unwrap(),
51+
stdin: child.stdin.take().unwrap(),
4652
child: Rc::new(child),
4753
})
4854
}
4955

5056
/// Returns a handle to the underlying `Child` process.
5157
/// Useful when waiting until child process exits.
52-
pub fn child(&self) -> Rc<Child> {
58+
pub fn child(&self) -> Rc<tokio::process::Child> {
5359
Rc::clone(&self.child)
5460
}
5561
}

0 commit comments

Comments
 (0)