-
Notifications
You must be signed in to change notification settings - Fork 127
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
Programatic use of Machine / Scryer as library #1880
Merged
Merged
Changes from all commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
95b3114
Add Machine::set_user_input(&mut self, input: String) and get_user_ou…
lucksus 112d398
Add Machine::run_input_once() which reads one goal from user input an…
lucksus 2f45f0c
Add convenience methods Machine::load_module_string() and Machine::ru…
lucksus 703efdb
Make run_input_once/0 match and print all results
lucksus 568abef
Parsed QueryResult
lucksus 3347f83
Remove debug println!s
lucksus f324c95
Refactor result parsing to idiomatic Rust and extract into parsed_res…
lucksus f656758
Fix build warnings
lucksus c0dd94c
Add test for programatic queries
lucksus 5f8cc3c
WIP: refactor to generalize Machine::run_top_level()
lucksus e7f1e32
fmt machine/parsed_results.rs
lucksus 3947390
Use lib constructor in lib tests
lucksus bb95ed3
Add back all needed predicates to lib_toplevel.pl
lucksus 644559b
Add back newline at end of toplevel.pl
lucksus 836f6c1
Don't panic when parsing results fails
lucksus cae32d6
Error handling
lucksus 7c93450
type QueryResult = Result<QueryResolution, String>
lucksus 0b833bd
Add missing write_goal/3 to lib_toplevel.pl
lucksus 9e85be1
Fix result parsing for complex string results
lucksus d8a9475
Add missing list_last_item to lib_toplevel.pl and increase MaxDepth o…
lucksus 9fd6e18
Dedupe machine results
lucksus 2f99bb0
Add consult that works with streams / strings in library use-case
lucksus 0d28404
Add special case when parsing
lucksus 30dac8e
HashSet -> BTreeSet: Make parsing or results and thus tests determini…
lucksus c2658dc
Try triska's toplevel and add some debugging println!s.
lucksus 21c3688
Fix build
lucksus df048a4
Switch back to run_input_once and use duplicated write_eqs/2 without …
lucksus 3ff02da
Deactivate some debugging outputs
lucksus 65eb937
dont spawn a runtime in machine; inherit from outside with runtime::h…
jdeepee ac61055
Remove some unused code from lib_toplevel.pl
lucksus 3cf3c0e
Integration stress test showing Machine blocking on query
lucksus 48a4835
Merge branch 'master' into library-use-case
lucksus cc04872
Merge branch 'master' into library-use-case
lucksus 579816a
Use new `double_quotes` write-option
lucksus 4e8f7f0
Remove unused toplevel predicate
lucksus cf63b58
Ignore stress test because it fails on windows
lucksus 72ceceb
Updated hyper to 1.0.0-rc.4
fayeed ce1c8aa
Fixed libffi dep
fayeed 7e97f16
Fix list result parsing
lucksus bfb3164
Enable multiple Machines per process by having ATOM_TABLE_BUF_BASE al…
lucksus c258882
Fix parsing of floats
lucksus afbadd9
Revert "Enable multiple Machines per process by having ATOM_TABLE_BUF…
lucksus d131739
Cargo feature "multi_thread" for thread-local ATOM_TABLE_BUF_BASE
lucksus 77394ba
Remove debug println!s
lucksus 44c274b
WIP: Pure Rust impl. of run_query
lucksus 4d19c43
Merge branch 'master' into library-use-case
lucksus 2b018be
Add back needed dep. hyper-util and upgrade hyper to rc4
lucksus 8a0685a
Debug print value of register 6 which leads to failing heap dereference
lucksus ef56193
Use write_term_to_heap as suggest, clean up, and include error in com…
lucksus 136463c
Merge branch 'master' into library-use-case
lucksus 5fa68e2
lib_machine tests should not be tokio/async
lucksus 6bdd7f3
mthom's revised run_query with manually created printer and some cleanup
lucksus 48283c4
mthom's changes to run_query with backtracking
lucksus f02728a
Construct QueryResult from printer output
lucksus 7c83a1f
Cleanup code that's not needed anymore
lucksus c86304b
Remove lib_toplevel.pl
lucksus d2f5291
mthom's changes fixing the panic
lucksus 65f64e4
Construct and return exception string
lucksus 5e55625
Remove some debug println!s
lucksus 4968fa0
Remove debugging println!
lucksus 7b128a9
Handle stub_b = b as false
lucksus fab5ca9
Fix nested List parsing
lucksus 640c637
Merge branch 'master' into library-use-case
lucksus 69cf2c3
Deactivate tokio runtime respawning on interrupt
lucksus 9990780
Merge branch 'master' into library-use-case
lucksus bfa7d3c
Remove unuse import
lucksus 025412a
Revert "Remove unuse import"
lucksus d7fa6c0
Fix signalling of success/failure (by @mthom)
lucksus 2776beb
Use std::sync::RwLock instead of tokio::sync::RwLock (by @aarroyoc)
lucksus 0c9740f
Fix wasm warnings
lucksus 69a0725
Cleanup Cargo.toml
lucksus ee1bd9e
Merge branch 'master' into library-use-case
lucksus 59264c0
Check for target_arch = “wasm32”
lucksus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
pub struct MachineConfig { | ||
pub streams: StreamConfig, | ||
pub toplevel: &'static str, | ||
} | ||
|
||
pub enum StreamConfig { | ||
Stdio, | ||
Memory, | ||
} | ||
|
||
impl Default for MachineConfig { | ||
fn default() -> Self { | ||
MachineConfig { | ||
streams: StreamConfig::Stdio, | ||
toplevel: include_str!("../toplevel.pl"), | ||
} | ||
} | ||
} | ||
|
||
impl MachineConfig { | ||
pub fn in_memory() -> Self { | ||
MachineConfig { | ||
streams: StreamConfig::Memory, | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn with_toplevel(mut self, toplevel: &'static str) -> Self { | ||
self.toplevel = toplevel; | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what's the purpose of this if everything inside is sync (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block seems to be the issue of the errors reported by @mthom . Removing it makes all the test pass, but of course
http_listen/2
crashes. There are two options that I see:http_listen/2
parts (but I don't mind)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough about async or tokio to make a judgment as to which course is best. Can there not be simultaneous tokio runtimes? Or runtimes within runtimes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After tinkering more with this, there's a third option. Change the
tokio::sync::RwLock
tostd::sync::RwLock
. This is a very small change (see https://github.com/aarroyoc/scryer-prolog/tree/library-use-case) and everything seems to work again (both tests andhttp_listen/2
). The ultimate reason seems to be that the machine executes now in an async environment (I still don't know why) andRwLock::blocking_read/blocking_write
are expected to panic when called in an async environment since they're designed for sync code (https://docs.rs/tokio/latest/tokio/sync/struct.RwLock.html#method.blocking_read)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust Futures need be polled in order to execute anything. That means you need at least one Future executor like
block_on
to keep polling the Futures to completion. If you would have this async block here in this main function, the app would return and never even start processing the async code.