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

world::World doctests sometimes hangs with Miri #5164

Closed
RalfJung opened this issue Jul 1, 2022 · 5 comments · Fixed by smol-rs/concurrent-queue#16
Closed

world::World doctests sometimes hangs with Miri #5164

RalfJung opened this issue Jul 1, 2022 · 5 comments · Fixed by smol-rs/concurrent-queue#16
Labels
A-Build-System Related to build systems or continuous integration A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior

Comments

@RalfJung
Copy link
Contributor

RalfJung commented Jul 1, 2022

When running the world::World (line 56) doctest in Miri with many different seeds, it eventually runs into an endless loop. This can be avoided by using -Zmiri-disable-weak-memory-emulation. This probably indicates a bug in bevy or its dependencies, but could also be a bug in Miri.

Weak memory emulation makes it so that an atomic load can return "outdated" values, as is permitted by the concurrent memory model of Rust (and C/C++). So likely, some code somewhere reads an old value, thinks it is current, and goes into some kind of spin loop -- and stays there forever.

See here for further analysis by @cbeuw.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events A-Build-System Related to build systems or continuous integration C-Bug An unexpected or incorrect behavior and removed A-Build-System Related to build systems or continuous integration labels Jul 1, 2022
@LegNeato
Copy link
Contributor

Possibly relevant: https://github.com/kanidm/concread

@RalfJung
Copy link
Contributor Author

RalfJung commented Jul 26, 2022

The fact that they advise to disable Stacked Borrows does not inspire a ton of confidence though. ;)

FWIW, latest Miri has -Zmiri-track-weak-memory-loads, which should help diagnose this issue. But OTOH @cbeuw pretty much figured it out already I think; someone probably needs to go fix smol-rs/concurrent-queue.

@RalfJung
Copy link
Contributor Author

Ah looks like this is tracked in concurrent-queue: smol-rs/concurrent-queue#17

@taiki-e
Copy link

taiki-e commented Jul 27, 2022

The problem in concurrent-queue that we agreed on is that it was using x86-specific fences that Miri does not understand. This has been fixed in concurrent-queue 1.2.4 (smol-rs/concurrent-queue@d61005f).

@RalfJung
Copy link
Contributor Author

RalfJung commented Jul 30, 2022

that Miri does not understand

To be more precise, using those fences is just wrong when writing Rust code, and Miri understands and detects that correctly. They can only be used correctly when writing inline assembly.

inodentry pushed a commit to IyesGames/bevy that referenced this issue Aug 8, 2022
# Objective

- Fixes bevyengine#5164
- Remove `miri-disable-weak-memory-emulation`
- Issue has been fixed in dependency
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
# Objective

- Fixes bevyengine#5164
- Remove `miri-disable-weak-memory-emulation`
- Issue has been fixed in dependency
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

- Fixes bevyengine#5164
- Remove `miri-disable-weak-memory-emulation`
- Issue has been fixed in dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Build-System Related to build systems or continuous integration A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior
Projects
None yet
4 participants