[VM] Iterative drop of vm values - #374
Conversation
musitdev
left a comment
There was a problem hiding this comment.
It seems fine. My only remarks is that there can have some memory leak because ValueImpls can contain a ValueImpls that point to the initial ValueImpls, creating a reference cycle. So the ValueImpls are never dropped.
I don't know if it's possible in the usage but if yes the case can be avoid by using a new container enum and a struct with Weak ref like:
pub(crate) struct WeakValueImpls(Weak<RefCell<Vec<ValueImpl>>>);
enum Container {
...
Parent(WeakValueImpls),
}
|
@musitdev Thanks for pointing out. Cyclic values shouldn't be constructed given the Move type system. I'll see if it's worth the extra effort to prevent against this. |
|
I'll also investigate if closure dropping can be unbounded. |
seanyoung
left a comment
There was a problem hiding this comment.
This code is tricky, it really needs a big fat comment and a test case.
Ideally, I would like to see a different fix. I do realise this might not be simple or might cost too much time. If we allow types to be nested 40,000 deep, then surely we will encounter all sorts of problems.
I think there should be some limit on the type depth rather than working around the problems of the same types in rust (e.g. recursion in Drop). I suspect there will be other problems For example, validator CPU cycles, 40,000 malloc's and free's are very costly too.
|
Yes, if the depth can be limited, it will be better. In fact, how big trees can be constructed in this context? |
998fce4 to
2af6533
Compare
Description
Implements a custom drop for values to prevent overflow when dropping deeply nested values.
How Has This Been Tested?
All existing vm tests.
Type of Change
Which Components or Systems Does This Change Impact?