Skip to content

[Relay][RFC] Resolve cyclic dependency in Closure #4143

@MarisaKirisame

Description

@MarisaKirisame

see #4139 .
Currently, relay evaluate a function to a closure. It contain both the code of the function, and a mapping of every free variable inside that function, to the value of the free variable. when a closure is invoked, that mapping is used for the free variable. This is needed because the default approach, looking up the value from the environment (also known as dynamic binding), is buggy and will cause incorrect evaluation.
However, when a recursive closure is created, the mapping will contain value of every free variable - including the recursive function, and, subsequently, the closure itself!
I propose to add the following value, a RecValue, and a RecTable.
A RecValue is a shared_ptr of a RecTable, and a size_t index.
A RecTable is a vector of Closure.
Additionally, every closure will now have a Map<Variable, size_t> mapping, which store value of mutually recursive variable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions