Simplify binder flow. (alternate approach)#2843
Merged
Merged
Conversation
We now only recurse in a single place in the binder. The rest of the binding code is only concerned with how to bind a single node to a symbol and add that symbol to a symbol table. Recursion is handled as a separate concern, greatly simplifying binder flow.
Don't use SymbolFlags to direct how we handle containers in the binder. Instead, Just determine what we should do based on the .kind of the node itself, and nothing more.
Member
|
@CyrusNajmabadi should |
Contributor
There was a problem hiding this comment.
can we use bit shifts instead of hex values? personally I find bit shifts easier to reason about current\subsequent values of the flag since next value of the shift is always +1 to the current one
Contributor
|
looks good! |
Contributor
|
👍 I think this is a good augmentation of your prior change #2832 |
Contributor
|
Any movement on this? |
Conflicts: src/compiler/binder.ts
CyrusNajmabadi
added a commit
that referenced
this pull request
Jun 3, 2015
Simplify binder flow. (alternate approach)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This approach differs from PR #2832 in that it no longer uses SymbolFlags to control recursion and container setting logic in the binder. Instead, we simply use the kind of the node we're currently on to determine what to do. I personally think this is much cleaner and simpler, but i'm sending it out to see what other people think. If you've already reviewed the previous PR, then you only have to start looking at this one with the commits starting on April 20th.
CR notes: I recommend reading this CR one commit at a time to better understand what's going on.
Previously, it was very difficult to reason about the flow of the binder. Different parts of the binder recursed in different ways. For example, some codepaths called
bindChildren. Others calledforEachChild(node, bind). Some codepaths did not recurse, but were called from paths that woudl then laterbreakout and recurse. This made it very easy to end up doing something wrong if you accidentallyreturned early. It was also very difficult to know if you should should recurse if you were inbindorbindDeclarationorbindAnonymousDeclaration. The answer was always "it depends".I've gone in and completely unified the recursion logic in the binder. The top level logic looks like this now:
That's it. Individual binding functions never need to worry about recursing. Instead, they just deal with the node they have, and they top level bind driver will always be responsible for recursing. This makes things much easier to reason about and provides a consistent framework for future binding code to follow.