meta for "unmanaging" a value
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.
Can you give an example of how this would look in code?
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.
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).
Maybe marking them as refs with static lifetimes could work?
Maybe marking them as refs with static lifetimes could work?
I think that both makes more sense and leads to greater consistency!
@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.