-
Notifications
You must be signed in to change notification settings - Fork 126
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
Add run_query_iter() #2472
Add run_query_iter() #2472
Conversation
I forgot that Miri is now enabled in CI. My new tests create a whole |
Ok, after some bit of testing and thought, I think that the I think this is ready for review @mthom. |
This looks great! Thanks for doing this refactoring into an iterator <3 But: if the tests in lib_machine pass, including the "integration test" (which is a log of our ad4m integration tests and how those drive the included scryer lib_machine), it should all be fine on our end too. |
The integration tests do pass on this PR. It's completely backwards compatible as far as I know. #2475, however, is definitely a breaking change. I would appreciate if you also took a look, because it significantly improves the accuracy and representation of answers. |
This PR addresses one of the biggest limitations of the Rust embedding API introduced in #1880, which was the lack of an iterator API on answers.
I used the "generator" code of @jjtolton from #2465 as a basis for the iterator
QueryState
, which is returned by the new functionrun_query_iter()
. This iterator can express determinism, in the sense that it can differentiate an extrafalse
caused by backtracking from having no more answers:The old
run_query()
is implemented in terms ofrun_query_iter()
(just collecting the iterator), with (as far as I tested) the same behavior and functionality1.The only question I have is if calling
trust_me()
is sufficient to clean the state of theMachine
, even if the whole iteration is not consumed, but it seems to pass all tests so I guess it's fine.@lucksus, I would appreciate if you tested this on your use cases to see if it works, because you are probably the person that most uses this API.
Footnotes
In fact, I solved a "bug" that the older
run_query()
had, in which it didn't backtrack on queries without variables, like?- true;false.
. You could consider that a feature, because it acted like a fusing||
(if you know the first argument of a disjunction is true you don't have to check the other), but that also means that the alternative choice points weren't running which seems wrong (they could have side effects after all). That also means that now instead oftrue;false.
resulting in the equivalent of[true]
it returns[true, false]
, which is a change of behavior, but I think this is much more expressive. ↩