Skip to content

Commit

Permalink
Merge pull request #85 from niklasdewally/issue/78
Browse files Browse the repository at this point in the history
Minion: more robust error handling, and make clippy happy
  • Loading branch information
ozgurakgun authored Nov 20, 2023
2 parents 42dc9e6 + fb0a418 commit 3085b0f
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 77 deletions.
154 changes: 149 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,157 @@
# rust/c++
target
*.log
coverage

## Rust
debug/
target/

## C++
solvers/**/vendor/build
*.o
*.a

# python
## Python
.env
venv
__pycache__
.ruff_cache

# IDE
.idea
## Global tool/OS ignores from :
## https://github.com/github/gitignore/blob/main/Global

## LINUX
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

## MACOS
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

## VSCODE
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix


## Jetbrains

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
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 clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
allow-unwrap-in-tests=true
allow-expect-in-tests=true


11 changes: 7 additions & 4 deletions solvers/minion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ 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]
cc = { version = "1.0.84", features = ["parallel"] }
bindgen = "0.69.1"
glob = "0.3.1"


[lints]
workspace = true

[lints.clippy]
unwrap_used = "deny"
expect_used = "deny"
panic_in_result_fn = "warn"
panic = "warn"
todo = "warn"
7 changes: 5 additions & 2 deletions solvers/minion/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// - https://github.com/gokberkkocak/rust_glucose/blob/master/build.rs
// - https://rust-lang.github.io/rust-bindgen/non-system-libraries.html
// - 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 @@ -60,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 3085b0f

Please sign in to comment.