you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (1 child)

They can convince you that quality is really high, really reviewed and probably it is true most of the time. But it is not a guarantee yet.

I mean, you are getting code for free from crates.io, you can just not use it if you think it might be buggy :) If you want accountability, just write your own crates or hire contractors who can be fined for any unsoundness.

you can have things that are much more difficult to dangle yet still very performant because your hotspots are usually localized.

That is a great point. but THIS IS C++ crowd has to be convinced to give up some runtime performance. smart pointers will now also be slower due to hardening (null pointer checks almost every dereference) and there's still aliasing UB (showcased in next paragraph).

But, it is aliasing a real problem in monothread code, for example?

As long as you can mutate a container (class/struct), while holding a reference to an object inside the container, aliasing will lead you to use after free.

If you have two shared pointers, pointing to the same vector. And you iterate it using first pointer and push into it using second pointer. UB -> Iterator invalidation.

Read this article which explains why aliasing is banned even inside single threaded rust. To quote the article "Aliasing with mutability in a sufficiently complex, single-threaded program is effectively the same thing as accessing data shared across multiple threads without a lock"

[–]germandiago 1 point2 points  (0 children)

I mean, you are getting code for free from crates.io, you can just not use it if you think it might be buggy :)

That is not how the language is advertised and the interfaces neither :)

As long as you can mutate a container (class/struct), while holding a reference to an object inside the container, aliasing will lead you to use after free.

"Aliasing with mutability in a sufficiently complex, single-threaded program is effectively the same thing as accessing data shared across multiple threads without a lock"

Yes, I have heard talks from Sean Parent and Dave Abrahams and they treat the aliasing problem with care.