-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic values are allocated on the stack during construction #48
Comments
The proposed fix has the following advantages:
EDIT: However, if a class does not have naked generic values, this method would have a small overhead (one extra function call, since all |
What do you think about auto-generating |
Right, it seems we always have to |
Yes, from what I've seen Auto generating |
You can think of generic values as byte arrays for all intents and purposes, with additional typechecking, automatic casting and nicer assignment (auto- This is why you always need to free them. |
Exactly right. This sounds really nice, however I'm now thinking that having to manually free everything except a generic variable simplifies the use of the language for anyone. It might even be more confusing that calling |
Sure, but generics are supposed to be baked into the language and automatically managed. MyCell: class <T> {
val: T
init: func (=val)
} I think it is reasonable to assume that the generic value will be cleaned up when calling EDIT: |
What actually happens when you do |
@marcusnaslund Your actual object still lives. |
That makes sense. In that case the auto free sounds perfectly reasonable to me. @thomasfanell knows more about rock than I do, though. |
Starting work on this. Auto generating |
Awesome. |
Having a bit of an issue with multiple evaluation of That means that not all EDIT: It seems you can devirtualize a call manually in rock source, yay! |
This issue is discussed in #41
Basically, in code like this:
The following C code is generated:
The result is that the generic value is actually a dangling pointer.
To solve this, one can currently do:
And then manually free the generic value.
As discussed in that PR, I believe the best course of action would be to automatically assume
__onheap__
for "naked" (non pointer) generic values and autogenerate a free function that deletes them and calls the user defined__destroy__
function (if a free function is not user defined).The text was updated successfully, but these errors were encountered: