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

Merge updates needed for SHA with lookups. #196

Merged
merged 7 commits into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions circ_fields/src/lib.rs
Original file line number Diff line number Diff line change
@@ -371,14 +371,22 @@ impl PartialOrd for FieldV {
impl Ord for FieldV {
#[inline]
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.full_cow().cmp(&other.full_cow())
if self.is_full() || other.is_full() {
self.full_cow().cmp(&other.full_cow())
} else {
self.inline_i64().cmp(&other.inline_i64())
}
}
}

impl PartialEq for FieldV {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.full_cow().eq(&other.full_cow())
if self.is_full() || other.is_full() {
self.full_cow().eq(&other.full_cow())
} else {
self.inline_i64().eq(&other.inline_i64())
}
}
}

2 changes: 1 addition & 1 deletion circ_hc/src/hashconsing/example_u8.rs
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ impl crate::Table<u8> for Table {
"hashconsing"
}

fn for_each(f: impl FnMut(&u8, &[Self::Node])) {
fn for_each(_f: impl FnMut(&u8, &[Self::Node])) {
panic!()
}

2 changes: 1 addition & 1 deletion circ_hc/src/hashconsing/macro_.rs
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ macro_rules! generate_hashcons_hashconsing {
"hashconsing"
}

fn for_each(f: impl FnMut(&$Op, &[Self::Node])) {
fn for_each(_f: impl FnMut(&$Op, &[Self::Node])) {
panic!()
}

2 changes: 1 addition & 1 deletion circ_hc/src/hashconsing/template.rs
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ impl crate::Table<TemplateOp> for Table {
"hashconsing"
}

fn for_each(f: impl FnMut(&TemplateOp, &[Self::Node])) {
fn for_each(_f: impl FnMut(&TemplateOp, &[Self::Node])) {
panic!()
}

41 changes: 24 additions & 17 deletions circ_hc/src/rc/example_u8.rs
Original file line number Diff line number Diff line change
@@ -3,20 +3,18 @@ use fxhash::FxHashMap as HashMap;

use crate::Id;
use log::trace;
use std::borrow::Borrow;
use std::cell::{Cell, RefCell};
use std::rc::Rc;
use std::sync::atomic::AtomicU64;
use std::thread_local;

#[allow(dead_code)]
struct NodeData {
op: u8,
hash: AtomicU64,
cs: Box<[Node]>,
}

#[allow(dead_code)]
struct NodeDataRef<'a, Q: Borrow<[Node]>>(&'a u8, &'a Q);

#[derive(Clone)]
pub struct Node {
data: Rc<NodeData>,
@@ -158,6 +156,7 @@ impl Manager {
let mut table = self.table.borrow_mut();
let data = Rc::new(NodeData {
op: op.clone(),
hash: Default::default(),
cs: children.into(),
});

@@ -218,10 +217,10 @@ impl Manager {
let duration = start.elapsed();
self.in_gc.set(false);
trace!(
"GC: {} terms -> {} terms in {} us",
"GC: {} terms -> {} terms in {} ns",
collected,
new_size,
duration.as_micros()
duration.as_nanos()
);
collected
} else {
@@ -296,37 +295,45 @@ impl crate::Weak<u8> for Weak {
}

mod hash {
use super::{Node, NodeData, NodeDataRef, Weak};
use std::borrow::Borrow;
use super::{Node, NodeData, Weak};
use fxhash::FxHasher;
use std::hash::{Hash, Hasher};
use std::sync::atomic::Ordering::SeqCst;

impl Hash for Node {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state)
}
}

impl Hash for Weak {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state)
}
}

impl Hash for NodeData {
fn hash<H: Hasher>(&self, state: &mut H) {
self.op.hash(state);
impl NodeData {
fn rehash(&self) -> u64 {
let mut hasher = FxHasher::default();
self.op.hash(&mut hasher);
for c in self.cs.iter() {
c.hash(state);
c.hash(&mut hasher);
}
let current_hash = hasher.finish();
self.hash.store(current_hash, SeqCst);
current_hash
}
}

impl<'a, Q: Borrow<[Node]>> Hash for NodeDataRef<'a, Q> {
impl Hash for NodeData {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.hash(state);
for c in self.1.borrow().iter() {
c.hash(state);
let mut current_hash: u64 = self.hash.load(SeqCst);
if current_hash == 0 {
current_hash = self.rehash();
}
state.write_u64(current_hash);
}
}
}
41 changes: 24 additions & 17 deletions circ_hc/src/rc/macro_.rs
Original file line number Diff line number Diff line change
@@ -5,21 +5,19 @@ macro_rules! generate_hashcons_rc {
use fxhash::FxHashMap as HashMap;

use log::trace;
use std::borrow::Borrow;
use std::cell::{Cell, RefCell};
use std::rc::Rc;
use std::sync::atomic::AtomicU64;
use std::thread_local;
use $crate::Id;

#[allow(dead_code)]
struct NodeData {
op: $Op,
hash: AtomicU64,
cs: Box<[Node]>,
}

#[allow(dead_code)]
struct NodeDataRef<'a, Q: Borrow<[Node]>>(&'a $Op, &'a Q);

#[derive(Clone)]
pub struct Node {
data: Rc<NodeData>,
@@ -161,6 +159,7 @@ macro_rules! generate_hashcons_rc {
let mut table = self.table.borrow_mut();
let data = Rc::new(NodeData {
op: op.clone(),
hash: Default::default(),
cs: children.into(),
});

@@ -221,10 +220,10 @@ macro_rules! generate_hashcons_rc {
let duration = start.elapsed();
self.in_gc.set(false);
trace!(
"GC: {} terms -> {} terms in {} us",
"GC: {} terms -> {} terms in {} ns",
collected,
new_size,
duration.as_micros()
duration.as_nanos()
);
collected
} else {
@@ -299,37 +298,45 @@ macro_rules! generate_hashcons_rc {
}

mod hash {
use super::{Node, NodeData, NodeDataRef, Weak};
use std::borrow::Borrow;
use super::{Node, NodeData, Weak};
use fxhash::FxHasher;
use std::hash::{Hash, Hasher};
use std::sync::atomic::Ordering::SeqCst;

impl Hash for Node {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state)
}
}

impl Hash for Weak {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state)
}
}

impl Hash for NodeData {
fn hash<H: Hasher>(&self, state: &mut H) {
self.op.hash(state);
impl NodeData {
fn rehash(&self) -> u64 {
let mut hasher = FxHasher::default();
self.op.hash(&mut hasher);
for c in self.cs.iter() {
c.hash(state);
c.hash(&mut hasher);
}
let current_hash = hasher.finish();
self.hash.store(current_hash, SeqCst);
current_hash
}
}

impl<'a, Q: Borrow<[Node]>> Hash for NodeDataRef<'a, Q> {
impl Hash for NodeData {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.hash(state);
for c in self.1.borrow().iter() {
c.hash(state);
let mut current_hash: u64 = self.hash.load(SeqCst);
if current_hash == 0 {
current_hash = self.rehash();
}
state.write_u64(current_hash);
}
}
}
40 changes: 24 additions & 16 deletions circ_hc/src/rc/template.rs
Original file line number Diff line number Diff line change
@@ -2,21 +2,19 @@ use fxhash::FxHashMap as HashMap;

use crate::Id;
use log::trace;
use std::borrow::Borrow;
use std::cell::{Cell, RefCell};
use std::net::SocketAddrV6 as TemplateOp;
use std::rc::Rc;
use std::sync::atomic::AtomicU64;
use std::thread_local;

#[allow(dead_code)]
struct NodeData {
op: TemplateOp,
hash: AtomicU64,
cs: Box<[Node]>,
}

#[allow(dead_code)]
struct NodeDataRef<'a, Q: Borrow<[Node]>>(&'a TemplateOp, &'a Q);

#[derive(Clone)]
pub struct Node {
data: Rc<NodeData>,
@@ -158,6 +156,7 @@ impl Manager {
let mut table = self.table.borrow_mut();
let data = Rc::new(NodeData {
op: op.clone(),
hash: Default::default(),
cs: children.into(),
});

@@ -218,10 +217,10 @@ impl Manager {
let duration = start.elapsed();
self.in_gc.set(false);
trace!(
"GC: {} terms -> {} terms in {} us",
"GC: {} terms -> {} terms in {} ns",
collected,
new_size,
duration.as_micros()
duration.as_nanos()
);
collected
} else {
@@ -296,37 +295,46 @@ impl crate::Weak<TemplateOp> for Weak {
}

mod hash {
use super::{Node, NodeData, NodeDataRef, Weak};
use std::borrow::Borrow;
use super::{Node, NodeData, Weak};
use fxhash::FxHasher;
use std::hash::{Hash, Hasher};
use std::sync::atomic::Ordering::SeqCst;

impl Hash for Node {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state)
}
}

impl Hash for Weak {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state)
}
}

impl Hash for NodeData {
fn hash<H: Hasher>(&self, state: &mut H) {
self.op.hash(state);
impl NodeData {
fn rehash(&self) -> u64 {
let mut hasher = FxHasher::default();
self.op.hash(&mut hasher);
for c in self.cs.iter() {
c.hash(state);
c.hash(&mut hasher);
}
let current_hash = hasher.finish();
self.hash.store(current_hash, SeqCst);
current_hash
}
}

impl<'a, Q: Borrow<[Node]>> Hash for NodeDataRef<'a, Q> {
impl Hash for NodeData {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.hash(state);
for c in self.1.borrow().iter() {
c.hash(state);
let mut current_hash: u64 = self.hash.load(SeqCst);
if current_hash == 0 {
current_hash = self.rehash();
}
state.write_u64(current_hash);
}
}
}
9 changes: 9 additions & 0 deletions circ_opt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -194,6 +194,14 @@ pub struct IrOpt {
default_value = "true"
)]
pub fits_in_bits_ip: bool,
/// Time operator evaluations
#[arg(
long = "ir-time-eval-ops",
env = "IR_TIME_EVAL_OPS",
action = ArgAction::Set,
default_value = "false"
)]
pub time_eval_ops: bool,
}

impl Default for IrOpt {
@@ -202,6 +210,7 @@ impl Default for IrOpt {
field_to_bv: Default::default(),
frequent_gc: Default::default(),
fits_in_bits_ip: true,
time_eval_ops: false,
}
}
}
2 changes: 1 addition & 1 deletion examples/ZoKrates/pf/2024_05_24_benny_bug.zok.vin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513
(let (
(x #f6)
(return #f6)
(return #f0)
) false ; ignored
))

1 change: 1 addition & 0 deletions examples/ZoKrates/pf/hash/sha256lookup/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains a SHA256 implementation by Anna Woo.
Loading