3 ms·
> I'm more worried about the float/128bit integer thing he mentioned, as I don't know anything about it. I assume it's not just a miss understanding of overflow
by littlestymaar 6y ago
> I'm more worried about the float/128bit integer thing he mentioned, as I don't know anything about it. I assume it's not just a miss understanding of overflow checks and other debug assertions the kernel likely will disable for non-debug builds?
Idk about 128bits integer, but the floating point question has been discussed on Rust's subreddit[1]:
> Normally, the kernel leaves the floating-point state of the CPU in whatever state the userspace process left it in, so that you can do a quick system call without having to save and restore all that state. It's possible to use floating point in the kernel with a great deal of care, but you have to notify the kernel that you're doing so, so that it can save the userspace floating-point state.
> So, it'd be helpful if by default Rust didn't allow use of floating-point, and then you could opt in to allowing it for specific code.
And from Linus[2]
> In other words: it's still very much a special case, and if the question was "can I just use FP in the kernel" then the answer is still a resounding NO, since other architectures may not support it AT ALL.
[1]: https://www.reddit.com/r/rust/comments/mqxr1a/rfc_rust_support_for_linux_kernel/gujty1u/?context=3 https://www.reddit.com/r/rust/comments/mqxr1a/rfc_rust_suppo...
[2]: (from the same reddit thread) https://ipfs.io/ipfs/QmdA5WkDNALetBn4iFeSepHjdLGJdxPBwZyY47ir1bZGAK/comp/linux/kernel_fp.html https://ipfs.io/ipfs/QmdA5WkDNALetBn4iFeSepHjdLGJdxPBwZyY47i...
- dathinab 6y agoWell if that it all this could be solved by rust by having a "floating_point_usage" (or similar) lint which normally defaults to "allow" but for kernel devs defaults to "error" (which could be done through an option in the target spec, which as a side note is also what defines if you have hard,soft or no fp support). (there are probably better solution but this one should be the easiest).
- ssokolow 6y agoThere's actually a lint specifically intended for that already. `float_arithmetic`: https://rust-lang.github.io/rust-clippy/master/#float_arithmetic https://rust-lang.github.io/rust-clippy/master/#float_arithm... # What it does Checks for float arithmetic. # Why is this bad For some embedded systems or kernel development, it can be useful to rule out floating-point numbers.
- dathinab 6y agoThanks, nice, but for the kernel use case it would need to be part of rustc.
- zaarn 6y agoSimply install clippy and call "clippy-driver" instead of "rustc", which will handle this. Clippy is largely the lints that haven't either made it into rustc or are fairly edge-case-y.
- littlestymaar 6y agoWhy? The Rust-for-Linux team already made Clippy a requirement for Rust kernel code. For niche configuration that are really project-specific like this, it makes total sense to use external tooling to ensure the guidelines are respected, it doesn't need to be the compiler enforcing these guidelines.