Skip to content

[Merged by Bors] - CI runs cargo miri test -p bevy_ecs - #4310

Closed
BoxyUwU wants to merge 11 commits into
bevyengine:mainfrom
BoxyUwU:bevy_ecs_miri
Closed

[Merged by Bors] - CI runs cargo miri test -p bevy_ecs#4310
BoxyUwU wants to merge 11 commits into
bevyengine:mainfrom
BoxyUwU:bevy_ecs_miri

Conversation

@BoxyUwU

@BoxyUwU BoxyUwU commented Mar 24, 2022

Copy link
Copy Markdown
Member

Objective

Fixes #1529
Run bevy_ecs in miri

Solution

@BoxyUwU BoxyUwU changed the title Run bevy_ecs in miri (wip) Run bevy_ecs in miri Mar 24, 2022
@github-actions github-actions Bot added the S-Needs-Triage This issue needs to be labelled label Mar 24, 2022
@BoxyUwU BoxyUwU changed the title (wip) Run bevy_ecs in miri CI runs cargo miri test -p bevy_ecs Mar 24, 2022
@BoxyUwU BoxyUwU added A-ECS Entities, components, systems, and events C-Dependencies A change to the crates that Bevy depends on and removed S-Needs-Triage This issue needs to be labelled labels Mar 24, 2022
@BoxyUwU
BoxyUwU requested a review from mockersf March 24, 2022 05:38
Comment thread .github/workflows/ci.yml
Comment thread crates/bevy_ecs/src/lib.rs Outdated
[dependencies]
futures-lite = "1.4.0"
event-listener = "2.4.0"
event-listener = "2.5.2"

@mockersf mockersf Mar 24, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependabot should have warned us of this one... 🤔

Comment thread crates/bevy_tasks/src/task_pool.rs Outdated
@mockersf

Copy link
Copy Markdown
Member

This adds 7 minutes to CI but is probably worth it

@alice-i-cecile

Copy link
Copy Markdown
Member

This adds 7 minutes to CI but is probably worth it

@mockersf down the line, can we change this to only run on PRs that modify bevy_ecs?

Also as someone prone to who touches code that could produce UB, I totally agree.

@mockersf

Copy link
Copy Markdown
Member

It should be added to Bors in https://github.com/bevyengine/bevy/blob/main/.github/bors.toml

@mockersf down the line, can we change this to only run on PRs that modify bevy_ecs?

Yes, but I'm not sure how Bors handles a job that only run on some of the PR...

BoxyUwU and others added 5 commits March 24, 2022 13:12
Co-authored-by: François <mockersf@gmail.com>
Co-authored-by: François <mockersf@gmail.com>
@BoxyUwU BoxyUwU closed this Mar 24, 2022
@BoxyUwU BoxyUwU reopened this Mar 24, 2022
Comment thread .github/workflows/ci.yml Outdated
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Mar 24, 2022
@cart

cart commented Mar 24, 2022

Copy link
Copy Markdown
Member

Can you push something that introduces UB so we can prove this will fail CI if we "regress"?

@cart

cart commented Mar 24, 2022

Copy link
Copy Markdown
Member

(or if you've already tested this case on CI, can you send me a link?)

Comment thread crates/bevy_tasks/src/task_pool.rs Outdated
@BoxyUwU

BoxyUwU commented Mar 25, 2022

Copy link
Copy Markdown
Member Author

@cart cart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant. LGTM!

@cart

cart commented Mar 25, 2022

Copy link
Copy Markdown
Member

bors r+

bors Bot pushed a commit that referenced this pull request Mar 25, 2022
# Objective

Fixes #1529
Run bevy_ecs in miri

## Solution

- Don't set thread names when running in miri rust-lang/miri/issues/1717
- Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5)
- Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481
- Make `table_add_remove_many` test less "many" because miri is really quite slow :)
- Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
@bors bors Bot changed the title CI runs cargo miri test -p bevy_ecs [Merged by Bors] - CI runs cargo miri test -p bevy_ecs Mar 25, 2022
@bors bors Bot closed this Mar 25, 2022
Comment thread .github/workflows/ci.yml
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to not cache ~/.cargo/{.crates2.json,.crates.toml} so I assume it will still rebuild xargo each time? I am not sure how caching works for GHA though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the list of paths to cache is from https://github.com/actions/cache/blob/main/examples.md#rust---cargo... maybe it's not complete?

aevyrie pushed a commit to aevyrie/bevy that referenced this pull request Jun 7, 2022
# Objective

Fixes bevyengine#1529
Run bevy_ecs in miri

## Solution

- Don't set thread names when running in miri rust-lang/miri/issues/1717
- Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5)
- Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481
- Make `table_add_remove_many` test less "many" because miri is really quite slow :)
- Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

Fixes bevyengine#1529
Run bevy_ecs in miri

## Solution

- Don't set thread names when running in miri rust-lang/miri/issues/1717
- Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5)
- Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481
- Make `table_add_remove_many` test less "many" because miri is really quite slow :)
- Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
salixsalicaceae pushed a commit to fslabs/bevy that referenced this pull request Mar 26, 2026
# Objective

Fixes bevyengine#1529
Run bevy_ecs in miri

## Solution

- Don't set thread names when running in miri rust-lang/miri/issues/1717
- Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5)
- Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481
- Make `table_add_remove_many` test less "many" because miri is really quite slow :)
- Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
pull Bot pushed a commit to CrazyForks/bevy that referenced this pull request Jul 14, 2026
# Objective

Make it possible to run miri with memory leak detection enabled. It is
enabled by default, so it reports errors whenever I run it locally. And
running it in CI should help prevent any new leaks from being
introduced.

See bevyengine#4310 and bevyengine#4959 for previous attempts to enable this. Note that miri
has added backtraces to leaked allocations since then
(rust-lang/rust#109061), so leaks are much
easier to diagnose.

## Solution

The first leak: When trying to drop non-send data on the wrong thread,
the allocation for the value was being leaked. We can't drop the value
from the wrong thread, but we could still deallocate its storage.

Rework the thread check in `NonSendData::drop` so that it still
deallocates, setting `present = false` to ensure the value's `drop` is
not called. Change the `panic!` to a `warn!` so that we can have the
check work the same way during unwinding.

The second leak: The tests for `Interned` intentionally leak data! So we
can't exactly "fix" them, but I'd like miri to stop failing on them.
Then I realized that miri does not report leaks for our use of
`Interned` for things like `ScheduleLabel`. That's because those values
are stored in a `static`, so are still reachable.

So, add a `static` to each of the tests with intentional leaks and store
the leaked values there. miri will consider those values reachable, and
not report any leaks.

---------

Co-authored-by: Daniel Skates <zeophlite@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Dependencies A change to the crates that Bevy depends on S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run bevy_ecs in miri on CI

6 participants