Self-referential predicate hashes as statement template args (#494)
* Support quoted predicate hashes, including self-referential predicates * Clippy * Review feedback
This commit is contained in:
parent
13cabdb511
commit
1e592e11cf
9 changed files with 573 additions and 31 deletions
|
|
@ -771,7 +771,8 @@ impl CustomPredicateEntryTarget {
|
|||
pw.set_target_arr(&self.id.elements, &predicate.batch.id().0)?;
|
||||
pw.set_target(self.index, F::from_canonical_usize(predicate.index))?;
|
||||
|
||||
// Replace statement templates of batch-self with (id,index)
|
||||
// Replace BatchSelf predicates with Custom(batch, i), and
|
||||
// SelfPredicateHash args with Literal(hash(Custom(batch, i)))
|
||||
let batch = &predicate.batch;
|
||||
let predicate = predicate.predicate();
|
||||
let statements = predicate
|
||||
|
|
@ -788,10 +789,22 @@ impl CustomPredicateEntryTarget {
|
|||
}
|
||||
x => x.clone(),
|
||||
};
|
||||
StatementTmpl {
|
||||
pred_or_wc,
|
||||
args: st_tmpl.args,
|
||||
}
|
||||
let args = st_tmpl
|
||||
.args
|
||||
.into_iter()
|
||||
.map(|arg| match arg {
|
||||
StatementTmplArg::SelfPredicateHash(i) => {
|
||||
let pred_hash = Predicate::Custom(CustomPredicateRef {
|
||||
batch: batch.clone(),
|
||||
index: i,
|
||||
})
|
||||
.hash();
|
||||
StatementTmplArg::Literal(Value::from(pred_hash))
|
||||
}
|
||||
other => other,
|
||||
})
|
||||
.collect();
|
||||
StatementTmpl { pred_or_wc, args }
|
||||
})
|
||||
.collect_vec();
|
||||
let predicate = CustomPredicate {
|
||||
|
|
@ -2012,7 +2025,7 @@ pub(crate) mod tests {
|
|||
// Empty case
|
||||
let mut cpb_builder = CustomPredicateBatchBuilder::new(params.clone(), "empty".into());
|
||||
_ = cpb_builder.predicate_and("empty", &[], &[], &[])?;
|
||||
let custom_predicate_batch = cpb_builder.finish();
|
||||
let custom_predicate_batch = cpb_builder.finish()?;
|
||||
helper_custom_predicate_in_batch_target(&custom_predicate_batch).unwrap();
|
||||
|
||||
// Some cases from the examples
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue