grain icon indicating copy to clipboard operation
grain copied to clipboard

How should we handle mutable heap objects in runtime mode?

Open ospencer opened this issue 3 years ago • 0 comments

Maybe? The plan is for only malloc.gr and gc.gr to use runtime mode, so it might not be necessary. But it's not really just a problem for boxes; it's for anything that gets allocated in runtime mode that gets mutated by things outside of the runtime.

I actually thought about a couple of solutions for this:

  • The fake reference count of runtime objects is 1; could just set it to 0xefffffff. While this would work, I'd be worried about some large program that could decRef enough that the problem would occur, and it'd be a hell of a time debugging that.
  • Could alter free to never free anything in runtime land. Actually fairly easy to implement with lowish perf overhead, though I dislike that the reference counts for runtime values would be essentially random. That's more of an aesthetic problem though since the count doesn't matter at all.
  • Disallow mutable boxes/arrays/record fields in runtime mode. That'd completely prevent this (which is handy) though of course we couldn't use those constructs (which isn't a big deal since we don't need them, but it'd prevent doing backrefs for debugging like this, etc.).

But also maybe this comment is fine 🤷

Up to you if you want to make an issue for it.

Originally posted by @ospencer in https://github.com/grain-lang/grain/pull/1135#discussion_r815485017

ospencer avatar Mar 06 '22 03:03 ospencer