Skip to content

Commit

Permalink
minion_rs: better error handling, and clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasdewally committed Nov 20, 2023
1 parent fe0de68 commit fb0a418
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 67 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"conjure_oxide",
"solvers/kissat",
Expand Down
4 changes: 4 additions & 0 deletions solvers/minion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.75"
thiserror = "1.0.50"

[build-dependencies]
Expand All @@ -16,3 +17,6 @@ glob = "0.3.1"
[lints.clippy]
unwrap_used = "deny"
expect_used = "deny"
panic_in_result_fn = "warn"
panic = "warn"
todo = "warn"
4 changes: 3 additions & 1 deletion solvers/minion/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// - https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed
#![allow(clippy::unwrap_used)]
#![allow(clippy::expect_used)]
#![allow(clippy::panic)]

use std::env;
use std::path::PathBuf;
use std::process::Command;
Expand Down Expand Up @@ -61,7 +63,7 @@ fn bind() {
.header("vendor/minion/libwrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Make all templates opaque as reccomended by bindgen
.opaque_type("std::.*")
// Manually allow C++ functions to stop bindgen getting confused.
Expand Down
17 changes: 11 additions & 6 deletions solvers/minion/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ impl Model {
}
}

impl Default for Model {
fn default() -> Self {
Self::new()
}
}

#[derive(Debug)]
pub enum Constraint {
SumLeq(Vec<Var>, Var),
SumGeq(Vec<Var>, Var),
Expand All @@ -30,6 +37,7 @@ pub enum Constraint {
/// The latter is not stored in the symbol table, or counted in Minions internal list of all
/// variables, but is used to allow the use of a constant in the place of a variable in a
/// constraint.
#[derive(Debug)]
pub enum Var {
NameRef(VarName),
ConstantAsVar(i32),
Expand All @@ -41,7 +49,7 @@ pub enum Constant {
Integer(i32),
}

#[derive(Copy, Clone)]
#[derive(Debug, Copy, Clone)]
pub enum VarDomain {
Bound(i32, i32),
Discrete(i32, i32),
Expand Down Expand Up @@ -74,14 +82,11 @@ impl SymbolTable {
self.table.insert(name.clone(), vartype);
self.var_order.push(name);

return Some(());
Some(())
}

pub fn get_vartype(&self, name: VarName) -> Option<VarDomain> {
match self.table.get(&name) {
Some(m) => Some(*m),
None => None,
}
self.table.get(&name).cloned()
}

pub fn get_variable_order(&self) -> Vec<VarName> {
Expand Down
6 changes: 5 additions & 1 deletion solvers/minion/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ use thiserror::Error;
/// `Error` allows functions involving Minion to return a single error type. All error types in
/// `minion_rs` are able to be converted into this type using into / from.
#[derive(Debug, Error)]
pub enum Error {
pub enum MinionError {
#[error("runtime error: `{0}.to_string()`")]
RuntimeError(#[from] RuntimeError),
#[error("not implemented: {0}")]
NotImplemented(String),
#[error(transparent)]
Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error
}

/// RuntimeErrors are thrown by Minion during execution.
Expand Down
Loading

0 comments on commit fb0a418

Please sign in to comment.