You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
inl main() =
inl ~x : option i32 = None
match x with
| Some: x => x
| None => 0
cdef class US0:
cdef readonly unsigned long tag
cdef class US0_0(US0): # none
def __init__(self): self.tag = 0
cdef class US0_1(US0): # some_
cdef readonly signed long v0
def __init__(self, signed long v0): self.tag = 1; self.v0 = v0
cpdef signed long main():
cdef US0 v0
cdef signed long v1
v0 = US0_0()
if v0.tag == 0: # none
return 0
elif v0.tag == 1: # some_
v1 = (<US0_1>v0).v0
return v1
Right now there is no difference between how stack (non-recursive) and heap (recursive) unions are compiled in the Cython backend. I had no choice, but to do a heap implementation for both of them.
Cython's cdef unions are not the right tool for the job. Not only do they not support Python objects, even if they did, the memory management system would not be able to handle them. So unless I want to mess with memory management and pointer myself in the backend, I have no choice but to leave the implementation as it is for the time being.
The result of that is that option types will have to go through the heap and be less efficient as a result.
But overall this issue is not as high priority as stack tuples.
The text was updated successfully, but these errors were encountered:
I suppose the option type could be optimized for extension types and objects to just check whether they are None instead of wrapping them with the union wrapper. But this is not particularly important for me.
Much like with stack tuples, the main benefit of stack unions would be that they avoid the heap allocation of heap unions. That fact that the tag field would take some extra space on the stack is trivial in comparison.
This particular feature even F# got recently.
Right now there is no difference between how stack (non-recursive) and heap (recursive) unions are compiled in the Cython backend. I had no choice, but to do a heap implementation for both of them.
Cython's cdef unions are not the right tool for the job. Not only do they not support Python objects, even if they did, the memory management system would not be able to handle them. So unless I want to mess with memory management and pointer myself in the backend, I have no choice but to leave the implementation as it is for the time being.
The result of that is that option types will have to go through the heap and be less efficient as a result.
But overall this issue is not as high priority as stack tuples.
The text was updated successfully, but these errors were encountered: