Skip to content

Commit

Permalink
IDE warnings fixed and upgraded to version 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
t-lohse committed Feb 19, 2024
1 parent f33e56e commit b23b6e9
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 181 deletions.
25 changes: 12 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "reveaal"
version = "0.1.0"
build = "src/build.rs"
authors = ["Thomas Lohse", "Sebastian Lund", "Thorulf Neustrup", "Peter Greve"]
edition = "2018"
edition = "2021"

[lib]
name = "reveaal"
Expand All @@ -27,22 +27,21 @@ xml-rs = "0.8.3"
serde-xml-rs = "0.6.0"
elementtree = "1.2.2"
dyn-clone = "1.0"
tonic = "0.8.3"
prost = "0.11.0"
tokio = { version = "1.0", features = ["macros", "rt"] }
tonic = "0.11.0"
prost = "0.12.3"
tokio = { version = "1.36.0", features = ["macros", "rt"] }
colored = "2.0.0"
simple-error = "0.2.3"
force_graph = "0.3.2"
rand = "0.8.5"
futures = "0.3.21"
edbm = { git = "https://github.com/Ecdar/EDBM" }
log = "0.4.17"
env_logger = { version = "0.9.0", optional = true }
env_logger = { version = "0.11.2", optional = true }
chrono = { version = "0.4.22", optional = true }
test-case = "2.2.2"
test-case = "3.3.1"
num_cpus = "1.13.1"
lru = "0.8.1"
itertools = "0.10.5"
lru = "0.12.2"
itertools = "0.12.1"
regex = "1"
rayon = "1.6.1"
lazy_static = "1.4.0"
Expand All @@ -53,14 +52,14 @@ num = "0.4.1"
opt-level = 3

[build-dependencies]
tonic-build = "0.8.2"
tonic-build = "0.11.0"

[dev-dependencies]
test-case = "2.2.2"
criterion = { version = "0.4.0", features = ["async_futures"] }
test-case = "3.3.1"
criterion = { version = "0.5.1", features = ["async_futures"] }

[target.'cfg(unix)'.dev-dependencies]
pprof = { version = "0.10.1", features = ["flamegraph"] }
pprof = { version = "0.13.0", features = ["flamegraph"] }

[[bench]]
name = "refinement_bench"
Expand Down
4 changes: 2 additions & 2 deletions src/data_reader/grammars/edge_grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ bool_op = _{ and | or }
and = { "&&" }
or = { "||" }

arith_op = _{ add | sub | mul | div | mod }
arith_op = _{ add | sub | mul | div | modulo }
add = { "+" } // Addition
sub = { "-" } // Subtraction
mul = { "*" } // Multiplication
div = { "/" } // Division
mod = { "%" } // Modulo
modulo = { "%" } // Modulo

compare_op = _{ geq | leq | eq | lt | gt }
geq = { ">=" } // Greater than or equal to
Expand Down
4 changes: 2 additions & 2 deletions src/data_reader/parse_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lazy_static! {
.op(Op::infix(Rule::add, Assoc::Left) | Op::infix(Rule::sub, Assoc::Left))
.op(Op::infix(Rule::mul, Assoc::Left)
| Op::infix(Rule::div, Assoc::Left)
| Op::infix(Rule::r#mod, Assoc::Left))
| Op::infix(Rule::modulo, Assoc::Left))
.op(Op::infix(Rule::and, Assoc::Left))
.op(Op::infix(Rule::or, Assoc::Left));
}
Expand Down Expand Up @@ -180,7 +180,7 @@ fn parse_arith_expr(pair: pest::iterators::Pair<Rule>) -> ArithExpression {
Rule::sub => ArithExpression::Difference(left, right),
Rule::mul => ArithExpression::Multiplication(left, right),
Rule::div => ArithExpression::Division(left, right),
Rule::r#mod => ArithExpression::Modulo(left, right),
Rule::modulo => ArithExpression::Modulo(left, right),
_ => unreachable!("Unable to match: {:?} as rule, arith", op),
}
})
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern crate colored;
extern crate core;
extern crate serde;
extern crate serde_xml_rs;
extern crate simple_error;
extern crate xml;
#[macro_use]
extern crate lazy_static;
2 changes: 1 addition & 1 deletion src/model_objects/expressions/arith_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl ArithExpression {
let mut new_constraint = 0;

self.iterate_constraints(&mut |left, right| {
//Start by matching left and right operands to get constant, this might fail if it does we skip constraint defaulting to 0
//Start by matching left and right operands to get constant, this might fail. If it does, we skip constraint defaulting to 0
let constant = ArithExpression::get_constant(left, right, clock, clock_name);

if new_constraint < constant {
Expand Down
99 changes: 34 additions & 65 deletions src/model_objects/expressions/bool_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,81 +309,50 @@ impl BoolExpression {
fn simplify_helper(&mut self) -> bool {
let mut changed = false;
let mut value = None;
let mut handle = |l: &mut Box<ArithExpression>,
r: &mut Box<ArithExpression>,
//r: ArithExpression,
cmp: &(dyn Fn(&i32, &i32) -> bool)| {
**l = l.simplify().expect("Can't simplify");
**r = r.simplify().expect("Can't simplify");
if let ArithExpression::Int(x) = **l {
if let ArithExpression::Int(y) = **r {
value = Some(BoolExpression::Bool(cmp(&x, &y)))
}
}
};
match self {
BoolExpression::AndOp(left, right) => {
changed |= left.simplify_helper();
changed |= right.simplify_helper();
match **left {
BoolExpression::Bool(false) => value = Some(BoolExpression::Bool(false)),
BoolExpression::Bool(true) => value = Some((**right).clone()),
_ => {}
}
match **right {
BoolExpression::Bool(false) => value = Some(BoolExpression::Bool(false)),
BoolExpression::Bool(true) => value = Some((**left).clone()),
_ => {}
}

value = match (left.as_ref(), right.as_ref()) {
// Short-circuiting
(BoolExpression::Bool(false), _) => Some(BoolExpression::Bool(false)),
(BoolExpression::Bool(true), BoolExpression::Bool(b)) => {
Some(BoolExpression::Bool(*b))
}
(_, _) => None,
};
}
BoolExpression::OrOp(left, right) => {
changed |= left.simplify_helper();
changed |= right.simplify_helper();
match **left {
BoolExpression::Bool(true) => value = Some(BoolExpression::Bool(true)),
BoolExpression::Bool(false) => value = Some((**right).clone()),
_ => {}
}
match **right {
BoolExpression::Bool(true) => value = Some(BoolExpression::Bool(true)),
BoolExpression::Bool(false) => value = Some((**left).clone()),
_ => {}
}
}

BoolExpression::LessEQ(l, r) => {
**l = l.simplify().expect("Can't simplify");
**r = r.simplify().expect("Can't simplify");
if let ArithExpression::Int(x) = **l {
if let ArithExpression::Int(y) = **r {
value = Some(BoolExpression::Bool(x <= y))
value = match (left.as_ref(), right.as_ref()) {
// Short-circuiting
(BoolExpression::Bool(true), _) => Some(BoolExpression::Bool(true)),
(BoolExpression::Bool(false), BoolExpression::Bool(b)) => {
Some(BoolExpression::Bool(*b))
}
}
}
BoolExpression::GreatEQ(l, r) => {
**l = l.simplify().expect("Can't simplify");
**r = r.simplify().expect("Can't simplify");
if let ArithExpression::Int(x) = **l {
if let ArithExpression::Int(y) = **r {
value = Some(BoolExpression::Bool(x >= y))
}
}
}
BoolExpression::LessT(l, r) => {
**l = l.simplify().expect("Can't simplify");
**r = r.simplify().expect("Can't simplify");
if let ArithExpression::Int(x) = **l {
if let ArithExpression::Int(y) = **r {
value = Some(BoolExpression::Bool(x < y))
}
}
}
BoolExpression::GreatT(l, r) => {
**l = l.simplify().expect("Can't simplify");
**r = r.simplify().expect("Can't simplify");
if let ArithExpression::Int(x) = **l {
if let ArithExpression::Int(y) = **r {
value = Some(BoolExpression::Bool(x > y))
}
}
}
BoolExpression::EQ(l, r) => {
**l = l.simplify().expect("Can't simplify");
**r = r.simplify().expect("Can't simplify");
if let ArithExpression::Int(x) = **l {
if let ArithExpression::Int(y) = **r {
value = Some(BoolExpression::Bool(x == y))
}
}
(_, _) => None,
};
}

BoolExpression::LessEQ(l, r) => handle(l, r, &i32::le),
BoolExpression::GreatEQ(l, r) => handle(l, r, &i32::ge),
BoolExpression::LessT(l, r) => handle(l, r, &i32::lt),
BoolExpression::GreatT(l, r) => handle(l, r, &i32::gt),
BoolExpression::EQ(l, r) => handle(l, r, &i32::eq),
BoolExpression::Bool(_) => {}
}

Expand Down
20 changes: 11 additions & 9 deletions src/protobuf_server/ecdar_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ where
}
}

match future.catch_unwind().await {
Ok(response) => response,
Err(e) => Err(Status::internal(format!(
"{}, please report this bug to the developers",
downcast_to_string(e)
))),
}
.map(Response::new)
future
.catch_unwind()
.await
.unwrap_or_else(|e| {
Err(Status::internal(format!(
"{}, please report this bug to the developers",
downcast_to_string(e)
)))
})
.map(Response::new)
}

impl ConcreteEcdarBackend {}
Expand All @@ -81,7 +83,7 @@ impl EcdarBackend for ConcreteEcdarBackend {
) -> Result<Response<UserTokenResponse>, Status> {
let id = self.num.fetch_add(1, Ordering::SeqCst);
let token_response = UserTokenResponse { user_id: id };
Result::Ok(Response::new(token_response))
Ok(Response::new(token_response))
}

async fn send_query(
Expand Down
1 change: 0 additions & 1 deletion src/protobuf_server/proto_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ impl From<SpecificConstraint> for ProtoConstraint {

impl From<SpecificClockVar> for ProtoClock {
fn from(clock: SpecificClockVar) -> Self {
use std::convert::TryFrom;
match clock {
SpecificClockVar::Zero => Self {
clock: Some(ProtoClockEnum::ZeroClock(Default::default())),
Expand Down
11 changes: 4 additions & 7 deletions src/simulation/graph_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ impl Default for Config {
}

fn get_config() -> Config {
match read_config("config.json") {
Ok(config) => config,
Err(_) => {
info!("Could not find graph layout config, using defaults");
Config::default()
}
}
read_config("config.json").unwrap_or_else(|_| {
info!("Could not find graph layout config, using defaults");
Config::default()
})
}

fn read_config<P: AsRef<Path>>(path: P) -> Result<Config, Box<dyn Error>> {
Expand Down
5 changes: 2 additions & 3 deletions src/system/extract_system_rep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use super::query_failures::{SyntaxResult, SystemRecipeFailure};
use crate::system::pruning;
use edbm::util::constraints::ClockIndex;
use log::debug;
use simple_error::bail;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ExecutableQueryError {
Expand Down Expand Up @@ -157,10 +156,10 @@ pub fn create_executable_query<'a>(
}

// Should handle consistency, Implementation, determinism and specification here, but we cant deal with it atm anyway
_ => bail!("Not yet setup to handle query"),
_ => Err("Not yet setup to handle query".into()),
}
} else {
bail!("No query was supplied for extraction")
Err("No query was supplied for extraction".into())
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/tests/failure_message/actions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod test {

use crate::system::query_failures::{
ConsistencyFailure, DeterminismFailure, DeterminismResult, QueryResult, RefinementFailure,
ConsistencyFailure, DeterminismFailure, QueryResult, RefinementFailure,
RefinementPrecondition,
};
use crate::system::specifics::SpecificLocation;
Expand All @@ -14,7 +14,7 @@ mod test {
fn determinism_test() {
let expected_action = String::from("1");
let expected_location = SpecificLocation::new("NonDeterministic1", "L1", 0); //LocationID::Simple(String::from("L1"));
if let QueryResult::Determinism(DeterminismResult::Err(DeterminismFailure {
if let QueryResult::Determinism(Err(DeterminismFailure {
state: actual_state,
action: actual_action,
system: actual_system,
Expand All @@ -40,7 +40,7 @@ mod test {
})) = json_run_query(PATH, "consistency: NonConsistent").unwrap()
{
let actual_location = actual_state.locations;
assert_eq!((expected_location), (actual_location));
assert_eq!(expected_location, actual_location);
assert_eq!(actual_system, "NonConsistent");
} else {
panic!("Models in samples/action have been changed, REVERT!");
Expand Down Expand Up @@ -87,7 +87,7 @@ mod test {
))) = json_run_query(PATH, "refinement: NonConsistent <= CorrectComponent").unwrap()
{
let actual_location = actual_state.locations;
assert_eq!((expected_location), (actual_location));
assert_eq!(expected_location, actual_location);
assert_eq!(actual_system, "NonConsistent");
} else {
panic!("Models in samples/action have been changed, REVERT!");
Expand Down
6 changes: 2 additions & 4 deletions src/tests/failure_message/consistency_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mod test {
use crate::{
system::query_failures::{ConsistencyFailure, ConsistencyResult, QueryResult},
system::query_failures::{ConsistencyFailure, QueryResult},
tests::refinement::helper::json_run_query,
};

Expand All @@ -13,9 +13,7 @@ mod test {
let actual = json_run_query(PATH, "consistency: notConsistent").unwrap();
assert!(matches!(
actual,
QueryResult::Consistency(ConsistencyResult::Err(
ConsistencyFailure::InconsistentFrom { .. }
))
QueryResult::Consistency(Err(ConsistencyFailure::InconsistentFrom { .. }))
));
}
}
4 changes: 2 additions & 2 deletions src/tests/failure_message/syntax_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mod test {
use crate::{
system::query_failures::{QueryResult, SyntaxFailure, SyntaxResult},
system::query_failures::{QueryResult, SyntaxFailure},
tests::refinement::helper::json_run_query,
};

Expand All @@ -13,7 +13,7 @@ mod test {
let actual = json_run_query(PATH, "syntax: syntaxFailure").unwrap();
assert!(matches!(
actual,
QueryResult::Syntax(SyntaxResult::Err(SyntaxFailure::Unparsable { .. }))
QueryResult::Syntax(Err(SyntaxFailure::Unparsable { .. }))
));
}
}
1 change: 1 addition & 0 deletions src/tests/reachability/partial_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod reachability_partial_states_test {
use crate::model_objects::{Declarations, Location, LocationType};
use crate::transition_systems::CompositionType;
use crate::transition_systems::LocationTree;

use test_case::test_case;

fn build_location_tree_helper(id: &str, location_type: LocationType) -> Rc<LocationTree> {
Expand Down
Loading

0 comments on commit b23b6e9

Please sign in to comment.