News for hackers. Stuff that matters.
Re:Microsoft is to enable Rust use for Windows 11 kernel by shortrounddev on Friday April 28, 2023 @10:10AM (#35741454)
I like writing C++ code, and I like using SAL annotations to try to improve safety. I try to remember to be const correct as best as I can. Is Rust something I would enjoy? It's hard to discern the signal from the noise on this lang
Re:Microsoft is to enable Rust use for Windows 11 kernel by _flux on Friday April 28, 2023 @10:13AM (#35741492)
I think you will appreciate that moving objects actually invalidates the original bindings and the compiler checks for this quite effectively.

Though there is some learning curve..

Re:Microsoft is to enable Rust use for Windows 11 kernel by shortrounddev on Friday April 28, 2023 @10:16AM (#35741523)
So the equivalent of std::move will also make sure to "null" the original object at the same time?
Re:Microsoft is to enable Rust use for Windows 11 kernel by VWWHFSfQ on Friday April 28, 2023 @10:18AM (#35741542)
It's not just a matter of "null"ing the reference. The program just won't compile at all if you try to use that reference again
Re:Microsoft is to enable Rust use for Windows 11 kernel by dataflow on Friday April 28, 2023 @10:43AM (#35741860)
Surely there's more to it than this? Otherwise you can just set up bugprone-use-after-move checks in C++ and call it a day.
Re:Microsoft is to enable Rust use for Windows 11 kernel by dmkolobov on Friday April 28, 2023 @11:48AM (#35742818)
The difference is that your C++ checks are executed at runtime. Rust's borrow-checker rules ensure this occurs at compile-time, before you ever run any code.
Re:Microsoft is to enable Rust use for Windows 11 kernel by dataflow on Friday April 28, 2023 @11:55AM (#35742949)
The check I mentioned is a compile time check. I'm not referring to ASAN.
Re:Microsoft is to enable Rust use for Windows 11 kernel by masklinn on Friday April 28, 2023 @12:11PM (#35743260)
Well yes for starters this is not an optional check and it’s not on just “bug-prone” moves it’s on all for them.

Then it also has a borrow checker so if you refer to the content of an other object the langage ensures the (non-owning) pointer does not outlive the pointee, at compile-time. Though this concept is lexical so it’s quite restrictive.

And then it encodes some forms of thread-safety in the langage directly.

It also removes things like nullable pointers.

Re:Microsoft is to enable Rust use for Windows 11 kernel by duped on Friday April 28, 2023 @02:58PM (#35745575)
The "more to it" is that the use-after-move checks aren't bugprone in Rust, you cannot use a value after it has been moved in safe code (additionally, when you call a function, values are moved and not copied, and when you capture a value in a closure, it is either by unique mutable reference, immutable reference, or moved and therefore safe*).

Essentially all the stuff that makes std::move questionable "just works" in Rust. It doesn't even exist, values are moved by default and clones must be explicit (equivalent of a copy constructor for non-trivially copyable types).

The other giant advantage is that use-after-free doesn't exist in safe Rust, since you can't have a reference to a value outlive the value.

* It is also a compile error for a closure that captures a value by reference to outlive the value.

Re:Microsoft is to enable Rust use for Windows 11 kernel by dataflow on Friday April 28, 2023 @03:26PM (#35745974)
> the use-after-move checks aren't bugprone in Rust

I can't tell if one if us is confused here or if this is just confusing wording, but the check I referred to is not bug-prone. The pattern of using something after it's been moved from is bug-prone (even though it'd work fine for things like integers, in either language), and it's checking for that bug-prone pattern, hence the name.

Re:Microsoft is to enable Rust use for Windows 11 kernel by db48x on Friday April 28, 2023 @06:06PM (#35747692)
In Rust it’s not bug–prone. The compiler knows which types are moved and which are copied, and if you write code that uses something after it was moved you get a compile–time error.
Re:Microsoft is to enable Rust use for Windows 11 kernel by _flux on Friday April 28, 2023 @10:43AM (#35741869)
In practical terms the original variable or field will be out of scope after the move (well not really, but that's how effective the checking is).
Re:Microsoft is to enable Rust use for Windows 11 kernel by eska on Friday April 28, 2023 @12:22PM (#35743457)
It’s a heuristic. And it doesn’t catch when your move isn’t really a move. And writing move constructors is difficult busywork.
Re:Microsoft is to enable Rust use for Windows 11 kernel by masklinn on Saturday April 29, 2023 @02:18AM (#35750505)
Your comment is really confusing, none of that is true for Rust.
Re:Microsoft is to enable Rust use for Windows 11 kernel by eska on Saturday April 29, 2023 @01:02PM (#35754754)
Because it was about C++
Re:Microsoft is to enable Rust use for Windows 11 kernel by SturgeonsLaw on Friday April 28, 2023 @10:16AM (#35741526)
Try it and see :)

I didn't find the syntax very ergonomic but then I'm the kinda guy that likes Python because it's so loose

Re:Microsoft is to enable Rust use for Windows 11 kernel by bfrog on Friday April 28, 2023 @02:38PM (#35745334)
Maybe!

If you hate writing cmake/make/vcpkg/conan bs, and want to be able to git clone and build anyproject, without installing anything beyond rust+cargo... rust will be nice to use.

If you hate the idea of class hierarchies to try and describe behavior and would prefer to attach behavior to any type through traits... rust will be nice to use.

If you like the idea of having generics checking on said traits at compile time with sensible messages rather than the duck typed macros also termed templates with their horrendous error messages... rust will be nice to use

If you like the idea that the compiler verifies for you at compile time the concept of ownership while giving out references, ensuring 1 mutable reference and 0 immutable references, or N immutable references are allowed, while also ensuring the variable being referenced lives longer or as long as the references... rust will be nice to use

If you love spending time debugging invalid references/pointers, races, and more then rust isn't going to nice to use.

Re:Microsoft is to enable Rust use for Windows 11 kernel by nyanpasu64 on Friday April 28, 2023 @03:05PM (#35745683)
If you don't like the idea that the compiler will fight against you if you try to create multiple simultaneous interchangeable mutable references on a single thread, even when it's the right thing to do in a case, you might struggle with Rust for problems that require that (intrusive linked lists, emulators with multiple interacting objects, etc.).
Re:Microsoft is to enable Rust use for Windows 11 kernel by pkolaczk on Friday April 28, 2023 @04:02PM (#35746379)
You can always tell it to shut up by using pointers and unsafe.
Re:Microsoft is to enable Rust use for Windows 11 kernel by calo_star on Friday April 28, 2023 @05:03PM (#35747084)
What would be the particular difficulty with intrusive linked lists?
Re:Microsoft is to enable Rust use for Windows 11 kernel by pjmlp on Saturday April 29, 2023 @04:28AM (#35751148)
concepts are a thing now, compile time execution keeps getting better, and stuff like clang tidy help where C++ fails short.

While C++ will never be as safe as Rust, mastering it is still a must in many domains, including contributing to Rust's compiler backends.