4 ms·
What I increasingly want to see is a language where a garbage collector is optional in the main executable, but not (directly) available to library code. Becau
by bunderbunder 3y ago
What I increasingly want to see is a language where a garbage collector is optional in the main executable, but not (directly) available to library code.
Because I want to have a language that I can use to write lean libraries that are available to any language with a C FFI, and that can be linked directly by AOT-compiled languages, without getting into a horrible quagmire of dueling heaps and copying. But I also want to have proper functional and asynchronous programming, and generally just to not have to manually fuss with memory in the higher-level code.
Python and C/C++/Rust/Cython/etc extensions kindasorta achieves this, and it's a huge factor in the language's ascendance in scientific computing applications. Game development has a long history of achieving a similar effect by embedding Lua or Lisp. But I think that it might be more pleasant to have it formalized and baked into a single language.
- AndrewDucker 3y agoPossibly Rust needs a GC<> wrapper type, which makes everything it contains garbage collectable. And then you could be bare metal, except when you want to not be.
- zozbot234 3y agoThere are a number of efforts along these lines, the most interesting is probably Samsara https://github.com/chc4/samsara https://github.com/chc4/samsara https://redvice.org/2023/samsara-garbage-collector/ https://redvice.org/2023/samsara-garbage-collector/ which implements a concurrent, thread-safe GC with no global "stop the world" phase.
- deleted 3y ago[deleted]
- yjftsjthsd-h 3y agoI'm reminded of wuffs, which only allows writing libraries and explicitly doesn't support allocateing memory, requiring the calling program to provide memory. It seemed like a nice separation of concerns in my non-expert view. (And then wuffs compiles to C, which is nice for interoperability)
- cpeterso 3y agoI hadn’t seen wuffs before. Interesting approach to writing safe libraries: Wuffs is not a general purpose programming language. It is for writing libraries, not programs. Wuffs code is hermetic and can only compute (e.g. convert "compressed bytes" to "decompressed bytes"). It cannot make any syscalls (e.g. it has no ambient authority to read your files), implying that it cannot allocate or free memory (and is therefore trivially safe against things like memory leaks, use-after-frees and double-frees). https://github.com/google/wuffs https://github.com/google/wuffs