-
Couldn't load subscription status.
- Fork 643
Rust module bindings and macros for defining procedures #3444
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
Conversation
This commit adds a macro attribute `#[procedure]` which applies to functions,
and various in-WASM machinery for defining, calling and running procedures.
A simple example of a procedure, included in `modules/module-test`:
```rust
fn sleep_one_second(ctx: &mut ProcedureContext) {
let prev_time = ctx.timestamp;
let target = prev_time + Duration::from_secs(1);
ctx.sleep_until(target);
let new_time = ctx.timestamp;
let actual_delta = new_time.duration_since(prev_time).unwrap();
log::info!("Slept from {prev_time} to {new_time}, a total of {actual_delta:?}");
}
```
We intend eventually to make procedures be `async` functions
(with the trivial `now_or_never` executor from `future-util`),
but I found that making the types work for this was giving me a lot of trouble,
and decided to put it off in the interest of unblocking more parallelizable work.
Host-side infrastructure for executing procedures is not included in this commit.
I have a prototype working, but cleaning it up for review and merge will come a bit later.
|
Test failures are coming from two places, AFAICT:
1 is easy enough, but 2 is challenging. Rust seems to not like implementing traits for specific function types, and is not smart enough to recognize that |
…st-module-bindings
Using Will Crichton's blog post about Tacit Trait Parameters, https://willcrichton.net/notes/defeating-coherence-rust/
|
I have fixed the bug I listed above as 2! I will update the PR description with a note. |
|
Looks like I was wrong about the ensure_same_schema checks, actually - those don't seem to care about reducers and procedures. |
Turns out I can't type/spell
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.
Approving, pending a doc comment for the macro.
These are quite bare-bones, as much of the stuff we'd want to document isn't implemented yet.
Description of Changes
This commit adds a macro attribute
#[procedure]which applies to functions, and various in-WASM machinery for defining, calling and running procedures.A simple example of a procedure, included in
modules/module-test:We intend eventually to make procedures be
asyncfunctions (with the trivialnow_or_neverexecutor fromfuture-util), but I found that making the types work for this was giving me a lot of trouble, and decided to put it off in the interest of unblocking more parallelizable work.Host-side infrastructure for executing procedures is not included in this commit. I have a prototype working, but cleaning it up for review and merge will come a bit later.
One item of complexity in this PR is enabling scheduled tables to specify either reducers or procedures, while still providing compile-time diagnostics for ill-typed scheduled functions (as opposed to publish-time). I had to rewrite the previous
schedule_reducer_typecheckinto a more complexschedule_typecheckwith a traitExportFunctionForScheduledTable, which takes a "tacit trait parameter" encoding reducer-ness or procedure-ness, as described in https://willcrichton.net/notes/defeating-coherence-rust/ .The trait name
ExportFunctionForScheduledTableis user-facing in the sense that it will appear in compiler diagnostics in ill-typed modules. As such, I am open to bikeshedding.API and ABI breaking changes
Adds a new user-facing API, which we intend to change before releasing.
Expected complexity level and risk
2? Mostly pretty mechanical changes to macros and bindings.
Testing
module-test, saw that it typechecks.