Closed JoschuaL closed 2 years ago
It looks like Rust merges the two Atoms together when they're unused. This causes issues with down casting and TypeIds.
Instead of panicking here, we should combine the typeid of the pointer to use as the hash, so these collisions can't occur even in apps that don't use various atoms.
If you change the contents of either vet or actually use them in your app, Rust won't merge them together.
Edit: I put up a branch that fixes this issue by making the AtomId hold the typeid to prevent this bug.
Thank you so much for the repro - it made it super easy to fix.
If you want to ride on master until this fix is merged, then you'll need to update your Cargo.toml and project.
dioxus = {git = "https://github.com/dioxuslabs/dioxus.git"}
dioxus-web = {git = "https://github.com/dioxuslabs/dioxus.git"}
fermi = { git = "https://github.com/dioxuslabs/dioxus.git"}
Let me know when the fix lands in something i could try out, because this also happens in a non-trivial context where im pretty sure im using all of the atoms. But there might also one im just overlooking, or the code using it might be unused or stuff like that.
sorry, pressed the wrong thing there
Problem
When compiling a simple programm using dioxus with fermi and the web feature enabled, using trunk, this error message appears and the application does not work properly as soon as the page is opened in a browser
Error Message
panicked at 'called `Result::unwrap()` on an `Err` value: Any { .. }', /home/misha/.cargo/registry/src/github.com-1ecc6299db9ec823/fermi-0.2.1/src/root.rs:47:43 Stack: getImports/imports.wbg.__wbg_new_693216e109162396@http://localhost:8080/frontend-a85016710e7cf20c.js:338:21 console_error_panic_hook::hook::hccdc65123d386add@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[223]:0x1fd63 core::ops::function::Fn::call::h03b5ba35aba6f2f3@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[1013]:0x3ab25 std::panicking::rust_panic_with_hook::h84feca33bd4bd229@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[418]:0x30cb3 std::panicking::begin_panic_handler::{{closure}}::hd2eacd3bb9ff1eab@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[493]:0x34113 std::sys_common::backtrace::__rust_end_short_backtrace::h976699518d897fb1@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[845]:0x3a2c6 rust_begin_unwind@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[687]:0x38a98 core::panicking::panic_fmt::hc171d095bc4a492d@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[689]:0x38b19 core::result::unwrap_failed::h68ab818eb89182b6@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[515]:0x34cdf fermi::root::AtomRoot::register::hf7d7317a0f91fa2a@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[210]:0x1dde5 fermi::hooks::read::use_read::hb21da33d9e04cfca@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[488]:0x33dfd frontend::Component::ha848ed4cf3cb4e81@http://localhost:8080/frontend-a85016710e7cf20c_bg.wasm:wasm-function[848]:0x3a2f8This only happens when rusts opt-level is set to 2 or 3 (either manually in cargo.toml or by doing a release build, which defaults to 3) On all other opt-levels, no error message appears and the application behaves as intended
Steps To Reproduce
I uploaded a minnimum Setup to trigger the error in this repo
Alternatively, the code in the main.rs is
And otherwise its just a minimal dioxus application for the web.
Of note, the error can be avoided by removing either of the use_read use_read expressions, changing the type in other atom to a numeric type (i64), the type in ATOM to some simple type like string, removing the field x of struct S or changing its type to a numeric type.
So overall very peculiar.
It could also be that this is in fact not a bug in dioxus but a bug in the rust compiler/optimizer/wasm toolchain, though i think that that is less likely than a dioxus bug.
Expected behavior
The behavior for any opt-level is the same, the application works without an error message
Screenshots
Environment: