Open alexnask opened 8 years ago
call
free()
without casting all your Funcs into Closures.
This would make so, so, happy. :)
@marcusnaslund
I guessed so, and I see no reason why it shouldn't work when Func types are already baked in and considered as Closure by rock.
I'm curious, what is the underlying difference between a Closure
and a Func
, and why are they two different types?
@marcusnaslund
As far as I am aware, there is no actual difference between the types in the C output.
The two types are exactly the same, which is why you can cast from one to another without issues in ooc.
Using Func types assumes a Closure type with a thunk and context Pointer is defined by the SDK and that is about it.
Now, Func types are needed to keep type information about the closure and ensure typechecking, since a Closure is simply a pair of Pointers (casting a Func to a Closure means you don't know how to call it anymore).
In other words, Func types are not actually defined anywhere (as opposed to pretty much every other type in ooc), they behave as (and expect) Closures but are a necessity for typecheking and calling the functions correctly.
Interesting, thanks. Sounds like an easy fix, then.
Shouldn't be too difficult, especially making the types compatible.
The access stuff could be a little bit more tricky but I do think it's pretty straightforward.
I will be trying to fix #998 today and then I'll be on this one.
Concretely, you should be able to access Closure fields and methods without having to cast a Func into a Closure.
Func should really just be used to specify the type of the raw function pointer (thunk) stored by the Closure.
In the bundled sdk, this change has two small effects:
In ooc-kean, this helps with cleaning up closures, since you can call
free()
without casting all your Funcs into Closures.All in all, I believe this is the kind of small features that should be acceptable, since it is just a small quality of life improvement regarding two baked-in types that have been known to be a hassle to work together, while they effectively represent the same thing.