Skip to content

dioxus hello world example causes compiler panic on windows #92537

Closed

Description

@anderslanglands

As title. Happens with both stable and nightly

Code

main.rs:

use dioxus::prelude::*;

fn main() {
    dioxus::desktop::launch(App);
}

fn App(cx: Scope) -> Element {
    cx.render(rsx! {
        div { "Hello, world!"}
    })
}

Cargo.toml:

[package]
name = "hello-dioxus"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dioxus = { version = "0.1.4", features = ["desktop"] }

Meta

rustc --version --verbose:

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-pc-windows-msvc
release: 1.57.0
LLVM version: 13.0.0

rustc +nightly --version --verbose:

rustc 1.59.0-nightly (8f3238f89 2022-01-02)
binary: rustc
commit-hash: 8f3238f898163f09726c3d2b2cc9bafb09da26f3
commit-date: 2022-01-02
host: x86_64-pc-windows-msvc
release: 1.59.0-nightly
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'assertion failed: !value.has_escaping_bound_vars()', /rustc/8f3238f898163f09726c3d2b2cc9bafb09da26f3\compiler\rustc_middle\src\ty\sty.rs:1036:9
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.59.0-nightly (8f3238f89 2022-01-02) 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<'_>]`
end of query stack
error: could not compile `dioxus-core`
warning: build failed, waiting for other jobs to finish...
error: build failed
Backtrace

thread 'rustc' panicked at 'assertion failed: !value.has_escaping_bound_vars()', /rustc/8f3238f898163f09726c3d2b2cc9bafb09da26f3\compiler\rustc_middle\src\ty\sty.rs:1036: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.59.0-nightly (8f3238f89 2022-01-02) 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

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jan 3, 2022
  2. Patrick-Poitras commented on Jan 3, 2022

    @Patrick-Poitras
    Contributor

    Can confirm bug is replicable with example above.

    thread 'rustc' panicked at 'assertion failed: !value.has_escaping_bound_vars()', /rustc/efec545293b9263be9edfb283a7aa66350b3acbf\compiler\rustc_middle\src\ty\sty.rs:1038:9
    note: run with `RUST_BACKTRACE=1` environment variable to display a 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.59.0-nightly (efec54529 2021-12-04) running on x86_64-pc-windows-msvc
    
    
    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<'_>]`
    end of query stack
    error: could not compile `dioxus-core`
    
  3. cbeust commented on Jan 3, 2022

    @cbeust

    Confirmed on Windows 10 for me as well (cargo build is enough to produce the error).

  4. cbeust commented on Jan 3, 2022

    @cbeust

    Including the error for completeness.

    ☻~/rust/dioxus $ cargo build
       Compiling dioxus-html v0.1.2 (...)
    thread 'rustc' panicked at 'assertion failed: !value.has_escaping_bound_vars()', /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\compiler\rustc_middle\src\ty\sty.rs:974:9
    note: run with `RUST_BACKTRACE=1` environment variable to display a 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 -C incremental --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<'_>]`
    end of query stack
    error: could not compile `dioxus-core`
    warning: build failed, waiting for other jobs to finish...
    error: build failed
    
  5. Patrick-Poitras commented on Jan 3, 2022

    @Patrick-Poitras
    Contributor

    Seems like they managed to get a patch out that fixes the issue.

    With that information, I think this may be related to #89189.

  6. Patrick-Poitras commented on Jan 4, 2022

    @Patrick-Poitras
    Contributor

    I have spent the last 2 hours whittling down the entire codebase that they had, in order to have a minimal example. It's fairly weird.

    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'm not 100%, but I figure that mem::MaybeUninit::<*mut T>::uninit().assume_init() isn't supposed to be like that. Either way, this reproduces the issue.

  7. Patrick-Poitras commented on Jan 4, 2022

    @Patrick-Poitras
    Contributor

    Can someone on Windows try this as well (build as lib), because I've tried to add this to glacier, but it seems to compile there, and it seems to also compile on Rust Playground. I'm a bit at a loss.

  8. cbeust commented on Jan 4, 2022

    @cbeust

    @Patrick-Poitras Can you be more specific? What do you want me (us) to try?

  9. anderslanglands commented on Jan 4, 2022

    @anderslanglands
    Author

    @Patrick-Poitras yep your example panics for me on Windows.

  10. Patrick-Poitras commented on Jan 4, 2022

    @Patrick-Poitras
    Contributor

    @cbeust I'd like someone to try the minimal example that I've pasted above, since it doesn't compile on my machine (Windows), but it seems from the other issues thread (on dioxus) that it's a Windows-specific problem. When I've run it on linux machines, it seems to compile there.

    Edit: @anderslanglands, thanks! I'll try to get a discussion going on Zulip as to what could cause this.

  11. Alexendoo commented on Jan 4, 2022

    @Alexendoo
    Member

    Doesn't ICE for windows -gnu targets, just -msvc

  12. added
    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)
    on Jan 4, 2022
  13. Alexendoo commented on Jan 4, 2022

    @Alexendoo
    Member

    Seems to be debug info related, only ices with -C debuginfo=1 or -C debuginfo=2

  14. Patrick-Poitras commented on Jan 4, 2022

    @Patrick-Poitras
    Contributor

    I have further narrowed it down:

    use std::mem::MaybeUninit;
    
    unsafe fn make_fat_ptr<T: ?Sized>(_: &u32) -> *mut T {
        MaybeUninit::<*mut T>::uninit().assume_init()
    }
    
    struct VNode<'src> {
        _x: &'src [VNode<'src>]
    }
    
    fn main() {
        let g: *mut dyn Fn(&'_ u32) -> Option<VNode<'_>> =
            unsafe {make_fat_ptr(&12)};
    }

    The key here is really in the small modifications that will make it work. I now think the bug occurs when it's trying to check if Option<VNode<'_>> fits the T:?Sized condition. The uninit().assume_init() bit seems to only be required to get something that is not type resolved once it leaves the function.

  15. Patrick-Poitras commented on Jan 4, 2022

    @Patrick-Poitras
    Contributor

    Here is what I've gathered so far:

    Clue 1: The self-referential slice is important.

    VNode<'src> can't be rewritten without the reference to the slice, as

    struct VNode {
        _x: [VNode]
    }

    Will give the the size for values of type `[VNode]` cannot be known at compilation time error.

    However, removing the slice compiles:

    struct VNode<'src> {
        _x: &'src VNode<'src>
    }

    Clue 2: Not wrapping in an Option type compiles successfully.

    If we change Option<VNode<'_>> to VNode<'_>, then the code compiles.

    fn main() {
        let g: *mut dyn Fn(&'_ u32) -> VNode<'_> =
            unsafe {make_fat_ptr(&12)};
    }

    Less key bits

    • The type *mut dyn Fn(&'_ u32) -> Option<VNode<'_>> requires the &'_ u32 argument to introduce the '_ lifetime.
  16. Patrick-Poitras commented on Jan 7, 2022

    @Patrick-Poitras
    Contributor

    Bisect results:

    refreshing repository at "rust.git"
    From https://github.com/rust-lang/rust
     * branch                    HEAD       -> FETCH_HEAD
    opening existing repository at "rust.git"
    looking up first commit
    looking up second commit
    checking that commits are by bors and thus have ci artifacts...
    finding bors merge commits
    found 10 bors merge commits in the specified range
      commit[0] 2021-07-18UTC: Auto merge of #86950 - tmiasko:personality, r=nagisa
      commit[1] 2021-07-18UTC: Auto merge of #87004 - JamieCunliffe:pgo-gc-sections, r=Mark-Simulacrum      
      commit[2] 2021-07-19UTC: Auto merge of #86848 - notriddle:notriddle/drop-dyn, r=varkor
      commit[3] 2021-07-19UTC: Auto merge of #87146 - Aaron1011:better-macro-lint, r=petrochenkov
      commit[4] 2021-07-19UTC: Auto merge of #87196 - oxalica:option-insert-must-use, r=joshtriplett        
      commit[5] 2021-07-19UTC: Auto merge of #87269 - GuillaumeGomez:rollup-qukedv0, r=GuillaumeGomez       
      commit[6] 2021-07-19UTC: Auto merge of #86970 - inquisitivecrystal:force-warn, r=davidtwco
      commit[7] 2021-07-19UTC: Auto merge of #87271 - flip1995:clippyup, r=Manishearth
      commit[8] 2021-07-19UTC: Auto merge of #87225 - estebank:cleanup, r=oli-obk
      commit[9] 2021-07-19UTC: Auto merge of #87153 - michaelwoerister:debuginfo-names-dyn-trait-projection-bounds, r=wesleywiser
    ERROR: no CI builds available between 59216858a323978a97593cba22b5ed84350a3783 and 014026d1a7ca991f82f12efa95ef4dffb29dc8af within last 167 days
    
  17. Patrick-Poitras commented on Jan 7, 2022

    @Patrick-Poitras
    Contributor

    I think its #87153, it has a provision that changed the generation of MSVC-only debug information. I'm going to confirm manually.

    Tagging @michaelwoerister, who might have some input on how to remedy this.

  18. Alexendoo commented on Mar 19, 2022

    @Alexendoo
    Member

    No longer ICEs since #95020

  19. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Mar 19, 2022
  20. michaelwoerister commented on Mar 21, 2022

    @michaelwoerister
    Member

    Hi, sorry, this somehow slipped through the cracks. Yes, #95020 should be the proper fix here. The test case there should be pretty much equivalent to the one listed in #92537 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️O-windowsOperating system: WindowsO-windows-msvcToolchain: MSVC, Operating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions