#fishshell rewrite-it-in #rust progress, 2023-11-20
76909 rust lines added
48105 / 77063 C++ lines removed
▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░ 62 %
#riir #rustlang
--
So, that's a significant jump - mostly thanks to the merge of the parser rewrite branch, described as "Herculean". The parser, autoloading module, completion module, function management, history management, and the builtins for complete, disown, eval, fg, history, jobs, read, set, and source have all been ported, as well as many other parts of the code.
This also allowed the removal of lots of supporting tools, including the UTF-8 modules, and quite a few bits of the FFI.
After a few months of slow progress this is a huge step forwards.
Not really. Rewriting something in Rust has some obvious advantages. But those advantages diminish with the age of the old code base. For example, the biggest advantage is memory safety. But old C or C++ code bases would have undergone so much real world use and testing that most of the memory safety bugs would have been corrected anyway. Similarly, the new code (in Rust in this case) may fail to capture lessons from the old code that may not be well documented.
For these reasons, the common approach followed is to wrap old code in safe Rust and use it, instead of completely rewriting it in Rust. This was a stated objective (C & C++ FFI) of Rust project since its early days. This is also the reason why core Rust team often doesn’t support the RiiR zealotry.
In this case though, the developers of fish themselves decided that the hassles of C++ is worse than completely rewriting such a big and old code base in another language. I’m interested in C++ as well, though Rust is my primary language these days. I thought that it would be interesting to hear the experience of someone who made this unusual decision after dealing with both languages.
I wonder what sort of problems they had with C++ that prompted them to port such an old codebase to Rust.
This comment is probably the most interesting (from the PR that was already linked): https://github.com/fish-shell/fish-shell/pull/9512#issuecomment-1410820102
Most specific and technically relevant point:
You can read more in the RIIR PR.
deleted by creator
Not really. Rewriting something in Rust has some obvious advantages. But those advantages diminish with the age of the old code base. For example, the biggest advantage is memory safety. But old C or C++ code bases would have undergone so much real world use and testing that most of the memory safety bugs would have been corrected anyway. Similarly, the new code (in Rust in this case) may fail to capture lessons from the old code that may not be well documented.
For these reasons, the common approach followed is to wrap old code in safe Rust and use it, instead of completely rewriting it in Rust. This was a stated objective (C & C++ FFI) of Rust project since its early days. This is also the reason why core Rust team often doesn’t support the RiiR zealotry.
In this case though, the developers of fish themselves decided that the hassles of C++ is worse than completely rewriting such a big and old code base in another language. I’m interested in C++ as well, though Rust is my primary language these days. I thought that it would be interesting to hear the experience of someone who made this unusual decision after dealing with both languages.