From c14c6cb91a9f624ae55653b36620372ccc81c8c3 Mon Sep 17 00:00:00 2001 From: Lionel Sambuc Date: Fri, 9 Aug 2024 19:15:19 +0200 Subject: [PATCH] Updated compiler and dependencies * Upgraded to rustc 1.80 * Updated dependencies * Fixed most linter warnings --- Cargo.toml | 11 +++++++---- rust-toolchain.toml | 2 ++ src/executors.rs | 9 ++++----- src/lib.rs | 14 +++++++------- src/predictors.rs | 2 +- src/queries.lalrpop | 2 +- src/symbols.rs | 14 ++++++-------- src/types.rs | 21 ++++----------------- src/validators.rs | 7 ++----- 9 files changed, 34 insertions(+), 48 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/Cargo.toml b/Cargo.toml index 950be1b..a260669 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,15 +37,18 @@ bin = ["measure_time", "pretty_env_logger"] [dependencies] mercator_db = "0.1" -lalrpop-util = "0.19.0" + +lalrpop-util = "0.20" +regex = "1.10" # Logging macros API #log = { version = "0.4", features = ["max_level_trace", "release_max_level_info"] } log = { version = "0.4", features = ["max_level_trace", "release_max_level_trace"] } # Used for main.rs -pretty_env_logger = { version = "0.3", optional = true } # Logger implementation -measure_time = { version = "0.6", optional = true } # To mesure parsing time, only required by binary +pretty_env_logger = { version = "0.5", optional = true } # Logger implementation +measure_time = { version = "0.8", optional = true } # To mesure parsing time, only required by binary [build-dependencies] -lalrpop = { version = "0.19.0", features = ["lexer"] } +lalrpop = "0.20" + diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..4d2dee8 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.80.0" diff --git a/src/executors.rs b/src/executors.rs index 1e41810..4af8829 100644 --- a/src/executors.rs +++ b/src/executors.rs @@ -260,8 +260,7 @@ impl Shape { let (space_id, inside) = match self { Shape::Point(space_id, position) => { let position: Vec = position.into(); - let mut positions = Vec::with_capacity(1); - positions.push(position.into()); + let positions = vec![position.into()]; let inside = core.get_by_positions(parameters, positions, space_id)?; Ok((space_id, inside)) @@ -275,7 +274,7 @@ impl Shape { // Smallest increment possible let mut increment = Vec::with_capacity(bounding_box[0].dimensions()); for _ in 0..bounding_box[0].dimensions() { - increment.push(std::f64::EPSILON); + increment.push(f64::EPSILON); } // Add it to the lower bound @@ -294,7 +293,7 @@ impl Shape { Shape::HyperSphere(space_id, center, radius) => { // Smallest decrement possible, to exclude the surface let mut radius: f64 = radius.into(); - radius -= std::f64::EPSILON; + radius -= f64::EPSILON; let center: space::Position = center.into(); let inside = core.get_by_shape( @@ -353,7 +352,7 @@ impl<'e> Executor<'e> for Projection { ) -> Self::ResultSet { match self { Projection::Nifti(_, _, _bag) => Err("Proj-Nifti: not yet implemented".to_string()), - Projection::JSON(_, _format, bag) => { + Projection::Json(_, _format, bag) => { bag.execute(core_id, parameters) // FIXME: Add projections here } diff --git a/src/lib.rs b/src/lib.rs index 3481ecb..4a60882 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,20 +38,20 @@ lalrpop_mod!(#[allow(clippy::all,unused_parens)] pub queries); // synthesized by // as well. // Instead we enable it per modules below, except for the tests. -#[warn(missing_docs)] +//#[warn(missing_docs)] mod evaluators; -#[warn(missing_docs)] +//#[warn(missing_docs)] mod executors; -#[warn(missing_docs)] +//#[warn(missing_docs)] mod expressions; -#[warn(missing_docs)] +//#[warn(missing_docs)] mod predictors; -#[warn(missing_docs)] +//#[warn(missing_docs)] mod validators; -#[warn(missing_docs)] +//#[warn(missing_docs)] mod symbols; -#[warn(missing_docs)] +//#[warn(missing_docs)] mod types; pub use expressions::Executor; diff --git a/src/predictors.rs b/src/predictors.rs index 706e890..89f557e 100644 --- a/src/predictors.rs +++ b/src/predictors.rs @@ -7,7 +7,7 @@ impl Predictor for Projection { fn predict(&self, db: &DataBase) -> Result { match self { Projection::Nifti(_, _, bag) => bag.predict(db), - Projection::JSON(_, _, bag) => bag.predict(db), + Projection::Json(_, _, bag) => bag.predict(db), } } } diff --git a/src/queries.lalrpop b/src/queries.lalrpop index 598cf49..abaf5e4 100644 --- a/src/queries.lalrpop +++ b/src/queries.lalrpop @@ -51,7 +51,7 @@ JsonOperator: symbols::Projection = { None => Space::universe().name().clone(), }; - symbols::Projection::JSON(space_id, f, b) + symbols::Projection::Json(space_id, f, b) } }; diff --git a/src/symbols.rs b/src/symbols.rs index b48ece7..32fe74a 100644 --- a/src/symbols.rs +++ b/src/symbols.rs @@ -11,14 +11,14 @@ pub use super::types::*; #[derive(Clone, Debug)] pub enum Projection { Nifti(String, LiteralSelector, Bag), - JSON(String, JsonValue, Bag), + Json(String, JsonValue, Bag), } impl Projection { pub fn space(&self) -> &String { match self { - Projection::Nifti(space, _, _) => &space, - Projection::JSON(space, _, _) => &space, + Projection::Nifti(space, _, _) => space, + Projection::Json(space, _, _) => space, } } } @@ -138,7 +138,7 @@ impl Shape { pub fn volume(&self) -> f64 { match self { - Shape::Point(_, _) => std::f64::EPSILON, // The smallest non-zero volume possible + Shape::Point(_, _) => f64::EPSILON, // The smallest non-zero volume possible Shape::HyperRectangle(_space, pos) => { //TODO: At this time, only aligned to the axes, defined by two points, hyperrectangles are supported. assert_eq!(pos.len(), 2); @@ -202,7 +202,7 @@ impl Shape { } Shape::Label(_, _) => { // FIXME: Needs to find a way to figure out the approximate volume of this specific ID, or return MAX or MIN.. - std::f64::EPSILON + f64::EPSILON } Shape::Nifti(_) => unimplemented!("Nifti"), } @@ -238,9 +238,7 @@ impl Position { Ordering::Less => -1, }; - let mut v = Vec::with_capacity(1); - v.push(LiteralNumber::Int(x)); - + let v = vec![LiteralNumber::Int(x)]; LiteralPosition(v) } } diff --git a/src/types.rs b/src/types.rs index 3abc766..8b44d38 100644 --- a/src/types.rs +++ b/src/types.rs @@ -11,23 +11,10 @@ pub enum LiteralTypes { impl PartialEq for LiteralTypes { fn eq(&self, other: &Self) -> bool { match self { - LiteralTypes::String => match other { - LiteralTypes::String => true, - _ => false, - }, - LiteralTypes::Int => match other { - LiteralTypes::Int => true, - _ => false, - }, - LiteralTypes::Float => match other { - LiteralTypes::Float => true, - LiteralTypes::Int => true, - _ => false, - }, - LiteralTypes::Bag(_) => match other { - LiteralTypes::Bag(_) => true, - _ => false, - }, + LiteralTypes::String => matches!(other, LiteralTypes::String), + LiteralTypes::Int => matches!(other, LiteralTypes::Int), + LiteralTypes::Float => matches!(other, LiteralTypes::Float | LiteralTypes::Int), + LiteralTypes::Bag(_) => matches!(other, LiteralTypes::Bag(_)), LiteralTypes::Vector(v) => match other { LiteralTypes::Vector(ov) => { let n = v.len(); diff --git a/src/validators.rs b/src/validators.rs index 79e94bd..b7b13cb 100644 --- a/src/validators.rs +++ b/src/validators.rs @@ -9,7 +9,7 @@ impl Validator for Projection { fn validate(&self) -> ValidationResult { match self { Projection::Nifti(_, _, _) => Err("not yet implemented".to_string()), - Projection::JSON(_, _format, bag) => bag.validate(), + Projection::Json(_, _format, bag) => bag.validate(), //FIXME: Add support for projections /* match format.validate() { Ok(_) => bag.validate(), @@ -61,10 +61,7 @@ impl Validator for Bag { Bag::Union(lh, rh) => compare_bag_types(lh, rh), Bag::Bag(bags) => { for b in bags { - let t = b.validate(); - if t.is_err() { - return t; - } + b.validate()?; } Ok(get_type())