A simplified model of Fil-C
Posted by aw1621107 5 hours ago
Comments
Comment by whatsakandr 5 hours ago
Comment by tialaramex 4 hours ago
1. Fil-C is slower and bigger. Noticeably so. If you were OK with slower and bigger then the rewrite you should have considered wasn't to Rust in the last ten years but to Java or C# much earlier. That doesn't invalidate Fil'C's existence, but I want to point that out.
2. You're still writing C. If the program is finished or just occasionally doing a little bit of maintenance that's fine. I wrote C for most of my career, it's not a miserable language, and you are avoiding a rewrite. But if you're writing much new code Rust is just so much nicer. I stopped writing any C when I learned Rust.
3. This is runtime safety and you might need more. Rust gives you a bit more, often you can express at compile time things Fil-C would only have checked at runtime, but you might need everything and languages like WUFFS deliver that. WUFFS doesn't have runtime checks. It has proved to its satisfaction during compilation that your code is safe, so it can be executed at runtime in absolute safety. Your code might be wrong. Maybe your WUFFS GIF flipper actually makes frog GIFs purple instead of flipping them. But it can't crash, or execute x86 machine code hidden in the GIF, or whatever, that's the whole point.
Comment by whatsakandr 3 hours ago
I'm not convinced that tying the lifetimes into the type system is the correct way to do memory management. I've read too many articles of people being forced into refactoring the entire codebase to implement a feature.
Comment by brucehoult 2 hours ago
Not some random dad, but a GC expert and former leader of the JavaScript VM team at Apple.
Comment by achierius 2 hours ago
Comment by gmueckl 1 hour ago
Comment by cxr 1 hour ago
It's not any slower or (proportionally) bigger compared to the experience you would have had 20 years ago running all sorts of utilities that happen to be the best candidates for Fil-C, and people got along just fine. How fast do ls and mkdir need to be?
Comment by up2isomorphism 31 minutes ago
Comment by gnabgib 5 hours ago
Fil-Qt: A Qt Base build with Fil-C experience (143 points, 3 months ago, 134 comments) https://news.ycombinator.com/item?id=46646080
Linux Sandboxes and Fil-C (343 points, 4 months ago, 156 comments) https://news.ycombinator.com/item?id=46259064
Ported freetype, fontconfig, harfbuzz, and graphite to Fil-C (67 points, 5 months ago, 56 comments) https://news.ycombinator.com/item?id=46090009
A Note on Fil-C (241 points, 5 months ago, 210 comments) https://news.ycombinator.com/item?id=45842494
Notes by djb on using Fil-C (365 points, 6 months ago, 246 comments) https://news.ycombinator.com/item?id=45788040
Fil-C: A memory-safe C implementation (283 points, 6 months ago, 135 comments) https://news.ycombinator.com/item?id=45735877
Fil's Unbelievable Garbage Collector (603 points, 7 months ago, 281 comments) https://news.ycombinator.com/item?id=45133938
Comment by omcnoe 4 hours ago
Guaranteed memory safety at compile time is clearly the better approach when you care about programs that are both functionally correct and memory safe. If I'm writing something that takes untrusted user input like a web API memory safety issues still end up as denial-of-service vulns. That's better, but it's still not great.
Not to disparage the Fil-C work, but the runtime approach has limitations.
Comment by pizlonator 4 hours ago
If it's guaranteed to crash, then it's memory-safe.
If you dislike that definition, then no mainstream language is memory-safe, since they all use crashes to handle out of bounds array accesses
Comment by omcnoe 4 hours ago
Other languages have runtime exceptions on out-of-bounds access, Fil-C has unrecoverable crashes. This makes it pretty unsuitable to a lot of use cases. In Go or Java (arbitrary examples) I can write a web service full of unsafe out-of-bounds array reads, any exception/panic raised is scoped to the specific malformed request and doesn't affect the overall process. A design that's impossible in Fil-C.
Comment by wren6991 59 minutes ago
Comment by dzaima 3 hours ago
try-catch isn't a particularly complete solution either if you have any code outside of it (at the very least, the catch arm) or if data can get preserved across iterations that can easily get messed up if left half-updated (say, caches, poisoned mutexes, stuck-borrowed refcells) so you'll likely want a full restart to work well too, and might even prefer it sometimes.
Comment by wakawaka28 4 hours ago
Comment by pizlonator 3 hours ago
I just don’t like that design. It’s a matter of taste
Comment by ori_b 4 hours ago
Comment by DetroitThrow 3 hours ago
Comment by p1necone 3 hours ago
(Also I think the commenter you're replying to just worded their comment innacurately, code that crashes instead of violating memory safety is memory safe, a compilation error would just have been more useful than a runtime crash in most cases)
Comment by 100ms 4 hours ago
https://play.rust-lang.org/?version=stable&mode=debug&editio...
Comment by zamadatix 4 hours ago
- Explicitly unsafe
- Runtime crash
- Runtime crash w/ compile time avoidence when possible
Comment by omcnoe 4 hours ago
Catch the panic & unwind, safe program execution continues. Fundamentally impossible in Fil-C.
Comment by uecker 3 hours ago
Comment by wakawaka28 3 hours ago
Comment by omcnoe 3 hours ago
I also don't think it's that niche a use case. It's one encountered by every web server or web client (scope exception to single connection/request). Or anything involving batch processing, something like "extract the text from these 10k PDFs on disk".
Comment by wakawaka28 3 hours ago
Generally, I think one could want to recover from errors. But error recovery is something that needs to be designed in. You probably don't want to catch all errors, even in a loop handling requests for an application. If your application isn't designed to handle the same kinds of memory access issues as we're talking about here, the whole thing turns into non-existent-apples to non-existent-apples lol.
Comment by boredatoms 4 hours ago
Comment by forrestthewoods 4 hours ago
It’s true that, assuming all things equal, compile-time checks are better than run-time. I love Rust. But Rust is only practical for a subset of correct programs. Rust is terrible for things like games where Rust simply can not prove at compile-time that usage is correct. And inability to prove correctness does NOT imply incorrectness.
I love Rust. I use it as much as I can. But it’s not the one true solution to all things.
Comment by omcnoe 3 hours ago
But Rust provides both checked alternatives to indexed reads/writes (compile time safe returning Option<_>), and an exception recovery mechanism for out-of-bounds unsafe read/write. Fil-C only has one choice which is "crash immediately".
Comment by uecker 3 hours ago
Comment by tialaramex 2 hours ago
Comment by uecker 2 hours ago
Comment by omcnoe 3 hours ago
Comment by kimixa 1 hour ago
Programming languages have always been more about what they don't let you do rather than what they do - and where that lies on the spectrum of blocking "Possibly Valid" constructs vs "Possibly Invalid".
Comment by uecker 2 hours ago
Comment by wakawaka28 3 hours ago
And inability to prove incorrectness does NOT imply correctness. I think most Rust users don't understand either, because of the hype.
Comment by pizlonator 4 hours ago
> "rewrite it in rust for safety" just sounds stupid
To be fair, Fil-C is quite a bit slower than Rust, and uses more memory.
On the other hand, Fil-C supports safe dynamic linking and is strictly safer than Rust.
It's a trade off, so do what you feel
Comment by masfuerte 4 hours ago
ar->invisible_bytes = calloc(length, sizeof(AllocationRecord));Comment by pizlonator 4 hours ago
I am the author of Fil-C
If you want to see my write-ups of how it works, start here: https://fil-c.org/how
Comment by masfuerte 4 hours ago
Comment by dataflow 4 hours ago
When's the last time you told a C/C++ programmer you could add a garbage collector to their program, and saw their eyes light up?
Comment by fulafel 47 minutes ago
And of course it's easy to think of lots of apps that heavily use those or another form of GC.
Comment by dataflow 26 minutes ago
Comment by FuckButtons 4 hours ago
Comment by brucehoult 1 hour ago
Comment by dataflow 22 minutes ago
Comment by pizlonator 4 hours ago
- Me. I'm a C++ programmer.
- Any C++ programmer who has added a GC to their C++ program. (Like the programmers who used the web browser you're using right now.)
- Folks who are already using Fil-C.
Comment by FuckButtons 4 hours ago
Comment by pizlonator 3 hours ago
My original foray into GCs was making real time ones, and the Fil-C GC is based on that work. I haven’t fully made it real time friendly (the few locks it has aren’t RT-friendly) but if I had more time I could make it give you hard guarantees.
It’s already full concurrent and on the fly, so it won’t pause you
Comment by cxr 1 hour ago
Comment by kbolino 4 hours ago
Comment by pizlonator 4 hours ago
Comment by kbolino 4 hours ago
Comment by pizlonator 4 hours ago
Here's why:
1. For the first year of Fil-C development, I was doing it on a Mac, and it worked fine. I had lots of stuff running. No GUI in that version, though.
2. You could give Fil-C an FFI to Yolo-C. It would look sort of like the FFIs that Java, Python, or Ruby do. So, it would be a bit annoying to bridge to native APIs, but not infeasible. I've chosen not to give Fil-C such an FFI (except a very limited FFI to assembly for constant time crypto) because I wanted to force myself to port the underlying libraries to Fil-C.
3. Apple could do a Fil-C build of their userland, and MS could do a Fil-C build of their userland. Not saying they will do it. But the feasibility of this is "just" a matter of certain humans making choices, not anything technical.
Comment by kvemkon 4 hours ago
Interesting, how costly would be hardware acceleration support for Fil-C code.
Comment by kbolino 4 hours ago
[1]: https://en.wikipedia.org/wiki/Capability_Hardware_Enhanced_R...
Comment by Findecanor 2 hours ago
There is a startup working on "Object Memory Addressing" (OMA) with tracing GC in hardware [1], and its model seems to map quite well to Fil-C's. I have also seen a discussion on RISC-V's "sig-j" mailing list about possible hardware support for ZGC's pointer colours in upper pointer bits, so that it wouldn't have to occupy virtual memory bits — and space — for those.
However, I think that tagged pointers with reference counting GC could be a better choice for hardware acceleration than tracing GC. The biggest performance bottleneck with RC in software are the many atomic counter updates, and I think those could instead be done transparently in parallel by a dedicated hardware unit. Cycles would still have to be reclaimed by tracing but modern RC algorithms typically need to trace only small subsets of the object graph.
[1]: "Two Paths to Memory Safety: CHERI and OMA" https://news.ycombinator.com/item?id=45566660
Comment by rvz 4 hours ago
Fil-C just does the job with existing software in C or C++ without an expensive and bug riddled re-write and serves as a quick protection layer against the common memory corruption bugs found in those languages.
Comment by uecker 3 hours ago
Comment by GaggiX 4 hours ago
Comment by DetroitThrow 3 hours ago
I love Fil-C. It's underrated. Not the same niche as Rust or Ada.
Comment by andai 3 hours ago
Comment by adamnemecek 3 hours ago
Comment by hsaliak 2 hours ago
Comment by vzaliva 4 hours ago