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

hello world example causes compiler panic on windows #56

Closed
anderslanglands opened this issue Jan 3, 2022 · 16 comments
Closed

hello world example causes compiler panic on windows #56

anderslanglands opened this issue Jan 3, 2022 · 16 comments

Comments

@anderslanglands
Copy link

Excited to try it out so had a crack at the hello world example on Windows just now and it causes an ICE:

rust-lang/rust#92537

@jkelleyrtp
Copy link
Member

Hmm.... that's not good. I don't have a windows box but my version running on macOS checks just fine. Can you try checking the expansion too? I could release a patch that works around this bug, since given your stack trace I think I know where the ICE is coming from.

fn app(cx: Scope) -> Element {
    cx.render(LazyNodes::new_some(move |__cx: NodeFactory| -> VNode {
        use dioxus_elements::{GlobalAttributes, SvgAttributes};
        __cx.element(
            dioxus_elements::div,
            [],
            [],
            [__cx.text(format_args!("Hello, world!"))],
            None,
        )
    }))
}

@anderslanglands
Copy link
Author

I get the same result with the expanded code:

thread 'rustc' panicked at 'assertion failed: !value.has_escaping_bound_vars()', /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\compiler\rustc_middle\src\ty\sty.rs:974:9
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.57.0 (f1edd0429 2021-11-29) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [is_sized_raw] computing whether `[nodes::VNode<'_>]` is `Sized`
#1 [layout_of] computing layout of `&[nodes::VNode<'_>]`
#2 [layout_of] computing layout of `nodes::VFragment<'_>`
#3 [layout_of] computing layout of `nodes::VNode<'_>`
#4 [layout_of] computing layout of `core::option::Option<nodes::VNode<'_>>`
end of query stack
error: could not compile `dioxus-core`
warning: build failed, waiting for other jobs to finish...
error: build failed

@Patrick-Poitras
Copy link

Patrick-Poitras commented Jan 3, 2022

Can you try cargo clean then cargo build?

Edit: I have been able to replicate the bug compiling from scratch. Disregard the previous suggestion.

@Patrick-Poitras
Copy link

For what it's worth, any code that has a dependency on dioxus seems to yield the same error, even with my main code being fn main(){}.

Something inside dioxus is causing the rust compiler to panic.

@jkelleyrtp
Copy link
Member

I've uploaded jk/fix-ice which I think should address this bug.

Can you try changing your Dioxus dependency to

dioxus = { git = "https://github.com/DioxusLabs/dioxus", branch = "jk/fix-ice", features = [ "desktop"] }

This should remove the generics around AsRef - it makes the NodeFactory API slightly more cumbersome but I think should fix this issue.

@Patrick-Poitras
Copy link

@jkelleyrtp I'm trying (and failing) to create a minimally reproducible example for the rust compiler team. I see that the generics around AsRef seem to be the issue, so I'll check if that's in the known internal compiler errors repository.

@jkelleyrtp
Copy link
Member

The core crate is pretty small, so maybe just comment out module by module until the culprit is found. I've trying to spin up a windows vm.

The LazyNodes module dances around sized/unsized types, try checking there? By getting rid of AsRef, I was able to shrink the error, so it might be in a handful of places.

@jkelleyrtp
Copy link
Member

jkelleyrtp commented Jan 4, 2022

Looks like the bug is in LazyNodes. I use the same logic from https://docs.rs/stack_dst/latest/stack_dst/ - maybe they also cause an ICE. Found a simply workaround/fix, going to publish it. @anderslanglands @Patrick-Poitras

@Patrick-Poitras
Copy link

Patrick-Poitras commented Jan 4, 2022

I found a minimal example, it features the stuff from nodes and lazynodes.

use std::mem;
use std::marker::PhantomData;

struct LazyStack {}

impl Drop for LazyStack {
    fn drop(&mut self) {
        let g: *mut dyn FnMut(Option<NodeFactory<'_>>) -> Option<VNode<'_>> =
            unsafe {make_fat_ptr()};

        let clos = (unsafe { &mut *g });
        clos(None);
    }
}

unsafe fn make_fat_ptr<T: ?Sized>() -> *mut T {
    mem::MaybeUninit::<*mut T>::uninit().assume_init()
}

enum VNode<'src> {
    Fragment(&'src [VNode<'src>]),
}

struct NodeFactory<'a> {
    x : &'a PhantomData<u32>,
}

I don't know what simplified into mem::MaybeUninit::<*mut T>::uninit().assume_init(), but someone might want to have a look at that, it seems to me like that's a potential issue.

@jkelleyrtp
Copy link
Member

The current version of Dioxus runs in my windows VM and has been pushed. Very interesting it triggered the ICE.

@Patrick-Poitras That's a pretty crazy set of incantations...

@anderslanglands
Copy link
Author

@jkelleyrtp the `jk/fix-ice' branch does indeed fix the ICE but running the example gives me:

thread 'main' panicked at 'not implemented: path index.html/', C:\Users\ander\.cargo\git\checkouts\dioxus-1e619ce595d3799d\4ea5c99\packages\desktop\src\lib.rs:347:26
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:517
   1: core::panicking::panic_fmt
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\core\src\panicking.rs:100
   2: dioxus_desktop::impl$0::new_window::closure$1
             at C:\Users\ander\.cargo\git\checkouts\dioxus-1e619ce595d3799d\4ea5c99\packages\desktop\src\lib.rs:347
   3: alloc::boxed::impl$46::call<tuple$<ref$<wry::shared::http::request::Request> >,dyn$<core::ops::function::Fn<tuple$<ref$<wry::shared::http::request::Request> >,assoc$<Output,enum$<core::result::Result<wry::shared::http::response::Response,enum$<wry::Error>
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\alloc\src\boxed.rs:1705
   4: wry::webview::webview2::impl$0::new::closure$0::closure$0::closure$4
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\wry-0.12.2\src\webview\webview2\mod.rs:232
   5: webview2::impl$4::add_web_resource_requested::closure$0<wry::webview::webview2::impl$0::new::closure$0::closure$0::closure$4>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\webview2-0.1.4\src\lib.rs:1023
   6: alloc::boxed::impl$46::call<tuple$<ptr_mut$<ptr_mut$<webview2_sys::ICoreWebView2VTable> >,ptr_mut$<ptr_mut$<webview2_sys::ICoreWebView2WebResourceRequestedEventArgsVTable> > >,dyn$<core::ops::function::Fn<tuple$<ptr_mut$<ptr_mut$<webview2_sys::ICoreWebVie
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\alloc\src\boxed.rs:1705
   7: webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\webview2-0.1.4\src\lib.rs:96
   8: core::ops::function::FnOnce::call_once<webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0,tuple$<> >
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ops\function.rs:227
   9: core::panic::unwind_safe::impl$23::call_once<i32,webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0>
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\panic\unwind_safe.rs:271
  10: std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0>,i32>
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panicking.rs:403
  11: std::panicking::begin_panic::impl$1::take_box<str>
  12: std::panicking::try<i32,core::panic::unwind_safe::AssertUnwindSafe<webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0> >
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panicking.rs:367
  13: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0>,i32>
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panic.rs:133
  14: webview2::impl$4::add_web_resource_requested::impl$0::invoke
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\webview2-0.1.4\src\lib.rs:95
  15: webview2_sys::impl$329::vtable::icorewebview2webresourcerequestedeventhandler_invoke<webview2::impl$4::add_web_resource_requested::Impl,com::offset::Zero>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\webview2-sys-0.1.1\src\lib.rs:3178
  16: CreateWebViewEnvironmentWithOptionsInternal
  17: CreateWebViewEnvironmentWithOptionsInternal
  18: CreateWebViewEnvironmentWithOptionsInternal
  19: CreateWebViewEnvironmentWithOptionsInternal
  20: DllCanUnloadNow
  21: CreateWebViewEnvironmentWithOptionsInternal
  22: DllCanUnloadNow
  23: DllCanUnloadNow
  24: DllCanUnloadNow
  25: DllCanUnloadNow
  26: DllCanUnloadNow
  27: DllCanUnloadNow
  28: DllCanUnloadNow
  29: DllCanUnloadNow
  30: DllCanUnloadNow
  31: DllCanUnloadNow
  32: DllCanUnloadNow
  33: Ordinal0
  34: DllCanUnloadNow
  35: CallWindowProcW
  36: DispatchMessageW
  37: tao::platform_impl::platform::event_loop::EventLoop<enum$<dioxus_desktop::UserWindowEvent> >::run_return<enum$<dioxus_desktop::UserWindowEvent>,dioxus_desktop::launch_with_props::closure$0>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\tao-0.5.2\src\platform_impl\windows\event_loop.rs:248
  38: tao::platform_impl::platform::event_loop::EventLoop<enum$<dioxus_desktop::UserWindowEvent> >::run<enum$<dioxus_desktop::UserWindowEvent>,dioxus_desktop::launch_with_props::closure$0>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\tao-0.5.2\src\platform_impl\windows\event_loop.rs:203
  39: tao::event_loop::EventLoop<enum$<dioxus_desktop::UserWindowEvent> >::run<enum$<dioxus_desktop::UserWindowEvent>,dioxus_desktop::launch_with_props::closure$0>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\tao-0.5.2\src\event_loop.rs:151
  40: dioxus_desktop::launch_with_props<tuple$<>,dioxus_desktop::launch::closure$0>
             at C:\Users\ander\.cargo\git\checkouts\dioxus-1e619ce595d3799d\4ea5c99\packages\desktop\src\lib.rs:163
  41: dioxus_desktop::launch
             at C:\Users\ander\.cargo\git\checkouts\dioxus-1e619ce595d3799d\4ea5c99\packages\desktop\src\lib.rs:98
  42: hello_dioxus::main
             at .\src\main.rs:4
  43: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
webview2: panic in callback function. Aborting because it's UB to unwind across FFI boundaries.
error: process didn't exit successfully: `target\debug\hello-dioxus.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)

@jkelleyrtp
Copy link
Member

@jkelleyrtp the `jk/fix-ice' branch does indeed fix the ICE but running the example gives me:

thread 'main' panicked at 'not implemented: path index.html/', C:\Users\ander\.cargo\git\checkouts\dioxus-1e619ce595d3799d\4ea5c99\packages\desktop\src\lib.rs:347:26
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:517
   1: core::panicking::panic_fmt
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\core\src\panicking.rs:100
   2: dioxus_desktop::impl$0::new_window::closure$1
             at C:\Users\ander\.cargo\git\checkouts\dioxus-1e619ce595d3799d\4ea5c99\packages\desktop\src\lib.rs:347
   3: alloc::boxed::impl$46::call<tuple$<ref$<wry::shared::http::request::Request> >,dyn$<core::ops::function::Fn<tuple$<ref$<wry::shared::http::request::Request> >,assoc$<Output,enum$<core::result::Result<wry::shared::http::response::Response,enum$<wry::Error>
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\alloc\src\boxed.rs:1705
   4: wry::webview::webview2::impl$0::new::closure$0::closure$0::closure$4
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\wry-0.12.2\src\webview\webview2\mod.rs:232
   5: webview2::impl$4::add_web_resource_requested::closure$0<wry::webview::webview2::impl$0::new::closure$0::closure$0::closure$4>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\webview2-0.1.4\src\lib.rs:1023
   6: alloc::boxed::impl$46::call<tuple$<ptr_mut$<ptr_mut$<webview2_sys::ICoreWebView2VTable> >,ptr_mut$<ptr_mut$<webview2_sys::ICoreWebView2WebResourceRequestedEventArgsVTable> > >,dyn$<core::ops::function::Fn<tuple$<ptr_mut$<ptr_mut$<webview2_sys::ICoreWebVie
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\alloc\src\boxed.rs:1705
   7: webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\webview2-0.1.4\src\lib.rs:96
   8: core::ops::function::FnOnce::call_once<webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0,tuple$<> >
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ops\function.rs:227
   9: core::panic::unwind_safe::impl$23::call_once<i32,webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0>
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\panic\unwind_safe.rs:271
  10: std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0>,i32>
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panicking.rs:403
  11: std::panicking::begin_panic::impl$1::take_box<str>
  12: std::panicking::try<i32,core::panic::unwind_safe::AssertUnwindSafe<webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0> >
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panicking.rs:367
  13: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<webview2::impl$4::add_web_resource_requested::impl$0::invoke::closure$0>,i32>
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\panic.rs:133
  14: webview2::impl$4::add_web_resource_requested::impl$0::invoke
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\webview2-0.1.4\src\lib.rs:95
  15: webview2_sys::impl$329::vtable::icorewebview2webresourcerequestedeventhandler_invoke<webview2::impl$4::add_web_resource_requested::Impl,com::offset::Zero>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\webview2-sys-0.1.1\src\lib.rs:3178
  16: CreateWebViewEnvironmentWithOptionsInternal
  17: CreateWebViewEnvironmentWithOptionsInternal
  18: CreateWebViewEnvironmentWithOptionsInternal
  19: CreateWebViewEnvironmentWithOptionsInternal
  20: DllCanUnloadNow
  21: CreateWebViewEnvironmentWithOptionsInternal
  22: DllCanUnloadNow
  23: DllCanUnloadNow
  24: DllCanUnloadNow
  25: DllCanUnloadNow
  26: DllCanUnloadNow
  27: DllCanUnloadNow
  28: DllCanUnloadNow
  29: DllCanUnloadNow
  30: DllCanUnloadNow
  31: DllCanUnloadNow
  32: DllCanUnloadNow
  33: Ordinal0
  34: DllCanUnloadNow
  35: CallWindowProcW
  36: DispatchMessageW
  37: tao::platform_impl::platform::event_loop::EventLoop<enum$<dioxus_desktop::UserWindowEvent> >::run_return<enum$<dioxus_desktop::UserWindowEvent>,dioxus_desktop::launch_with_props::closure$0>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\tao-0.5.2\src\platform_impl\windows\event_loop.rs:248
  38: tao::platform_impl::platform::event_loop::EventLoop<enum$<dioxus_desktop::UserWindowEvent> >::run<enum$<dioxus_desktop::UserWindowEvent>,dioxus_desktop::launch_with_props::closure$0>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\tao-0.5.2\src\platform_impl\windows\event_loop.rs:203
  39: tao::event_loop::EventLoop<enum$<dioxus_desktop::UserWindowEvent> >::run<enum$<dioxus_desktop::UserWindowEvent>,dioxus_desktop::launch_with_props::closure$0>
             at C:\Users\ander\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\tao-0.5.2\src\event_loop.rs:151
  40: dioxus_desktop::launch_with_props<tuple$<>,dioxus_desktop::launch::closure$0>
             at C:\Users\ander\.cargo\git\checkouts\dioxus-1e619ce595d3799d\4ea5c99\packages\desktop\src\lib.rs:163
  41: dioxus_desktop::launch
             at C:\Users\ander\.cargo\git\checkouts\dioxus-1e619ce595d3799d\4ea5c99\packages\desktop\src\lib.rs:98
  42: hello_dioxus::main
             at .\src\main.rs:4
  43: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
webview2: panic in callback function. Aborting because it's UB to unwind across FFI boundaries.
error: process didn't exit successfully: `target\debug\hello-dioxus.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)

Looks like windows redirects the WebView when it loads. Try the jk/windows-desktop branch - I merged this fix in with the ICE fix but this fix hasn't been published to crates yet.

Sorry... I don't use windows so I didn't know about either of these!

@anderslanglands
Copy link
Author

@jkelleyrtp yep that works now! Only weird thing is that the "Hello, world!" text doesn't render until I move or resize the window.

@jkelleyrtp
Copy link
Member

@jkelleyrtp yep that works now! Only weird thing is that the "Hello, world!" text doesn't render until I move or resize the window.

Strange - but at least I know where to look. The event loop on windows probably sleeps or doesn't call the "events cleared" message. I'm getting the same behavior so at least I can debug it now.

@jkelleyrtp
Copy link
Member

Closing this issue because we no longer cause an ICE, but looking at the other win issues.

@Patrick-Poitras
Copy link

We've put the ICE into the database over on the language side.

jkelleyrtp pushed a commit that referenced this issue Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants