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

dioxus hello world example causes compiler panic on windows #92537

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

dioxus hello world example causes compiler panic on windows #92537

anderslanglands opened this issue Jan 3, 2022 · 17 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. E-needs-test Call for participation: Writing correctness tests. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-windows Operating system: Windows O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@anderslanglands
Copy link

anderslanglands commented Jan 3, 2022

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

@anderslanglands anderslanglands added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 3, 2022
@Patrick-Poitras
Copy link
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`

@cbeust
Copy link

cbeust commented Jan 3, 2022

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

@cbeust
Copy link

cbeust commented Jan 3, 2022

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

@Patrick-Poitras
Copy link
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.

@Patrick-Poitras
Copy link
Contributor

Patrick-Poitras commented Jan 4, 2022

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.

@Patrick-Poitras
Copy link
Contributor

Patrick-Poitras commented Jan 4, 2022

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.

@cbeust
Copy link

cbeust commented Jan 4, 2022

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

@anderslanglands
Copy link
Author

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

@Patrick-Poitras
Copy link
Contributor

Patrick-Poitras commented Jan 4, 2022

@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.

@Alexendoo Alexendoo added O-windows Operating system: Windows O-windows-msvc Toolchain: MSVC, Operating system: Windows labels Jan 4, 2022
@Alexendoo
Copy link
Member

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

@Alexendoo Alexendoo added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Jan 4, 2022
@Alexendoo
Copy link
Member

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

@Patrick-Poitras
Copy link
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.

@Patrick-Poitras
Copy link
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.

@Patrick-Poitras
Copy link
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

@Patrick-Poitras
Copy link
Contributor

Patrick-Poitras commented Jan 7, 2022

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.

@Alexendoo
Copy link
Member

No longer ICEs since #95020

@Alexendoo Alexendoo added the E-needs-test Call for participation: Writing correctness tests. label Mar 19, 2022
@michaelwoerister
Copy link
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
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. E-needs-test Call for participation: Writing correctness tests. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-windows Operating system: Windows O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants