-
Notifications
You must be signed in to change notification settings - Fork 139
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
Wasm rework #2825
base: master
Are you sure you want to change the base?
Wasm rework #2825
Conversation
Working great! Added support in libscryer-clj. For sake of completion, will mention only thing I've noticed missing so far is Working fantastic! It's a low level test, will clean up the API, but couldn't be more psyched that it's working in the browser with ITERATIVE QUERIES!!! WOOOO!!! |
Playing around with this a bit, got an npm package ( Some thoughts/nitpicks/observations follow (caveat: I'm not super familiar with wasm-bindgen/wasm-pack so I might be missing some things) It seems like it's not possible to import the term types ( The classes should declare their members like so: export class PrologInteger {
type = "integer"; // here
integer; // and here
constructor(integerStr) {
this.integer = BigInt(integerStr);
}
} Nitpick: Starting a query with a syntax error (example: forgetting the dot) makes the Rust code panic with "unreachable". Anyway, so good so far! I'll keep hacking on this package as the wasm interface coalesces, and I think it won't be too long before we can get parity with trealla-js. I'd be happy to donate the code/npm package name/etc later on once the dust settles. |
Great work with |
And I'm not very familiar with Javascript so these nitpicks are exactly what I'm looking for!
This was intentional, but also temporary. I wanted to just have it work first, and doing this for all term types is a lot of boilerplate. Also, I currently use the
Sure! Also, is the builder pattern common in Javascript or is there a better way that this may be exposed? The builder pattern is used in Rust right now to configure the
This is actually a problem in the Rust interface! I plan to deal with it there eventually, and so it will automatically be fixed here also. |
Here's how I did my Term types, it's also kind of inspired by Tau in that they are all classes and discriminated by instanceof. Not totally sure this is the best approach. https://github.com/guregu/trealla-js/blob/9c9cc972c795895fde93bf02783cb73935e3bcdc/src/term.ts#L3-L137. The nice thing about classes is you can give them all a Speaking of imports, personally I think it's fine to stick with ESModules (also called 'esnext' build target). These days I write all my JS stuff using them. Bundlers can convert them into the other module systems if necessary. There's some nice new tooling around modules too (such as esm.sh, and the new npm alternative https://jsr.io/). I like how easy it is to import modules in browsers and start hacking with them. Re: builder pattern. I think it's fine, there are other JS projects like ORMs (Prisma comes to mind?) that use a similar builder/fluent/whatever-it's-called pattern. Probably the most idiomatic JS way to configure things is to just shove a big options object into the constructor, but the builder pattern makes sense when you've got multiple "phases" (e.g. in Prisma's case you have the select, then filter phases). This one I don't have a super strong opinion about, and it's easy enough to write wrappers in either direction. I'll add that I thought Tau's callback-based query interface was pretty hard to use. I think it's like that because Tau supports older browsers before generators were a thing. I think Scryer's current query interface that uses Iterable is ideal, and I also think it's fair to only target "evergreen" browsers (that is, forget about Internet Explorer support -- not that it could run modern Wasm regardless 😄). |
Thank you for all the feedback!
I was worried about NodeJS, but I tried and if you bindgen with |
Ok, it seems wasm bindgen doesn't let you re-export I think I will just return raw internally tagged Javascript objects (so aways with a |
I've added functionality to consult modules. I forgot about it initially. |
Ok, with documentation and consulting I think this is all I have in scope for this PR and it's ready for review. |
Updated the npm package with the latest changes. I was able to get some modules to talk to each other, but the behavior is a bit odd, throwing an |
Ok, I experimented with the Rust API and it's indeed a mess. Consulting modules is currently completely borked and often just panics. I don't think this is a complete deal breaker for this MVP though, as just using Thanks a lot for finding these problems! I will address them in the Rust API in separate PRs, which will then automatically fix them here too. |
This reworks the Wasm API to match the Rust API and therefore be much more flexible (query iterators allowing continuous feedback and infinite leaf answers, actual term data representation instead of just strings, etc...). This was some of the trickiest Rust code I've ever wrote (self-referential structs, single threaded channels, etc...), but I managed to do all of it without using unsafe. If anyone has suggestions on how to do it better please tell me. If anyone has suggestions on how to make the interface more idiomatic for Javascript I would also like to hear it!
This is still very rough and needs polish (and documentation, which I intentionally deferred), but already works really well as is.
Non-goals for this PR:
eval_code
, and some way to interface with stdin. This is needed for eventually running the CLI toplevel in Scryer Playground. Doing this properly depends on Callback streams for use as library #2799, and I will do that in another PR. Just having access to queries is already powerful enough for the vast majority of use cases.