diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/flat.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/flat.svg new file mode 100644 index 0000000000..bf23e67c31 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/flat.svg @@ -0,0 +1,23 @@ + + coverage: 0% + + + + + + + + + + + + + + + coverage + + 0% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/flat_square.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/flat_square.svg new file mode 100644 index 0000000000..dd62fd7016 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/flat_square.svg @@ -0,0 +1,13 @@ + + coverage: 0% + + + + + + coverage + 0% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/for_the_badge.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/for_the_badge.svg new file mode 100644 index 0000000000..0b8854cd6b --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/for_the_badge.svg @@ -0,0 +1,13 @@ + + COVERAGE: 0% + + + + + + COVERAGE + 0% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/plastic.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/plastic.svg new file mode 100644 index 0000000000..56ddfa74e6 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/plastic.svg @@ -0,0 +1,25 @@ + + coverage: 0% + + + + + + + + + + + + + + + + + coverage + + 0% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/social.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/social.svg new file mode 100644 index 0000000000..4675a1a427 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/badges/social.svg @@ -0,0 +1,27 @@ + + Coverage: 0% + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/coverage.json b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/coverage.json new file mode 100644 index 0000000000..13bbdcbd82 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/coverage.json @@ -0,0 +1 @@ +{"schemaVersion":1,"label":"coverage","message":"0.00%","color":"red"} \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/index.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/index.html new file mode 100644 index 0000000000..7bc0b775cf --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/index.html @@ -0,0 +1,88 @@ + + + + + Grcov report - top_level + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DirectoryLine CoverageFunctionsBranches
src + + 0% + + + 0% + + 0 / 41 + 0%0 / 20 100%0 / 0
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/src/index.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/src/index.html new file mode 100644 index 0000000000..7fa1abd285 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/src/index.html @@ -0,0 +1,88 @@ + + + + + Grcov report - src + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileLine CoverageFunctionsBranches
lib.rs + + 0% + + + 0% + + 0 / 41 + 0%0 / 20 100%0 / 0
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/src/lib.rs.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/src/lib.rs.html new file mode 100644 index 0000000000..049bfb15cc --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/chuffed/src/lib.rs.html @@ -0,0 +1,1106 @@ + + + + + Grcov report - lib.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
pub mod bindings {
+
+
+
+ 2 +
+
+ +
+
+
    #![allow(non_upper_case_globals)]
+
+
+
+ 3 +
+
+ +
+
+
    #![allow(non_camel_case_types)]
+
+
+
+ 4 +
+
+ +
+
+
    #![allow(non_snake_case)]
+
+
+
+ 5 +
+
+ +
+
+
    include!(concat!(env!("OUT_DIR"), "/chuffed_bindings.rs"));
+
+
+
+ 6 +
+
+ +
+
+
}
+
+
+
+ 7 +
+
+ +
+
+

+            
+
+
+ 8 +
+
+ +
+
+
pub mod wrappers {
+
+
+
+ 9 +
+
+ +
+
+
    use crate::bindings::{
+
+
+
+ 10 +
+
+ +
+
+
        all_different, branch_IntVar, createVar, createVars, make_vec_intvar, output_vars1,
+
+
+
+ 11 +
+
+ +
+
+
        var_sym_break, vec, ConLevel, IntVar, ValBranch, VarBranch,
+
+
+
+ 12 +
+
+ +
+
+
    };
+
+
+
+ 13 +
+
+ +
+
+
    use core::ptr;
+
+
+
+ 14 +
+
+ +
+
+

+            
+
+
+ 15 +
+
+ +
+
+
    // The signature of createVar is below for reference.
+
+
+
+ 16 +
+
+ +
+
+
    // createVar(x: *mut *mut IntVar, min: ::std::os::raw::c_int, max: ::std::os::raw::c_int, el: bool)
+
+
+
+ 17 +
+
+ +
+
+
    pub fn create_var(min: i32, max: i32, el: bool) -> *mut IntVar {
+
+
+
+ 18 +
+
+ +
+
+
        let mut ptr: *mut IntVar = ptr::null_mut();
+
+
+
+ 19 +
+
+ +
+
+

+            
+
+
+ 20 +
+
+ +
+
+
        unsafe {
+
+
+
+ 21 +
+
+ +
+
+
            createVar(&mut ptr, min, max, el);
+
+
+
+ 22 +
+
+ +
+
+
            ptr
+
+
+
+ 23 +
+
+ +
+
+
        }
+
+
+
+ 24 +
+
+ +
+
+
    }
+
+
+
+ 25 +
+
+ +
+
+

+            
+
+
+ 26 +
+
+ +
+
+
    // createVars void createVars(vec<IntVar*>& x, int n, int min, int max, bool el)
+
+
+
+ 27 +
+
+ +
+
+
    pub fn create_vars(n: i32, min: i32, max: i32, el: bool) -> *mut vec<*mut IntVar> {
+
+
+
+ 28 +
+
+ +
+
+
        let ptr: *mut vec<*mut IntVar> = unsafe { make_vec_intvar() };
+
+
+
+ 29 +
+
+ +
+
+

+            
+
+
+ 30 +
+
+ +
+
+
        unsafe {
+
+
+
+ 31 +
+
+ +
+
+
            createVars(ptr, n, min, max, el);
+
+
+
+ 32 +
+
+ +
+
+
            ptr
+
+
+
+ 33 +
+
+ +
+
+
        }
+
+
+
+ 34 +
+
+ +
+
+
    }
+
+
+
+ 35 +
+
+ +
+
+

+            
+
+
+ 36 +
+
+ +
+
+
    // void all_different(vec<IntVar*>& x, ConLevel cl)
+
+
+
+ 37 +
+
+ +
+
+
    pub unsafe fn all_different_wrapper(x: *mut vec<*mut IntVar>, cl: ConLevel) {
+
+
+
+ 38 +
+
+ +
+
+
        unsafe {
+
+
+
+ 39 +
+
+ +
+
+
            all_different(x, cl);
+
+
+
+ 40 +
+
+ +
+
+
        }
+
+
+
+ 41 +
+
+ +
+
+
    }
+
+
+
+ 42 +
+
+ +
+
+

+            
+
+
+ 43 +
+
+ +
+
+
    // void branch(vec<Branching*> x, VarBranch var_branch, ValBranch val_branch);
+
+
+
+ 44 +
+
+ +
+
+
    pub unsafe fn branch_wrapper(
+
+
+
+ 45 +
+
+ +
+
+
        x: *mut vec<*mut IntVar>,
+
+
+
+ 46 +
+
+ +
+
+
        var_branch: VarBranch,
+
+
+
+ 47 +
+
+ +
+
+
        val_branch: ValBranch,
+
+
+
+ 48 +
+
+ +
+
+
    ) {
+
+
+
+ 49 +
+
+ +
+
+
        unsafe {
+
+
+
+ 50 +
+
+ +
+
+
            branch_IntVar(x, var_branch, val_branch);
+
+
+
+ 51 +
+
+ +
+
+
        }
+
+
+
+ 52 +
+
+ +
+
+
    }
+
+
+
+ 53 +
+
+ +
+
+

+            
+
+
+ 54 +
+
+ +
+
+
    pub unsafe fn output_vars_wrapper(x: *mut vec<*mut IntVar>) {
+
+
+
+ 55 +
+
+ +
+
+
        unsafe {
+
+
+
+ 56 +
+
+ +
+
+
            // output_vars1 takes in an vec<IntVar*> instead of branching
+
+
+
+ 57 +
+
+ +
+
+
            output_vars1(x);
+
+
+
+ 58 +
+
+ +
+
+
        }
+
+
+
+ 59 +
+
+ +
+
+
    }
+
+
+
+ 60 +
+
+ +
+
+

+            
+
+
+ 61 +
+
+ +
+
+
    pub unsafe fn var_sym_break_wrapper(x: *mut vec<*mut IntVar>) {
+
+
+
+ 62 +
+
+ +
+
+
        unsafe {
+
+
+
+ 63 +
+
+ +
+
+
            var_sym_break(x);
+
+
+
+ 64 +
+
+ +
+
+
        }
+
+
+
+ 65 +
+
+ +
+
+
    }
+
+
+
+ 66 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/flat.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/flat.svg new file mode 100644 index 0000000000..617990c047 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/flat.svg @@ -0,0 +1,23 @@ + + coverage: 81% + + + + + + + + + + + + + + + coverage + + 81% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/flat_square.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/flat_square.svg new file mode 100644 index 0000000000..61ac9234cd --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/flat_square.svg @@ -0,0 +1,13 @@ + + coverage: 81% + + + + + + coverage + 81% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/for_the_badge.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/for_the_badge.svg new file mode 100644 index 0000000000..47e896f018 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/for_the_badge.svg @@ -0,0 +1,13 @@ + + COVERAGE: 81% + + + + + + COVERAGE + 81% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/plastic.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/plastic.svg new file mode 100644 index 0000000000..b3880efbcb --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/plastic.svg @@ -0,0 +1,25 @@ + + coverage: 81% + + + + + + + + + + + + + + + + + coverage + + 81% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/social.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/social.svg new file mode 100644 index 0000000000..de42d48917 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/badges/social.svg @@ -0,0 +1,27 @@ + + Coverage: 81% + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/coverage.json b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/coverage.json new file mode 100644 index 0000000000..101bc105c2 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/coverage.json @@ -0,0 +1 @@ +{"schemaVersion":1,"label":"coverage","message":"81.82%","color":"yellow"} \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/index.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/index.html new file mode 100644 index 0000000000..64b0c579b2 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/index.html @@ -0,0 +1,88 @@ + + + + + Grcov report - top_level + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DirectoryLine CoverageFunctionsBranches
src/common/ast + + 81.82% + + + 81.82% + + 9 / 11 + 15.58%12 / 77 100%0 / 0
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/src/common/ast/ast.rs.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/src/common/ast/ast.rs.html new file mode 100644 index 0000000000..2dab885f62 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/src/common/ast/ast.rs.html @@ -0,0 +1,818 @@ + + + + + Grcov report - ast.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
use std::collections::HashMap;
+
+
+
+ 2 +
+
+ +
+
+

+            
+
+
+ 3 +
+
+ +
+
+
#[derive(Debug)]
+
+
+
+ 4 +
+
+ +
+
+
pub struct Model {
+
+
+
+ 5 +
+
+ +
+
+
    pub variables: HashMap<Name, DecisionVariable>,
+
+
+
+ 6 +
+
+ +
+
+
    pub constraints: Vec<Expression>,
+
+
+
+ 7 +
+
+ +
+
+
}
+
+
+
+ 8 +
+
+ +
+
+

+            
+
+
+ 9 +
+
+ +
+
+
impl Model {
+
+
+
+ 10 +
+
+ +
+
+
    // Function to update a DecisionVariable based on its Name
+
+
+
+ 11 +
+
+ 2 +
+
+
    pub fn update_domain(&mut self, name: &Name, new_domain: Domain) {
+
+
+
+ 12 +
+
+ 2 +
+
+
        if let Some(decision_var) = self.variables.get_mut(name) {
+
+
+
+ 13 +
+
+ 2 +
+
+
            decision_var.domain = new_domain;
+
+
+
+ 14 +
+
+ 2 +
+
+
        }
+
+
+
+ 15 +
+
+ 2 +
+
+
    }
+
+
+
+ 16 +
+
+ +
+
+
}
+
+
+
+ 17 +
+
+ +
+
+

+            
+
+
+ 18 +
+
+ 8 +
+
+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
+
+
+
+ 19 +
+
+ +
+
+
pub enum Name {
+
+
+
+ 20 +
+
+ +
+
+
    UserName(String),
+
+
+
+ 21 +
+
+ +
+
+
    MachineName(i32),
+
+
+
+ 22 +
+
+ +
+
+
}
+
+
+
+ 23 +
+
+ +
+
+

+            
+
+
+ 24 +
+
+ +
+
+
#[derive(Debug, PartialEq)]
+
+
+
+ 25 +
+
+ +
+
+
pub struct DecisionVariable {
+
+
+
+ 26 +
+
+ +
+
+
    pub domain: Domain,
+
+
+
+ 27 +
+
+ +
+
+
}
+
+
+
+ 28 +
+
+ +
+
+

+            
+
+
+ 29 +
+
+ 2 +
+
+
#[derive(Clone, Debug, PartialEq)]
+
+
+
+ 30 +
+
+ +
+
+
pub enum Domain {
+
+
+
+ 31 +
+
+ +
+
+
    BoolDomain,
+
+
+
+ 32 +
+
+ +
+
+
    IntDomain(Vec<Range<i32>>),
+
+
+
+ 33 +
+
+ +
+
+
}
+
+
+
+ 34 +
+
+ +
+
+

+            
+
+
+ 35 +
+
+ 2 +
+
+
#[derive(Clone, Debug, PartialEq)]
+
+
+
+ 36 +
+
+ +
+
+
pub enum Range<A> {
+
+
+
+ 37 +
+
+ +
+
+
    Single(A),
+
+
+
+ 38 +
+
+ +
+
+
    Bounded(A, A),
+
+
+
+ 39 +
+
+ +
+
+
}
+
+
+
+ 40 +
+
+ +
+
+

+            
+
+
+ 41 +
+
+ 17 +
+
+
#[derive(Clone, Debug, PartialEq)]
+
+
+
+ 42 +
+
+ +
+
+
pub enum Expression {
+
+
+
+ 43 +
+
+ +
+
+
    ConstantInt(i32),
+
+
+
+ 44 +
+
+ +
+
+
    Reference(Name),
+
+
+
+ 45 +
+
+ +
+
+
    Sum(Vec<Expression>),
+
+
+
+ 46 +
+
+ +
+
+
    Eq(Box<Expression>, Box<Expression>),
+
+
+
+ 47 +
+
+ +
+
+
    Geq(Box<Expression>, Box<Expression>),
+
+
+
+ 48 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/src/common/ast/index.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/src/common/ast/index.html new file mode 100644 index 0000000000..6a6f3ada8e --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/conjure-oxide/src/common/ast/index.html @@ -0,0 +1,88 @@ + + + + + Grcov report - src/common/ast + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileLine CoverageFunctionsBranches
ast.rs + + 81.82% + + + 81.82% + + 9 / 11 + 15.58%12 / 77 100%0 / 0
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/flat.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/flat.svg new file mode 100644 index 0000000000..606ea84823 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/flat.svg @@ -0,0 +1,23 @@ + + coverage: 76% + + + + + + + + + + + + + + + coverage + + 76% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/flat_square.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/flat_square.svg new file mode 100644 index 0000000000..fc84cccdf0 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/flat_square.svg @@ -0,0 +1,13 @@ + + coverage: 76% + + + + + + coverage + 76% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/for_the_badge.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/for_the_badge.svg new file mode 100644 index 0000000000..11a6e0ee88 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/for_the_badge.svg @@ -0,0 +1,13 @@ + + COVERAGE: 76% + + + + + + COVERAGE + 76% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/plastic.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/plastic.svg new file mode 100644 index 0000000000..ee25c04aed --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/plastic.svg @@ -0,0 +1,25 @@ + + coverage: 76% + + + + + + + + + + + + + + + + + coverage + + 76% + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/social.svg b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/social.svg new file mode 100644 index 0000000000..aa95beecb2 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/badges/social.svg @@ -0,0 +1,27 @@ + + Coverage: 76% + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/coverage.json b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/coverage.json new file mode 100644 index 0000000000..d09fc6bd77 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/coverage.json @@ -0,0 +1 @@ +{"schemaVersion":1,"label":"coverage","message":"76.35%","color":"yellow"} \ No newline at end of file diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/index.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/index.html new file mode 100644 index 0000000000..5caf4975d3 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/index.html @@ -0,0 +1,88 @@ + + + + + Grcov report - top_level + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DirectoryLine CoverageFunctionsBranches
src + + 76.35% + + + 76.35% + + 297 / 389 + 45.88%39 / 85 100%0 / 0
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/ast.rs.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/ast.rs.html new file mode 100644 index 0000000000..21275be442 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/ast.rs.html @@ -0,0 +1,1634 @@ + + + + + Grcov report - ast.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
/*
+
+
+
+ 2 +
+
+ +
+
+
 * This Source Code Form is subject to the terms of the Mozilla Public
+
+
+
+ 3 +
+
+ +
+
+
 * License, v. 2.0. If a copy of the MPL was not distributed with this
+
+
+
+ 4 +
+
+ +
+
+
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+
+
+ 5 +
+
+ +
+
+
 */
+
+
+
+ 6 +
+
+ +
+
+

+            
+
+
+ 7 +
+
+ +
+
+
//! The Model Syntax tree for the Minion bindings.
+
+
+
+ 8 +
+
+ +
+
+

+            
+
+
+ 9 +
+
+ +
+
+
use std::collections::HashMap;
+
+
+
+ 10 +
+
+ +
+
+

+            
+
+
+ 11 +
+
+ +
+
+
pub type VarName = String;
+
+
+
+ 12 +
+
+ +
+
+

+            
+
+
+ 13 +
+
+ +
+
+
pub struct Model {
+
+
+
+ 14 +
+
+ +
+
+
    /// A lookup table of all named variables.
+
+
+
+ 15 +
+
+ +
+
+
    pub named_variables: SymbolTable,
+
+
+
+ 16 +
+
+ +
+
+
    pub constraints: Vec<Constraint>,
+
+
+
+ 17 +
+
+ +
+
+
}
+
+
+
+ 18 +
+
+ +
+
+

+            
+
+
+ 19 +
+
+ +
+
+
impl Model {
+
+
+
+ 20 +
+
+ 1 +
+
+
    pub fn new() -> Model {
+
+
+
+ 21 +
+
+ 1 +
+
+
        Model {
+
+
+
+ 22 +
+
+ 1 +
+
+
            named_variables: SymbolTable::new(),
+
+
+
+ 23 +
+
+ 1 +
+
+
            constraints: Vec::new(),
+
+
+
+ 24 +
+
+ 1 +
+
+
        }
+
+
+
+ 25 +
+
+ 1 +
+
+
    }
+
+
+
+ 26 +
+
+ +
+
+
}
+
+
+
+ 27 +
+
+ +
+
+

+            
+
+
+ 28 +
+
+ +
+
+
pub enum Constraint {
+
+
+
+ 29 +
+
+ +
+
+
    SumLeq(Vec<Var>, Var),
+
+
+
+ 30 +
+
+ +
+
+
    SumGeq(Vec<Var>, Var),
+
+
+
+ 31 +
+
+ +
+
+
    Ineq(Var, Var, Constant),
+
+
+
+ 32 +
+
+ +
+
+
}
+
+
+
+ 33 +
+
+ +
+
+

+            
+
+
+ 34 +
+
+ +
+
+
/// A variable can either be a named variable, or an anomynous "constant as a variable".
+
+
+
+ 35 +
+
+ +
+
+
///
+
+
+
+ 36 +
+
+ +
+
+
/// The latter is not stored in the symbol table, or counted in Minions internal list of all
+
+
+
+ 37 +
+
+ +
+
+
/// variables, but is used to allow the use of a constant in the place of a variable in a
+
+
+
+ 38 +
+
+ +
+
+
/// constraint.
+
+
+
+ 39 +
+
+ +
+
+
pub enum Var {
+
+
+
+ 40 +
+
+ +
+
+
    NameRef(VarName),
+
+
+
+ 41 +
+
+ +
+
+
    ConstantAsVar(i32),
+
+
+
+ 42 +
+
+ +
+
+
}
+
+
+
+ 43 +
+
+ +
+
+

+            
+
+
+ 44 +
+
+ +
+
+
pub enum Constant {
+
+
+
+ 45 +
+
+ +
+
+
    Bool(bool),
+
+
+
+ 46 +
+
+ +
+
+
    Integer(i32),
+
+
+
+ 47 +
+
+ +
+
+
}
+
+
+
+ 48 +
+
+ +
+
+

+            
+
+
+ 49 +
+
+ +
+
+
#[derive(Copy, Clone)]
+
+
+
+ 50 +
+
+ +
+
+
pub enum VarDomain {
+
+
+
+ 51 +
+
+ +
+
+
    Bound(i32, i32),
+
+
+
+ 52 +
+
+ +
+
+
    Discrete(i32, i32),
+
+
+
+ 53 +
+
+ +
+
+
    SparseBound(i32, i32),
+
+
+
+ 54 +
+
+ +
+
+
    Bool(bool),
+
+
+
+ 55 +
+
+ +
+
+
}
+
+
+
+ 56 +
+
+ +
+
+

+            
+
+
+ 57 +
+
+ +
+
+
pub struct SymbolTable {
+
+
+
+ 58 +
+
+ +
+
+
    table: HashMap<VarName, VarDomain>,
+
+
+
+ 59 +
+
+ +
+
+

+            
+
+
+ 60 +
+
+ +
+
+
    // for now doubles both as Minion's SearchOrder and print order
+
+
+
+ 61 +
+
+ +
+
+
    var_order: Vec<VarName>,
+
+
+
+ 62 +
+
+ +
+
+
}
+
+
+
+ 63 +
+
+ +
+
+

+            
+
+
+ 64 +
+
+ +
+
+
impl SymbolTable {
+
+
+
+ 65 +
+
+ 1 +
+
+
    fn new() -> SymbolTable {
+
+
+
+ 66 +
+
+ 1 +
+
+
        SymbolTable {
+
+
+
+ 67 +
+
+ 1 +
+
+
            table: HashMap::new(),
+
+
+
+ 68 +
+
+ 1 +
+
+
            var_order: Vec::new(),
+
+
+
+ 69 +
+
+ 1 +
+
+
        }
+
+
+
+ 70 +
+
+ 1 +
+
+
    }
+
+
+
+ 71 +
+
+ +
+
+

+            
+
+
+ 72 +
+
+ +
+
+
    /// Creates a new variable and adds it to the symbol table.
+
+
+
+ 73 +
+
+ +
+
+
    /// If a variable already exists with the given name, an error is thrown.
+
+
+
+ 74 +
+
+ 3 +
+
+
    pub fn add_var(&mut self, name: VarName, vartype: VarDomain) -> Option<()> {
+
+
+
+ 75 +
+
+ 3 +
+
+
        if self.table.contains_key(&name) {
+
+
+
+ 76 +
+
+ +
+
+
            return None;
+
+
+
+ 77 +
+
+ 3 +
+
+
        }
+
+
+
+ 78 +
+
+ 3 +
+
+

+            
+
+
+ 79 +
+
+ 3 +
+
+
        self.table.insert(name.clone(), vartype);
+
+
+
+ 80 +
+
+ 3 +
+
+
        self.var_order.push(name);
+
+
+
+ 81 +
+
+ 3 +
+
+

+            
+
+
+ 82 +
+
+ 3 +
+
+
        return Some(());
+
+
+
+ 83 +
+
+ 3 +
+
+
    }
+
+
+
+ 84 +
+
+ +
+
+

+            
+
+
+ 85 +
+
+ 3 +
+
+
    pub fn get_vartype(&self, name: VarName) -> Option<VarDomain> {
+
+
+
+ 86 +
+
+ 3 +
+
+
        match self.table.get(&name) {
+
+
+
+ 87 +
+
+ 3 +
+
+
            Some(m) => Some(*m),
+
+
+
+ 88 +
+
+ +
+
+
            None => None,
+
+
+
+ 89 +
+
+ +
+
+
        }
+
+
+
+ 90 +
+
+ 3 +
+
+
    }
+
+
+
+ 91 +
+
+ +
+
+

+            
+
+
+ 92 +
+
+ 1 +
+
+
    pub fn get_variable_order(&self) -> Vec<VarName> {
+
+
+
+ 93 +
+
+ 1 +
+
+
        self.var_order.clone()
+
+
+
+ 94 +
+
+ 1 +
+
+
    }
+
+
+
+ 95 +
+
+ +
+
+

+            
+
+
+ 96 +
+
+ +
+
+
    pub fn contains(&self, name: VarName) -> bool {
+
+
+
+ 97 +
+
+ +
+
+
        self.table.contains_key(&name)
+
+
+
+ 98 +
+
+ +
+
+
    }
+
+
+
+ 99 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/error.rs.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/error.rs.html new file mode 100644 index 0000000000..d8805bb24b --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/error.rs.html @@ -0,0 +1,578 @@ + + + + + Grcov report - error.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
/*
+
+
+
+ 2 +
+
+ +
+
+
 * This Source Code Form is subject to the terms of the Mozilla Public
+
+
+
+ 3 +
+
+ +
+
+
 * License, v. 2.0. If a copy of the MPL was not distributed with this
+
+
+
+ 4 +
+
+ +
+
+
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+
+
+ 5 +
+
+ +
+
+
 */
+
+
+
+ 6 +
+
+ +
+
+

+            
+
+
+ 7 +
+
+ +
+
+
//! Error types for Minion bindings.
+
+
+
+ 8 +
+
+ +
+
+

+            
+
+
+ 9 +
+
+ +
+
+
use crate::raw_bindings::*;
+
+
+
+ 10 +
+
+ +
+
+
use thiserror::Error;
+
+
+
+ 11 +
+
+ +
+
+

+            
+
+
+ 12 +
+
+ +
+
+
/// RuntimeErrors are thrown by Minion during execution.
+
+
+
+ 13 +
+
+ +
+
+
#[derive(Debug, Error)]
+
+
+
+ 14 +
+
+ +
+
+
pub enum RuntimeError {
+
+
+
+ 15 +
+
+ +
+
+
    // These closely follow the ReturnCodes found in Minion's libwrapper.cpp.
+
+
+
+ 16 +
+
+ +
+
+
    #[error("the given instance is invalid")]
+
+
+
+ 17 +
+
+ +
+
+
    InvalidInstance,
+
+
+
+ 18 +
+
+ +
+
+

+            
+
+
+ 19 +
+
+ +
+
+
    #[error("an unknown error has occurred while running minion")]
+
+
+
+ 20 +
+
+ +
+
+
    UnknownError,
+
+
+
+ 21 +
+
+ +
+
+
}
+
+
+
+ 22 +
+
+ +
+
+

+            
+
+
+ 23 +
+
+ +
+
+
// Minion's ReturnCodes are passed over FFI as ints.
+
+
+
+ 24 +
+
+ +
+
+
// Convert them to their appropriate error.
+
+
+
+ 25 +
+
+ +
+
+
impl From<u32> for RuntimeError {
+
+
+
+ 26 +
+
+ +
+
+
    fn from(return_code: u32) -> Self {
+
+
+
+ 27 +
+
+ +
+
+
        match return_code {
+
+
+
+ 28 +
+
+ +
+
+
            #[allow(non_upper_case_globals)]
+
+
+
+ 29 +
+
+ +
+
+
            ReturnCodes_INVALID_INSTANCE => RuntimeError::InvalidInstance,
+
+
+
+ 30 +
+
+ +
+
+
            _ => RuntimeError::UnknownError,
+
+
+
+ 31 +
+
+ +
+
+
        }
+
+
+
+ 32 +
+
+ +
+
+
    }
+
+
+
+ 33 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/index.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/index.html new file mode 100644 index 0000000000..2a5f341cc6 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/index.html @@ -0,0 +1,196 @@ + + + + + Grcov report - src + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileLine CoverageFunctionsBranches
ast.rs + + 53.85% + + + 53.85% + + 28 / 52 + 35.71%5 / 14 100%0 / 0
error.rs + + 0% + + + 0% + + 0 / 7 + 0%0 / 3 100%0 / 0
raw_bindings.rs + + 97.7% + + + 97.7% + + 85 / 87 + 60%3 / 5 100%0 / 0
run.rs + + 76.86% + + + 76.86% + + 176 / 229 + 48.72%19 / 39 100%0 / 0
scoped_ptr.rs + + 57.14% + + + 57.14% + + 8 / 14 + 50%12 / 24 100%0 / 0
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/raw_bindings.rs.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/raw_bindings.rs.html new file mode 100644 index 0000000000..e692d8f009 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/raw_bindings.rs.html @@ -0,0 +1,1826 @@ + + + + + Grcov report - raw_bindings.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
/*
+
+
+
+ 2 +
+
+ +
+
+
 * This Source Code Form is subject to the terms of the Mozilla Public
+
+
+
+ 3 +
+
+ +
+
+
 * License, v. 2.0. If a copy of the MPL was not distributed with this
+
+
+
+ 4 +
+
+ +
+
+
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+
+
+ 5 +
+
+ +
+
+
 */
+
+
+
+ 6 +
+
+ +
+
+

+            
+
+
+ 7 +
+
+ +
+
+
#![allow(warnings)]
+
+
+
+ 8 +
+
+ +
+
+
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
+
+
+
+ 9 +
+
+ +
+
+

+            
+
+
+ 10 +
+
+ +
+
+
#[cfg(test)]
+
+
+
+ 11 +
+
+ +
+
+
mod tests {
+
+
+
+ 12 +
+
+ +
+
+

+            
+
+
+ 13 +
+
+ +
+
+
    use super::*;
+
+
+
+ 14 +
+
+ +
+
+
    use std::ffi::CString;
+
+
+
+ 15 +
+
+ +
+
+

+            
+
+
+ 16 +
+
+ +
+
+
    // solutions
+
+
+
+ 17 +
+
+ +
+
+
    static mut X_VAL: i32 = 0;
+
+
+
+ 18 +
+
+ +
+
+
    static mut Y_VAL: i32 = 0;
+
+
+
+ 19 +
+
+ +
+
+
    static mut Z_VAL: i32 = 0;
+
+
+
+ 20 +
+
+ +
+
+

+            
+
+
+ 21 +
+
+ +
+
+
    #[no_mangle]
+
+
+
+ 22 +
+
+ 1 +
+
+
    pub extern "C" fn hello_from_rust() -> bool {
+
+
+
+ 23 +
+
+ 1 +
+
+
        unsafe {
+
+
+
+ 24 +
+
+ 1 +
+
+
            X_VAL = printMatrix_getValue(0) as _;
+
+
+
+ 25 +
+
+ 1 +
+
+
            Y_VAL = printMatrix_getValue(1) as _;
+
+
+
+ 26 +
+
+ 1 +
+
+
            Z_VAL = printMatrix_getValue(2) as _;
+
+
+
+ 27 +
+
+ 1 +
+
+
            return true;
+
+
+
+ 28 +
+
+ 1 +
+
+
        }
+
+
+
+ 29 +
+
+ 1 +
+
+
    }
+
+
+
+ 30 +
+
+ +
+
+

+            
+
+
+ 31 +
+
+ 1 +
+
+
    #[test]
+
+
+
+ 32 +
+
+ 1 +
+
+
    fn xyz_raw() {
+
+
+
+ 33 +
+
+ 1 +
+
+
        // A simple constraints model, manually written using FFI functions.
+
+
+
+ 34 +
+
+ 1 +
+
+
        // Testing to see if it does not segfault.
+
+
+
+ 35 +
+
+ 1 +
+
+
        // Results can be manually inspected in the outputted minion logs.
+
+
+
+ 36 +
+
+ 1 +
+
+
        unsafe {
+
+
+
+ 37 +
+
+ 1 +
+
+
            // See https://rust-lang.github.io/rust-bindgen/cpp.html
+
+
+
+ 38 +
+
+ 1 +
+
+
            let options = newSearchOptions();
+
+
+
+ 39 +
+
+ 1 +
+
+
            let args = newSearchMethod();
+
+
+
+ 40 +
+
+ 1 +
+
+
            let instance = newInstance();
+
+
+
+ 41 +
+
+ 1 +
+
+

+            
+
+
+ 42 +
+
+ 1 +
+
+
            let x_str = CString::new("x").expect("bad x");
+
+
+
+ 43 +
+
+ 1 +
+
+
            let y_str = CString::new("y").expect("bad y");
+
+
+
+ 44 +
+
+ 1 +
+
+
            let z_str = CString::new("z").expect("bad z");
+
+
+
+ 45 +
+
+ 1 +
+
+

+            
+
+
+ 46 +
+
+ 1 +
+
+
            newVar_ffi(instance, x_str.as_ptr() as _, VariableType_VAR_BOUND, 1, 3);
+
+
+
+ 47 +
+
+ 1 +
+
+
            newVar_ffi(instance, y_str.as_ptr() as _, VariableType_VAR_BOUND, 2, 4);
+
+
+
+ 48 +
+
+ 1 +
+
+
            newVar_ffi(instance, z_str.as_ptr() as _, VariableType_VAR_BOUND, 1, 5);
+
+
+
+ 49 +
+
+ 1 +
+
+

+            
+
+
+ 50 +
+
+ 1 +
+
+
            let x = getVarByName(instance, x_str.as_ptr() as _);
+
+
+
+ 51 +
+
+ 1 +
+
+
            let y = getVarByName(instance, y_str.as_ptr() as _);
+
+
+
+ 52 +
+
+ 1 +
+
+
            let z = getVarByName(instance, z_str.as_ptr() as _);
+
+
+
+ 53 +
+
+ 1 +
+
+

+            
+
+
+ 54 +
+
+ 1 +
+
+
            // PRINT
+
+
+
+ 55 +
+
+ 1 +
+
+
            printMatrix_addVar(instance, x);
+
+
+
+ 56 +
+
+ 1 +
+
+
            printMatrix_addVar(instance, y);
+
+
+
+ 57 +
+
+ 1 +
+
+
            printMatrix_addVar(instance, z);
+
+
+
+ 58 +
+
+ 1 +
+
+

+            
+
+
+ 59 +
+
+ 1 +
+
+
            // VARORDER
+
+
+
+ 60 +
+
+ 1 +
+
+
            let search_vars = vec_var_new();
+
+
+
+ 61 +
+
+ 1 +
+
+
            vec_var_push_back(search_vars as _, x);
+
+
+
+ 62 +
+
+ 1 +
+
+
            vec_var_push_back(search_vars as _, y);
+
+
+
+ 63 +
+
+ 1 +
+
+
            vec_var_push_back(search_vars as _, z);
+
+
+
+ 64 +
+
+ 1 +
+
+
            let search_order = newSearchOrder(search_vars as _, VarOrderEnum_ORDER_STATIC, false);
+
+
+
+ 65 +
+
+ 1 +
+
+
            instance_addSearchOrder(instance, search_order);
+
+
+
+ 66 +
+
+ 1 +
+
+

+            
+
+
+ 67 +
+
+ 1 +
+
+
            // CONSTRAINTS
+
+
+
+ 68 +
+
+ 1 +
+
+
            let leq = newConstraintBlob(ConstraintType_CT_LEQSUM);
+
+
+
+ 69 +
+
+ 1 +
+
+
            let geq = newConstraintBlob(ConstraintType_CT_GEQSUM);
+
+
+
+ 70 +
+
+ 1 +
+
+
            let ineq = newConstraintBlob(ConstraintType_CT_INEQ);
+
+
+
+ 71 +
+
+ 1 +
+
+

+            
+
+
+ 72 +
+
+ 1 +
+
+
            let rhs_vars = vec_var_new();
+
+
+
+ 73 +
+
+ 1 +
+
+
            vec_var_push_back(rhs_vars, constantAsVar(4));
+
+
+
+ 74 +
+
+ 1 +
+
+

+            
+
+
+ 75 +
+
+ 1 +
+
+
            // leq / geq : [var] [var]
+
+
+
+ 76 +
+
+ 1 +
+
+
            constraint_addVarList(leq, search_vars as _);
+
+
+
+ 77 +
+
+ 1 +
+
+
            constraint_addVarList(leq, rhs_vars as _);
+
+
+
+ 78 +
+
+ 1 +
+
+

+            
+
+
+ 79 +
+
+ 1 +
+
+
            constraint_addVarList(geq, search_vars as _);
+
+
+
+ 80 +
+
+ 1 +
+
+
            constraint_addVarList(geq, rhs_vars as _);
+
+
+
+ 81 +
+
+ 1 +
+
+

+            
+
+
+ 82 +
+
+ 1 +
+
+
            // ineq: [var] [var] [const]
+
+
+
+ 83 +
+
+ 1 +
+
+
            let x_vec = vec_var_new();
+
+
+
+ 84 +
+
+ 1 +
+
+
            vec_var_push_back(x_vec, x);
+
+
+
+ 85 +
+
+ 1 +
+
+

+            
+
+
+ 86 +
+
+ 1 +
+
+
            let y_vec = vec_var_new();
+
+
+
+ 87 +
+
+ 1 +
+
+
            vec_var_push_back(y_vec, y);
+
+
+
+ 88 +
+
+ 1 +
+
+

+            
+
+
+ 89 +
+
+ 1 +
+
+
            let const_vec = vec_int_new();
+
+
+
+ 90 +
+
+ 1 +
+
+
            vec_int_push_back(const_vec, -1);
+
+
+
+ 91 +
+
+ 1 +
+
+

+            
+
+
+ 92 +
+
+ 1 +
+
+
            constraint_addVarList(ineq, x_vec as _);
+
+
+
+ 93 +
+
+ 1 +
+
+
            constraint_addVarList(ineq, y_vec as _);
+
+
+
+ 94 +
+
+ 1 +
+
+
            constraint_addConstantList(ineq, const_vec as _);
+
+
+
+ 95 +
+
+ 1 +
+
+

+            
+
+
+ 96 +
+
+ 1 +
+
+
            instance_addConstraint(instance, leq);
+
+
+
+ 97 +
+
+ 1 +
+
+
            instance_addConstraint(instance, geq);
+
+
+
+ 98 +
+
+ 1 +
+
+
            instance_addConstraint(instance, ineq);
+
+
+
+ 99 +
+
+ 1 +
+
+

+            
+
+
+ 100 +
+
+ 1 +
+
+
            let res = runMinion(options, args, instance, Some(hello_from_rust));
+
+
+
+ 101 +
+
+ 1 +
+
+

+            
+
+
+ 102 +
+
+ 1 +
+
+
            // does it get this far?
+
+
+
+ 103 +
+
+ 1 +
+
+
            assert_eq!(res, 0);
+
+
+
+ 104 +
+
+ +
+
+

+            
+
+
+ 105 +
+
+ +
+
+
            // test if solutions are correct
+
+
+
+ 106 +
+
+ 1 +
+
+
            assert_eq!(X_VAL, 1);
+
+
+
+ 107 +
+
+ 1 +
+
+
            assert_eq!(Y_VAL, 2);
+
+
+
+ 108 +
+
+ 1 +
+
+
            assert_eq!(Z_VAL, 1);
+
+
+
+ 109 +
+
+ +
+
+
        }
+
+
+
+ 110 +
+
+ 1 +
+
+
    }
+
+
+
+ 111 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/run.rs.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/run.rs.html new file mode 100644 index 0000000000..177bc93615 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/run.rs.html @@ -0,0 +1,4130 @@ + + + + + Grcov report - run.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
/*
+
+
+
+ 2 +
+
+ +
+
+
 * This Source Code Form is subject to the terms of the Mozilla Public
+
+
+
+ 3 +
+
+ +
+
+
 * License, v. 2.0. If a copy of the MPL was not distributed with this
+
+
+
+ 4 +
+
+ +
+
+
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+
+
+ 5 +
+
+ +
+
+
 */
+
+
+
+ 6 +
+
+ +
+
+

+            
+
+
+ 7 +
+
+ +
+
+
use std::ffi::CString;
+
+
+
+ 8 +
+
+ +
+
+

+            
+
+
+ 9 +
+
+ +
+
+
use crate::{ast::*, error::*, raw_bindings::*, scoped_ptr::Scoped};
+
+
+
+ 10 +
+
+ +
+
+

+            
+
+
+ 11 +
+
+ +
+
+
// TODO: allow passing of options.
+
+
+
+ 12 +
+
+ +
+
+

+            
+
+
+ 13 +
+
+ +
+
+
/// Callback function used to capture results from minion as they are generated.
+
+
+
+ 14 +
+
+ +
+
+
/// Should return `true` if search is to continue, `false` otherwise.
+
+
+
+ 15 +
+
+ +
+
+
pub type Callback = fn(Vec<(VarName, Constant)>) -> bool;
+
+
+
+ 16 +
+
+ +
+
+

+            
+
+
+ 17 +
+
+ +
+
+
#[no_mangle]
+
+
+
+ 18 +
+
+ 1 +
+
+
extern "C" fn hello_from_rust2() -> bool {
+
+
+
+ 19 +
+
+ 1 +
+
+
    return true;
+
+
+
+ 20 +
+
+ 1 +
+
+
}
+
+
+
+ 21 +
+
+ +
+
+

+            
+
+
+ 22 +
+
+ 1 +
+
+
pub fn run_minion(model: Model, callback: Callback) -> Result<(), RuntimeError> {
+
+
+
+ 23 +
+
+ 1 +
+
+
    unsafe {
+
+
+
+ 24 +
+
+ 1 +
+
+
        let options = Scoped::new(newSearchOptions(), |x| searchOptions_free(x as _));
+
+
+
+ 25 +
+
+ 1 +
+
+
        let args = Scoped::new(newSearchMethod(), |x| searchMethod_free(x as _));
+
+
+
+ 26 +
+
+ 1 +
+
+
        let instance = Scoped::new(convert_model_to_raw(&model), |x| instance_free(x as _));
+
+
+
+ 27 +
+
+ 1 +
+
+
        let res = runMinion(options.ptr, args.ptr, instance.ptr, Some(hello_from_rust2));
+
+
+
+ 28 +
+
+ 1 +
+
+

+            
+
+
+ 29 +
+
+ 1 +
+
+
        match res {
+
+
+
+ 30 +
+
+ 1 +
+
+
            0 => Ok(()),
+
+
+
+ 31 +
+
+ +
+
+
            x => Err(RuntimeError::from(x)),
+
+
+
+ 32 +
+
+ +
+
+
        }
+
+
+
+ 33 +
+
+ +
+
+
    }
+
+
+
+ 34 +
+
+ 1 +
+
+
}
+
+
+
+ 35 +
+
+ +
+
+

+            
+
+
+ 36 +
+
+ +
+
+
/// Callee owns the returned instance
+
+
+
+ 37 +
+
+ 1 +
+
+
unsafe fn convert_model_to_raw(model: &Model) -> *mut ProbSpec_CSPInstance {
+
+
+
+ 38 +
+
+ 1 +
+
+
    // This is managed in scope by the callee
+
+
+
+ 39 +
+
+ 1 +
+
+
    let instance = newInstance();
+
+
+
+ 40 +
+
+ 1 +
+
+

+            
+
+
+ 41 +
+
+ 1 +
+
+
    /*******************************/
+
+
+
+ 42 +
+
+ 1 +
+
+
    /*        Add variables        */
+
+
+
+ 43 +
+
+ 1 +
+
+
    /*******************************/
+
+
+
+ 44 +
+
+ 1 +
+
+

+            
+
+
+ 45 +
+
+ 1 +
+
+
    /*
+
+
+
+ 46 +
+
+ 1 +
+
+
     * Add variables to:
+
+
+
+ 47 +
+
+ 1 +
+
+
     * 1. symbol table
+
+
+
+ 48 +
+
+ 1 +
+
+
     * 2. print matrix
+
+
+
+ 49 +
+
+ 1 +
+
+
     * 3. search vars
+
+
+
+ 50 +
+
+ 1 +
+
+
     *
+
+
+
+ 51 +
+
+ 1 +
+
+
     * These are all done in the order saved in the SymbolTable.
+
+
+
+ 52 +
+
+ 1 +
+
+
     */
+
+
+
+ 53 +
+
+ 1 +
+
+

+            
+
+
+ 54 +
+
+ 1 +
+
+
    let search_vars = Scoped::new(vec_var_new(), |x| vec_var_free(x as _));
+
+
+
+ 55 +
+
+ +
+
+

+            
+
+
+ 56 +
+
+ 3 +
+
+
    for var_name in model.named_variables.get_variable_order() {
+
+
+
+ 57 +
+
+ +
+
+
        //TODO: make this return Result
+
+
+
+ 58 +
+
+ 3 +
+
+
        let c_str = CString::new(var_name.clone()).expect("");
+
+
+
+ 59 +
+
+ 3 +
+
+
        let vartype = model
+
+
+
+ 60 +
+
+ 3 +
+
+
            .named_variables
+
+
+
+ 61 +
+
+ 3 +
+
+
            .get_vartype(var_name.clone())
+
+
+
+ 62 +
+
+ 3 +
+
+
            .expect("");
+
+
+
+ 63 +
+
+ +
+
+

+            
+
+
+ 64 +
+
+ 3 +
+
+
        let (vartype_raw, domain_low, domain_high) = match vartype {
+
+
+
+ 65 +
+
+ 3 +
+
+
            VarDomain::Bound(a, b) => (VariableType_VAR_BOUND, a, b),
+
+
+
+ 66 +
+
+ +
+
+
            _ => panic!("NOT IMPLEMENTED"),
+
+
+
+ 67 +
+
+ +
+
+
        };
+
+
+
+ 68 +
+
+ +
+
+

+            
+
+
+ 69 +
+
+ 3 +
+
+
        newVar_ffi(
+
+
+
+ 70 +
+
+ 3 +
+
+
            instance,
+
+
+
+ 71 +
+
+ 3 +
+
+
            c_str.as_ptr() as _,
+
+
+
+ 72 +
+
+ 3 +
+
+
            vartype_raw,
+
+
+
+ 73 +
+
+ 3 +
+
+
            domain_low,
+
+
+
+ 74 +
+
+ 3 +
+
+
            domain_high,
+
+
+
+ 75 +
+
+ 3 +
+
+
        );
+
+
+
+ 76 +
+
+ 3 +
+
+

+            
+
+
+ 77 +
+
+ 3 +
+
+
        let var = getVarByName(instance, c_str.as_ptr() as _);
+
+
+
+ 78 +
+
+ 3 +
+
+

+            
+
+
+ 79 +
+
+ 3 +
+
+
        printMatrix_addVar(instance, var);
+
+
+
+ 80 +
+
+ 3 +
+
+
        vec_var_push_back(search_vars.ptr, var);
+
+
+
+ 81 +
+
+ +
+
+
    }
+
+
+
+ 82 +
+
+ +
+
+

+            
+
+
+ 83 +
+
+ 1 +
+
+
    let search_order = Scoped::new(
+
+
+
+ 84 +
+
+ 1 +
+
+
        newSearchOrder(search_vars.ptr, VarOrderEnum_ORDER_STATIC, false),
+
+
+
+ 85 +
+
+ 1 +
+
+
        |x| searchOrder_free(x as _),
+
+
+
+ 86 +
+
+ 1 +
+
+
    );
+
+
+
+ 87 +
+
+ 1 +
+
+

+            
+
+
+ 88 +
+
+ 1 +
+
+
    // this and other instance_ functions does not move so my use of ptrs are ok
+
+
+
+ 89 +
+
+ 1 +
+
+
    // TODO (nd60): document this
+
+
+
+ 90 +
+
+ 1 +
+
+
    instance_addSearchOrder(instance, search_order.ptr);
+
+
+
+ 91 +
+
+ +
+
+

+            
+
+
+ 92 +
+
+ +
+
+
    /*********************************/
+
+
+
+ 93 +
+
+ +
+
+
    /*        Add constraints        */
+
+
+
+ 94 +
+
+ +
+
+
    /*********************************/
+
+
+
+ 95 +
+
+ +
+
+

+            
+
+
+ 96 +
+
+ 4 +
+
+
    for constraint in &model.constraints {
+
+
+
+ 97 +
+
+ 3 +
+
+
        // 1. get constraint type and create C++ constraint object
+
+
+
+ 98 +
+
+ 3 +
+
+
        // 2. run through arguments and add them to the constraint
+
+
+
+ 99 +
+
+ 3 +
+
+
        // 3. add constraint to instance
+
+
+
+ 100 +
+
+ 3 +
+
+

+            
+
+
+ 101 +
+
+ 3 +
+
+
        let constraint_type = get_constraint_type(constraint);
+
+
+
+ 102 +
+
+ 3 +
+
+
        let raw_constraint = Scoped::new(newConstraintBlob(constraint_type), |x| {
+
+
+
+ 103 +
+
+ 3 +
+
+
            constraint_free(x as _)
+
+
+
+ 104 +
+
+ 3 +
+
+
        });
+
+
+
+ 105 +
+
+ 3 +
+
+

+            
+
+
+ 106 +
+
+ 3 +
+
+
        constraint_add_args(instance, raw_constraint.ptr, constraint);
+
+
+
+ 107 +
+
+ 3 +
+
+
        instance_addConstraint(instance, raw_constraint.ptr);
+
+
+
+ 108 +
+
+ 3 +
+
+
    }
+
+
+
+ 109 +
+
+ +
+
+

+            
+
+
+ 110 +
+
+ 1 +
+
+
    return instance;
+
+
+
+ 111 +
+
+ 1 +
+
+
}
+
+
+
+ 112 +
+
+ +
+
+

+            
+
+
+ 113 +
+
+ 3 +
+
+
unsafe fn get_constraint_type(constraint: &Constraint) -> u32 {
+
+
+
+ 114 +
+
+ 3 +
+
+
    match constraint {
+
+
+
+ 115 +
+
+ 1 +
+
+
        Constraint::SumGeq(_, _) => ConstraintType_CT_GEQSUM,
+
+
+
+ 116 +
+
+ 1 +
+
+
        Constraint::SumLeq(_, _) => ConstraintType_CT_LEQSUM,
+
+
+
+ 117 +
+
+ 1 +
+
+
        Constraint::Ineq(_, _, _) => ConstraintType_CT_INEQ,
+
+
+
+ 118 +
+
+ +
+
+
        #[allow(unreachable_patterns)]
+
+
+
+ 119 +
+
+ +
+
+
        _ => panic!("NOT IMPLEMENTED"),
+
+
+
+ 120 +
+
+ +
+
+
    }
+
+
+
+ 121 +
+
+ 3 +
+
+
}
+
+
+
+ 122 +
+
+ +
+
+

+            
+
+
+ 123 +
+
+ 3 +
+
+
unsafe fn constraint_add_args(
+
+
+
+ 124 +
+
+ 3 +
+
+
    i: *mut ProbSpec_CSPInstance,
+
+
+
+ 125 +
+
+ 3 +
+
+
    r_constr: *mut ProbSpec_ConstraintBlob,
+
+
+
+ 126 +
+
+ 3 +
+
+
    constr: &Constraint,
+
+
+
+ 127 +
+
+ 3 +
+
+
) {
+
+
+
+ 128 +
+
+ 3 +
+
+
    match constr {
+
+
+
+ 129 +
+
+ 1 +
+
+
        Constraint::SumGeq(lhs_vars, rhs_var) => {
+
+
+
+ 130 +
+
+ 1 +
+
+
            read_vars(i, r_constr, &lhs_vars);
+
+
+
+ 131 +
+
+ 1 +
+
+
            read_var(i, r_constr, rhs_var)
+
+
+
+ 132 +
+
+ +
+
+
        }
+
+
+
+ 133 +
+
+ 1 +
+
+
        Constraint::SumLeq(lhs_vars, rhs_var) => {
+
+
+
+ 134 +
+
+ 1 +
+
+
            read_vars(i, r_constr, &lhs_vars);
+
+
+
+ 135 +
+
+ 1 +
+
+
            read_var(i, r_constr, rhs_var)
+
+
+
+ 136 +
+
+ +
+
+
        }
+
+
+
+ 137 +
+
+ 1 +
+
+
        Constraint::Ineq(var1, var2, c) => {
+
+
+
+ 138 +
+
+ 1 +
+
+
            read_var(i, r_constr, &var1);
+
+
+
+ 139 +
+
+ 1 +
+
+
            read_var(i, r_constr, &var2);
+
+
+
+ 140 +
+
+ 1 +
+
+
            read_const(r_constr, c)
+
+
+
+ 141 +
+
+ +
+
+
        }
+
+
+
+ 142 +
+
+ +
+
+
        #[allow(unreachable_patterns)]
+
+
+
+ 143 +
+
+ +
+
+
        _ => panic!("NOT IMPLEMENTED"),
+
+
+
+ 144 +
+
+ +
+
+
    };
+
+
+
+ 145 +
+
+ 3 +
+
+
}
+
+
+
+ 146 +
+
+ +
+
+

+            
+
+
+ 147 +
+
+ +
+
+
// DO NOT call manually - this assumes that all needed vars are already in the symbol table.
+
+
+
+ 148 +
+
+ +
+
+
// TODO not happy with this just assuming the name is in the symbol table
+
+
+
+ 149 +
+
+ 2 +
+
+
unsafe fn read_vars(
+
+
+
+ 150 +
+
+ 2 +
+
+
    instance: *mut ProbSpec_CSPInstance,
+
+
+
+ 151 +
+
+ 2 +
+
+
    raw_constraint: *mut ProbSpec_ConstraintBlob,
+
+
+
+ 152 +
+
+ 2 +
+
+
    vars: &Vec<Var>,
+
+
+
+ 153 +
+
+ 2 +
+
+
) {
+
+
+
+ 154 +
+
+ 2 +
+
+
    let raw_vars = Scoped::new(vec_var_new(), |x| vec_var_free(x as _));
+
+
+
+ 155 +
+
+ 8 +
+
+
    for var in vars {
+
+
+
+ 156 +
+
+ 6 +
+
+
        // TODO: could easily break and segfault and die and so on
+
+
+
+ 157 +
+
+ 6 +
+
+
        let raw_var = match var {
+
+
+
+ 158 +
+
+ 6 +
+
+
            Var::NameRef(name) => {
+
+
+
+ 159 +
+
+ 6 +
+
+
                let c_str = CString::new(name.clone()).expect("");
+
+
+
+ 160 +
+
+ 6 +
+
+
                getVarByName(instance, c_str.as_ptr() as _)
+
+
+
+ 161 +
+
+ +
+
+
            }
+
+
+
+ 162 +
+
+ +
+
+
            Var::ConstantAsVar(n) => constantAsVar(*n),
+
+
+
+ 163 +
+
+ +
+
+
        };
+
+
+
+ 164 +
+
+ +
+
+

+            
+
+
+ 165 +
+
+ 6 +
+
+
        vec_var_push_back(raw_vars.ptr, raw_var);
+
+
+
+ 166 +
+
+ +
+
+
    }
+
+
+
+ 167 +
+
+ +
+
+

+            
+
+
+ 168 +
+
+ 2 +
+
+
    constraint_addVarList(raw_constraint, raw_vars.ptr);
+
+
+
+ 169 +
+
+ 2 +
+
+
}
+
+
+
+ 170 +
+
+ +
+
+

+            
+
+
+ 171 +
+
+ 4 +
+
+
unsafe fn read_var(
+
+
+
+ 172 +
+
+ 4 +
+
+
    instance: *mut ProbSpec_CSPInstance,
+
+
+
+ 173 +
+
+ 4 +
+
+
    raw_constraint: *mut ProbSpec_ConstraintBlob,
+
+
+
+ 174 +
+
+ 4 +
+
+
    var: &Var,
+
+
+
+ 175 +
+
+ 4 +
+
+
) {
+
+
+
+ 176 +
+
+ 4 +
+
+
    let raw_vars = Scoped::new(vec_var_new(), |x| vec_var_free(x as _));
+
+
+
+ 177 +
+
+ 4 +
+
+
    let raw_var = match var {
+
+
+
+ 178 +
+
+ 2 +
+
+
        Var::NameRef(name) => {
+
+
+
+ 179 +
+
+ 2 +
+
+
            let c_str = CString::new(name.clone()).expect("");
+
+
+
+ 180 +
+
+ 2 +
+
+
            getVarByName(instance, c_str.as_ptr() as _)
+
+
+
+ 181 +
+
+ +
+
+
        }
+
+
+
+ 182 +
+
+ 2 +
+
+
        Var::ConstantAsVar(n) => constantAsVar(*n),
+
+
+
+ 183 +
+
+ +
+
+
    };
+
+
+
+ 184 +
+
+ +
+
+

+            
+
+
+ 185 +
+
+ 4 +
+
+
    vec_var_push_back(raw_vars.ptr, raw_var);
+
+
+
+ 186 +
+
+ 4 +
+
+
    constraint_addVarList(raw_constraint, raw_vars.ptr);
+
+
+
+ 187 +
+
+ 4 +
+
+
}
+
+
+
+ 188 +
+
+ +
+
+

+            
+
+
+ 189 +
+
+ 1 +
+
+
unsafe fn read_const(raw_constraint: *mut ProbSpec_ConstraintBlob, constant: &Constant) {
+
+
+
+ 190 +
+
+ 1 +
+
+
    let raw_consts = Scoped::new(vec_int_new(), |x| vec_var_free(x as _));
+
+
+
+ 191 +
+
+ +
+
+

+            
+
+
+ 192 +
+
+ 1 +
+
+
    let val = match constant {
+
+
+
+ 193 +
+
+ 1 +
+
+
        Constant::Integer(n) => n,
+
+
+
+ 194 +
+
+ +
+
+
        _ => panic!("NOT IMPLEMENTED"),
+
+
+
+ 195 +
+
+ +
+
+
    };
+
+
+
+ 196 +
+
+ +
+
+

+            
+
+
+ 197 +
+
+ 1 +
+
+
    vec_int_push_back(raw_consts.ptr, *val);
+
+
+
+ 198 +
+
+ 1 +
+
+
    constraint_addConstantList(raw_constraint, raw_consts.ptr);
+
+
+
+ 199 +
+
+ 1 +
+
+
}
+
+
+
+ 200 +
+
+ +
+
+

+            
+
+
+ 201 +
+
+ +
+
+
#[cfg(test)]
+
+
+
+ 202 +
+
+ +
+
+
mod tests {
+
+
+
+ 203 +
+
+ +
+
+
    use std::error::Error;
+
+
+
+ 204 +
+
+ +
+
+

+            
+
+
+ 205 +
+
+ +
+
+
    use super::*;
+
+
+
+ 206 +
+
+ +
+
+

+            
+
+
+ 207 +
+
+ +
+
+
    /// .
+
+
+
+ 208 +
+
+ +
+
+
    fn callback(_: Vec<(VarName, Constant)>) -> bool {
+
+
+
+ 209 +
+
+ +
+
+
        return true;
+
+
+
+ 210 +
+
+ +
+
+
    }
+
+
+
+ 211 +
+
+ +
+
+

+            
+
+
+ 212 +
+
+ 1 +
+
+
    #[test]
+
+
+
+ 213 +
+
+ 1 +
+
+
    fn basic_ast_test() -> Result<(), RuntimeError> {
+
+
+
+ 214 +
+
+ 1 +
+
+
        let mut model = Model::new();
+
+
+
+ 215 +
+
+ 1 +
+
+
        model
+
+
+
+ 216 +
+
+ 1 +
+
+
            .named_variables
+
+
+
+ 217 +
+
+ 1 +
+
+
            .add_var("x".to_owned(), VarDomain::Bound(1, 3));
+
+
+
+ 218 +
+
+ 1 +
+
+
        model
+
+
+
+ 219 +
+
+ 1 +
+
+
            .named_variables
+
+
+
+ 220 +
+
+ 1 +
+
+
            .add_var("y".to_owned(), VarDomain::Bound(2, 4));
+
+
+
+ 221 +
+
+ 1 +
+
+
        model
+
+
+
+ 222 +
+
+ 1 +
+
+
            .named_variables
+
+
+
+ 223 +
+
+ 1 +
+
+
            .add_var("z".to_owned(), VarDomain::Bound(1, 5));
+
+
+
+ 224 +
+
+ 1 +
+
+

+            
+
+
+ 225 +
+
+ 1 +
+
+
        let leq = Constraint::SumLeq(
+
+
+
+ 226 +
+
+ 1 +
+
+
            vec![
+
+
+
+ 227 +
+
+ 1 +
+
+
                Var::NameRef("x".to_owned()),
+
+
+
+ 228 +
+
+ 1 +
+
+
                Var::NameRef("y".to_owned()),
+
+
+
+ 229 +
+
+ 1 +
+
+
                Var::NameRef("z".to_owned()),
+
+
+
+ 230 +
+
+ 1 +
+
+
            ],
+
+
+
+ 231 +
+
+ 1 +
+
+
            Var::ConstantAsVar(4),
+
+
+
+ 232 +
+
+ 1 +
+
+
        );
+
+
+
+ 233 +
+
+ 1 +
+
+

+            
+
+
+ 234 +
+
+ 1 +
+
+
        let geq = Constraint::SumGeq(
+
+
+
+ 235 +
+
+ 1 +
+
+
            vec![
+
+
+
+ 236 +
+
+ 1 +
+
+
                Var::NameRef("x".to_owned()),
+
+
+
+ 237 +
+
+ 1 +
+
+
                Var::NameRef("y".to_owned()),
+
+
+
+ 238 +
+
+ 1 +
+
+
                Var::NameRef("z".to_owned()),
+
+
+
+ 239 +
+
+ 1 +
+
+
            ],
+
+
+
+ 240 +
+
+ 1 +
+
+
            Var::ConstantAsVar(4),
+
+
+
+ 241 +
+
+ 1 +
+
+
        );
+
+
+
+ 242 +
+
+ 1 +
+
+

+            
+
+
+ 243 +
+
+ 1 +
+
+
        let ineq = Constraint::Ineq(
+
+
+
+ 244 +
+
+ 1 +
+
+
            Var::NameRef("x".to_owned()),
+
+
+
+ 245 +
+
+ 1 +
+
+
            Var::NameRef("y".to_owned()),
+
+
+
+ 246 +
+
+ 1 +
+
+
            Constant::Integer(-1),
+
+
+
+ 247 +
+
+ 1 +
+
+
        );
+
+
+
+ 248 +
+
+ 1 +
+
+

+            
+
+
+ 249 +
+
+ 1 +
+
+
        model.constraints.push(leq);
+
+
+
+ 250 +
+
+ 1 +
+
+
        model.constraints.push(geq);
+
+
+
+ 251 +
+
+ 1 +
+
+
        model.constraints.push(ineq);
+
+
+
+ 252 +
+
+ 1 +
+
+

+            
+
+
+ 253 +
+
+ 1 +
+
+
        run_minion(model, callback)
+
+
+
+ 254 +
+
+ 1 +
+
+
    }
+
+
+
+ 255 +
+
+ +
+
+
}
+
+
+
+ + + diff --git a/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/scoped_ptr.rs.html b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/scoped_ptr.rs.html new file mode 100644 index 0000000000..0c7d6917d6 --- /dev/null +++ b/coverage/edfa8dab93de094f8c1de4e5c57af8203b30c10f/minion/src/scoped_ptr.rs.html @@ -0,0 +1,594 @@ + + + + + Grcov report - scoped_ptr.rs + + +
+ + + +
+
+ 1 +
+
+ +
+
+
/*
+
+
+
+ 2 +
+
+ +
+
+
 * This Source Code Form is subject to the terms of the Mozilla Public
+
+
+
+ 3 +
+
+ +
+
+
 * License, v. 2.0. If a copy of the MPL was not distributed with this
+
+
+
+ 4 +
+
+ +
+
+
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+
+
+ 5 +
+
+ +
+
+
 */
+
+
+
+ 6 +
+
+ +
+
+

+            
+
+
+ 7 +
+
+ +
+
+
/// A light scoped wrapper over a raw *mut pointer.
+
+
+
+ 8 +
+
+ +
+
+
///
+
+
+
+ 9 +
+
+ +
+
+
/// Implements destruction of the pointer when it goes out of scope, but provides no other
+
+
+
+ 10 +
+
+ +
+
+
/// guarentees.
+
+
+
+ 11 +
+
+ +
+
+
pub struct Scoped<T> {
+
+
+
+ 12 +
+
+ +
+
+
    pub ptr: *mut T,
+
+
+
+ 13 +
+
+ +
+
+
    destructor: fn(*mut T),
+
+
+
+ 14 +
+
+ +
+
+
}
+
+
+
+ 15 +
+
+ +
+
+

+            
+
+
+ 16 +
+
+ +
+
+
// Could use
+
+
+
+ 17 +
+
+ +
+
+
// https://doc.rust-lang.org/std/alloc/trait.Allocator.html with box (in nightly only)
+
+
+
+ 18 +
+
+ +
+
+
// or
+
+
+
+ 19 +
+
+ +
+
+
// https://docs.rs/scopeguard/latest/scopeguard/
+
+
+
+ 20 +
+
+ +
+
+
// instead
+
+
+
+ 21 +
+
+ +
+
+
impl<T> Scoped<T> {
+
+
+
+ 22 +
+
+ 15 +
+
+
    pub unsafe fn new(ptr: *mut T, destructor: fn(*mut T)) -> Scoped<T> {
+
+
+
+ 23 +
+
+ 15 +
+
+
        return Scoped { ptr, destructor };
+
+
+
+ 24 +
+
+ 15 +
+
+
    }
+
+
+
+ 25 +
+
+ +
+
+
}
+
+
+
+ 26 +
+
+ +
+
+

+            
+
+
+ 27 +
+
+ +
+
+
// https://doc.rust-lang.org/nomicon/destructors.html
+
+
+
+ 28 +
+
+ +
+
+
impl<T> Drop for Scoped<T> {
+
+
+
+ 29 +
+
+ 15 +
+
+
    fn drop(&mut self) {
+
+
+
+ 30 +
+
+ 15 +
+
+
        unsafe {
+
+
+
+ 31 +
+
+ 15 +
+
+
            (self.destructor)(self.ptr);
+
+
+
+ 32 +
+
+ 15 +
+
+
        }
+
+
+
+ 33 +
+
+ 15 +
+
+
    }
+
+
+
+ 34 +
+
+ +
+
+
}
+
+
+
+ + +