4 ms·
I would have thought that Ladybird would be using a language that specifically guarantees memory safety which is Rust. But Swift is a very surprising choice but
by rvz 2y ago
I would have thought that Ladybird would be using a language that specifically guarantees memory safety which is Rust. But Swift is a very surprising choice but actually makes sense for a browser.
The browser story is not great for Rust as we can only point to Servo which isn't ready to be used as a daily driver for millions of users. But Arc Browser is written with a combination of Swift and C++ to run on macOS and Windows.
Other than iOS apps, perhaps Swift found another use-case in large C++ code bases thanks to the C++ interop story.
- jghn 2y ago> specifically guarantees memory safety which is Rust I think you mean "one of which is Rust".
- jsheard 2y agoI'm not sure if the comparison to Servo holds up since that's a browser engine, and Arcs engine (Chromium) is 100% C++. Swift is only used for the frontend.
- GeekyBear 2y ago> I would have thought that Ladybird would be using a language that specifically guarantees memory safety which is Rust. Rust isnt the only compiled language that provides memory safety by default. Swift does as well.
- zozbot234 2y agoDoes Swift enforce memory safety in concurrent code also, i.e. preventing thread-unsafe data access in safe code? That's a really hard problem that Rust tries to address mostly successfully, and many other languages don't.
- GeekyBear 2y agoYes. That is a new feature as of version 6 of Swift. https://www.swift.org/migration/documentation/swift-6-concurrency-migration-guide/dataracesafety/ https://www.swift.org/migration/documentation/swift-6-concur...
- stephen_g 2y agoSwift is memory safe. The C++ interop thing I think is massive. But isn’t there also the problem that with Rust you can’t have the equivalent of shared pointers, so you can only have a single reference to one object (sorry I don’t really know Rust, just going from how this has been described to me) which apparently makes representing things like DOMs and abstract syntax trees an absolute nightmare?
- rahkiin 2y agoAnd cannot have linked lists either. When you make a compiler in rust, basically you give everything the same lifetime and drop the memory at the very end. That allows cicular references. Or you use Rc, but that is against what purists want you to do. For longer lifetime programs with complex models the borrow checker becomes harder
- zozbot234 2y agoYou can express linked lists efficiently in Rust using the GhostCell/QCell pattern. Yes it's clunky, but this is after all an area of active research in PL theory. As it is, most ordinary "easy" implementations of linked lists do not actually prove memory safety - it's a genuinely non-trivial problem, not a case of mere incidental complexity.
- ghosty141 2y agothere are also classical shared pointers in rust: https://doc.rust-lang.org/std/cell/struct.RefCell.html https://doc.rust-lang.org/std/cell/struct.RefCell.html
- survirtual 2y agoRefCell is a shared pointer. Arc is a shared pointer with atomic reference counting (so it can be used between threads safely). Both these constructs use the "clone" trait to iterate the reference count. I make primarily concurrent and async applications these days so I use Arc a lot for accessing memory that is very large and shared many places, such as context. I think the real problem is Rust has a lot of rules (that make sense for safety) that take time to understand and most people aren't patient enough to make good software because of corporate conditioning.