r/programming • • Sep 19 '26

What if only one allocation needs to be borrow checked in a managed program?

https://nitinm.dev/blog/gradual_ownership_in_a_high_level_language
11 Upvotes

9 comments sorted by

20

u/valarauca14 Sep 19 '26 edited Sep 19 '26 • Bravo

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?

2

u/Practical-Medium-858 Sep 19 '26 edited Sep 19 '26

Hey! I really appreciate the critique.

Quick disclaimer: Jac is worked on by people much smarter than me, though I contribute occasionally, and its main strengths go well beyond the ownership model. This was just one part of the language that I found neat!

I agree that the original examples were unfair/trivial and didn’t make the comparison clearly enough, so I’ve updated the post to use the same data flow and API shape on both sides.

The point I was trying to make is that Jac lets me introduce ownership into the parts of the program only when it's needed, versus having it be the model for the entire program, while the rest of the application remains managed, like Swift for example.

1

u/ROBOTRON31415 Sep 24 '26

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 Sep 24 '26

Liveness is a new word to me! I didn't know you had different words for types vs values, thank you for the correction.

18

u/[deleted] Sep 19 '26

[removed] — view removed comment

2

u/Practical-Medium-858 Sep 19 '26

AFAIK get_mut isn't unsafe, are you talking about something else?

6

u/creeper6530 Sep 19 '26 edited Sep 19 '26

get_mut returns an optional, u/FantaZmio likely meant either the unstable get_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 T

both being in danger of UB.

2

u/Practical-Medium-858 Sep 19 '26

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!