Upcoming Rust language features for kernel development

41 pointsposted 4 hours ago
by pykello

11 Comments

PoignardAzur

an hour ago

> Since the talks described in this article, the work on field projection has received an update. Lossin wrote in to inform LWN that all fields of all structures are now considered structurally pinned, so projecting a Pin will now always produce a Pin<&mut Field> or similar value.

Huh, I missed that part. It's a pretty technical point, but I'm happy they made the decision, it held up a lot of discussions.

PoignardAzur

an hour ago

> The final design, taking inspiration from C++, would be a form of guaranteed optimization, where constructing a new value and then immediately moving it to the heap causes it to be constructed on the heap in the first place.

Note that there's some discussion about the name of that proposal, because "optimization" gives the wrong idea (that it's optional or could depend on the backend).

Tuna-Fish

22 minutes ago

I'm probably misunderstanding the complexity of the problem, but wouldn't this be solvable by just defining the right calling convention?

"Any structures larger than x, or any structures marked with a marker type, are returned by the caller providing an outref to a buffer with correct size, and the callee directly writes the structure into that buffer."

Then you could just write normal code like

    fn initialize() -> A { 
    // the initialization code 
    }
and it would just work? And it would reduce unnecessary copies in a lot of other situations too? Given how much work has been put into this issue, and how much less convenient the proposed solutions are, I feel like I must be missing something.

dapperdrake

an hour ago

How does "coalesced heap construction" or "coalesced heap allocation"?

hannesfur

an hour ago

These seem like the first features that Rust in Linux bring to the Rust language that are not almost exclusively useful to the kernel. In my perception the focus on bringing features for the kernel has held up development in other parts of the language and the standard library.

oersted

an hour ago

As I understand it systems programming is the priority application area for Rust, and there are plenty of projects working on OSs, embedded or other bare-metal cases, as well as interoperability with complex C codebases.

At first glance, these features look quite general to me and not particularly tied to the kernel, they are important utilities for doing this kind of programming in the real world.

pjmlp

34 minutes ago

I see Rust's place on low level systems programming, for everything else on userspace compiled managed languages are a much better option, systems following an architecture like Self, Inferno or Android, so I don't see a big deal with these efforts focusing on low level C like capabilities.

timschmidt

23 minutes ago

> for everything else on userspace compiled managed languages are a much better option

As someone who's written a number of userspace applications in many languages as well as embedded firmwares running on bare metal, Rust is a rare gem that excels at both.

discreteevent

8 minutes ago

> Rust is a rare gem that excels at both.

This can be true but it can still be the case that a managed language is even better at one of them.

pjmlp

15 minutes ago

Only if those userspace applications are headless, Rust exceling at GUIs is a bit of a strech.

timschmidt

12 minutes ago

Well https://github.com/timschmidt/egui-rad-builder has come together rather well in the last week of hacking, if I say so myself. I think building a similar app with QT, for example, would have been significantly more challenging.

I'm particularly fond of how easy it was to make all the controls live in the editor, and editable with changes appearing immediately. imgui would probably provide a similar experience, but I find C++ much more of a pain to work with than Rust.