fn next(&mut self, goal: Rc<Goal>) -> PolarResult<QueryEvent> {
        if self.log {
            self.print(&format!("{}", goal));
        }

        self.check_timeout()?;

        match goal.as_ref() {
            Goal::Backtrack => self.backtrack()?,
            Goal::Cut { choice_index } => self.cut(*choice_index),
            Goal::Debug { message } => return Ok(self.debug(&message)),
            Goal::Halt => return Ok(self.halt()),
            Goal::Isa { left, right } => self.isa(&left, &right)?,
            Goal::IsMoreSpecific { left, right, args } => {
                self.is_more_specific(left, right, args)?
            }
            Goal::IsSubspecializer {
                answer,
                left,
                right,
                arg,
            } => return self.is_subspecializer(answer, left, right, arg),
            Goal::Lookup { dict, field, value } => self.lookup(dict, field, value)?,
            Goal::LookupExternal {
                call_id,
                instance,
                field,
            } => return self.lookup_external(*call_id, instance, field),
            Goal::IsaExternal { instance, literal } => return self.isa_external(instance, literal),
            Goal::UnifyExternal {
                left_instance_id,
                right_instance_id,
            } => return self.unify_external(*left_instance_id, *right_instance_id),
            Goal::MakeExternal {
                constructor,
                instance_id,
            } => return Ok(self.make_external(constructor, *instance_id)),
            Goal::NextExternal { call_id, iterable } => {
                return self.next_external(*call_id, iterable)
            }
            Goal::CheckError => return self.check_error(),
            Goal::Noop => {}
            Goal::Query { term } => {
                let result = self.query(term);
                self.maybe_break(DebugEvent::Query)?;
                return result;
            }
            Goal::PopQuery { .. } => self.pop_query(),
            Goal::FilterRules {
                applicable_rules,
                unfiltered_rules,
                args,
            } => self.filter_rules(applicable_rules, unfiltered_rules, args)?,
            Goal::SortRules {
                rules,
                outer,
                inner,
                args,
            } => self.sort_rules(rules, args, *outer, *inner)?,
            Goal::TraceStackPush => {
                self.trace_stack.push(Rc::new(self.trace.clone()));
                self.trace = vec![];
            }
            Goal::TraceStackPop => {
                let mut children = self.trace.clone();
                self.trace = self.trace_stack.pop().unwrap().as_ref().clone();
                let mut trace = self.trace.pop().unwrap();
                let trace = Rc::make_mut(&mut trace);
                trace.children.append(&mut children);
                self.trace.push(Rc::new(trace.clone()));
                self.maybe_break(DebugEvent::Pop)?;
            }
            Goal::TraceRule { trace } => {
                if let Node::Rule(rule) = &trace.node {
                    self.log_with(
                        || {
                            let source_str = self.rule_source(&rule);
                            format!("RULE: {}", source_str)
                        },
                        &[],
                    );
                }
                self.trace.push(trace.clone());
            }
            Goal::Unify { left, right } => self.unify(&left, &right)?,
            Goal::AddConstraint { term } => self.add_constraint(&term)?,
            Goal::AddConstraintsBatch { add_constraints } => {
                add_constraints.borrow_mut().drain().try_for_each(
                    |(_, constraint)| -> PolarResult<()> { self.add_constraint(&constraint) },
                )?
            }
            Goal::Run { runnable } => return self.run_runnable(runnable.clone_runnable()),
        }
        Ok(QueryEvent::None)
    }
/// Try to achieve one goal. Return `Some(QueryEvent)` if an external
/// result is needed to achieve it, or `None` if it can run internally.
Try to achieve one goal. Return `Some(QueryEvent)` if an external
result is needed to achieve it, or `None` if it can run internally.
Try to achieve one goal . Return ` Some ( QueryEvent ) ` if an external result is needed to achieve it or ` None ` if it can run internally .
fn next(&mut self, goal: Rc<Goal>) -> PolarResult<QueryEvent> {
        if self.log {
            self.print(&format!("{}", goal));
        }
        self.check_timeout()?;
        match goal.as_ref() {
            Goal::Backtrack => self.backtrack()?,
            Goal::Cut { choice_index } => self.cut(*choice_index),
            Goal::Debug { message } => return Ok(self.debug(&message)),
            Goal::Halt => return Ok(self.halt()),
            Goal::Isa { left, right } => self.isa(&left, &right)?,
            Goal::IsMoreSpecific { left, right, args } => {
                self.is_more_specific(left, right, args)?
            }
            Goal::IsSubspecializer {
                answer,
                left,
                right,
                arg,
            } => return self.is_subspecializer(answer, left, right, arg),
            Goal::Lookup { dict, field, value } => self.lookup(dict, field, value)?,
            Goal::LookupExternal {
                call_id,
                instance,
                field,
            } => return self.lookup_external(*call_id, instance, field),
            Goal::IsaExternal { instance, literal } => return self.isa_external(instance, literal),
            Goal::UnifyExternal {
                left_instance_id,
                right_instance_id,
            } => return self.unify_external(*left_instance_id, *right_instance_id),
            Goal::MakeExternal {
                constructor,
                instance_id,
            } => return Ok(self.make_external(constructor, *instance_id)),
            Goal::NextExternal { call_id, iterable } => {
                return self.next_external(*call_id, iterable)
            }
            Goal::CheckError => return self.check_error(),
            Goal::Noop => {}
            Goal::Query { term } => {
                let result = self.query(term);
                self.maybe_break(DebugEvent::Query)?;
                return result;
            }
            Goal::PopQuery { .. } => self.pop_query(),
            Goal::FilterRules {
                applicable_rules,
                unfiltered_rules,
                args,
            } => self.filter_rules(applicable_rules, unfiltered_rules, args)?,
            Goal::SortRules {
                rules,
                outer,
                inner,
                args,
            } => self.sort_rules(rules, args, *outer, *inner)?,
            Goal::TraceStackPush => {
                self.trace_stack.push(Rc::new(self.trace.clone()));
                self.trace = vec![];
            }
            Goal::TraceStackPop => {
                let mut children = self.trace.clone();
                self.trace = self.trace_stack.pop().unwrap().as_ref().clone();
                let mut trace = self.trace.pop().unwrap();
                let trace = Rc::make_mut(&mut trace);
                trace.children.append(&mut children);
                self.trace.push(Rc::new(trace.clone()));
                self.maybe_break(DebugEvent::Pop)?;
            }
            Goal::TraceRule { trace } => {
                if let Node::Rule(rule) = &trace.node {
                    self.log_with(
                        || {
                            let source_str = self.rule_source(&rule);
                            format!("RULE: {}", source_str)
                        },
                        &[],
                    );
                }
                self.trace.push(trace.clone());
            }
            Goal::Unify { left, right } => self.unify(&left, &right)?,
            Goal::AddConstraint { term } => self.add_constraint(&term)?,
            Goal::AddConstraintsBatch { add_constraints } => {
                add_constraints.borrow_mut().drain().try_for_each(
                    |(_, constraint)| -> PolarResult<()> { self.add_constraint(&constraint) },
                )?
            }
            Goal::Run { runnable } => return self.run_runnable(runnable.clone_runnable()),
        }
        Ok(QueryEvent::None)
    }
fn next ( & mut self , goal : Rc < Goal > ) -> PolarResult < QueryEvent > { if self . log { self . print ( & format ! ( " " goal ) ) ; } self . check_timeout ( ) ? ; match goal . as_ref ( ) { Goal :: Backtrack => self . backtrack ( ) ? , Goal :: Cut { choice_index } => self . cut ( * choice_index ) , Goal :: Debug { message } => return Ok ( self . debug ( & message ) ) , Goal :: Halt => return Ok ( self . halt ( ) ) , Goal :: Isa { left , right } => self . isa ( & left , & right ) ? , Goal :: IsMoreSpecific { left , right , args } => { self . is_more_specific ( left , right , args ) ? } Goal :: IsSubspecializer { answer , left , right , arg , } => return self . is_subspecializer ( answer , left , right , arg ) , Goal :: Lookup { dict , field , value } => self . lookup ( dict , field , value ) ? , Goal :: LookupExternal { call_id , instance , field , } => return self . lookup_external ( * call_id , instance , field ) , Goal :: IsaExternal { instance , literal } => return self . isa_external ( instance , literal ) , Goal :: UnifyExternal { left_instance_id , right_instance_id , } => return self . unify_external ( * left_instance_id , * right_instance_id ) , Goal :: MakeExternal { constructor , instance_id , } => return Ok ( self . make_external ( constructor , * instance_id ) ) , Goal :: NextExternal { call_id , iterable } => { return self . next_external ( * call_id , iterable ) } Goal :: CheckError => return self . check_error ( ) , Goal :: Noop => { } Goal :: Query { term } => { let result = self . query ( term ) ; self . maybe_break ( DebugEvent :: Query ) ? ; return result ; } Goal :: PopQuery { .. } => self . pop_query ( ) , Goal :: FilterRules { applicable_rules , unfiltered_rules , args , } => self . filter_rules ( applicable_rules , unfiltered_rules , args ) ? , Goal :: SortRules { rules , outer , inner , args , } => self . sort_rules ( rules , args , * outer , * inner ) ? , Goal :: TraceStackPush => { self . trace_stack . push ( Rc :: new ( self . trace . clone ( ) ) ) ; self . trace = vec ! [ ] ; } Goal :: TraceStackPop => { let mut children = self . trace . clone ( ) ; self . trace = self . trace_stack . pop ( ) . unwrap ( ) . as_ref ( ) . clone ( ) ; let mut trace = self . trace . pop ( ) . unwrap ( ) ; let trace = Rc :: make_mut ( & mut trace ) ; trace . children . append ( & mut children ) ; self . trace . push ( Rc :: new ( trace . clone ( ) ) ) ; self . maybe_break ( DebugEvent :: Pop ) ? ; } Goal :: TraceRule { trace } => { if let Node :: Rule ( rule ) = & trace . node { self . log_with ( | | { let source_str = self . rule_source ( & rule ) ; format ! ( " " source_str ) } , & [ ] , ) ; } self . trace . push ( trace . clone ( ) ) ; } Goal :: Unify { left , right } => self . unify ( & left , & right ) ? , Goal :: AddConstraint { term } => self . add_constraint ( & term ) ? , Goal :: AddConstraintsBatch { add_constraints } => { add_constraints . borrow_mut ( ) . drain ( ) . try_for_each ( | ( _ , constraint ) | -> PolarResult < ( ) > { self . add_constraint ( & constraint ) } , ) ? } Goal :: Run { runnable } => return self . run_runnable ( runnable . clone_runnable ( ) ) , } Ok ( QueryEvent :: None ) }
Try to achieve one goal.
Try to achieve one goal .
&mut self
goal
Rc<Goal>