The Case for Rust (in the base system)

One simple example . In C you can dereference a null pointer & a pointer pointing to the sky. Never possible in F# or ada
Ada its quite easy:

Code:
with Ada.Text_IO;

procedure Erroneous is
   type Int_Ptr is access Integer;
   P : Int_Ptr;  -- uninitialized
begin
   -- ERRONEOUS EXECUTION
   Ada.Text_IO.Put_Line (Integer'Image (P.all));
end Erroneous;

F# is just .NET so the typical bindings marshal errors allow it too.

Code:
open Microsoft.FSharp.NativeInterop

#nowarn "9"   // allow NativePtr usage

let demo () =
    // Allocate stack memory for an int, but DO NOT initialize it
    let p = NativePtr.stackalloc<int> 1

    // ERRONEOUS / UNDEFINED BEHAVIOR
    let x = NativePtr.read p

    printfn "%d" x

demo ()

And since languages other than C or C++ need a *shedload* of bindings, this kind of dangerous stuff is very easy (and necessary) to creep in.
 
Ada its quite easy:

Code:
with Ada.Text_IO;

procedure Erroneous is
   type Int_Ptr is access Integer;
   P : Int_Ptr;  -- uninitialized
begin
   -- ERRONEOUS EXECUTION
   Ada.Text_IO.Put_Line (Integer'Image (P.all));
end Erroneous;

F# is just .NET so the typical bindings marshal errors allow it too.

Code:
open Microsoft.FSharp.NativeInterop

#nowarn "9"   // allow NativePtr usage

let demo () =
    // Allocate stack memory for an int, but DO NOT initialize it
    let p = NativePtr.stackalloc<int> 1

    // ERRONEOUS / UNDEFINED BEHAVIOR
    let x = NativePtr.read p

    printfn "%d" x

demo ()

And since languages other than C or C++ need a *shedload* of bindings, this kind of dangerous stuff is very easy (and necessary) to creep in.

What do you think of my cppfront program , hello.cpp2 ,

Code:
String: type == std::string; 
auto&   Cout =  std::cout;
#define Format  std::format

greet: (name: String) = {
    Cout << Format("Hello, {}\n", name);
}

sum: (a: i32, b: i32) -> i32 = {
    sum := a + b; // Type inference with :=
    return sum;
}

main: () = {
    x: String = "world";
    greet(x);
    s:=sum(10, 20);
    Cout << Format("Sum :  {}\n", s);
}
 
What do you think of my cppfront program , hello.cpp2 ,
I like it to an extent. I do think extensions of C (and C++) do have a lot of merit as a solution for a next gen language.

But my worry is that they focus on the wrong aspects and miss the important things that need to be improved.
 
And you miss to name those things that you regard as important.
Think about all these kids reading here ... do you think that they know?? :-/
The limitations of C++ are well cited in a number of papers. I don't expect every technical conversation needs to be suitable for kids.

Similarly to before, I can only recommend people read around if they are struggling to keep up 🤷‍♂️ .
 
And since languages other than C or C++ need a *shedload* of bindings, this kind of dangerous stuff is very easy (and necessary) to creep in.
And this is where we wrap around to C being the lingua franca of programming. No matter what language you write in, if you want to talk to anything that isn't your language, you must speak some dialect of C.
C has become more than a language, it holds a regal seat of power as the FFI Protocol. If you don't speak C, your language (or runtime) is useless.

But as for the thread topic, I don't think Rust in base is a good idea yet. While it would be nice to have, it's not yet stable enough to warrant it. Though I am looking forward to a future where it would be a good idea, and it gets included
 
I'm not familiar with Odin, nim and Zig are definitely proper alternatives. My personal preference is Rust though, hence why I'd look forward to having it in base. Zig would be fun too, not sure what that would mean for build times though, considering it _also_ needs its own LLVM.
 
Putting language grammers and ecosystems aside.

Considering current toolchain of FreeBSD is basically LLVM / Clang, any new languages introduced into base should be implemented by LLVM project and shipped as part of LLVM. This way, what toolchain team on FreeBSD project are forced to do would be minimized.

And as rewriting everything at once is NOT realistic, assuring sane linking and working fine with this "mixed up" situations are mandatory. I think current policy of Rust project is completely against it at least for default configurations. To introduce current form of Rust, Rust project should change their mind and default to "friendliest to link against old codes".

These should also apply to any other candidates, too (not limited with Rust alone). FreeBSD project is not enough large project, lacking sufficient dedicated fulltime developers unlike Windows and some of Linux distros.
 
Rust has no problem doing interop. It requires a Rust version of whatever symbols your C code is exposing, just like C needs headers for linking to other libraries. Those "headers but for Rust" are what they call "bindings".
For Rust to expose functions in the output dylib (or staticlib if you prefer), there is extern "C", and you'll need a C header for those exported symbols to be usable. There is tooling to generate both the Rust bindings and the C headers. Naturally you'll want to verify the output, and correct it where needed, but that gets most of the heavy lifting done.
Incrementally adding or rewriting things isn't an issue so long as you keep the headers and/or bindings updated. Rust is luckily also built on LLVM, so it should be possible to build Rust with the rest of the system toolchain.

Rust is just an example here. Zig is also built on LLVM, nim transpiles to C (or a handful of other languages) and has an unofficial LLVM backend, and many other new langs are built on it too. And the principles are usually the same, make the code aware of what symbols to expect snd it'll work.
 
Yes, I know at least Rust uses LLVM backend, but it's NOT the same as upstream LLVM project's one itself. This is the fatal problem.
Near-fatal is that LLVM project themselves does NOT releasing Rust frontend.
These should cause significant additional, SHALL-BE-UNNEEDED maintainance burden for toolkit team if incorporating Rust into base is wanted.
This is NOT limited with Rust. But I consider this FATAL.
 
No, Rust doesn't use upstream LLVM as default setting. It does, however, support upstream LLVM:
Rust supports building against multiple LLVM versions:

Tip-of-tree for the current LLVM development branch is usually supported within a few days. PRs for such fixes are tagged with llvm-main.
The latest released major version is always supported.
The one or two preceding major versions are usually supported.
From The rustc dev guide, Updating LLVM
 
No, Rust doesn't use upstream LLVM as default setting. It does, however, support upstream LLVM:

From The rustc dev guide, Updating LLVM
See this long-standing PR 274743.
At worst, need waiting for PORT_LLVM option to be always default and never be (means, "at least theoretically" cannot be made) broken.

And this PR 292101 could be matter, too.

Using Rust for ports are fine. But to incorporate into base, the above needs to be mutually assured. To be honest, base LLVM/Clang are actually ported, maintained by hard works by dim@ and only few other volunteers. NOT BY TENS OR HUNDREDS OF FULL TIME WORKERS. Minimizing maintainance / porting burden should be considered mandatory for in-base toolchains.
 
The limitations of C++ are well cited in a number of papers. I don't expect every technical conversation needs to be suitable for kids.

Similarly to before, I can only recommend people read around if they are struggling to keep up 🤷‍♂️ .
I read the link. If you suggest that it is important to be updated, it is a bad example. You can spend a lifetime studying only one fractal curve, a recent branch in topology, avoid this one.
 
Does Rust have a lower footprint than alternatives? https://join-lemmy.org/ mentions:
They probably are thinking comparatively to Rails or Node.js, as many on-premise webapps in the self-hosting circles are written with those. Lemmy is an ActivityPub-based software, for which the big dominant big brother, Mastodon, is a Rails app. My bet would be on the target audience for this part of the homepage's text to be the people who already ran an instance of Mastodon and maybe think running such thing is resource intensive (they should mention the storage footprint, though, as ActivityPub can be *really* verbose 😅).
 
And this is where we wrap around to C being the lingua franca of programming. No matter what language you write in, if you want to talk to anything that isn't your language, you must speak some dialect of C.
C has become more than a language, it holds a regal seat of power as the FFI Protocol. If you don't speak C, your language (or runtime) is useless.

But as for the thread topic, I don't think Rust in base is a good idea yet. While it would be nice to have, it's not yet stable enough to warrant it. Though I am looking forward to a future where it would be a good idea, and it gets included
I don't understand the persistent desire of it being in the base system. It makes me suspect corporate involvement. What exactly is it supposed to do, that apparently isn't possible while it's an external program? Are we sure that no other options are goimg to be limited for it? If not, the point of debate is bogus. It makes no difference apart from a pkg install command.
 
But to incorporate into base, the above needs to be mutually assured.
And I agree with that. Hence my message further up the thread: it's not a good idea yet, but that doesn't mean it'll never be.
Off-hand I don't know whether a modern C++ program or a Rust program come out bigger.
Very much something to judge on a case-by-case basis. Also depends on how you handle deps and linking.
I don't understand the persistent desire of it being in the base system. It makes me suspect corporate involvem
Just my two cents: Rust is a very nice language to work with (subjective, I know) that makes some things a lot easier to do, and that makes it much harder to get caught in some of the bugs and pitfalls of "obvious UB, but the compiler doesn't complain" that C(++) have. That also makes it much more approachable for little to no performance penalty. Which in turn is one of the driving forces of corporate adoption, because fewer bugs and easier entry means that it'll be cheaper to develop. Doesn't mean the drive for Rust in base is a corporate push though; companies using FreeBSD now clearly don't require it, and others wouldn't magically flock to it just because it has some Rust.

That said, Rust is not without its drawbacks. Little performance penalties can add up, and sometimes the compiler will force those on you even when you know it's useless. For that reason
unsafe exists, but that comes with both more verbosity and having to uphold guarantees that the compiler stops enforcing. Writing good and reliable Rust that performs on par with C(++) can be a real challenge. It's not a free performance booster without bugs in that regard.
Could it improve life for people working on base? Possibly, that's up to them. Could it attract more people to contribute to base? Definitely, but it might deter others. Is it a good fit right now? Absolutely not, it'd have to work seamlessly with the current LLVM toolchain, and neither side of that is at that point.
 
I don't understand the persistent desire of it being in the base system. It makes me suspect corporate involvement.
You generally won't see Rust on many job apps during our lifetime. But there is still a push by small but vocal companies to "sell" you new products (IDEs, books, courses) because there is less market competition compared to industry standard languages like C and C++.

In short, Rust is a hype bubble currently (but that is dying down). With any hype bubble, you do get good monetisation opportunities.
 
what i did not liked about rust
- dependencies , specific compiler , different then the one we use to compile kernel
- large specification , lots to read , too big.
----> I have no time for this

One can play with the idea of other languages in kernel/base. E.g. zig , but C has its development eco-system for kernel/base.
 
In short, Rust is a hype bubble currently (but that is dying down). With any hype bubble, you do get good monetisation opportunities.
Plus, I don't think there is reason to be suspicious, it's following the exact same hype cycle all trendy techs have done before. It always peaks with people being frankly fanatical about their tech, until comes the time where it's not new anymore, when you can't anymore write tutorials about how easy it is because it's starting accumulating baggage, and before you know it, it's just a weird corner of tech and a new trend is replacing it. I remember a time when people were very seriously discussing if the Linux kernel should be rewritten in Ruby (they were not kernel developers, of course, just Ruby developers convinced they were almighty right on all things). Let it settle and we'll see what survives of it.
 
Back
Top