Linus Torvalds talks AI, Rust, & why Linux is the only thing that matters
zdnet.com
zdnet.com
Switching to a more modern topic, the introduction of the Rust language into Linux, Torvalds is disappointed that its adoption isn't going faster. "I was expecting updates to be faster, but part of the problem is that old-time kernel developers are used to C and don't know Rust. They're not exactly excited about having to learn a new language that is, in some respects, very different. So there's been some pushback on Rust." On top of that, Torvalds commented, "Another reason has been the Rust infrastructure itself has not been super stable."
AI
"When AI came in, it was wonderful, because Nvidia got much more involved in the kernel. Nvidia went from being on my list of companies who are not good to my list of companies who are doing really good work."
https://www.youtube.com/watch?t=1529&v=WiPp9YEBV0Q&feature=y...
The return type of that get_or_create_inode() function is:
Result<Either<ARef<INode<T>>, inode::New<T>>>
I'd say that's a pretty good example for 'hideous'. It looks like some of the worst C++ code I've seen and then quickly tried to forget. If stuff like this ends up in the Linux kernel I would be pissed too as a Linux kernel greybeard....if you know how to decode it. That example looks like one of those C++ SFINAE hacks, e.g. trying to bend the template/generics syntax beyond what it was designed for.
If Rust APIs want to go that way (of overly expressive strong typing) then Rust really should offer a better syntax for describing such types. But it's not even clear to me if such strongly typed APIs are even a good idea. From my experience in C++ and (especially) Typescript with similar APIs, it's a PITA to work with in real world projects, and on both sides of the API.
But I also think that I wouldn’t design an API that works like this in Rust natively; this is adapting a signature from C rather than doing the API you’d want if you were creating something from whole cloth.
I also believe that static types are very different based on the language; I’d rather write Ruby than Java, but I’d rather write Rust than Ruby. More advanced type systems tend to actually pull their weight, whereas simpler ones don’t give enough juice for the squeeze, IMHO.
Going too far into either extreme has more downsides than upsides - yes, strongly typed code will be more correct because the types might catch usage 'logic errors' during compilation, but also harder to maintain when requirements change (because strong types tend to creep into every little corner of a code base - and they are extremely rigid by design making the code which uses them also very rigid).
My goto example where I burned myself in the past is splitting a vec4 into point and vector types.
It totally makes sense from a theoretical design pov (e.g. `point + point` would be illegal, while `point + vector` or `vector + vector` are allowed). But in reality such code is awkward to work with for many little reasons, and the enforced correctness pretty much never catches bugs, it just adds pointless busy work when the code needs to change.
For the lowest level (e.g. an OS) you really want an extremely strict regime. Bugs are "simply not allowed"…
For application level code I think it depends. Nobody would finish anything if the requirement would be to formally verify all your code.
The other thing is: How far you can get before "over-typing" starts is also dependent on the language and how powerful it's type inference system is. Rust is quite weak in this regard.
In a language where the compiler can pass context for you one can have very strong guaranties without making working with the code too awkward. Of course, changing the code will need work. But that's the whole point of type systems: If you change something the compiler will tell you any places where something needs repair. In less strongly typed languages you can just pray that your tests are good enough to cover the changes.
In case of changes a good compiler will even rewrite the trivial cases for you if you ask, and just leave what really needs human oversight. But such automatic rewriting (with the guaranty that nothing went wrong!) works only if you had very strong types in the first place.
> a PITA to work with in real world projects, and on both sides of the API.
Don't see how this is a Typing issue, sounds more like API issue
If I knew the answer I would design programming languages ;) Replacing `Either<this, that>` with something like `this | that` like in Typescript might be going into the right direction though. Zig has similar syntax sugar for Rust's Result<> and Option<>. Such things are so fundamental that they should be part of the language instead of the stdlib IMHO.
> Don't see how this is a Typing issue, sounds more like API issue
Designing an API is a typing issue, because an API is essentially nothing more than a list of types.
Making `Result` a built-in syntax will disallow such freedom, and Zig has whole dedicated features to tackle problems solved by having `Result` just a normal type. Everything here is just a trade-off and both Rust and Zig have reasonable solutions for their use cases.
That's not the same.
The first one is an ADT instance with exactly two cases, whereas the other is an arbitrary union type.
The difference is when you pattern match on them. In the first case the compiler can statically verify that you handled all (two) cases. In the second case you can deconstruct the union, but you're not forced to handle all cases, simply because there are no know "all cases"; you could have arbitrary unions of any amount of things. (Of course the compiler could create for any usage of an union type some synthetic ADTs behind the scenes and check exhaustivity on them, but this would explode pretty quickly, I think, because of code bloat and compile times. Also that's not the expected behavior of union types in general).
> Designing an API is a typing issue, because an API is essentially nothing more than a list of types.
It's more a list of signatures, and some interaction protocol on top of that. (Frankly not expressed in types usually. We don't have simple ways to use things like session types still).
The types used in your signatures can be as specific or general as you want. It's the choice of the API designer. There is no issue with typing as such. You could just declare everything being a function from `Any => Any`… That's of course as bad as having so specific types that there can be more or less only one object shape that fits it. Classical over-typing, and that's imho just bad API design…
You can't be too specific there, because being as specific as possible has advantages: https://news.ycombinator.com/item?id=41409475
Result (Either (ARef (INode T)) (inode::New T))
Maybe a single generic argument shouldn't need any parentheses. It would imply that `a b c` should be parsed as `a (b c)`, which is not super obvious due to the inverted order. ML instead swaps the entire order, so that `a b c` is sensibly `(a b) c` but here `b` and `c` would be base types. That yields the following: (T INode ARef, T inode::New) Either Result
I think this is indeed slightly better than the current Rust syntax, but any C developer will have hard time adjusting their brains to this order. This and the very existence of C++ prompted Rust to use the same syntax as C++ (the very early version used `A[B]` instead), but otherwise Rust types are much more predictable than C++ due to the lack of compile-time metaprogramming [1].The fact that Haskell is not very different from Rust in the type syntax complexity shows that this type is just fundamentally "complex", because it is composed of multiple composable types. (I will personally avoid `Either` because I think an explicit enum is better here, but otherwise everything is independent from each other.) And an equivalent C function will do the same thing but without any type declaration and ad-hoc error code and/or convention, which never works well in practice.
[1] Some Rust crates do still attempt this, like the `typenum` crate, but I would not recommend them in general because they are really awkward to use.
It's just nested generic types.
How would you otherwise express all the constrains in a type?
enum ReceivedINode<T> {
Existing(ARef<INode<T>)
New(inode::New<T>)
}
fn get(..) -> Result<ReceivedINode<T>>
Calm down with the bikeshedding. It’s just a complex C API and they wanted to convey the semantics concisely.If you never seen such types before it may look intimidating. But if you ever seen any ML style language the type of said function looks actually very ordinary. It does not use any really more complex concepts, it's just regular nested generic types. Pretty standard stuff.
In Rust you could also have things like:
fn foo<'a, T, U, V, W>(a: &'a T, b: U, c: V, d: W)
where
T: MyTrait<U> + Debug + 'a,
U: Debug + Hash,
V: SomeOtherTrait<V> + Debug + std::marker::Copy,
W: Box<dyn Fn(V) -> U> + Debug,
{
todo!("Just a demo");
}
That's indeed much more involved, even it doesn't use any deeply nested wrapper types.But I think nobody would force such complex signatures on API end-users.
(Even there is of course also no magic going on. It's just the quite quite expressive type language in Rust).
Not even one tubo-fish. No multiple lines of `where` clauses. No (dyn) trait impl. Not even a lambda!
On top of that Rust's syntax is full of noise. Curly braces, semicolons, ugly angel brackets, `::` instead of points for namespaces, etc.
Rust is a quite good language on the technical level. But the surface syntax is really ugly.
These people, while well intentioned in pushback, have difficulty separating benefit to the entity and benefit to themselves. So it takes a lot of work to impact change, and I understand the distance it has from normal technical work.
It's probably more difficult to handle in open source than in a company because authority less powerful and it's more difficult to wave both carrots and sticks...
The dev "pushing back" was being an asshole probably because of deep insecurity of gasp there being other programming languages than C.
Literally rust is currently being proposed for maybe new drivers and basically nothing else ATM. Nobody is suggesting rewriting code in rust or forcing people to learn rust. It is literally just "Hey, might be nice to write this driver for my mouse in a memory safe language".
He did a presentation on making a fs in rust, the response from this dev was "we won't be converting to your religion. We are going to continue modifying c code and your dumb rust code will always be a second class citizen."
Literally just hostility for hostility sake. He wasn't proposing to rewrite everything in rust. He wasn't proposing that everyone learns rust. He was just giving a freaking presentation on making a rust fs that integrates with the kernel and was immediately trashed for spreading religion or whatever.
Non-technical nonsense is charitable.
> I suspect part of the problem here is you're trying to convince everyone to switch over to the religion as promulgated by rust and the reality is that ain't going to happen because we have 50 plus filesystems in Linux, they will not all be instantaneously converted over to rust. Before that happens we will continue to refactor code because we want to make the C code better. If it breaks rust bindings, at least for the foreseeable future the rust bindings are a second class citizen and those file systems that depend on the rust bindings will break and that is the rust bindings problem, not the file system community at large's problem and that's going to be true for a long long time, okay, and I think we just simply need to accept that
That seems rather technical to me. To put words into their mouth because they had a snarky tone, or claim the presenter was "immediately stacked for spreading religion or whatever" hardly is.
From the closed captions with minor editing. In response to "we are going to provide API bindings"
> I suspect the problem here is you are trying to convert everyone to the religion as promulgated by rust and the reality is that ain't gonna happen. Because we have 50 plus filesystems in linux and they will not all be instantaneously converted over to rust. Before that happens we will continue to refactor code because we want to make C code better. If that breaks the rust bindings at least for the foreseeable future the rust bindings are a second class citizen. Those file systems that depend on the rust bindings will break and that is the rust bindings problem not the file system community at large problem. And that's going to be true for a long long time, OK. And I think we just simply accept that right because the answer you are not allowed to refactor C code because it would break 5 critical file systems that distros depend on is like not a star, OK.
And that critique is near the end of all the people who asked questions or made comments. So no, the presenter wasn't "immediately stacked" when making that presentation.
If you'll re-read the quote you claim to be literally quoting, nowhere does it say "spreading your religion":
> > I suspect the problem here is you are trying to convert everyone to the religion as promulgated by rust...
The other reason Linux is trustworthy because of the technical meritocracy culture. But since Rust is not a technical choice, as Rust cannot per-se do things that are impossible in C - you can do anything in C - the introduction of Rust falls outside the parameters of the regular rough-but-mostly-fair Linux exchanges. This leading to toxic reactions from the less socially-abled.
Have anything in particular in mind? It's been my understanding that Rust actually can do everything C can, but the additional safety guarantees imposed by the type system make it a bit harder.
A comment there has a link to a video of what seems to be the final straw.
> Lastly, I'll leave a small, 3min 30s, sample for context here: https://youtu.be/WiPp9YEBV0Q?t=1529 -- and to reiterate, no one is trying force anyone else to learn Rust nor prevent refactorings of C code.
0: https://www.reddit.com/r/linux/comments/1f3q0l8/one_of_the_r...
If kernel includes Rust, then that C code change could also require applying fixes to Rust code that breaks from that change
It's a little tough to build a safe abstraction layer on top of C or encourage maintainers to stick around with a hostile "that's a _you_ problem" mentality or inaccurate rhetoric that Rust are trying to force their religion onto the C devs.
https://lwn.net/Articles/978738/
While I disagree with his opinions here, Ted T'so is a long-time Linux kernel dev. He's been around since close to the beginning.
I have not seen many of those in my close to 32 years of involvement with Linux. In the beginning of the project they did occur 'every now and then' but once Linux got past v1.2 or thereabouts they're about as rare as hen's teeth. If Rust ever becomes widespread enough for kernel developers to pick it up with ease it will be a welcome addition but until such a time I prefer for the project to remain C-focused so as not to close out a large fraction of the potential developer base. If that means that some 'competing' kernel gets written in Rust and takes over from Linux that'd be fine by me as well, may the best [1] kernel win.
Suggesting making a new kernel is just total FUD. This is a multi decade project. It's like saying to a person who want some legislation in their country to change "why not make your own country, may the best country win". It's just so far removed from reality I'm very surprised I have seen this argument more then once.
Linux started as a hobby project of a single student and just a few years later it was already possible to build a full-blown UNIX desktop system with Linux as kernel.
Why should that not be possible to replicate today? Especially with modern development tooling and a big and motivated language community?
What is missing is the user base! When Linus started his project, many people knew Unix in their professional life and were disappointed with what the market (M$) was proposing for the personal computer world.
Today, no such multitude is waiting for the next Linux.
Linux may not be perfect, but it's definitely good enough.
That doesn't even begin to touch on the problem that linux came at just the right time.
Replacing any substantial parts of the Linux project with Rust also would be multi-decade effort, most likely more effort than forking off a separate evolutionary branch (which is probably the most realistic option). Such forks happened all the time in the history of UNIX.
No one wants to replace substantial parts of the linux project with Rust. This is a straw man, and the same bad faith argument the set in their ways kernel greybeards are making. People just want to be able to write green field drivers in Rust.
As long as they are the majority of the kernel developers, their wish is what matters the most.
This problem is not expected to be solved by current maintainers. They're just asked to make room for the next generation. "It should hurt you like it hurt me" is not an acceptable response.
> Does the proverbial rust programmer who doesn't know C even exist?
I have seen enough Python or JS programmers learning Rust without having any working knowledge about C. Of course Rust is not an easy language to learn for them, as they have to deal with a concept of explicit memory and lifetime that have no equivalent in Python or JS, but otherwise I didn't see any complication specific to Rust.
The rust guys were just asking for semantic information about the current C apis so they could try to encode them into the type system.
All they got in response to that were made up problems of them supposedly forcing everyone to adopt their religion, rust being too OOP or other nitpicks that had nothing to do with the issue the presenters were trying to talk about.
Nobody even answered their questions, people which obviously didn't even look at rust for more than an hour gave their opinion on why what they're doing is bad and destined to fail. It was rude, tone-deaf and not a single technically sound argument was actually made.
I love linux and I'm fine with the maintainers deciding to use C if they want to, but the behavior by the old guard here was actually appalling and reeks of deep insecurity and inability to communicate.
Since when is Rust a requirement to help Linux development? Only an utter idiot could think that such a big and successfully community would put any effort in addressing any issue that is not posed in their natural language!
If you want to introduce Rust into Linux, you learn C, you learn Linux, you add and maintain whatever you want.
It's not and it shouldn't be, but it is most definitely required if you want to criticize it's integration into the kernel due to its supposed flaws/merits in a "technical" discussion.
Nobody is forcing anyone to learn rust, the RiL folks are fine with maintaining bindings and handling the fallout of C API changes. They didn't even get to say that, because they were shouted at for asking a question.
> If you want to introduce Rust into Linux, you learn C, you learn Linux, you add and maintain whatever you want.
Which is basically exactly what the RiL community is doing. In the posted video you can see them TRYING their best to learn about the undocumented invariants of a C API and getting nothing but flak for it for completely made up reasons. I might be hard to understand, but many of the strongest advocates of rust know C well and are opposed to using it themselves for good reasons. The folks maintaining C API don't have to care much about the rust part, except maybe giving a friendly heads-up when they change API's they depend on, like you would in any kernel development work where you are impacting another subsystem.
Apparently this is too much to ask from some of these C grandpas.
While these guys have undoubtedly made great contributions to Linux and FOSS and I'll be forever thankful for that, some of their behavior towards the RiL community has been appalling and petty. They have been resistant to any sort of change, even if it does not impact them at all, are quick to criticize without any attempt at understanding the efforts and benefits of Rust integration or even making any technically coherent argument. Constructive criticism and open discussion is important, but it should be based on accurate information and a willingness to learn instead of knee-jerk reactions and reacting to people wanting to learn about the API of your subsystem with outright and unwarranted hostility.
Well, maybe that's exactly what should happen. Maybe rust should have never been allowed in the kernel in the first place.
It's caused a lot of trouble so far and for what? The dev community is fractured and infighting is rampant.
The "for what" seems pretty obvious, no? It's the same reason you would use Rust over C in any other project. Memory safety and more modern PL features.
And, there’s still no good and fast allocator:
Can you clarify these two sentences? You say there should be a memory-safe kernel, and then you say Rust should never have been allowed, which is the opposite.
Just because someone pushed some Rust into a kernel it does not make that kernel a Rust kernel, this is the issue with Rust community , hyping the fact that some devs managed to pushed a few lines of Rust in some kernel as some big victory.
Even Mozilla gave up on making a browser in 100% Rust, it seems that rewriting in Rust is not that easy and people like to talk then do the work.
> people like to talk then do the work.
There are tens of millions (I'm being conservative here, not sure I'd claim 100M) of Rust code running in production, at many very large tech companies. I feel like you have an opinion and are trying to fit the facts to it, rather than the other way around.
I did not say that there are not tons of millions of Rust lines of code used in production, I wish there would be a modern kernel for PCs not some micro/nano kernel for some board. I see it a big waste to push Rust into Linux or Windows kernels instead of those competent developers writing that new modern kernel, it feels like they are forced to work on Linux/Windows so they want to have fun with Rust at work. If Rust is so superior then you just need to start the kernel, prove is super fast and super safe and Big Tech will put the money so they can use it on their servers, Like why would Netflix not use the super kernel written in Rust ?
Other examples: https://tockos.org/ & https://oxidos.io/
"just" writing a production-grade Linux equivalent would take decades. Some people are working on such projects, but those will take a long time, if ever, to mature, whereas improving Linux means making positive change today. Both things can be pursued in parallel, by different people. It's not an either/or.
I honestly wish to see modern OS as a competition to the decades old Linux and Windows.
So the next paragraph means:
> Maybe rust should have never been allowed in the [Linux] kernel in the first place.
These are a Linux kernel people who want to use Rust. Writing a new kernel would be fundamentally different than working on Linux.
Also, they are “writing software,” and have been for a long time now. This isn’t just some random arguing on mailing lists, this is actual patches, with folks like Asahi and Android writing real meaningful drivers on top of it.
They may want to work on Linux but it's clear that the rest of the Linux developer community does not want to allow it, for reasons you are free to interpret as positive or negative as you see fit.
They want to write software, and they are getting somewhere, but they are restricted by the attitudes of the rest of the Linux kernel people fighting against them, so they are sucked into constant flamewars and divisive infighting. All just so they can say what they are working on is "Linux".
At the end, the question must be asked whether or not Linux and its decades of Linux/Unix baggage are worth holding back the progress represented by a kernel that is Rust from top to bottom, and written with safety and security as its top priorities from day zero instead of decades after.
Window GDI regions, CoreWrite, Drivers SDK
Android
Copilot+ PC firmware
There is no such thing.
There are people developing a complete OS in Rust: https://github.com/flosse/rust-os-comparison
There are people interested in making the Linux kernel more memory safe using Rust. And from what I am observing they aren't interested in a hard fork and are looking for collaboration.
These are different populations.
Contrary to what Theodore Ts'o is ignorantly saying, Rust is not a religion.
BTW: There are a few Rust OS kernels, but none of those have the popularity of Linux of course.
Can't find the name of that now. But there's also RedoxOS and probably several more.