3 ms·
Given the disposition of kernel developers and the bespoke needs of drivers, I assume that Rust-written drivers will be neither pulling in dependencies willy-ni
by kibwen 4y ago
Given the disposition of kernel developers and the bespoke needs of drivers, I assume that Rust-written drivers will be neither pulling in dependencies willy-nilly nor will they be using generics all that heavily (but feel free to correct me if I assume wrongly). In that instance I don't think the Rust compilatiom process would impose any undue burden, especially since Rust can only be used for optional components of the kernel since it doesn't compile for all the targets that the kernel supports.
- sebzim4500 4y agoThe Asahi GPU driver which is currently being developed uses a proc macro to deal with the different versions of firmware that the driver must support (i.e. fields are added/removed in firmware updates, and the driver must support both). That probably will never compile especially quickly. I'm not sure how sensitive kernel devs are to clean build times. Presumably doing a non-incremental build is relatively rare?
- kibwen 4y ago> That probably will never compile especially quickly. Can you link the code? Proc macros are not inherently slow to compile, but most proc macros pull in the `syn` and `quote` crates for convenience, which are fairly heavyweight (and then most people experience proc macros most commonly via Serde, which is doing a ton of work on its own). In simple cases you can forego most of that work, and some libraries like https://github.com/Manishearth/absolution https://github.com/Manishearth/absolution exist as lightweight alternatives in these cases. Depending on what the Asahi driver needs it could also benefit from something like this (although without seeing the code I'm not sure why it would need proc macros when it sounds like conditional compilation via `cfg` would suffice there).
- loeg 4y agoA big source of compile time used to be proc macros — the kernel could just disallow those?
- Matthias247 4y agoIf you watch the actual talk and check code at https://github.com/Rust-for-Linux https://github.com/Rust-for-Linux you will see that it’s actually pretty heavy on generics and macros. Eg for the trait that defines file system operations (https://github.com/Rust-for-Linux/linux/blob/459035ab65c0ebb8d7054b24b6c00de907819eb2/rust/kernel/file.rs#L774 https://github.com/Rust-for-Linux/linux/blob/459035ab65c0ebb...) and other bindings to C code. I was actually surprised of seeing those, since they certainly don’t help with telling people a story that Rust is an easy language. But it’s probably the best one can do when having to interface with predefined APIs. But You are certainly right in that external dependencies won’t be an issue.
- kibwen 4y agoThe trait there doesn't look concerning to me (e.g. none of its methods are generic (its methods do use associated types, but those are pretty trivial to resolve or generate code for; there's only ever one set of associated types per impl, whereas with generic functions there's the potential for combinatorial code explosion depending on usage)). However, I do see a custom `vtable` macro in there, and indeed macros can be a concern for compilation speed if they're not implemented with compiler-friendliness in mind. But other than that, I'd say that file shouldn't represent a problem for the compiler.