fn cmp_rule(ctx: &Context, rule: &Rule) -> Result<String> {
    let fact_positions: Vec<_> = rule
        .clauses
        .iter()
        .enumerate()
        .filter_map(|(i, clause)| match clause {
            Clause::Fact(fact) if ctx.results.contains(&fact.name) => Some(i),
            _ => None,
        })
        .collect();

    if fact_positions.is_empty() {
        // Will not change, so we only need to evaluate it once
        let eval_loop = cmp_rule_incremental(ctx, rule, None)?;
        Ok(format!(
            "if ({first_iter}) {{\n{eval_loop}\n}}",
            first_iter = VAR_FIRST_ITERATION,
            eval_loop = eval_loop
        ))
    } else {
        // Rule has one or more facts, so we use semi-naive evaluation
        let variants = fact_positions
            .into_iter()
            .map(|update_position| cmp_rule_incremental(ctx, rule, Some(update_position)))
            .collect::<Result<Box<_>>>()?;
        Ok(variants.join("\n"))
    }
}
/// Compile a single Datalog rule into a collection of loops.
Compile a single Datalog rule into a collection of loops.
Compile a single Datalog rule into a collection of loops .
fn cmp_rule(ctx: &Context, rule: &Rule) -> Result<String> {
    let fact_positions: Vec<_> = rule
        .clauses
        .iter()
        .enumerate()
        .filter_map(|(i, clause)| match clause {
            Clause::Fact(fact) if ctx.results.contains(&fact.name) => Some(i),
            _ => None,
        })
        .collect();
    if fact_positions.is_empty() {
        // Will not change, so we only need to evaluate it once
        let eval_loop = cmp_rule_incremental(ctx, rule, None)?;
        Ok(format!(
            "if ({first_iter}) {{\n{eval_loop}\n}}",
            first_iter = VAR_FIRST_ITERATION,
            eval_loop = eval_loop
        ))
    } else {
        // Rule has one or more facts, so we use semi-naive evaluation
        let variants = fact_positions
            .into_iter()
            .map(|update_position| cmp_rule_incremental(ctx, rule, Some(update_position)))
            .collect::<Result<Box<_>>>()?;
        Ok(variants.join("\n"))
    }
}
fn cmp_rule ( ctx : & Context , rule : & Rule ) -> Result < String > { let fact_positions : Vec < _ > = rule . clauses . iter ( ) . enumerate ( ) . filter_map ( | ( i , clause ) | match clause { Clause :: Fact ( fact ) if ctx . results . contains ( & fact . name ) => Some ( i ) , _ => None , } ) . collect ( ) ; if fact_positions . is_empty ( ) { // Will not change, so we only need to evaluate it once let eval_loop = cmp_rule_incremental ( ctx , rule , None ) ? ; Ok ( format ! ( " \n \n " first_iter VAR_FIRST_ITERATION eval_loop eval_loop ) ) } else { // Rule has one or more facts, so we use semi-naive evaluation let variants = fact_positions . into_iter ( ) . map ( | update_position | cmp_rule_incremental ( ctx , rule , Some ( update_position ) ) ) . collect :: < Result < Box < _ > > > ( ) ? ; Ok ( variants . join ( " \n " ) ) } }
Compile a single Datalog rule into a collection of loops.
Compile a single Datalog rule into a collection of loops .
ctx
&Context
rule
&Rule
ctx
&Context
rule
&Rule