[PRISM] Refactor local table lookups #9544
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Properly fixes ruby/prism#2053 (after a partial fix in #9445)
This PR refactors the methods prism was using to look for local variables. It does a few things:
Binds together the depth of the required local table, and the index into the table into a tuple
pm_local_index_t, so that we don't have to pass pointers to manipulate into the lookup functions.Reduces the API surface - previously we had 3 different ways for looking up local variables depending on whether we wanted to recurse or not, or start from a specific depth. Now we have a single function,
pm_lookup_local_index, that always starts from the current depth and recurses if it doesn't find a local. This matches Ruby semantics where variables defined in outer scope are always visible from inner scopes.Removes
scope_node->local_depth_offset. This method of selecting the local table hasn't worked out as well as I'd hoped. Because for deeply nested scopes it's not possible to accurately set the offset such that it'll work in all cases. Starting from the current scope and walking the tree until a local is found means that we don't need this functionality at all anymore.