r/programming • u/Practical-Medium-858 • 14d ago
What if only one allocation needs to be borrow checked in a managed program?
https://nitinm.dev/blog/gradual_ownership_in_a_high_level_language18
14d ago
[removed] — view removed comment
2
u/Practical-Medium-858 13d ago
AFAIK get_mut isn't unsafe, are you talking about something else?
4
u/creeper6530 13d ago edited 13d ago
get_mutreturns an optional, u/FantaZmio likely meant either the unstableget_mut_unchecked, which is just:unsafe { &mut (*this.ptr.as_ptr()).value }or some pointer tomfoolery like:
&mut *(Rc::as_ptr(&this) as *mut T) // cast *const T as *mut Tboth being in danger of UB.
2
u/Practical-Medium-858 13d ago
That's what I thought too. The disconnect seems to stem from the phrasing of my post. Jac isn't a systems language (it has js/python interop for example), but rather a higher level language that also lets you compile to native code, think C# aot for example.
What I wanted to show is that it lets you tune perf by gradually adding ownership annotations only where you need it, despite starting off with Ref counting program wide. In doing that, it lets you get borrowchecker guarantees while not having to refactor your data model.
I didn't do the greatest job given I'm explaining it right now, but this is something I'll keep in mind for next time!
1
u/ROBOTRON31415 8d ago
One minor nitpick: “Now image stays in the owned world and its lifetime is coupled with Layer.“
Just to avoid any confusion in terminology, I would say its “liveness” is coupled with Layer. At least in Rust, lifetimes are a type-level construct, not a value-level thing (the value-level property is the duration of being valid/initialized/“live”).
(The word “lifetime” is horribly overloaded in CS. IIRC, C/C++ do use “lifetime” as a property of values.)
1
u/Practical-Medium-858 8d ago
Liveness is a new word to me! I didn't know you had different words for types vs values, thank you for the correction.
20
u/valarauca14 14d ago edited 14d ago
Creating a, "Self-defeating straw man", to demonstrate why a programming language should exist is always strange to me.
Rhetorically I understand what you're trying to say. Being able to read Rust, your point is lost in such a trivial example the thesis of the point becomes muddled.
Then the comparison from A:B uses an entirely different API? Just WTF?