Carp icon indicating copy to clipboard operation
Carp copied to clipboard

meta for "unmanaging" a value

Open scolsen opened this issue 3 years ago • 6 comments

Currently, memory management in Carp is determined at the type level. If there's some type T that implements delete, all values of T are subject to memory management.

In rare cases, there may be a value of T in a non-global, but wide scope (e.g. a register of a value of type T in a module) that in the resulting C code is effectively global (or actually global) but is wrapped in a scope in Carp for API ergonomic reasons. It'd be good to be able to mark these special values of T as unmanaged, even though T is managed to avoid needing to copy the global value around.

scolsen avatar Jan 11 '22 01:01 scolsen

Can you give an example of how this would look in code?

eriksvedang avatar Jan 11 '22 05:01 eriksvedang

I'm thinking something like (static foo) which could expand to (meta-set! foo static true). or maybe we'd call it unmanage? Not sure what the best terminology would be.

Then in the memory management system we'd just have an extra check for static = true before we emit deletion calls.

Or, if it's already possible to do this by other means, that's fine too. I just had a situation where I needed some special values of an otherwise managed type not to be deleted. You could fake it by defining a separate type for these values on the Carp side and defining conversion functions to the underlying type, but this is kind of tedious.

scolsen avatar Jan 11 '22 16:01 scolsen

OK, I see. I think we should think carefully about this one... for starters I don't think the meta information is available at that point. And even if the deleter isn't emitted, would you really want it to be handled as if it was managed? (with borrowing rules, and so on).

eriksvedang avatar Jan 12 '22 14:01 eriksvedang

Maybe marking them as refs with static lifetimes could work?

eriksvedang avatar Jan 12 '22 14:01 eriksvedang

Maybe marking them as refs with static lifetimes could work?

I think that both makes more sense and leads to greater consistency!

scolsen avatar Jan 12 '22 15:01 scolsen

@scolsen OK, cool! Please be aware that right now static lifetimes are a bit broken. So maybe you need to use the type trick mentioned in your original post.

eriksvedang avatar Jan 13 '22 05:01 eriksvedang