diff --git a/nix-js/benches/basic_ops.rs b/nix-js/benches/basic_ops.rs index 155479d..4a1b170 100644 --- a/nix-js/benches/basic_ops.rs +++ b/nix-js/benches/basic_ops.rs @@ -1,7 +1,8 @@ mod utils; -use criterion::{Criterion, criterion_group, criterion_main}; use std::hint::black_box; + +use criterion::{Criterion, criterion_group, criterion_main}; use utils::eval; fn bench_arithmetic(c: &mut Criterion) { diff --git a/nix-js/benches/builtins.rs b/nix-js/benches/builtins.rs index 9e29907..5e6e7ef 100644 --- a/nix-js/benches/builtins.rs +++ b/nix-js/benches/builtins.rs @@ -1,7 +1,8 @@ mod utils; -use criterion::{Criterion, criterion_group, criterion_main}; use std::hint::black_box; + +use criterion::{Criterion, criterion_group, criterion_main}; use utils::eval; fn bench_builtin_math(c: &mut Criterion) { diff --git a/nix-js/benches/compile_time.rs b/nix-js/benches/compile_time.rs index d4e6436..fbfec20 100644 --- a/nix-js/benches/compile_time.rs +++ b/nix-js/benches/compile_time.rs @@ -1,8 +1,9 @@ mod utils; +use std::hint::black_box; + use criterion::{Criterion, criterion_group, criterion_main}; use nix_js::context::Context; -use std::hint::black_box; use utils::compile; fn bench_parse_and_downgrade(c: &mut Criterion) { diff --git a/nix-js/benches/thunk_scope.rs b/nix-js/benches/thunk_scope.rs index c90473e..d71e3ad 100644 --- a/nix-js/benches/thunk_scope.rs +++ b/nix-js/benches/thunk_scope.rs @@ -1,7 +1,8 @@ mod utils; -use criterion::{Criterion, criterion_group, criterion_main}; use std::hint::black_box; + +use criterion::{Criterion, criterion_group, criterion_main}; use utils::eval; fn bench_non_recursive(c: &mut Criterion) { diff --git a/nix-js/src/context.rs b/nix-js/src/context.rs index 447c686..5d97c45 100644 --- a/nix-js/src/context.rs +++ b/nix-js/src/context.rs @@ -8,7 +8,7 @@ use hashbrown::{DefaultHashBuilder, HashMap, HashSet, HashTable}; use rnix::TextRange; use string_interner::DefaultStringInterner; -use crate::bytecode::{self, BytecodeContext, Bytecode, Constant}; +use crate::bytecode::{self, Bytecode, BytecodeContext, Constant}; use crate::codegen::{CodegenContext, compile}; use crate::disassembler::{Disassembler, DisassemblerContext}; use crate::downgrade::*; @@ -383,11 +383,7 @@ impl Ctx { Ok(bytecode) } - fn compile_bytecode_scoped( - &mut self, - source: Source, - scope: Vec, - ) -> Result { + fn compile_bytecode_scoped(&mut self, source: Source, scope: Vec) -> Result { let scope = Scope::ScopedImport( scope .into_iter() @@ -477,11 +473,7 @@ impl RuntimeContext for Ctx { fn compile_bytecode(&mut self, source: Source) -> Result { self.compile_bytecode(source) } - fn compile_bytecode_scoped( - &mut self, - source: Source, - scope: Vec, - ) -> Result { + fn compile_bytecode_scoped(&mut self, source: Source, scope: Vec) -> Result { self.compile_bytecode_scoped(source, scope) } fn get_source(&self, id: usize) -> Source { @@ -494,11 +486,11 @@ impl RuntimeContext for Ctx { let spans = unsafe { &*self.spans.get() }; spans[id] } - fn take_unsynced(&mut self) -> (Vec, Vec, usize, usize) { + fn get_unsynced(&mut self) -> (&[String], &[Constant], usize, usize) { let strings_base = self.synced_strings; let constants_base = self.synced_constants; - let new_strings = self.global_strings[strings_base..].to_vec(); - let new_constants = self.global_constants[constants_base..].to_vec(); + let new_strings = &self.global_strings[strings_base..]; + let new_constants = &self.global_constants[constants_base..]; self.synced_strings = self.global_strings.len(); self.synced_constants = self.global_constants.len(); (new_strings, new_constants, strings_base, constants_base) @@ -507,10 +499,14 @@ impl RuntimeContext for Ctx { impl DisassemblerContext for Ctx { fn lookup_string(&self, id: u32) -> &str { - self.global_strings.get(id as usize).expect("string not found") + self.global_strings + .get(id as usize) + .expect("string not found") } fn lookup_constant(&self, id: u32) -> &Constant { - self.global_constants.get(id as usize).expect("constant not found") + self.global_constants + .get(id as usize) + .expect("constant not found") } } diff --git a/nix-js/src/downgrade.rs b/nix-js/src/downgrade.rs index 6bc8477..c69feec 100644 --- a/nix-js/src/downgrade.rs +++ b/nix-js/src/downgrade.rs @@ -25,8 +25,8 @@ impl<'id: 'ir, 'ir, Ctx: DowngradeContext<'id, 'ir>, T> Require<'id, 'ir, Ctx, T } } -impl<'id: 'ir, 'ir, Ctx: DowngradeContext<'id, 'ir>, T, E: std::fmt::Display> Require<'id, 'ir, Ctx, T> - for std::result::Result +impl<'id: 'ir, 'ir, Ctx: DowngradeContext<'id, 'ir>, T, E: std::fmt::Display> + Require<'id, 'ir, Ctx, T> for std::result::Result { #[inline] fn require(self, ctx: &Ctx, span: TextRange) -> Result { diff --git a/nix-js/src/fetcher/download.rs b/nix-js/src/fetcher/download.rs index 2295dc9..7fad254 100644 --- a/nix-js/src/fetcher/download.rs +++ b/nix-js/src/fetcher/download.rs @@ -1,6 +1,7 @@ -use reqwest::blocking::Client; use std::time::Duration; +use reqwest::blocking::Client; + pub struct Downloader { client: Client, } diff --git a/nix-js/src/fetcher/metadata_cache.rs b/nix-js/src/fetcher/metadata_cache.rs index 39180aa..dc8592f 100644 --- a/nix-js/src/fetcher/metadata_cache.rs +++ b/nix-js/src/fetcher/metadata_cache.rs @@ -1,9 +1,10 @@ #![allow(dead_code)] +use std::path::PathBuf; +use std::time::{SystemTime, UNIX_EPOCH}; + use rusqlite::{Connection, OptionalExtension, params}; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; -use std::time::{SystemTime, UNIX_EPOCH}; #[derive(Debug)] pub enum CacheError { diff --git a/nix-js/src/logging.rs b/nix-js/src/logging.rs index 78b147c..7110edb 100644 --- a/nix-js/src/logging.rs +++ b/nix-js/src/logging.rs @@ -1,5 +1,6 @@ use std::env; use std::io::IsTerminal; + use tracing_subscriber::{EnvFilter, Layer, fmt, layer::SubscriberExt, util::SubscriberInitExt}; pub fn init_logging() { diff --git a/nix-js/src/nar.rs b/nix-js/src/nar.rs index 4e38910..77b3579 100644 --- a/nix-js/src/nar.rs +++ b/nix-js/src/nar.rs @@ -1,8 +1,9 @@ -use nix_nar::Encoder; -use sha2::{Digest, Sha256}; use std::io::Read; use std::path::Path; +use nix_nar::Encoder; +use sha2::{Digest, Sha256}; + use crate::error::{Error, Result}; pub fn compute_nar_hash(path: &Path) -> Result<[u8; 32]> { @@ -27,10 +28,12 @@ pub fn pack_nar(path: &Path) -> Result> { #[cfg(test)] #[allow(clippy::unwrap_used)] mod tests { - use super::*; use std::fs; + use tempfile::TempDir; + use super::*; + #[test_log::test] fn test_simple_file() { let temp = TempDir::new().unwrap(); diff --git a/nix-js/src/runtime.rs b/nix-js/src/runtime.rs index 7a878e9..f45227c 100644 --- a/nix-js/src/runtime.rs +++ b/nix-js/src/runtime.rs @@ -26,15 +26,11 @@ pub(crate) trait RuntimeContext: 'static { fn compile(&mut self, source: Source) -> Result; fn compile_scoped(&mut self, source: Source, scope: Vec) -> Result; fn compile_bytecode(&mut self, source: Source) -> Result; - fn compile_bytecode_scoped( - &mut self, - source: Source, - scope: Vec, - ) -> Result; + fn compile_bytecode_scoped(&mut self, source: Source, scope: Vec) -> Result; fn get_source(&self, id: usize) -> Source; fn get_store(&self) -> &DaemonStore; fn get_span(&self, id: usize) -> (usize, rnix::TextRange); - fn take_unsynced(&mut self) -> (Vec, Vec, usize, usize); + fn get_unsynced(&mut self) -> (&[String], &[Constant], usize, usize); } pub(crate) trait OpStateExt { @@ -465,7 +461,7 @@ fn sync_global_tables( cached: &CachedFunctions, ctx: &mut Ctx, ) { - let (new_strings, new_constants, strings_base, constants_base) = ctx.take_unsynced(); + let (new_strings, new_constants, strings_base, constants_base) = ctx.get_unsynced(); if !new_strings.is_empty() { let s_array = v8::Local::new(scope, &cached.strings_array); diff --git a/nix-js/src/runtime/inspector.rs b/nix-js/src/runtime/inspector.rs index 3ab8ba9..781278f 100644 --- a/nix-js/src/runtime/inspector.rs +++ b/nix-js/src/runtime/inspector.rs @@ -2,6 +2,14 @@ // Alias for the future `!` type. use core::convert::Infallible as Never; +use std::cell::RefCell; +use std::net::SocketAddr; +use std::pin::pin; +use std::process; +use std::rc::Rc; +use std::task::Poll; +use std::thread; + use deno_core::InspectorMsg; use deno_core::InspectorSessionChannels; use deno_core::InspectorSessionKind; @@ -24,13 +32,6 @@ use fastwebsockets::WebSocket; use hashbrown::HashMap; use hyper::body::Bytes; use hyper_util::rt::TokioIo; -use std::cell::RefCell; -use std::net::SocketAddr; -use std::pin::pin; -use std::process; -use std::rc::Rc; -use std::task::Poll; -use std::thread; use tokio::net::TcpListener; use tokio::sync::broadcast; use uuid::Uuid; diff --git a/nix-js/src/store/daemon.rs b/nix-js/src/store/daemon.rs index eed6213..8ce4705 100644 --- a/nix-js/src/store/daemon.rs +++ b/nix-js/src/store/daemon.rs @@ -87,11 +87,12 @@ impl Store for DaemonStore { recursive: bool, references: Vec, ) -> Result { + use std::fs; + use nix_compat::nix_daemon::types::AddToStoreNarRequest; use nix_compat::nixhash::{CAHash, NixHash}; use nix_compat::store_path::{StorePath, build_ca_path}; use sha2::{Digest, Sha256}; - use std::fs; use tempfile::NamedTempFile; let temp_file = NamedTempFile::new() @@ -237,11 +238,12 @@ impl Store for DaemonStore { content: &str, references: Vec, ) -> Result { + use std::fs; + use nix_compat::nix_daemon::types::AddToStoreNarRequest; use nix_compat::nixhash::CAHash; use nix_compat::store_path::{StorePath, build_text_path}; use sha2::{Digest, Sha256}; - use std::fs; use tempfile::NamedTempFile; let temp_file = NamedTempFile::new() diff --git a/nix-js/src/value.rs b/nix-js/src/value.rs index 8161084..49fa388 100644 --- a/nix-js/src/value.rs +++ b/nix-js/src/value.rs @@ -1,7 +1,6 @@ use core::fmt::{Debug, Display, Formatter, Result as FmtResult}; use core::hash::Hash; use core::ops::Deref; - use std::borrow::Cow; use std::collections::BTreeMap; use std::ops::DerefMut; diff --git a/nix-js/tests/tests/basic_eval.rs b/nix-js/tests/tests/basic_eval.rs index 828ab50..6a00e44 100644 --- a/nix-js/tests/tests/basic_eval.rs +++ b/nix-js/tests/tests/basic_eval.rs @@ -1,6 +1,7 @@ -use crate::utils::{eval, eval_result}; use nix_js::value::Value; +use crate::utils::{eval, eval_result}; + #[test_log::test] fn arithmetic() { assert_eq!(eval("1 + 1"), Value::Int(2)); diff --git a/nix-js/tests/tests/builtins.rs b/nix-js/tests/tests/builtins.rs index c18dedb..6cd944b 100644 --- a/nix-js/tests/tests/builtins.rs +++ b/nix-js/tests/tests/builtins.rs @@ -1,7 +1,9 @@ -use crate::utils::eval; -use nix_js::value::{AttrSet, List, Value}; use std::collections::BTreeMap; +use nix_js::value::{AttrSet, List, Value}; + +use crate::utils::eval; + #[test_log::test] fn builtins_accessible() { let result = eval("builtins"); diff --git a/nix-js/tests/tests/builtins_store.rs b/nix-js/tests/tests/builtins_store.rs index 58127e1..1c21414 100644 --- a/nix-js/tests/tests/builtins_store.rs +++ b/nix-js/tests/tests/builtins_store.rs @@ -1,6 +1,7 @@ -use crate::utils::eval_result; use nix_js::value::Value; +use crate::utils::eval_result; + #[test_log::test] fn to_file_simple() { let result = diff --git a/nix-js/tests/tests/derivation.rs b/nix-js/tests/tests/derivation.rs index 5509622..5eb2937 100644 --- a/nix-js/tests/tests/derivation.rs +++ b/nix-js/tests/tests/derivation.rs @@ -1,6 +1,7 @@ -use crate::utils::{eval_deep, eval_deep_result}; use nix_js::value::Value; +use crate::utils::{eval_deep, eval_deep_result}; + #[test_log::test] fn add_operator_preserves_derivation_context() { let result = eval_deep( diff --git a/nix-js/tests/tests/free_globals.rs b/nix-js/tests/tests/free_globals.rs index 8e23396..6f7b13e 100644 --- a/nix-js/tests/tests/free_globals.rs +++ b/nix-js/tests/tests/free_globals.rs @@ -1,6 +1,7 @@ -use crate::utils::{eval, eval_result}; use nix_js::value::{List, Value}; +use crate::utils::{eval, eval_result}; + #[test_log::test] fn true_literal() { assert_eq!(eval("true"), Value::Bool(true)); diff --git a/nix-js/tests/tests/functions.rs b/nix-js/tests/tests/functions.rs index b3a06b1..5bf9199 100644 --- a/nix-js/tests/tests/functions.rs +++ b/nix-js/tests/tests/functions.rs @@ -1,6 +1,7 @@ -use crate::utils::{eval, eval_result}; use nix_js::value::Value; +use crate::utils::{eval, eval_result}; + #[test_log::test] fn required_parameters() { assert_eq!(eval("({ a, b }: a + b) { a = 1; b = 2; }"), Value::Int(3)); diff --git a/nix-js/tests/tests/io_operations.rs b/nix-js/tests/tests/io_operations.rs index dd85770..a22e4c5 100644 --- a/nix-js/tests/tests/io_operations.rs +++ b/nix-js/tests/tests/io_operations.rs @@ -1,8 +1,9 @@ -use crate::utils::{eval, eval_result}; use nix_js::context::Context; use nix_js::error::Source; use nix_js::value::Value; +use crate::utils::{eval, eval_result}; + #[test_log::test] fn import_absolute_path() { let temp_dir = tempfile::tempdir().unwrap(); diff --git a/nix-js/tests/tests/numeric_types.rs b/nix-js/tests/tests/numeric_types.rs index 4b0c3f2..a0465e7 100644 --- a/nix-js/tests/tests/numeric_types.rs +++ b/nix-js/tests/tests/numeric_types.rs @@ -1,6 +1,7 @@ -use crate::utils::eval; use nix_js::value::Value; +use crate::utils::eval; + #[test_log::test] fn large_i64_max() { assert_eq!(eval("9223372036854775807"), Value::Int(9223372036854775807)); diff --git a/nix-js/tests/tests/operators.rs b/nix-js/tests/tests/operators.rs index 7adddee..fb9d66d 100644 --- a/nix-js/tests/tests/operators.rs +++ b/nix-js/tests/tests/operators.rs @@ -1,7 +1,9 @@ -use crate::utils::eval; -use nix_js::value::{AttrSet, List, Symbol, Value}; use std::collections::BTreeMap; +use nix_js::value::{AttrSet, List, Symbol, Value}; + +use crate::utils::eval; + #[test_log::test] fn addition() { assert_eq!(eval("1 + 1"), Value::Int(2)); diff --git a/nix-js/tests/tests/path_operations.rs b/nix-js/tests/tests/path_operations.rs index 470843c..609d3f7 100644 --- a/nix-js/tests/tests/path_operations.rs +++ b/nix-js/tests/tests/path_operations.rs @@ -1,6 +1,7 @@ -use crate::utils::{eval, eval_result}; use nix_js::value::Value; +use crate::utils::{eval, eval_result}; + #[test_log::test] fn path_type_of() { let result = eval("builtins.typeOf ./foo"); diff --git a/nix-js/tests/tests/regex.rs b/nix-js/tests/tests/regex.rs index 4c4f328..358346c 100644 --- a/nix-js/tests/tests/regex.rs +++ b/nix-js/tests/tests/regex.rs @@ -1,6 +1,6 @@ -use crate::utils::eval; use nix_js::value::{List, Value}; +use crate::utils::eval; use crate::utils::eval_result; #[test_log::test] diff --git a/nix-js/tests/tests/string_context.rs b/nix-js/tests/tests/string_context.rs index 4b0b0d8..85ed1d0 100644 --- a/nix-js/tests/tests/string_context.rs +++ b/nix-js/tests/tests/string_context.rs @@ -1,7 +1,8 @@ -use crate::utils::eval_result; use nix_js::context::Context; use nix_js::value::Value; +use crate::utils::eval_result; + fn eval(expr: &str) -> Value { eval_result(expr).unwrap_or_else(|e| panic!("{}", e)) } diff --git a/nix-js/tests/tests/thunk_scope.rs b/nix-js/tests/tests/thunk_scope.rs index 0bdfbc3..dfc9f52 100644 --- a/nix-js/tests/tests/thunk_scope.rs +++ b/nix-js/tests/tests/thunk_scope.rs @@ -1,6 +1,7 @@ -use crate::utils::eval; use nix_js::value::Value; +use crate::utils::eval; + #[test_log::test] fn non_recursive_bindings() { assert_eq!(eval("let x = 1; y = 2; z = x + y; in z"), Value::Int(3)); diff --git a/nix-js/tests/tests/to_string.rs b/nix-js/tests/tests/to_string.rs index 7614990..e1a27bb 100644 --- a/nix-js/tests/tests/to_string.rs +++ b/nix-js/tests/tests/to_string.rs @@ -1,6 +1,7 @@ -use crate::utils::{eval, eval_result}; use nix_js::value::Value; +use crate::utils::{eval, eval_result}; + #[test_log::test] fn string_returns_as_is() { assert_eq!( diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..bf96e77 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +group_imports = "StdExternalCrate"