News for hackers. Stuff that matters.
Re:Solving the ABA Problem in Rust with Tagged Pointers by wyager on Friday February 14, 2025 @02:40PM (#43052197)
> Rust has approximately 1.5 advantages over C/C++

I can think of at least 3 that deserve a whole integral bullet point:

* ADTs

* Hindley-Milner/typeclass type system

* Lifetimes and affine types

And a bunch of minor ones that count for something like 0.1-0.5 of an advantage.

I would guess we're on track for a majority-of-new-code switchover point somewhere around 2030-2035.

Re:Solving the ABA Problem in Rust with Tagged Pointers by milesrout on Friday February 14, 2025 @05:56PM (#43053979)
Maybe he meant net advantages. Rust has some advantages (ADTs, no constructors, no overloading, no preprocessor, well thought out set of string types) and some disadvantages (compile times, debug performance, heaps of wrapper cruft to step through when debugging, explicit lifetimes, pervasive type inference, ad-hoc polymorphism, no ABI stability, poor support for dynamic linking, anemic standard library, pervasive one-element-thinking encouraging millions of separate allocations all over the place, culture of simplifying code by adding copying and reallocation everywhere because the borrow checker makes sharing verbose and difficult ("just use clone"), general complexity, dramatic and dogmatic community with a penchant for social media bullying (eg serde, actix)).

What is an advantage or a disadvantage depends on who you are. Personally, I find the disadvantages (as I see them) outweigh the advantages. Others believe that some of those disadvantages are actually good things. And some of them depend on whether you are comparing to C or C++: compared to C, Rust has many disadvantages, but C++ has many of the same disadvantages, and often is worse.

I don't think Rust will ever have more new code being written in it than C and C++ combined. I doubt it will overtake either individually.

Re:Solving the ABA Problem in Rust with Tagged Pointers by amluto on Friday February 14, 2025 @08:08PM (#43054822)
> compile times

C++, especially “modern” C++, can have truly horrible compile times. The lack of a usable module system makes it worse.

Variadic templates helped some. Fold expressions will help some. I expect concepts and if constexpr and such to help some: relying on SFINAE never did the compiler any favors.

But, in general, C++ template programming is quite nasty for compile times.

Re:Solving the ABA Problem in Rust with Tagged Pointers by milesrout on Saturday February 15, 2025 @12:30AM (#43056137)
Yes as I said "And some of them depend on whether you are comparing to C or C++: compared to C, Rust has many disadvantages, but C++ has many of the same disadvantages, and often is worse."

C++ compile times can be as bad as Rust's or worse. It does depend on how you structure things and how much you use templates. You don't need to have 10 layers of "zero cost abstraction" around everything. But that is the "proper" way to use it and what is now taught, so there is a lot of it out there and the standard library does it pervasively.

Variadic templates don't fix much compared to just writing straight line code or doing a tiny bit more work at runtime using stdarg.h.

Re:Solving the ABA Problem in Rust with Tagged Pointers by amluto on Saturday February 15, 2025 @10:07AM (#43059002)
Variadic templates help quite a lot compared to what older libraries did or even still do to approximate them. Check out boost::variant’s shenanigans — I recall a single-line file that includes <boost/variant.hpp> and doesn’t even instantiate the variant template taking several seconds to compile.
Re:Solving the ABA Problem in Rust with Tagged Pointers by kobebrookskC3 on Friday February 14, 2025 @09:00PM (#43055125)
all those advantages and disadvantages you list are basically insignificant compared to rust being memory safe by default and c/c++ not. governments aren't bugging projects about any of those, but are about memory safety.
Re:Solving the ABA Problem in Rust with Tagged Pointers by milesrout on Saturday February 15, 2025 @12:33AM (#43056147)
You might think so. I strongly disagree. I think Rust's supposed memory safety advantages are a distraction. If people really cared about that above all else they would use a memory-safe language, which Rust is not, such as Java or Python or Haskell or something. There are tons.

Governments aren't "bugging" anyone about memory safety and if they were, they wouldn't want you to use Rust. Rust isn't memory-safe.

Re:Solving the ABA Problem in Rust with Tagged Pointers by kobebrookskC3 on Saturday February 15, 2025 @02:41AM (#43056674)
> If people really cared about that above all else they would use a memory-safe language, which Rust is not, such as Java or Python or Haskell or something.

people already use languages like java or python or js in most cases! it's only in rare cases it made sense to write stuff in c or c++. now with rust, that niche becomes even smaller.

> Governments aren't "bugging" anyone about memory safety

idk this report sounds like bugging from governments (plural) to me: https://www.cisa.gov/sites/default/files/2023-12/The-Case-fo...

no one who isn't being obtuse would say rust isn't memory safe. the linked report also deems rust a memory safe language.

Re:Solving the ABA Problem in Rust with Tagged Pointers by oneshtein on Saturday February 15, 2025 @01:23AM (#43056376)
Safe Rust is memory-safe enough for practical needs, while maintaining top performance.
Re:Solving the ABA Problem in Rust with Tagged Pointers by menaerus on Saturday February 15, 2025 @02:47AM (#43056700)
Is it still safe even if it depends on the dependencies which are not safe?
Re:Solving the ABA Problem in Rust with Tagged Pointers by kobebrookskC3 on Saturday February 15, 2025 @03:16AM (#43056836)
Re:Solving the ABA Problem in Rust with Tagged Pointers by menaerus on Saturday February 15, 2025 @05:15AM (#43057412)
I know it's an unpopular opinion but tbh those Google security blogs always read more as a marketing material than engineering effort. Why I think so it's because statistics always has two side of the coins - if you want to make something look better or worse than it really is, it's trivial to do so. There's simply not enough data or methodology or different angles taken for me personally to take these blogs as a very relevant source of information but YMMV. We are all different.
Re:Solving the ABA Problem in Rust with Tagged Pointers by whytevuhuni on Saturday February 15, 2025 @05:39AM (#43057524)
Note that memory-safe languages like Java and Python will also depend on libraries which are not safe, e.g. in their implementation of the interpreter/VM, standard library, native libraries like numpy, etc.

In practice unsafe Rust tends to be less than 1% of the code (or around 5% in low-level things like kernels), which is a similar ratio of trusted/untrusted code. The top-level application code is generally expected to have 0%.

Re:Solving the ABA Problem in Rust with Tagged Pointers by milesrout on Saturday February 15, 2025 @06:45AM (#43057819)
This statistic is based on the lines of code bounded by the "unsafe" keyword but that is not the full picture. Unsafe code relies for its safety on the logical correctness of safe code. In theory, as "proper practice", the trust boundary should be the crate. In other words, the safety of a particular "unsafe" block should be verifiable by checking the correctness of code within the same crate. In practice, this is not true: much unsafe code relies for safety on correctness properties in external code, especially from the standard library, like the fact that "Vec" stores elements contiguously in memory in order of index.

That isn't to say the concept is useless. But it is not the case that you just need to inspect code marked "unsafe". A change to code not marked "unsafe" can break the invariants and assumptions that unsafe blocks elsewhere rely on.

Re:Solving the ABA Problem in Rust with Tagged Pointers by whytevuhuni on Saturday February 15, 2025 @08:40AM (#43058398)
That's right, unsafety extends to the whole module, and anything else that relies on the module's internal implementation. Generally all the way up to the abstraction's public API, whatever that abstraction is (a Vec, a Mutex, etc).

But it's nevertheless still not different from other languages that are deemed memory safe.

Re:Solving the ABA Problem in Rust with Tagged Pointers by kobebrookskC3 on Saturday February 15, 2025 @07:23PM (#43063984)
modules are meant to be the boundary for a safe abstraction, but sometimes you get fun holes like https://github.com/rust-lang/rust/issues/128872 where you can implement Copy for a type in a different module in the same crate, even if the fields are private
Re:Solving the ABA Problem in Rust with Tagged Pointers by whytevuhuni on Sunday February 16, 2025 @02:28AM (#43066118)
I'll admit, that's a pretty funny bug. Thankfully it seems like the Rust devs are pretty keen on fixing it somehow.
Re:Solving the ABA Problem in Rust with Tagged Pointers by damon_dam on Saturday February 15, 2025 @08:55AM (#43058493)
Agreed. I would add to your argument as follows.

If you stick with "21st Century C++" [1], you never have to use a pointer. At some point, there will be (say) a -W20 flag that produces a warning if you use a pointer or other potentially-unsafe idiom without marking it with a [[20th_century]] attribute.

That attribute is equivalent to Rust's unsafe keyword. At that point, the safety difference will boil down to opt-in versus opt-out. But you can already opt-in today by policing yourself.

That's quite far from the radical language difference it's made out to be.

[1] https://news.ycombinator.com/item?id=42946321

Re:Solving the ABA Problem in Rust with Tagged Pointers by whytevuhuni on Saturday February 15, 2025 @11:50AM (#43059952)
I've used both, and I'd say it's still quite a difference.

There's many examples, but one I stumble on often is functions that accept a std::string_view, and return a part of that string. It's quite dangerous to make it return a std::string_view as well, especially given how easy it is to create temporaries (e.g. get_word(sentence1 + sentence2) would return a string_view to temporary data). Similar story with functions that return element references out of collections, functions that choose an element out of two, etc.

In Rust on the other hand, you can get very reckless with very long chains of functions that return references out of other references, especially with parsers, iterators, and lambdas/closures.

The Send/Sync traits for thread safety are also unmatched in C++, tagged union pattern matching will also heavily restrict invalid states, and so will Rust's affine(ish) types, which force a single owner for resources, as opposed to C++'s somewhat hard-to-use move semantics.

The standard library also prefers safety over speed by default, e.g. with std::string_view's indexing being UB, std::optional's dereference being UB, and so on.

Re:Solving the ABA Problem in Rust with Tagged Pointers by damon_dam on Saturday February 15, 2025 @01:00PM (#43060572)
I don't really disagree with what you wrote. To expand upon my argument, the issues you mention can also be self-policed, or maybe enforced with higher safety levels of the presumptive -W20 switch:

- No reference variables in user code (reference parameters are OK.)

- Any classes that hold reference member variables can only be instantiated on the stack. The objects the references refer to must either be stack objects or reference parameters to the instantiating function.

- For durable links to sub-objects, use handles (tuples of std::shared_ptr to the main object plus a sub-object link or identifier.)

- Alternatively, require externally-accessible sub-objects to be held in shared_ptr's by the main object. They can then have superset lifetimes when needed.

I'll stick to the memory safety topic, but similar solutions exist for some of the other topics you mention, e.g. by avoiding std::optional.

Re:Solving the ABA Problem in Rust with Tagged Pointers by oneshtein on Saturday February 15, 2025 @06:21AM (#43057713)
Any and all safe code depends on unsafe code to do something, including Java and Python. Yep, unsafe code may contains bugs, but their surface is much smaller, so, at same ratio of bugs to code, numbers of bugs is much smaller.
Re:Solving the ABA Problem in Rust with Tagged Pointers by menaerus on Sunday February 16, 2025 @08:49AM (#43067947)
If you're open to a bit different and perhaps thought provoking perspective let me say that for your hypothesis to be true we would need to assume that the distribution of memory-safety bugs is uniform across the codebase. From my experience this is not true, it usually follows uni-modal or at most bi-modal distribution, so it follows that the surface is not much smaller.
Re:Solving the ABA Problem in Rust with Tagged Pointers by robocat on Friday February 14, 2025 @08:20PM (#43054900)
Would C, could C, implement those features?
Re:Solving the ABA Problem in Rust with Tagged Pointers by oneshtein on Saturday February 15, 2025 @12:23AM (#43056118)
* unsafe blocks for unsafe code

* Memory safety in safe code

* Fearless concurrency.

* match operator and destructuring