slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 565 forks source link

What do do when having division by zero in slint code #3982

Open qarmin opened 10 months ago

qarmin commented 10 months ago

The current situation is not well defined. We sometimes get crashes/panic at runtime, or NaN where we might not expect them. What should we do instead?

Original report (but compilation problem was fixed)

Slint 1.3.0, Slint LSP nightly

in-out property <int> aa: 2 / 0;

works fine in lsp, but fails to compile

error: failed to run custom build command for `krokiet v6.1.0 (/home/rafal/Projekty/Rust/czkawka/krokiet)`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `/home/rafal/Projekty/Rust/czkawka/target/debug/build/krokiet-24d92d05e8b2bf86/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at /home/rafal/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.69/src/lib.rs:1159:9:
  assertion failed: f.is_finite()
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/std/src/panicking.rs:645:5
     1: core::panicking::panic_fmt
               at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/core/src/panicking.rs:72:14
     2: core::panicking::panic
               at /rustc/6b771f6b5a6c8b03b6322a9c77ac77cb346148f0/library/core/src/panicking.rs:127:5
     3: proc_macro2::Literal::f64_suffixed
     4: <f64 as quote::to_tokens::ToTokens>::to_tokens
     5: i_slint_compiler::generator::rust::compile_expression
     6: i_slint_compiler::generator::rust::compile_expression
     7: i_slint_compiler::generator::rust::handle_property_init
     8: i_slint_compiler::generator::rust::generate_sub_component
     9: i_slint_compiler::generator::rust::generate_item_tree
    10: i_slint_compiler::generator::rust::generate_public_component
    11: i_slint_compiler::generator::rust::generate
    12: slint_build::compile_with_config
    13: build_script_build::main
    14: core::ops::function::FnOnce::call_once
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
ogoffart commented 10 months ago

Thanks for the bug report.

I could also reproduce it in C++, where our codegen generates +inf which is not a valid number literal in C++.

Also in C++, if the division by zero happens at runtime on integer, we get a crash. (crash don't happen in rust or interpreter)

tronical commented 9 months ago

What's left for this issue to be done? Should we detect division by zero at run-time in C++? (My feeling is no, but happy to discuss of course)

ogoffart commented 9 months ago

I think we should do something about it.