Comments (7)
Looks like you can. I opened #42
from thunderdome.
Went ahead and pushed changes to consolidate a lot of the branches
from thunderdome.
Hey, thanks for checking this out! MIRI is serious business, we should fix these issues and add it to our CI pipeline.
from thunderdome.
Similar to orlp/slotmap#92 (comment), using MIRIFLAGS='-Zmiri-tree-borrows'
does not report any issues!
from thunderdome.
Noticed this because of the linked issue
It looks like this crate is very similar to slab
which implements .get2_mut()
by using .split_at_mut()
on the underlying Vec
to get two mutable slices that each contain one of the desired elements. Then you can call .get_mut()
on each of the slices to get a mutable reference
https://docs.rs/slab/latest/src/slab/lib.rs.html#751-773
Do you think the same technique would work here? It allows you to avoid using unsafe
from thunderdome.
Thanks for the investigation and PR!
In general, I'm happy to reduce unsafety in crates when there's an easy replacement. In this case though, I'm a little concerned — this safe alternative has a lot more code! It's hard to make sure that all of these branches are tested and work correctly when compared with the original code.
Based on orlp/slotmap#92 (comment), I'm not sure we should change the implementation of this method. It seems like there might be a compelling argument that MIRI is raising a false alarm here. I am not familiar enough with the current status of UB in Rust to know for sure.
from thunderdome.
The main part that has a lot of explicit branches is when the two indices occupy the same slot. I was mostly trying to avoid duplicate checks, but they could probably just use .get_mut()
and the compiler should be smart enough to remove the duplicate checks. That should reduce a lot of the near-duplicate logic
I was mostly just making this change to reduce unsafe usage, not because I'm worried about aliasing issues here (which the compiler doesn't have a firm stance on yet). slab
seems to be largely the same as this library aside from the generational indices and manages to avoid any unsafe aside from a couple of unsafe methods they expose for comparison
from thunderdome.
Related Issues (20)
- Add iter() and iter_mut() methods
- Benchmarks HOT 1
- no_std support
- Fuzzing HOT 1
- Release a new version HOT 1
- Update slotmap features HOT 1
- Index<T>? HOT 6
- Iterator API design HOT 2
- Arena::insert(impl Into<T>) HOT 1
- Add Arena::get2_mut(Index, Index) or similar methods HOT 1
- drain_filter HOT 2
- Exposing iterators via `iter` module HOT 4
- API for tree HOT 2
- `miri` test complains about `Arena::get2_mut` HOT 2
- `Index::from_bits` should return `Option<Index>`
- Serde Support
- Consider exposing generation HOT 2
- shrink_to_fit
- Clarify background / motivation for this crate HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thunderdome.