Implement proper 'this' capturing for local functions (#14736)
Currently, when a local function is captured inside another local function or lambda it can capture 'this' without generating a frame. This is useful, but when that lambda is itself captured then the capturing closure must also capture the frame pointer, namely 'this'. Currently, local function frame pointers are not correctly captured when the captured local function itself captures something from a "higher" scope than the capturing local function. This change solves this problem by: 1) Considering a local function's captured variables when deciding its scope. If the local function captures variables from a higher scope, that local function will be analyzed as belonging to the "higher" scope, causing that local function to register for frame capturing. 2) Since the proxies for capturing frames are not available at the time of local function reference rewriting, the proxies must be saved. There is a new temporary bound node for this purpose, PartiallyLoweredLocalFunctionReference, that stores the proxies and the underlying node for later use during the rewriting phase. This node should never make it past LocalFunctionReferenceRewriting. When these steps are completed, local functions should act very similarly to all other captured variables with different frames, where the frame pointers are captured and walked in a linked list in order to access the target with the proper receiver/frame pointer.
Showing
想要评论请 注册 或 登录