Feat/fst order pred part1 & part2 (#454)
Implement support for first order predicates in the backend. Now a statement template can have a predicate hash or a wildcard. ## predicate <-> predicate hash constraints To build the custom predicate table we need to calculate the custom predicate batch id, which uses the serialization of the statement templates before normalization. This serialization uses the predicate hash when the template uses a predicate (instead of a wildcard). Then in normalization we recalculate the predicate hash if it was a Batch Self. This means that the relation between hash and predicate must be checked before and after normalization when the template is not using a wildcard. How this is achieved: - Before normalization: the constructor of StatementTmplTarget forces that if we keep a predicate, it's hash must be equal to the pred_hash when the template has a predicate (and not a wildcard) - After normalization: the predicate hash is calculated in the normalization and replaced in the case of the template using a predicate and it being a BatchSelf. If it was a predicate but not batch self, the old value was used which was constrained via the constructor. See `CircuitBuilder::add_virtual_statement_tmpl` and `normalize_st_tmpl_circuit` ## Wildcard predicate resolution It is done via `make_predicate_from_template_circuit` and is fairly simple as it's contains similar logic to `make_statement_arg_from_template_circuit` but simpler.
This commit is contained in:
parent
1724e7b146
commit
9c9a2c454c
11 changed files with 569 additions and 240 deletions
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
frontend::{AnchoredKey, Error, Result, Statement, StatementArg},
|
||||
middleware::{
|
||||
self, hash_str, CustomPredicate, CustomPredicateBatch, Hash, Key, NativePredicate, Params,
|
||||
Predicate, StatementTmpl, StatementTmplArg, ToFields, Value, Wildcard,
|
||||
Predicate, PredicateOrWildcard, StatementTmpl, StatementTmplArg, ToFields, Value, Wildcard,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -217,7 +217,8 @@ impl CustomPredicateBatchBuilder {
|
|||
})
|
||||
.collect::<Result<_>>()?;
|
||||
Ok(StatementTmpl {
|
||||
pred: stb.predicate.clone(),
|
||||
// TODO: Support wildcard
|
||||
pred_or_wc: PredicateOrWildcard::Predicate(stb.predicate.clone()),
|
||||
args,
|
||||
})
|
||||
})
|
||||
|
|
@ -319,7 +320,10 @@ mod tests {
|
|||
// Check that the desugared predicate is the same as the one in the statement template
|
||||
assert_eq!(
|
||||
desugared_gt.predicate(),
|
||||
*batch_clone.predicates()[0].statements[0].pred()
|
||||
*batch_clone.predicates()[0].statements[0]
|
||||
.pred_or_wc()
|
||||
.as_pred()
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
// Check that our custom predicate matches the statement template
|
||||
|
|
@ -366,7 +370,10 @@ mod tests {
|
|||
);
|
||||
assert_eq!(
|
||||
set_contains.predicate(),
|
||||
*batch_clone.predicates()[0].statements[0].pred()
|
||||
*batch_clone.predicates()[0].statements[0]
|
||||
.pred_or_wc()
|
||||
.as_pred()
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
let set_contains_custom_pred = CustomPredicateRef::new(batch, 0);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ use std::{collections::HashMap, fmt::Display};
|
|||
use crate::{
|
||||
frontend::{Error, Result},
|
||||
lang::PrettyPrint,
|
||||
middleware::{Pod, Statement, StatementArg, StatementTmpl, StatementTmplArg, Value},
|
||||
middleware::{
|
||||
Pod, PredicateOrWildcard, Statement, StatementArg, StatementTmpl, StatementTmplArg, Value,
|
||||
},
|
||||
};
|
||||
|
||||
/// Represents a request for a POD, in terms of a set of statement templates.
|
||||
|
|
@ -76,7 +78,8 @@ impl PodRequest {
|
|||
statement: &Statement,
|
||||
current_bindings: &HashMap<String, Value>,
|
||||
) -> Option<HashMap<String, Value>> {
|
||||
if template.pred != statement.predicate() {
|
||||
// TODO: Support wildcard
|
||||
if template.pred_or_wc != PredicateOrWildcard::Predicate(statement.predicate()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue