GithubHelp home page GithubHelp logo

Comments (7)

CosmicHorrorDev avatar CosmicHorrorDev commented on August 18, 2024 1

Looks like you can. I opened #42

from thunderdome.

CosmicHorrorDev avatar CosmicHorrorDev commented on August 18, 2024 1

Went ahead and pushed changes to consolidate a lot of the branches

from thunderdome.

LPGhatguy avatar LPGhatguy commented on August 18, 2024

Hey, thanks for checking this out! MIRI is serious business, we should fix these issues and add it to our CI pipeline.

from thunderdome.

parasyte avatar parasyte commented on August 18, 2024

Similar to orlp/slotmap#92 (comment), using MIRIFLAGS='-Zmiri-tree-borrows' does not report any issues!

from thunderdome.

CosmicHorrorDev avatar CosmicHorrorDev commented on August 18, 2024

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.

LPGhatguy avatar LPGhatguy commented on August 18, 2024

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.

CosmicHorrorDev avatar CosmicHorrorDev commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.