-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Support asynchronous WebAssembly compilation #21476
Comments
This looks like something we need to configure properly to support: https://github.com/servo/mozjs/blob/9b44b1e870cae2d96ea41bf2aa8a7d5eaa4cdce7/mozjs/js/src/wasm/WasmJS.cpp#L2337-L2345 |
This should be fixed after servo#21476 done.
This should be fixed after servo#21476 done.
This should be fixed after servo#21476 done.
This should be fixed after servo#21476 done.
This should be fixed after servo#21476 done.
Now happens in the tanks wasm demo. This used to work, did the demo get upgraded to use promises at some point?
|
It did. It used to use the WebAssembly.compile API, iirc. |
https://wasm.bootcss.com/demo/Tanks/ is the updated tanks game URL. |
Based on https://github.com/servo/servo/wiki/Asynchronous-WebAssembly-compilation-project, from a private communication:
Let's put all of the new code in components/script/script_runtime.rs in the Servo code for the short term. And there is no need to implement any functionality, only define methods for the new Rust struct that call these functions:
You can see some other uses of functions from that same servo/components/script/script_runtime.rs Line 28 in dc8be8f
|
@jdm We wanted to know how to test our changes functionally, to make sure our changes are in accordance to the actual requirement. |
@shubham-pampattiwar Unfortunately the code added in the initial steps is not expected to have any change in behaviour on its own. The best we can do right now is load https://wasm.bootcss.com/demo/Tanks/ and verify that there is no change in behaviour with your changes. |
@jdm we have raised a PR for a few changes related to this issue. We have completed a couple of tasks listed in the initial steps. However, we are not clear on the requirement of the second task,
Despite having StreamConsumer as an argument in the ConsumeStreamCallback signature and the stated task requires us to create a new StreamConsumer wrapper and stores it in the Response object. Could you correct us if we are not interpreting it correctly? We have come up with the following function signature: #[allow(unsafe_code)]
unsafe extern "C" fn ConsumeStreamCallback(
_cx: *mut JSContext,
obj: HandleObject,
mimeType: MimeType,
consumer: *mut StreamConsumer,
) { } |
The equivalent code in Firefox is a useful model to follow here. You will need to:
These changes should cause some of the automated tests in |
…r=jdm Binding stream consumer to support asynchronous WebAssembly compilation This PR contains changes related to binding the Stream Consumer wrapper for supporting async WebAssembly compilation in Servo. The changes are listed below: - Added a StreamConsumer wrapper and implemented its corresponding behaviors such as consumeChunk, streamEnd, streamError, and noteResponseURLs. - Added ReportStreamErrorCallback for reporting the CompileError/TypeError occurred during the compilation. --- - [X] `./mach build -d` does not report any errors, however, it has a few warnings of unused functions since we are calling them as yet. - [X] `./mach test-tidy` does not report any errors - [X] These changes are part of #21476 fix
@jdm Is the mimetype passed to the ConsumeStreamCallback the extracted mimeType from the response object. Although, this doesn't seem very likely. As per the firefox implementation the mimetype passed to the callback is first checked against the 'application/wasm' type and then compared against the response's mimetype. Are we expected to implement something similar here? |
@ridhimrastogi The mimeType argument is the JS engine's way of saying "this is expected to be a WASM mime type (for example), please perform checks appropriately." Given #24628, I recommend getting |
@jdm Since root_from_handle_object returns a Root<Dom< Response>> object we can use the extract_mime_type method implemented in the ResponseMethods trait associated with the Response object. Is it necessary/possible to convert the Root<Dom< Response>> to net_trait implementation of Response done in servo for further processing. |
Good find! It's not necessary to convert a Dom::Response to a net_traits::Response. |
@jdm we have raised a PR for the issue. Regarding the next step as mentioned below:
Do we need to call the consume_chunk method defined in the StreamConsumerWrapper for step 2-6 as mentioned here. |
consume_chunk is not required until the final step of "Subsequent steps". |
…nitial-2, r=jdm Add consume stream callback <!-- Please describe your changes on the following line: --> Added the consume stream callback function as per the steps mentioned [here](https://webassembly.github.io/spec/web-api/index.html#compile-a-potential-webassembly-response) --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21476 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…nitial-2, r=jdm Add consume stream callback <!-- Please describe your changes on the following line: --> Added the consume stream callback function as per the steps mentioned [here](https://webassembly.github.io/spec/web-api/index.html#compile-a-potential-webassembly-response) --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21476 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
…nitial-2, r=jdm Add consume stream callback <!-- Please describe your changes on the following line: --> Added the consume stream callback function as per the steps mentioned [here](https://webassembly.github.io/spec/web-api/index.html#compile-a-potential-webassembly-response) --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21476 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This is only partially fixed so far. |
@jdm We are a little unclear about the requirement of second step in binding runnable dispatching. Which new C function exactly is it refering to?
And for the third step, it asks us to use the network task source to queue a task (which returns Result object) that calls the run method of the runnable wrapper and at the same time, dispatch_to_event_loop_callback expects bool as the function return type. #[allow(unsafe_code)]
unsafe fn new_rt_and_cx_with_parent(
parent: Option<ParentRuntime>,
network_task_source: Option<*mut NetworkingTaskSource>,
) -> Runtime {
let network_task_src = if let Some(source) = network_task_source {
source as *mut c_void
} else {
ptr::null_mut()
};
unsafe extern "C" fn dispatch_to_event_loop(
closure: *mut c_void,
dispatchable: *mut Dispatchable,
) -> bool {
let network_task_src: &NetworkingTaskSource = &*(closure as *mut NetworkingTaskSource);
let runnable: &Runnable = &*(dispatchable as *mut Runnable);
network_task_src.queue_unconditionally(runnable.run); // -> Result<(),()>
false // -> expects bool
}
InitDispatchToEventLoop(cx, Some(dispatch_to_event_loop), network_task_src);
}
pub struct Runnable(*mut Runnable);
impl Runnable {
fn run(&self) {}
} Also, there are some modules that are calling new_rt_and_cx function so as we have added |
Whoops, I previously rewrote some of the steps in the project description and missed the C function reference. It is referring to https://doc.servo.org/mozjs/glue/fn.DispatchableRun.html which wraps Dispatchable::Run from the C++ API. As for the question about the networking task source, we will need to do a few things:
Rather than taking a pointer to a NetworkingTaskSource, we should accept it by value, then box it (Box::new) and call Box::into_raw (https://doc.rust-lang.org/stable/std/boxed/struct.Box.html#method.into_raw) to give us a pointer we can use as the closure argument. As for interacting with the runnable, you will want to create an instance of your new Rust Runnable type that stores the pointer to the JS Runnable object, then create a task that invokes your run method on this Rust object. This may require adding Finally, you will want to return |
@jdm I was trying to create task for invoking run method, but getting this error that says use js::jsapi::{Dispatchable as JSRunnable, Dispatchable_MaybeShuttingDown};
unsafe extern "C" fn dispatch_to_event_loop(
closure: *mut c_void,
dispatchable: *mut JSRunnable,
) -> bool {
let networking_task_src: &NetworkingTaskSource = &*(closure as *mut NetworkingTaskSource);
let runnable = Runnable(dispatchable);
let task = task!(dispatch_to_event_loop_message: move || {
let cx = cx.root(); // **Error**
runnable.run(cx, Dispatchable_MaybeShuttingDown::NotShuttingDown);
});
match networking_task_src.queue_unconditionally(task) {
Ok(q) => return true,
Err(_) => return false,
};
} Runnable Definition: pub struct Runnable(*mut JSRunnable);
#[allow(unsafe_code)]
unsafe impl Sync for Runnable {}
#[allow(unsafe_code)]
unsafe impl Send for Runnable {}
#[allow(unsafe_code)]
impl Runnable {
fn run(&self, cx: *mut RawJSContext, maybe_shutting_down: Dispatchable_MaybeShuttingDown) {
unsafe {
DispatchableRun(cx, self.0, maybe_shutting_down);
}
}
} Also, I am hard-coding Dispatchable_MaybeShuttingDown to |
The problem you are facing is that |
…t, r=<try> Async wasm compilation subsequent The PR contains changes related to binding the runnable dispatching in script_runtime and is part of the Asynchronous WebAssembly Compilation fix. This is the first step in the subsequent steps mentioned in the [wiki](https://github.com/servo/servo/wiki/Asynchronous-WebAssembly-compilation-project). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes are part of #21476 fix
…t, r=<try> Async wasm compilation event loop integration The PR contains changes related to binding the runnable dispatching in script_runtime and is part of the Asynchronous WebAssembly Compilation fix. This is the first step in the subsequent steps mentioned in the [wiki](https://github.com/servo/servo/wiki/Asynchronous-WebAssembly-compilation-project). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes are part of #21476 fix
…t, r=jdm Async wasm compilation event loop integration The PR contains changes related to binding the runnable dispatching in script_runtime and is part of the Asynchronous WebAssembly Compilation fix. This is the first step in the subsequent steps mentioned in the [wiki](https://github.com/servo/servo/wiki/Asynchronous-WebAssembly-compilation-project). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes are part of #21476 fix
…t, r=jdm Async wasm compilation event loop integration The PR contains changes related to binding the runnable dispatching in script_runtime and is part of the Asynchronous WebAssembly Compilation fix. This is the first step in the subsequent steps mentioned in the [wiki](https://github.com/servo/servo/wiki/Asynchronous-WebAssembly-compilation-project). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes are part of #21476 fix
…t, r=jdm Async wasm compilation event loop integration The PR contains changes related to binding the runnable dispatching in script_runtime and is part of the Asynchronous WebAssembly Compilation fix. This is the first step in the subsequent steps mentioned in the [wiki](https://github.com/servo/servo/wiki/Asynchronous-WebAssembly-compilation-project). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes are part of #21476 fix
…t, r=jdm Async wasm compilation event loop integration The PR contains changes related to binding the runnable dispatching in script_runtime and is part of the Asynchronous WebAssembly Compilation fix. This is the first step in the subsequent steps mentioned in the [wiki](https://github.com/servo/servo/wiki/Asynchronous-WebAssembly-compilation-project). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes are part of #21476 fix
@jdm In the next step we have to store a StreamConsumer wrapper object in the Response. Does this imply creating a new Response object with the call to constructor and store StreamConsumer object in the body. |
@ridhimrastogi No; there's is already a Response object available in |
@jdm Right now I have added this implementation in the consume_stream function that continues the steps 6 and 7 menioned in the Web assembly implementation.
Here is what I am not sure of :
|
With respect to step 6 and 7, you're going to be adding something that is equivalent but not exactly the same. We won't be using promises here, so that code you quoted won't help us, unfortunately.
|
Add StreamConsumer wrapper and methods to response <!-- Please describe your changes on the following line: --> Add Streamconsumer wrapper to Response --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21476 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Add StreamConsumer wrapper and methods to response <!-- Please describe your changes on the following line: --> Add Streamconsumer wrapper to Response --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21476 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@ridhimrastogi Both https://www.funkykarts.rocks/demo.html and https://wasm.bootcss.com/demo/Tanks/ work with your group's changes! In an older build (like https://download.servo.org/nightly/mac/2019-09-16T11:09:48Z-servo-tech-demo.dmg) they don't run at all. |
@jdm Can you provide a link to an older build for windows or linux. |
Anything from http://servo-builds.s3.amazonaws.com/?list-type=2&prefix=nightly/mac/2019 (or replace mac with Linux, for example), and append the key name to download.servo.org like: http://download.seevo.org/nightly/mac/2019-08-03T11:08:27Z-servo-tech-demo.dmg |
This is a web assembly game demo.
STR:
Expected:
Observed:
WebAssembly Promise APIs not supported in this runtime
I guess these are the streaming apis from https://webassembly.github.io/spec/web-api/index.html
The text was updated successfully, but these errors were encountered: