r/linux • • Aug 29 '24

Kernel One Of The Rust Linux Kernel Maintainers Steps Down - Cites "Nontechnical Nonsense"

https://www.phoronix.com/news/Rust-Linux-Maintainer-Step-Down
1.1k Upvotes

794 comments sorted by

View all comments

Show parent comments

1

u/erichkeane Aug 29 '24

I really don't have those problems at all. I'm currently a maintainer on the Clang project, so that is where I spend most of my time these days, but I did a networking framework and networking software before that. 

Pointer/iterator invalidation is just something I haven't had a problem with in a very long time. Thanks to RAII, I have little/no interaction with pointers mixing with ownership semantics, and iterator invalidation is something that is pretty trivial to avoid.

As far as the RAII model, it isn't the model itself, it was that the inconsistent use of 'drop' in libraries/other people's code(admittedly, about 10 years ago now) meant I couldn't mentally count on destructors doing cleanup.

When writing C++ code, all libraries are expected to do their own clean up(to the point the community would consider it a "bad" library otherwise), so I was mentally able to count on it.

As far as destructive move, it is a good idea too! I expect C++ to have it in the next release or two, we have two competing proposals, one of which has really solid design, that are likely to be decided on/put into the standard soon.

1

u/cmrschwarz Aug 29 '24

Interesting. Thank you for your work on clang, awesome software! I currently work on database OLAP / concurrent data transformation stuff so this might just be my domain bias.

C++ APIs always feel a bit brittle to me because the responsibility of cleanup is essentially ruled through code comments. Hearing you say that you are perfectly fine with this because the ecosystem has essentially reached the consensus that libraries ought to free by themselves is a new perspective for me.

I guess this depends on the domain though, as C++ is a large ecosystem. Most GPU / graphics APIs seem to use the opposite model for example. (Nvidia's CUB even has you ask it for how much temporary storage space it needs and then expects you to manage that for it).

I guess the LLVM/MLIR APIs themselves are an example of why I dislike these non enforced contracts. Reading through the heavily templated code in order to fully understand the ownership model of stuff like LLVMValue / ArrayRef / etc. was quite exhausting to me. But when allocating random stuff I at least want to roughly understand how it is being managed / how long it will live.

In Rust on the other hand every function signature tells you exactly how long stuff lives and who is responsible, and the compiler catches you if you get it wrong. Non lexical lifetimes (2018) have also solved most of the pain associated with using these kinds of apis.

It's true that this leads to more libraries leaving ownership up to the user of the API, but I personally find that a good thing for performance reasons because it allows me to stick data into collections instead of having libraries heap allocate individual nodes. The consumer of an API will usually have more context, allowing them to use a more efficient solution.

1

u/erichkeane Aug 29 '24

Typically c++ libraries do a good job of making it clear via interface who owns the memory. That said, we have a lot of C libraries that dona bad job of that.

For libraries that want you to manage memory, I vastly prefer when they provide/use scope based objects to manage that for you. Even a unique_ptr with custom deleter. It is very rare for me to want memory allocated to not have a scope that properly owns it.

I will say that I appreciate the Rush expressivity in this regard, but isn't something Ive ever wanted/missed in C++.

As far as the LLVM types, comments/names should be sufficient to understand ownership, but it does so by convention, which, among other things raises the learning curve(which is absolutely a weakness of C++).

2

u/cmrschwarz Aug 29 '24

I mostly agree. I just really strongly prefer compiler errors over conventions.

There's significantly more joy for me when programming in Rust, because the compiler watches out for me, so I don't have to be as vigilant. Especially during large refactorings where I might not fully understand the context of the piece of code I'm editing, the compiler will pay attention to the defails for me. It almost feels like a free code review / pair programming.

This is of course a very subjective/anecdotal argument, so I won't claim to be 'right' there.

Thank you for the very insightful discussion.

1

u/erichkeane Aug 29 '24

I tend to err that way as well, I prefer a strong type system and a compiler that can catch as much as possible. In my experience, the C++ compilers with warnings can and do catch a vast majority of the issues, and most of the ones we can't catch are a result of what we inherited from C (and, besides everything having to do with templates), most of the valid criticisms are a result of that.

I'm happy that there is a language that is doing quite successfully in the space that doesn't HAVE to deal with those problems and can make better decisions informed by previous languages. I'm not a fan of the Rust syntax (perhaps just familiarity), and have concerns on some of what the Rust language makes the compiler do (and how that scales, and how it'll limit design in the future), but I definitely enjoy seeing the language succeed.

Anyway, I appreciate the discussion as well!