Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about define Lit as (&Var, bool) to shorten dereference chains? #283

Open
shnarazk opened this issue Jan 27, 2025 · 0 comments · Fixed by #288 or #289 · May be fixed by #284 or #285
Open

How about define Lit as (&Var, bool) to shorten dereference chains? #283

shnarazk opened this issue Jan 27, 2025 · 0 comments · Fixed by #288 or #289 · May be fixed by #284 or #285
Assignees
Labels
idea My original idea

Comments

@shnarazk
Copy link
Owner

shnarazk commented Jan 27, 2025

Clauses only refer to properties. We don't need mutual references!

Approach

  1. reorganize primitive types
  2. move vars from AssignStack to ClauseDB or static mut
  3. move out heap of AssignStack
  4. change the type of clause.lits from Vec<Lit> to Vec<&Var<'a>>

Let's dive into the unsafe hell

There's no mutable reference!

#![allow(static_mut_refs)]
static mut VECTOR: Vec<usize> = Vec::new();

pub trait VarIF {
    fn push(&self, x: usize);
    fn get(&self) -> usize;
    fn set(&self, x: usize);
    fn increment(&self, offset: usize);
}

struct Var(usize);

impl VarIF for Var {
    fn push(&self, x: usize) {
        unsafe {
            VECTOR.push(x);
        }
    }
    fn get(&self) -> usize {
        unsafe { VECTOR[self.0] }
    }
    fn set(&self, x: usize) {
        unsafe {
            VECTOR[self.0] = x;
        }
    }
    fn increment(&self, offset: usize) {
        unsafe {
            VECTOR[self.0] += offset;
        }
    }
}

fn main() {
    Var(0).push(0);
    println!("{}", Var(0).get());
    Var(0).increment(2);
    println!("{}", Var(0).get());
}
@shnarazk shnarazk added the idea My original idea label Jan 27, 2025
@shnarazk shnarazk self-assigned this Jan 27, 2025
@shnarazk shnarazk changed the title How about define Lit as (&Var, bool) to reduce indirect hops? How about define Lit as (&Var, bool) to shorten dereference chains? Jan 27, 2025
This was linked to pull requests Jan 28, 2025
@shnarazk shnarazk pinned this issue Jan 28, 2025
This was linked to pull requests Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea My original idea
Projects
None yet
1 participant