-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Relay] Resolve cyclic dependency in Closure #4139
Comments
I am not sure I get it, as for recursive call we are capturing Variable, as opposed to the its binding I think this problem worth a bit of more thoughts. Essentially it was the same problem in the global modules, in which case we resolve by global var. Do you think if it is possible to do the same thing, eg lamda lift then only capture global vars. You will need the module map to be able to run closure |
@MarisaKirisame given that it is an interesting design question, can you open an RFC discuss thread ? |
let's take this standard program, the factorial, for example. |
consolidate to #4143 |
Right now relay leak memory for all of the executor (aot, interpreter, vm), for even the simplest program (id = fun x => x). They all happened to be caused by the exact same problem.
In Relay Implementation, a closure capture over all the free variables, holding a reference to all of them. However, it also hold a reference of itself (as long as it has a name, while ANF give everything a name). This make all closure cyclic data structure.
I propose to solve it by making the two following modification:
add a new Value, RecFunc. RecFunc hold a shared_ptr of a vector of closure, and a size_t index into it.
Every Closure will now have another field, a Map<Var, size_t> which store all recursive call (if any, including mutually recursive one) from the parent RecFunc.
This is in inspiration from https://cs.indiana.edu/ftp/techreports/TR73.pdf -
I will submit a PR soon, issuing here for visibility so ppl can avoid the same problem again.
The text was updated successfully, but these errors were encountered: