r/ProgrammingLanguages • u/ergeysay • May 27 '26
Requesting criticism Safe Made Easy Pt.1: Single Ownership is (Not) Optional
https://ergeysay.github.io/safe-made-easy-pt1.htmlPart 1 of planned series of ~6 posts on how to make a super-safe language without borrow-checker headaches.
Any feedback much appreciated!
48
Upvotes
14
u/RedCrafter_LP May 27 '26
Intresting use of control flow sensitive typing. I might implement something inspired by it.
What I particularly like is the implicit type change based on state sensitive statements in the branch (drop).
What I'm concerned with is the seemingly compiler defined nature of Some <=> Optional <=> None. This is a pitfall rust also fell in originally with its ? Operator. They were(are) treated as something special by the compiler. What is better (and rust is in the process of retrofitting) is to make such feature abstract. Let users use the language features for their own types.
This also leads to my second point. The entirety implicit nature of the narrowing "if x" reads nicely with optional in particular. But falls apart on other types like a Result for example where one might want to take the if branch on err or ok varients depending on context.
The language feature is a great composition but the syntax and integration in the language (as far as I understood reading the short writeup) could be tighter.
7
u/initial-algebra May 27 '26 edited May 27 '26
The feature you've shown here is basically a special case of typestate, but implicit.
Or, if
Option<T>is actually the union typeT|None, you can just write:Though, this can also be simulated with renaming in Rust (or other languages with ownership but not true typestate), so I'm not sure it's all that significant.
Can it handle other kinds of typestate changes, which involve more general union/sum types and aren't necessarily related to conditional dropping?
Or, explicitly:
Also, how does a
Some<T>differ from a reference to aT?I am always very skeptical when someone claims they have found a system both more expressive and more ergonomic than Rust (that isn't garbage collection, anyway), but maybe you can prove me wrong!
6
u/esotologist May 28 '26
I thought the title of this post was an evangelion reference for a second
11
u/tobega May 28 '26
I like it!
One small but important comment unrelated to the main idea: Please don't introduce truthiness, it's a non-obvious type coercion that has caused lots of bugs. Instead of
if x, please require some more explicit type test likeif exists(x)or whatever you do to explicitly test theOption<T>.And a possibly unimportant comment related to the main idea: is it possible that x can change types invisibly by direct access from another file? That may not be desirable.
5
u/anterak13 May 28 '26
If you ensure unique write access could safe concurrency be naturally supported in the language?
3
u/AdvanceAdvance May 28 '26
Does anyone have the references for how many outages are caused by ownership issues?
3
u/X4RC05 May 28 '26
What code patterns would this uniquely enable?
2
u/Bitterbalpizza May 29 '26
Noob here, but isn't that called a phi node? Like in LLVM?
1
u/oscarryz Yz May 28 '26
I think you already consider it, but what are your thoughts to add a new variable in the dropping so the change of type is less surprising? I understand in the language this would be a known mechanic (just like it is in Rust when you try to use a reassigned variable ), because in flow typing it is usually inside a branch.
1
u/ProPuke May 28 '26
Nice. It's a single owner pointer with enforced nullability checks.
Nothing too exotic, but well written and explained. Curious to see what you layer in next.
1
u/EggplantExtra4946 May 30 '26
Amazing stuff.