Notes on a smaller Rust (2019)
21 points by nortti
21 points by nortti
Another idea to keep the runtime performance more stable would be to use reference counting instead of a GC when the compiler can’t infer the ownership of things. And add a weak
keyword for the cycle case like in Swift if i remember correctly.
About the macro part, I just want more languages to add quotation (ad quasi quotation) from lisp as a first class citizen. This is what I think enables a great “small” language.
I think Julia is a great example of this, the only difference for this Rust-ike language would be to run code at compile time otherwise you mostly need a JIT to efficiency run “macros” (evaluate quoted forms) at runtime
On the whole, these are good points. I don’t want what follows to make it seem like this article is terrible.
But the biggest thing I’m unsure about - and the most controversial - is error handling. I would probably experiment with exceptions if I were making this language.
I hate exceptions for handling recoverable errors. If you’ve ever written a C++ constructor for a vector where the constructor of T can throw, you know how bad it is.
Exceptions make reasoning about state so difficult. You have to be prepared for the object to be in ANY state, INCLUDING invalid ones, unless you’re EXTREMELY careful. This is the same reason we got poisoned mutexes (which are necessary). In a language where exceptions are first class, poisoned mutexes are suddenly everywhere.
The next change would to make trait objects the primary form of polymorphism. Every trait would be object safe, and casting a type into a trait it implements would be lightweight and easy because it can be heap-allocated by the compiler behind the scenes. No more monomorphization (at least, except as an optimization). Generics would exist only for creating polymorphic container types, not as the main way of making polymorphic functions.
How do you allocate a vector, or any container then? Polymorphic types are great until you want to know how big it is. Are you going to make a Vec<Box>? Your performance will be abysmal. What if you want to make a second copy of an object in a function? Welcome to DynClone.