diff --git a/Cargo.lock b/Cargo.lock index 516cdb2..8018fdd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,9 +75,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2faccea4cc4ab4a667ce676a30e8ec13922a692c99bb8f5b11f1502c72e04220" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anstyle-parse" @@ -289,15 +289,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "deranged" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" -dependencies = [ - "powerfmt", -] - [[package]] name = "difference" version = "2.0.0" @@ -360,15 +351,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "error-chain" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" -dependencies = [ - "version_check", -] - [[package]] name = "exitcode" version = "1.1.2" @@ -387,107 +369,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" -[[package]] -name = "flume" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" -dependencies = [ - "futures-core", - "futures-sink", - "nanorand", - "spin", -] - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2 1.0.78", - "quote 1.0.35", - "syn 2.0.48", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - [[package]] name = "gc" version = "0.5.0" @@ -526,10 +407,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi", - "wasm-bindgen", ] [[package]] @@ -571,26 +450,15 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" - -[[package]] -name = "hostname" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" -dependencies = [ - "libc", - "match_cfg", - "winapi", -] +checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" [[package]] name = "iana-time-zone" -version = "0.1.59" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -638,9 +506,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.67" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" dependencies = [ "wasm-bindgen", ] @@ -679,16 +547,6 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -705,12 +563,6 @@ dependencies = [ "log", ] -[[package]] -name = "match_cfg" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" - [[package]] name = "memchr" version = "2.7.1" @@ -719,9 +571,9 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ "adler", ] @@ -737,15 +589,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "nanorand" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" -dependencies = [ - "getrandom", -] - [[package]] name = "nix" version = "0.27.1" @@ -757,12 +600,6 @@ dependencies = [ "libc", ] -[[package]] -name = "num-conv" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" - [[package]] name = "num-traits" version = "0.2.17" @@ -772,15 +609,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_threads" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" -dependencies = [ - "libc", -] - [[package]] name = "object" version = "0.32.2" @@ -802,6 +630,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "owo-colors" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caff54706df99d2a78a5a4e3455ff45448d81ef1bb63c22cd14052ca0e993a3f" + [[package]] name = "pest" version = "2.7.7" @@ -853,24 +687,12 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pkg-config" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - [[package]] name = "proc-macro2" version = "0.4.30" @@ -963,7 +785,6 @@ dependencies = [ "async-recursion", "bstr", "dirs", - "futures", "gc", "log", "nix", @@ -981,21 +802,18 @@ dependencies = [ "clap", "directories", "exitcode", - "flume", - "futures", "log", "log-panics", + "owo-colors", "riptide-runtime", "riptide-stdlib", "rusqlite", "scopeguard", "serde", - "syslog", "termios", "tokio", "toml", "vte", - "yansi", ] [[package]] @@ -1131,15 +949,6 @@ dependencies = [ "libc", ] -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - [[package]] name = "smallvec" version = "1.13.1" @@ -1156,15 +965,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "stderrlog" version = "0.6.0" @@ -1229,19 +1029,6 @@ dependencies = [ "unicode-xid 0.2.4", ] -[[package]] -name = "syslog" -version = "6.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7434e95bcccce1215d30f4bf84fe8c00e8de1b9be4fb736d747ca53d36e7f96f" -dependencies = [ - "error-chain", - "hostname", - "libc", - "log", - "time", -] - [[package]] name = "termcolor" version = "1.1.3" @@ -1302,39 +1089,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "time" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe80ced77cbfb4cb91a94bf72b378b4b6791a0d9b7f09d0be747d1bdff4e68bd" -dependencies = [ - "deranged", - "itoa", - "libc", - "num-conv", - "num_threads", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" - -[[package]] -name = "time-macros" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" -dependencies = [ - "num-conv", - "time-core", -] - [[package]] name = "tokio" version = "1.36.0" @@ -1490,9 +1244,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1500,9 +1254,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" dependencies = [ "bumpalo", "log", @@ -1515,9 +1269,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" dependencies = [ "quote 1.0.35", "wasm-bindgen-macro-support", @@ -1525,9 +1279,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", @@ -1538,9 +1292,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" [[package]] name = "winapi" @@ -1723,12 +1477,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" - [[package]] name = "zerocopy" version = "0.7.32" diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 2f42998..3dcd46f 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -11,7 +11,6 @@ edition.workspace = true async-recursion = "1.0" bstr = "1.9" dirs.workspace = true -futures = "0.3" log.workspace = true regex.workspace = true riptide-syntax.path = "../syntax" diff --git a/runtime/src/eval.rs b/runtime/src/eval.rs index 292a528..c7b5b34 100644 --- a/runtime/src/eval.rs +++ b/runtime/src/eval.rs @@ -13,10 +13,10 @@ use crate::{ throw, value::Value, }; -use futures::future::try_join_all; use gc::Gc; use riptide_syntax::{ast::*, parse, source::*}; use std::ops::ControlFlow::Continue; +use tokio::task::JoinSet; /// Compile the given source code as a closure. pub(crate) fn compile( @@ -239,28 +239,32 @@ async fn evaluate_pipeline(fiber: &mut Fiber, pipeline: Pipeline) -> ControlFlow // pipes between them for their I/O context, and then execute each call // in the pipeline in their respective fibers concurrently. count => { - let mut futures = Vec::new(); + let mut values = Vec::with_capacity(count); + let mut futures = JoinSet::new(); + let mut ios = match fiber.io.try_clone().and_then(|io| io.split_n(count)) { Ok(io) => io.into_iter(), Err(e) => return ControlFlow::Break(BreakAction::Throw(e.into())), }; - for call in pipeline.0.iter() { + for call in pipeline.0 { let mut fiber = fiber.fork(); fiber.io = ios.next().unwrap(); - futures.push(async move { - match evaluate_call(&mut fiber, call.clone()).await { - Continue(value) => Ok(value), - ControlFlow::Break(action) => Err(action), - } + futures.spawn_local(async move { + evaluate_call(&mut fiber, call).await }); } - match try_join_all(futures).await { - Ok(values) => Continue(Value::List(values)), - Err(action) => ControlFlow::Break(action), + while let Some(result) = futures.join_next().await { + match result { + Ok(Continue(value)) => values.push(value), + Ok(ControlFlow::Break(action)) => return ControlFlow::Break(action), + Err(e) => throw_cf!("{}", e), + } } + + Continue(Value::List(values)) } } } diff --git a/runtime/src/foreign.rs b/runtime/src/foreign.rs index b89491b..70da9c1 100644 --- a/runtime/src/foreign.rs +++ b/runtime/src/foreign.rs @@ -1,9 +1,7 @@ use crate::prelude::*; -use futures::future::{FutureExt, LocalBoxFuture}; -use std::{ - future::Future, - rc::Rc, -}; +use std::{future::Future, pin::Pin, rc::Rc}; + +type LocalBoxFuture<'a, T> = Pin + 'a>>; /// A native function that can be invoked by scripts through a runtime as well /// as in native code. @@ -30,15 +28,23 @@ mod private { use super::*; pub trait ForeignFnTrait: 'static { - fn call<'a>(&self, fiber: &'a mut Fiber, args: Vec) -> LocalBoxFuture<'a, Result>; + fn call<'a>( + &self, + fiber: &'a mut Fiber, + args: Vec, + ) -> LocalBoxFuture<'a, Result>; } impl ForeignFnTrait for F where - F: for<'a> AsyncFn2<&'a mut Fiber, Vec, Output = Result> + 'static + F: for<'a> AsyncFn2<&'a mut Fiber, Vec, Output = Result> + 'static, { - fn call<'a>(&self, fiber: &'a mut Fiber, args: Vec) -> LocalBoxFuture<'a, Result> { - self.call(fiber, args).boxed_local() + fn call<'a>( + &self, + fiber: &'a mut Fiber, + args: Vec, + ) -> LocalBoxFuture<'a, Result> { + Box::pin(self.call(fiber, args)) } } diff --git a/shell/Cargo.toml b/shell/Cargo.toml index 15344ea..fccc070 100644 --- a/shell/Cargo.toml +++ b/shell/Cargo.toml @@ -9,14 +9,11 @@ edition.workspace = true [dependencies] directories.workspace = true exitcode = "1.1" -flume = "0.11" -futures = "0.3" +owo-colors = "4" riptide-runtime.path = "../runtime" riptide-stdlib.path = "../stdlib" scopeguard.workspace = true -syslog = "6" toml = "0.8" -yansi = "0.5" [dependencies.clap] version = "4.4" diff --git a/shell/src/editor/mod.rs b/shell/src/editor/mod.rs index 9b63a82..4a999cc 100644 --- a/shell/src/editor/mod.rs +++ b/shell/src/editor/mod.rs @@ -6,13 +6,13 @@ use crate::{ os::{TerminalInput, TerminalOutput}, theme::Theme, }; +use owo_colors::OwoColorize; use riptide_runtime::{Fiber, Value}; use std::{ fmt::Write, os::unix::io::AsRawFd, }; use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt}; -use yansi::Paint; pub mod command; pub mod event; @@ -89,7 +89,7 @@ impl Editor { write!( &mut buf, "{}{}", - Paint::blue(theme.prompt.as_ref().unwrap().item_format.as_ref().unwrap().replace("%s", &cwd)), + theme.prompt.as_ref().unwrap().item_format.as_ref().unwrap().replace("%s", &cwd).blue(), theme.prompt.as_ref().unwrap().item_separator.as_ref().unwrap(), ).unwrap(); @@ -236,7 +236,7 @@ impl Editor if let Some(suffix) = suggestion.strip_prefix(self.buffer.text()) { if !suffix.is_empty() { self.stdout - .write_all(format!("{}", Paint::new(suffix).dimmed()).as_bytes()) + .write_all(format!("{}", suffix.dimmed()).as_bytes()) .await .unwrap(); diff --git a/shell/src/logger.rs b/shell/src/logger.rs index f2af644..4159e55 100644 --- a/shell/src/logger.rs +++ b/shell/src/logger.rs @@ -1,13 +1,8 @@ -use log::{ - Level, - LevelFilter, - Log, - Metadata, - Record, -}; +use log::{Level, LevelFilter, Log, Metadata, Record}; use std::{ io::IsTerminal, net::UdpSocket, + sync::mpsc::{sync_channel, SyncSender}, thread, }; @@ -32,14 +27,14 @@ pub fn init(level: LevelFilter) { /// tool like `socat`, this allows you to read even noisy debug logs without /// messing up the interactive shell. struct UdpLogger { - sender: flume::Sender, + sender: SyncSender, inner: L, } impl UdpLogger { fn new(inner: L) -> Self { let socket = UdpSocket::bind("127.0.0.1:0").unwrap(); - let (sender, receiver) = flume::bounded::(1024); + let (sender, receiver) = sync_channel::(1024); thread::spawn(move || { for record in receiver.iter() { @@ -47,10 +42,7 @@ impl UdpLogger { } }); - Self { - sender, - inner, - } + Self { sender, inner } } } @@ -60,7 +52,9 @@ impl Log for UdpLogger { } fn log(&self, record: &Record) { - let _ = self.sender.send(format!("{}: {}\n", record.level(), record.args())); + let _ = self + .sender + .send(format!("{}: {}\n", record.level(), record.args())); self.inner.log(record); }