Stream: compiler development

Topic: interpreter reference counting


view this post on Zulip Anton (Jun 21 2025 at 09:32):

A random thing I've been wondering; for the first version of the interpreter can we simply not do any reference counting and just clean things up after execution is done?

view this post on Zulip Richard Feldman (Jun 21 2025 at 11:25):

yeah I'm already assuming that will happen, bc reference counting won't exist yet at that point, and it's only needed for performance, not correctness :grinning_face_with_smiling_eyes:

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 03:26):

Hmm.... I don't think this is correct. We definitely need reference counting in the interpreter, but it can be completely dealt at runtime...no pass required.

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 03:26):

But definitely required

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 03:27):

Cause we have to match the contract with the host and we have to free memory or risk ooms.

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 03:28):

It can all just be done adhoc at runtime when calling various functions/builtins or cloning a variable. So it won't be at all optimized....will just be part of the primitive operations and handling of scope

view this post on Zulip Luke Boswell (Jun 22 2025 at 04:08):

@Brendan Hansknecht we're not far from putting a super minimal interpreter together. We could almost do compile time eval adding a list of integers or something if we wanted to explore the above..

view this post on Zulip Richard Feldman (Jun 22 2025 at 04:41):

yeah sorry, this was just thinking in terms of internal interpreter for compile-time evaluation of constants

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 04:47):

You still would want refcounting for in place mutation and calls to zig builtins

view this post on Zulip Richard Feldman (Jun 22 2025 at 04:58):

right, the point is that it's not a blocker to getting up and running

view this post on Zulip Richard Feldman (Jun 22 2025 at 04:58):

obviously we want refcounting, it's just a question of what to do in which order :smile:

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 05:02):

Ah. Sure

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 05:03):

I just don't want us to design assuming we don't need it

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 05:03):

We 100% require it

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 05:03):

Also, I think it should be pretty easy to do on the fly as opposed to dealing with all the optimizations

view this post on Zulip Brendan Hansknecht (Jun 22 2025 at 05:03):

Mostly is just scope tracking and tracking which builtins require a refcount increment.


Last updated: Jul 06 2025 at 12:14 UTC