From 0d95568972260b69cefb31ffa14ba10434faeba6 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 30 Dec 2022 14:34:44 -0500 Subject: [PATCH 1/7] chore: add miri and windows test --- .github/workflows/miri.yml | 72 ++++++++++++++++++++++++++++ packages/core/tests/miri_stress.rs | 77 ++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 .github/workflows/miri.yml diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml new file mode 100644 index 000000000..d1bba9964 --- /dev/null +++ b/.github/workflows/miri.yml @@ -0,0 +1,72 @@ +name: CI + +on: + push: + # Run in PRs and for bors, but not on master. + branches: + - 'auto' + - 'try' + pull_request: + branches: + - 'master' + schedule: + - cron: '6 6 * * *' # At 6:06 UTC every day. + +env: + CARGO_UNSTABLE_SPARSE_REGISTRY: 'true' + +jobs: + build: + runs-on: ${{ matrix.os }} + env: + RUST_BACKTRACE: 1 + HOST_TARGET: ${{ matrix.host_target }} + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + host_target: i686-pc-windows-msvc + steps: + - uses: actions/checkout@v3 + + # Cache the global cargo directory, but NOT the local `target` directory which + # we cannot reuse anyway when the nightly changes (and it grows quite large + # over time). + - name: Add cache for cargo + id: cache + uses: actions/cache@v3 + with: + path: | + # Taken from . + ~/.cargo/bin + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git/db + # contains package information of crates installed via `cargo install`. + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo + + - name: Install rustup-toolchain-install-master + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + shell: bash + run: | + cargo install -f rustup-toolchain-install-master + - name: Install "master" toolchain + shell: bash + run: | + if [[ ${{ github.event_name }} == 'schedule' ]]; then + echo "Building against latest rustc git version" + git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version + fi + ./miri toolchain --host ${{ matrix.host_target }} + - name: Show Rust version + run: | + rustup show + rustc -Vv + cargo -V + - name: Test + run: | + MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-core --test miri_stress -- --exact --nocapture diff --git a/packages/core/tests/miri_stress.rs b/packages/core/tests/miri_stress.rs index 160baa25d..5ceb8d528 100644 --- a/packages/core/tests/miri_stress.rs +++ b/packages/core/tests/miri_stress.rs @@ -137,6 +137,83 @@ fn free_works_on_root_hooks() { assert_eq!(Rc::strong_count(&ptr), 1); } +#[test] +fn supports_async() { + use std::time::Duration; + use tokio::time::sleep; + + fn app(cx: Scope) -> Element { + let colors = use_state(&cx, || vec!["green", "blue", "red"]); + let padding = use_state(&cx, || 10); + + use_effect(&cx, colors, |colors| async move { + sleep(Duration::from_millis(1000)).await; + colors.with_mut(|colors| colors.reverse()); + }); + + use_effect(&cx, padding, |padding| async move { + sleep(Duration::from_millis(10)).await; + padding.with_mut(|padding| { + if *padding < 65 { + *padding += 1; + } else { + *padding = 5; + } + }); + }); + + let big = colors[0]; + let mid = colors[1]; + let small = colors[2]; + + cx.render(rsx! { + div { + background: "{big}", + height: "stretch", + width: "stretch", + padding: "50", + label { + "hello", + } + div { + background: "{mid}", + height: "auto", + width: "stretch", + padding: "{padding}", + label { + "World", + } + div { + background: "{small}", + height: "auto", + width: "stretch", + padding: "20", + label { + "ddddddd", + } + } + }, + } + }) + } + + let rt = tokio::runtime::Builder::new_current_thread() + .enable_time() + .build() + .unwrap(); + + rt.block_on(async { + let mut dom = VirtualDom::new(app); + let _ = dom.rebuild(); + + for x in 0..10 { + let _ = dom.wait_for_work().await; + let edits = dom.render_immediate(); + dbg!(edits); + } + }); +} + // #[test] // fn old_props_arent_stale() { // fn app(cx: Scope) -> Element { From b351345db932eef28263e95463b68ad35e9cb94a Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 30 Dec 2022 14:45:45 -0500 Subject: [PATCH 2/7] chore: use miri on native-core too --- .github/workflows/miri.yml | 21 +++- packages/native-core/Cargo.toml | 4 +- packages/native-core/tests/miri_native.rs | 146 ++++++++++++++++++++++ 3 files changed, 167 insertions(+), 4 deletions(-) create mode 100644 packages/native-core/tests/miri_native.rs diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml index d1bba9964..ac6482b29 100644 --- a/.github/workflows/miri.yml +++ b/.github/workflows/miri.yml @@ -1,4 +1,4 @@ -name: CI +name: Miri Tests on: push: @@ -25,11 +25,25 @@ jobs: fail-fast: false matrix: include: - - os: windows-latest - host_target: i686-pc-windows-msvc + - os: ubuntu-latest + host_target: x86_64-unknown-linux-gnu + # - os: macos-latest + # host_target: x86_64-apple-darwin + # - os: windows-latest + # host_target: i686-pc-windows-msvc + # - os: windows-latest + # host_target: i686-pc-windows-msvc + # - os: windows-latest + # host_target: i686-pc-windows-msvc + # - os: windows-latest + # host_target: i686-pc-windows-msvc steps: - uses: actions/checkout@v3 + - name: Set the tag GC interval to 1 on linux + if: runner.os == 'Linux' + run: echo "MIRIFLAGS=-Zmiri-tag-gc=1" >> $GITHUB_ENV + # Cache the global cargo directory, but NOT the local `target` directory which # we cannot reuse anyway when the nightly changes (and it grows quite large # over time). @@ -70,3 +84,4 @@ jobs: - name: Test run: | MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-core --test miri_stress -- --exact --nocapture + MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-native-core --test miri_native -- --exact --nocapture diff --git a/packages/native-core/Cargo.toml b/packages/native-core/Cargo.toml index 309fba781..2c09ecf4c 100644 --- a/packages/native-core/Cargo.toml +++ b/packages/native-core/Cargo.toml @@ -26,4 +26,6 @@ dashmap = "5.4.0" [dev-dependencies] rand = "0.8.5" -dioxus = { path = "../dioxus", version = "^0.2.1" } \ No newline at end of file +dioxus = { path = "../dioxus", version = "^0.2.1" } +dioxus-native-core-macro = { path = "../native-core-macro" } +tokio = { version = "*", features = ["full"] } diff --git a/packages/native-core/tests/miri_native.rs b/packages/native-core/tests/miri_native.rs new file mode 100644 index 000000000..5823fb5a1 --- /dev/null +++ b/packages/native-core/tests/miri_native.rs @@ -0,0 +1,146 @@ +use dioxus::prelude::*; +use dioxus_native_core::*; +use dioxus_native_core::{ + node_ref::{AttributeMask, NodeView}, + real_dom::RealDom, + state::{ParentDepState, State}, + NodeMask, SendAnyMap, +}; +use dioxus_native_core_macro::{sorted_str_slice, State}; +use std::{ + sync::{Arc, Mutex}, + time::Duration, +}; +use tokio::time::sleep; + +#[derive(Debug, Clone, PartialEq, Default)] +pub struct BlablaState {} + +/// Font style are inherited by default if not specified otherwise by some of the supported attributes. +impl ParentDepState for BlablaState { + type Ctx = (); + type DepState = (Self,); + + const NODE_MASK: NodeMask = + NodeMask::new_with_attrs(AttributeMask::Static(&sorted_str_slice!(["blabla",]))); + + fn reduce<'a>( + &mut self, + _node: NodeView, + _parent: Option<(&'a Self,)>, + _ctx: &Self::Ctx, + ) -> bool { + false + } +} + +#[derive(Clone, State, Default, Debug)] +pub struct NodeState { + #[parent_dep_state(blabla)] + blabla: BlablaState, +} + +mod dioxus_elements { + macro_rules! builder_constructors { + ( + $( + $(#[$attr:meta])* + $name:ident { + $( + $(#[$attr_method:meta])* + $fil:ident: $vil:ident, + )* + }; + )* + ) => { + $( + #[allow(non_camel_case_types)] + $(#[$attr])* + pub struct $name; + + impl $name { + pub const TAG_NAME: &'static str = stringify!($name); + pub const NAME_SPACE: Option<&'static str> = None; + + $( + pub const $fil: (&'static str, Option<&'static str>, bool) = (stringify!($fil), None, false); + )* + } + + impl GlobalAttributes for $name {} + )* + } + } + + pub trait GlobalAttributes {} + + pub trait SvgAttributes {} + + builder_constructors! { + blabla { + + }; + } +} + +#[test] +fn native_core_is_okay() { + use std::time::Duration; + + fn app(cx: Scope) -> Element { + let colors = use_state(&cx, || vec!["green", "blue", "red"]); + let padding = use_state(&cx, || 10); + + use_effect(&cx, colors, |colors| async move { + sleep(Duration::from_millis(1000)).await; + colors.with_mut(|colors| colors.reverse()); + }); + + use_effect(&cx, padding, |padding| async move { + sleep(Duration::from_millis(10)).await; + padding.with_mut(|padding| { + if *padding < 65 { + *padding += 1; + } else { + *padding = 5; + } + }); + }); + + let big = colors[0]; + let mid = colors[1]; + let small = colors[2]; + + cx.render(rsx! { + blabla {} + }) + } + + let rt = tokio::runtime::Builder::new_current_thread() + .enable_time() + .build() + .unwrap(); + + rt.block_on(async { + let rdom = Arc::new(Mutex::new(RealDom::::new())); + let mut dom = VirtualDom::new(app); + + let muts = dom.rebuild(); + let (to_update, _diff) = rdom.lock().unwrap().apply_mutations(muts); + + let ctx = SendAnyMap::new(); + let ctx = SendAnyMap::new(); + rdom.lock().unwrap().update_state(to_update, ctx); + + for x in 0..10 { + dom.wait_for_work().await; + + let mutations = dom.render_immediate(); + let (to_update, _diff) = rdom.lock().unwrap().apply_mutations(mutations); + + let ctx = SendAnyMap::new(); + let ctx = SendAnyMap::new(); + rdom.lock().unwrap().update_state(to_update, ctx); + } + }); +} From 7a0c00ab6f45ec42e231522a795a715f3304b4d7 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 30 Dec 2022 14:47:06 -0500 Subject: [PATCH 3/7] fix: dont install master miri --- .github/workflows/miri.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml index ac6482b29..2c78bdcab 100644 --- a/.github/workflows/miri.yml +++ b/.github/workflows/miri.yml @@ -68,14 +68,14 @@ jobs: shell: bash run: | cargo install -f rustup-toolchain-install-master - - name: Install "master" toolchain - shell: bash - run: | - if [[ ${{ github.event_name }} == 'schedule' ]]; then - echo "Building against latest rustc git version" - git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version - fi - ./miri toolchain --host ${{ matrix.host_target }} + # - name: Install "master" toolchain + # shell: bash + # run: | + # if [[ ${{ github.event_name }} == 'schedule' ]]; then + # echo "Building against latest rustc git version" + # git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version + # fi + # toolchain --host ${{ matrix.host_target }} - name: Show Rust version run: | rustup show From 6cc4dac3a3e5851bfd98191e5192038f5ce877eb Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Tue, 10 Jan 2023 17:57:38 -0800 Subject: [PATCH 4/7] wip: use tokios runtime --- .github/workflows/miri.yml | 80 +++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml index 2c78bdcab..f40ed78f3 100644 --- a/.github/workflows/miri.yml +++ b/.github/workflows/miri.yml @@ -38,36 +38,54 @@ jobs: # - os: windows-latest # host_target: i686-pc-windows-msvc steps: - - uses: actions/checkout@v3 - - name: Set the tag GC interval to 1 on linux if: runner.os == 'Linux' run: echo "MIRIFLAGS=-Zmiri-tag-gc=1" >> $GITHUB_ENV + - uses: actions/checkout@v3 + - name: Install Rust ${{ env.rust_nightly }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.rust_nightly }} + components: miri + - uses: Swatinem/rust-cache@v2 + - name: miri + # Many of tests in tokio/tests and doctests use #[tokio::test] or + # #[tokio::main] that calls epoll_create1 that Miri does not support. + # run: cargo miri test --features full --lib --no-fail-fast + run: | + cargo miri test --package dioxus-core --test miri_stress -- --exact --nocapture + cargo miri test --package dioxus-native-core --test miri_native -- --exact --nocapture + + # working-directory: tokio + env: + MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields + PROPTEST_CASES: 10 + # Cache the global cargo directory, but NOT the local `target` directory which # we cannot reuse anyway when the nightly changes (and it grows quite large # over time). - - name: Add cache for cargo - id: cache - uses: actions/cache@v3 - with: - path: | - # Taken from . - ~/.cargo/bin - ~/.cargo/registry/index - ~/.cargo/registry/cache - ~/.cargo/git/db - # contains package information of crates installed via `cargo install`. - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo + # - name: Add cache for cargo + # id: cache + # uses: actions/cache@v3 + # with: + # path: | + # # Taken from . + # ~/.cargo/bin + # ~/.cargo/registry/index + # ~/.cargo/registry/cache + # ~/.cargo/git/db + # # contains package information of crates installed via `cargo install`. + # ~/.cargo/.crates.toml + # ~/.cargo/.crates2.json + # key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + # restore-keys: ${{ runner.os }}-cargo - - name: Install rustup-toolchain-install-master - if: ${{ steps.cache.outputs.cache-hit != 'true' }} - shell: bash - run: | - cargo install -f rustup-toolchain-install-master + # - name: Install rustup-toolchain-install-master + # if: ${{ steps.cache.outputs.cache-hit != 'true' }} + # shell: bash + # run: | + # cargo install -f rustup-toolchain-install-master # - name: Install "master" toolchain # shell: bash # run: | @@ -76,12 +94,12 @@ jobs: # git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version # fi # toolchain --host ${{ matrix.host_target }} - - name: Show Rust version - run: | - rustup show - rustc -Vv - cargo -V - - name: Test - run: | - MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-core --test miri_stress -- --exact --nocapture - MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-native-core --test miri_native -- --exact --nocapture + # - name: Show Rust version + # run: | + # rustup show + # rustc -Vv + # cargo -V + # - name: Test + # run: | + # MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-core --test miri_stress -- --exact --nocapture + # MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-native-core --test miri_native -- --exact --nocapture From 8df6be9508c43cd89eca2590a286591384f4a565 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Tue, 10 Jan 2023 18:01:52 -0800 Subject: [PATCH 5/7] wip: add more flags to env for CI --- .github/workflows/miri.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml index f40ed78f3..9ae294bed 100644 --- a/.github/workflows/miri.yml +++ b/.github/workflows/miri.yml @@ -14,9 +14,26 @@ on: env: CARGO_UNSTABLE_SPARSE_REGISTRY: 'true' + RUSTFLAGS: -Dwarnings + RUST_BACKTRACE: 1 + # Change to specific Rust release to pin + rust_stable: stable + rust_nightly: nightly-2022-11-03 + rust_clippy: 1.65.0 + # When updating this, also update: + # - README.md + # - tokio/README.md + # - CONTRIBUTING.md + # - tokio/Cargo.toml + # - tokio-util/Cargo.toml + # - tokio-test/Cargo.toml + # - tokio-stream/Cargo.toml + # rust_min: 1.49.0 + + jobs: - build: + test: runs-on: ${{ matrix.os }} env: RUST_BACKTRACE: 1 From 74af8f0f52ad17dcf1e75bf3bd3bb4bd0b136cbd Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Tue, 10 Jan 2023 18:05:48 -0800 Subject: [PATCH 6/7] chore: smallbox unused on miri ci --- packages/core/src/lazynodes.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/lazynodes.rs b/packages/core/src/lazynodes.rs index 2b7c4feb3..811dbb734 100644 --- a/packages/core/src/lazynodes.rs +++ b/packages/core/src/lazynodes.rs @@ -11,6 +11,7 @@ //! The logic for this was borrowed from . Unfortunately, this crate does not //! support non-static closures, so we've implemented the core logic of `ValueA` in this module. +#[allow(unused_imports)] use smallbox::{smallbox, space::S16, SmallBox}; use crate::{innerlude::VNode, ScopeState}; From 6d24fc3a6facca86272796b3b102ad4257bcb377 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Tue, 10 Jan 2023 18:08:41 -0800 Subject: [PATCH 7/7] ci: make CI pass for miri --- .github/workflows/miri.yml | 3 ++- packages/core/tests/miri_stress.rs | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml index 9ae294bed..8894dbace 100644 --- a/.github/workflows/miri.yml +++ b/.github/workflows/miri.yml @@ -76,7 +76,8 @@ jobs: # working-directory: tokio env: - MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields + # todo: disable memory leaks ignore + MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields -Zmiri-ignore-leaks PROPTEST_CASES: 10 # Cache the global cargo directory, but NOT the local `target` directory which diff --git a/packages/core/tests/miri_stress.rs b/packages/core/tests/miri_stress.rs index 5ceb8d528..c73847c19 100644 --- a/packages/core/tests/miri_stress.rs +++ b/packages/core/tests/miri_stress.rs @@ -209,7 +209,6 @@ fn supports_async() { for x in 0..10 { let _ = dom.wait_for_work().await; let edits = dom.render_immediate(); - dbg!(edits); } }); }