Skip to content
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 dynamic-import of module script #25439

Closed
CYBAI opened this issue Jan 6, 2020 · 25 comments
Closed

Support dynamic-import of module script #25439

CYBAI opened this issue Jan 6, 2020 · 25 comments
Assignees
Projects

Comments

@CYBAI
Copy link
Collaborator

@CYBAI CYBAI commented Jan 6, 2020

@jdm jdm added this to To do in WebGPU MVP via automation May 25, 2020
@jdm
Copy link
Member

@jdm jdm commented May 25, 2020

Dynamic imports are apparently a significant piece of most webgpu example code as well as the testsuite.

@jdm jdm self-assigned this May 25, 2020
@jdm
Copy link
Member

@jdm jdm commented May 25, 2020

@kunalmohan https://github.com/jdm/servo/tree/dynamic-module is a branch that supports the most common cases for dynamic module imports (importing inside of a module script, and importing inside of a classic script). Hopefully this will be enough for you to run tests in the short term.

@jdm jdm added the C-has-patch label May 26, 2020
@CYBAI
Copy link
Collaborator Author

@CYBAI CYBAI commented Jun 13, 2020

I'm trying to help to rebase @jdm 's branch to align the refactored module script design.

@CYBAI
Copy link
Collaborator Author

@CYBAI CYBAI commented Jun 13, 2020

I basically fix the type checking but the dynamic module is broken now. Will try to figure out how to fix it :/

The branch is at https://github.com/CYBAI/servo/tree/dynamic-module

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jun 13, 2020

I tested it with my latest webgpu code just now. It works fine with simple script like this. But while loading one of the live examples it panics with the following backtrace-

no current script? (thread ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }, at components/script/script_module.rs:1267)
   0: servo::backtrace::print
   1: servo::main::{{closure}}
   2: std::panicking::rust_panic_with_hook
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/panicking.rs:481
   3: rust_begin_unwind
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/panicking.rs:385
   4: core::panicking::panic_fmt
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libcore/panicking.rs:89
   5: core::option::expect_failed
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libcore/option.rs:1264
   6: script::script_module::host_import_module_dynamically
   7: _ZN2js24StartDynamicModuleImportEP9JSContextN2JS6HandleIP8JSScriptEENS3_INS2_5ValueEEE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/ModuleObject.cpp:1752
   8: _ZL9InterpretP9JSContextRN2js8RunStateE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:4286
   9: _ZN2js9RunScriptEP9JSContextRNS_8RunStateE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:423
  10: _ZN2js23InternalCallOrConstructEP9JSContextRKN2JS8CallArgsENS_14MaybeConstructENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:589
  11: _ZN2js4CallEP9JSContextN2JS6HandleINS2_5ValueEEES5_RKNS_13AnyInvokeArgsENS2_13MutableHandleIS4_EENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:634
  12: _ZN2js13PromiseObject6createEP9JSContextN2JS6HandleIP8JSObjectEES7_b
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/Promise.cpp:2346
  13: _ZL18PromiseConstructorP9JSContextjPN2JS5ValueE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/Promise.cpp:2267
  14: _Z12CallJSNativeP9JSContextPFbS0_jPN2JS5ValueEEN2js10CallReasonERKNS1_8CallArgsE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:456
      _Z23CallJSNativeConstructorP9JSContextPFbS0_jPN2JS5ValueEERKNS1_8CallArgsE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:472
      _ZL17InternalConstructP9JSContextRKN2js16AnyConstructArgsE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:661
  15: _ZN2js18ConstructFromStackEP9JSContextRKN2JS8CallArgsE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:707
      _ZL9InterpretP9JSContextRN2js8RunStateE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:3108
  16: _ZN2js9RunScriptEP9JSContextRNS_8RunStateE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:423
  17: _ZN2js23InternalCallOrConstructEP9JSContextRKN2JS8CallArgsENS_14MaybeConstructENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:589
  18: _ZN2js4CallEP9JSContextN2JS6HandleINS2_5ValueEEES5_RKNS_13AnyInvokeArgsENS2_13MutableHandleIS4_EENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:634
  19: _ZN2js4CallEP9JSContextN2JS6HandleINS2_5ValueEEES5_S5_NS2_13MutableHandleIS4_EE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.h:103
      _ZL18PromiseReactionJobP9JSContextjPN2JS5ValueE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/Promise.cpp:1813
  20: _Z12CallJSNativeP9JSContextPFbS0_jPN2JS5ValueEEN2js10CallReasonERKNS1_8CallArgsE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:456
      _ZN2js23InternalCallOrConstructEP9JSContextRKN2JS8CallArgsENS_14MaybeConstructENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:548
  21: _ZN2js4CallEP9JSContextN2JS6HandleINS2_5ValueEEES5_RKNS_13AnyInvokeArgsENS2_13MutableHandleIS4_EENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:634
  22: _Z20JS_CallFunctionValueP9JSContextN2JS6HandleIP8JSObjectEENS2_INS1_5ValueEEERKNS1_16HandleValueArrayENS1_13MutableHandleIS6_EE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/jsapi.cpp:2689
  23: script::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback::Call
  24: script::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback::Call_
  25: script::microtask::MicrotaskQueue::checkpoint
  26: script::script_thread::ScriptThread::handle_msgs
  27: profile_traits::mem::ProfilerChan::run_with_memory_reporting
  28: std::sys_common::backtrace::__rust_begin_short_backtrace
  29: core::ops::function::FnOnce::call_once{{vtable.shim}}
  30: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/liballoc/boxed.rs:1034
      <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/liballoc/boxed.rs:1034
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/sys/unix/thread.rs:87
  31: start_thread
  32: __clone
[2020-06-13T18:25:19Z ERROR servo] no current script?
assertion failed: *self.stack == self as *mut _ as usize as _ (thread ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }, at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/macros.rs:13)
   0: servo::backtrace::print
   1: servo::main::{{closure}}
   2: std::panicking::rust_panic_with_hook
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/panicking.rs:481
   3: std::panicking::begin_panic
   4: core::ptr::drop_in_place
   5: script::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback::Call_
   6: script::microtask::MicrotaskQueue::checkpoint
   7: script::script_thread::ScriptThread::handle_msgs
   8: profile_traits::mem::ProfilerChan::run_with_memory_reporting
   9: std::sys_common::backtrace::__rust_begin_short_backtrace
  10: core::ops::function::FnOnce::call_once{{vtable.shim}}
  11: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/liballoc/boxed.rs:1034
      <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/liballoc/boxed.rs:1034
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/sys/unix/thread.rs:87
  12: start_thread
  13: __clone
[2020-06-13T18:25:19Z ERROR servo] assertion failed: *self.stack == self as *mut _ as usize as _
thread panicked while panicking. aborting.
Stack trace for thread "ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }"
Servo exited with return value 11

I hope this helps in some way.

@jdm
Copy link
Member

@jdm jdm commented Jun 13, 2020

Hmm, looks like there's code that runs an import from inside of a promise callback. I was hoping cases like that wouldn't be common; master...CYBAI:dynamic-modulediff-3fe97584f564214ec8e7ebbf91747e03R1350-R1359 is a short-term hack that grabs the currently executing script from the document, but that only works for JS executed directly from <script> elements.

@jdm
Copy link
Member

@jdm jdm commented Jun 13, 2020

The solution is to attach important data to the private fields of JSScript objects, and I think ModuleOwner::Window will need to contain something else than an HTMLScriptElement, or else we need to tie JSScripts to HTMLScriptElements more directly somehow. The issue is that when we hit a dynamic import that's not already inside of an existing module, at the moment we need to pass a module owner to fetch_single_module_script. Either we need a more general module owner, or we need to not require a module owner when calling that method.

@CYBAI
Copy link
Collaborator Author

@CYBAI CYBAI commented Jun 14, 2020

The solution is to attach important data to the private fields of JSScript objects, and I think ModuleOwner::Window will need to contain something else than an HTMLScriptElement, or else we need to tie JSScripts to HTMLScriptElements more directly somehow.

I see! Thanks for pointing that out! If so, I'd like to add one more branch to the ModuleOwner enum because we also save the dynamic module list in global scope separately; it might be reasonable be a different module owner?

The issue is that when we hit a dynamic import that's not already inside of an existing module, at the moment we need to pass a module owner to fetch_single_module_script. Either we need a more general module owner, or we need to not require a module owner when calling that method.

Yes! I think I can understand the issue now! We will need a proper owner type for dynamic module to handle it. I will look into it and update anything here!

Also thanks @kunalmohan for helping to check it works in your repo!

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jun 14, 2020

A different panic when running the live test-suite at http://gpuweb-cts-glsl.github.io/standalone/. The code rests in branch glsl-dependent at https://github.com/gpuweb/cts/tree/glsl-dependent. This one's intermittent though.

DomRefCell<T> already borrowed: BorrowMutError (thread ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }, at components/script/dom/bindings/cell.rs:93)
   0: servo::backtrace::print
   1: servo::main::{{closure}}
   2: std::panicking::rust_panic_with_hook
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/panicking.rs:481
   3: rust_begin_unwind
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/panicking.rs:385
   4: core::panicking::panic_fmt
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libcore/panicking.rs:89
   5: core::option::expect_none_failed
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libcore/option.rs:1272
   6: script::dom::globalscope::GlobalScope::set_module_map
   7: script::script_module::fetch_single_module_script
   8: script::script_module::host_import_module_dynamically
   9: _ZN2js24StartDynamicModuleImportEP9JSContextN2JS6HandleIP8JSScriptEENS3_INS2_5ValueEEE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/ModuleObject.cpp:1752
  10: _ZL9InterpretP9JSContextRN2js8RunStateE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:4286
  11: _ZN2js9RunScriptEP9JSContextRNS_8RunStateE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:423
  12: _ZN2js13ExecuteKernelEP9JSContextN2JS6HandleIP8JSScriptEER8JSObjectRKNS2_5ValueENS_16AbstractFramePtrEPS9_
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:810
  13: _ZN2js7ExecuteEP9JSContextN2JS6HandleIP8JSScriptEER8JSObjectPNS2_5ValueE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:843
  14: _ZN2js12ModuleObject7executeEP9JSContextN2JS6HandleIPS0_EENS3_13MutableHandleINS3_5ValueEEE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/ModuleObject.cpp:1076
  15: _ZL23intrinsic_ExecuteModuleP9JSContextjPN2JS5ValueE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/SelfHosting.cpp:1976
  16: <unknown>
  17: <unknown>
  18: <unknown>
  19: _ZL13EnterBaselineP9JSContextRN2js3jit12EnterJitDataE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/jit/BaselineJIT.cpp:113
      _ZN2js3jit32EnterBaselineInterpreterAtBranchEP9JSContextPNS_16InterpreterFrameEPh
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/jit/BaselineJIT.cpp:186
  20: <unknown>
  21: <unknown>
[2020-06-14T14:24:09Z ERROR servo] DomRefCell<T> already borrowed: BorrowMutError
fatal runtime error: failed to initiate panic, error 5
Redirecting call to abort() to mozalloc_abort

Stack trace for thread "ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }"
Servo exited with return value 11

@jdm iirc, I reported a similar error while running my test example initially. You fixed it on that occasion. I wonder if this one's related.

@jdm
Copy link
Member

@jdm jdm commented Jun 14, 2020

@kunalmohan if you could build with --features refcell_backtrace, the output from that build would be helpful!

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jun 14, 2020

@jdm I tried a number of times, but couldn't reproduce the error on a dev build. On a release build with that feature, I got a similar backtrace as before expect with one additional line(above the 6th line of previous backtrace)-

script::dom::bindings::cell::DomRefCell<T>::borrow_mut

which probably isn't very helpful.

Although, on a debug build a warning shows up- failed to compile module .... which is not related to the panic, I suppose.

@jdm
Copy link
Member

@jdm jdm commented Jun 18, 2020

The output of the borrow failure when using refcell_backtrace will be more useful with #26975 applied.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jun 19, 2020

I ran it on the latest master, facing a different error now-

assertion failed: fetched_module_object.is_some() (thread ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }, at components/script/script_module.rs:1175)
   0: servo::backtrace::print
   1: servo::main::{{closure}}
   2: std::panicking::rust_panic_with_hook
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/panicking.rs:481
   3: std::panicking::begin_panic
   4: script::script_module::HostResolveImportedModule
   5: _ZN2js21CallModuleResolveHookEP9JSContextN2JS6HandleINS2_5ValueEEENS3_IP8JSStringEE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/ModuleObject.cpp:1698
   6: _ZL35intrinsic_HostResolveImportedModuleP9JSContextjPN2JS5ValueE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/SelfHosting.cpp:1914
   7: _Z12CallJSNativeP9JSContextPFbS0_jPN2JS5ValueEEN2js10CallReasonERKNS1_8CallArgsE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:456
      _ZN2js23InternalCallOrConstructEP9JSContextRKN2JS8CallArgsENS_14MaybeConstructENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:548
   8: _ZN2js13CallFromStackEP9JSContextRKN2JS8CallArgsE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:621
      _ZL9InterpretP9JSContextRN2js8RunStateE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:3117
   9: _ZN2js9RunScriptEP9JSContextRNS_8RunStateE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:423
  10: _ZN2js23InternalCallOrConstructEP9JSContextRKN2JS8CallArgsENS_14MaybeConstructENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:589
  11: _ZN2js4CallEP9JSContextN2JS6HandleINS2_5ValueEEES5_RKNS_13AnyInvokeArgsENS2_13MutableHandleIS4_EENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:634
  12: _ZN2js3jit14InvokeFunctionEP9JSContextN2JS6HandleIP8JSObjectEEbbjPNS3_5ValueENS3_13MutableHandleIS8_EE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/jit/VMFunctions.cpp:261
  13: _ZN2js3jit25InvokeFromInterpreterStubEP9JSContextPNS0_30InterpreterStubExitFrameLayoutE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/jit/VMFunctions.cpp:290
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: <unknown>
  19: _ZL8EnterJitP9JSContextRN2js8RunStateEPh
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/jit/Jit.cpp:109
      _ZN2js3jit13MaybeEnterJitEP9JSContextRNS_8RunStateE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/jit/Jit.cpp:200
  21: <unknown>
[2020-06-19T06:32:54Z ERROR servo] assertion failed: fetched_module_object.is_some()
fatal runtime error: failed to initiate panic, error 5
Redirecting call to abort() to mozalloc_abort

Stack trace for thread "ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }"
@CYBAI
Copy link
Collaborator Author

@CYBAI CYBAI commented Jun 22, 2020

@kunalmohan @jdm sorry, I'm quite busy recently and don't have enough time to investigate the crash (#25439 (comment)) yet.

But, I tried to fix some more tests for dynamic module yesterday but there are still some TIMEOUTs that I haven't investigated yet. I think I'm going to send a draft PR and bors will remind me to rebase if there's any conflicts.

Also, I tried to run the http://gpuweb-cts-glsl.github.io/standalone/ page with latest master and it crashed on my local too so I think it might be related to bugs in existing module script instead of dynamic module. I will investigate it! Thanks!

@CYBAI
Copy link
Collaborator Author

@CYBAI CYBAI commented Jun 22, 2020

Draft PR at #27026

@CYBAI
Copy link
Collaborator Author

@CYBAI CYBAI commented Jun 22, 2020

@kunalmohan @jdm Because the issue is basically not related to dynamic import, I filed #27029 and summarized at #27029 (comment). I'm going to send a PR for it.

@CYBAI
Copy link
Collaborator Author

@CYBAI CYBAI commented Jun 22, 2020

With cherry-pick-ing the commit in #27034 to the dynamic module branch and running the http://gpuweb-cts-glsl.github.io/standalone/ page, I found I still can't see the test results.

Then, I saw we fail to compile the https://gpuweb-cts-glsl.github.io/out/webgpu/gpu_test.js script in Servo 🤔 It works fine in my Chrome Canary and Firefox Nightly (both with webgpu enabled).

[2020-06-22T15:03:20Z WARN  script::script_module] fail to compile module script of https://gpuweb-cts-glsl.github.io/out/webgpu/gpu_test.js
[2020-06-22T15:03:20Z DEBUG script::script_module] Going to advance and finish for: https://gpuweb-cts-glsl.github.io/out/webgpu/gpu_test.js

Will try to investigate what makes it fail.

@CYBAI
Copy link
Collaborator Author

@CYBAI CYBAI commented Jun 22, 2020

[2020-06-22T15:45:18Z ERROR script::dom::bindings::error] Error at https://gpuweb-cts-glsl.github.io/out/webgpu/gpu_test.js:238:37 expected expression, got '.'

cool, so the issue is the web page is using optional chaining which causes a syntax error for Servo now.

image

We might need a smup to support the syntax.

@jdm
Copy link
Member

@jdm jdm commented Jun 22, 2020

If possible, I would recommend submitting changes upstream to avoid using the latest bleeding edge JS features.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jun 22, 2020

We'll change this in the test-suite, so there won't be a need to support it yet.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jun 23, 2020

@jdm @CYBAI really appreciate you both helping me so much in my project! Thank you!

I replaced the optional-chaining syntax and tested on my local system with the dynamic-module branch rebase over latest master. gpu-test.js compiles successfully. But there is a different panic now (which is unrelated to dynamic module)-

assertion failed: url.is_ok() (thread ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }, at components/script/script_module.rs:1389)
   0: servo::backtrace::print
   1: servo::main::{{closure}}
   2: std::panicking::rust_panic_with_hook
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/panicking.rs:481
   3: std::panicking::begin_panic
   4: script::script_module::HostResolveImportedModule
   5: _ZN2js21CallModuleResolveHookEP9JSContextN2JS6HandleINS2_5ValueEEENS3_IP8JSStringEE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/ModuleObject.cpp:1698
      _ZN2js25FinishDynamicModuleImportEP9JSContextN2JS6HandleINS2_5ValueEEENS3_IP8JSStringEENS3_IP8JSObjectEE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/ModuleObject.cpp:1781
   6: <T as script::task::TaskBox>::run_box
   7: <script::script_module::ModuleHandler as script::dom::promisenativehandler::Callback>::callback
   8: script::dom::promise::native_handler_callback
   9: _Z12CallJSNativeP9JSContextPFbS0_jPN2JS5ValueEEN2js10CallReasonERKNS1_8CallArgsE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:456
      _ZN2js23InternalCallOrConstructEP9JSContextRKN2JS8CallArgsENS_14MaybeConstructENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:548
  10: _ZN2js4CallEP9JSContextN2JS6HandleINS2_5ValueEEES5_RKNS_13AnyInvokeArgsENS2_13MutableHandleIS4_EENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:634
  11: _ZN2js4CallEP9JSContextN2JS6HandleINS2_5ValueEEES5_S5_NS2_13MutableHandleIS4_EE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.h:103
      _ZL18PromiseReactionJobP9JSContextjPN2JS5ValueE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/builtin/Promise.cpp:1813
  12: _Z12CallJSNativeP9JSContextPFbS0_jPN2JS5ValueEEN2js10CallReasonERKNS1_8CallArgsE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:456
      _ZN2js23InternalCallOrConstructEP9JSContextRKN2JS8CallArgsENS_14MaybeConstructENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:548
  13: _ZN2js4CallEP9JSContextN2JS6HandleINS2_5ValueEEES5_RKNS_13AnyInvokeArgsENS2_13MutableHandleIS4_EENS_10CallReasonE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/vm/Interpreter.cpp:634
  14: _Z20JS_CallFunctionValueP9JSContextN2JS6HandleIP8JSObjectEENS2_INS1_5ValueEEERKNS1_16HandleValueArrayENS1_13MutableHandleIS6_EE
             at /home/kunal/.cargo/git/checkouts/mozjs-fa11ffc7d4f1cc2d/9a6d8fc/mozjs/js/src/jsapi.cpp:2689
  15: script::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback::Call
  16: script::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback::Call_
  17: script::microtask::MicrotaskQueue::checkpoint
  18: script::script_thread::ScriptThread::handle_msgs
  19: profile_traits::mem::ProfilerChan::run_with_memory_reporting
  20: std::sys_common::backtrace::__rust_begin_short_backtrace
  21: core::ops::function::FnOnce::call_once{{vtable.shim}}
  22: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/liballoc/boxed.rs:1034
      <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/liballoc/boxed.rs:1034
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/sys/unix/thread.rs:87
  23: start_thread
  24: __clone
[2020-06-23T10:41:24Z ERROR servo] assertion failed: url.is_ok()
assertion failed: *self.stack == self as *mut _ as usize as _ (thread ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }, at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/macros.rs:13)
   0: servo::backtrace::print
   1: servo::main::{{closure}}
   2: std::panicking::rust_panic_with_hook
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/panicking.rs:481
   3: std::panicking::begin_panic
   4: core::ptr::drop_in_place
   5: script::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback::Call_
   6: script::microtask::MicrotaskQueue::checkpoint
   7: script::script_thread::ScriptThread::handle_msgs
   8: profile_traits::mem::ProfilerChan::run_with_memory_reporting
   9: std::sys_common::backtrace::__rust_begin_short_backtrace
  10: core::ops::function::FnOnce::call_once{{vtable.shim}}
  11: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/liballoc/boxed.rs:1034
      <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/liballoc/boxed.rs:1034
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/a74d1862d4d87a56244958416fd05976c58ca1a8/src/libstd/sys/unix/thread.rs:87
  12: start_thread
  13: __clone
[2020-06-23T10:41:24Z ERROR servo] assertion failed: *self.stack == self as *mut _ as usize as _
thread panicked while panicking. aborting.
Stack trace for thread "ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }"

I also realised that we already have test-suite under tests/wpt/web-platform-tests/webgpu. So I tried running them and most of them run successfully (i.e. they fail instead of throwing an Error) except a few that crash with the above panic. I noticed that the URL for those tests end with *.

Also I want to confirm one thing. The tests Fail (instead of Error) after removing the optional chaining operator. Will it be safe to say that there is no more unsupported syntax in the tests? (Also, I did not see any fail to compile module warning in the logs while running the live test, apart from the above panic)

@jdm
Copy link
Member

@jdm jdm commented Jun 23, 2020

Yes, FAIL means the test failed some assertions, while ERROR means that a JS exception was raised.

@CYBAI
Copy link
Collaborator Author

@CYBAI CYBAI commented Jun 23, 2020

Interesting! The panic looks like it fails to parse the module specifier.

let url = ModuleTree::resolve_module_specifier(*global_scope.get_cx(), &base_url, specifier);
// Step 6.
assert!(url.is_ok());

So I tried running them and most of them run successfully (i.e. they fail instead of throwing an Error) except a few that crash with the above panic. I noticed that the URL for those tests end with *.

Hmmm, if it's a valid URL, it should be parse-able 🤔 I'm curious does the tests work fine on Chrome and Firefox? and could you point me to the tests?

Also, if it works fine on Chrome and Firefox but not on Servo, maybe it's worth filing it as a new issue! Thanks!

@jdm

This comment was marked as outdated.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jun 30, 2020

Live test suite has been updated after removing optional chaining operator (https://gpuweb.github.io/cts/standalone/).
(Really sorry for the late update)

Good news is that the page loads successfully and the tests are visible and we can run and see the results as expected.

@CYBAI CYBAI mentioned this issue Jul 17, 2020
4 of 4 tasks complete
bors-servo added a commit that referenced this issue Jul 17, 2020
Introduce dynamic module

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #25439
- [x] There are tests for these changes
bors-servo added a commit that referenced this issue Jul 17, 2020
Introduce dynamic module

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #25439
- [x] There are tests for these changes
bors-servo added a commit that referenced this issue Jul 19, 2020
Introduce dynamic module

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #25439
- [x] There are tests for these changes
WebGPU MVP automation moved this from To do to Done Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
WebGPU MVP
  
Done
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.