Skip to content
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

Param scope and body scope should not be merged on this case. #6290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

akroshg
Copy link
Contributor

@akroshg akroshg commented Sep 19, 2019

When the param is used in the function, defined at the param scope, we should be have different param and body scope for the the enclosing function.
However we are using the function id from the top ref of the pidRefStack. This is not correct as we could have pushed a ref on the stack with different block id
but for the same function - so this logic could break.
For fixing that we should walk that pidRefStack to see if there is access to the inner function.

When the param is used in the function, defined at the param scope, we should be have different param and body scope for the the enclosing function.
However we are using the function id from the top ref of the pidRefStack. This is not correct as we could have pushed a ref on the stack with different block id
but for the same function - so this logic could break.
For fixing that we should walk that pidRefStack to see if there is access to the inner function.
@pleath
Copy link
Contributor

pleath commented Sep 20, 2019

So why isn’t the capture found when we do binding, which pops the stack? It shouldn’t be necessary to walk it like this.

@akroshg
Copy link
Contributor Author

akroshg commented Sep 20, 2019

@pleath Because of deferparsing. As we already merged the param scope and body scope - but while restoring from the scopeinfo we don't have that detail anymore thus the param scope does not have anything (as they were merged already).

@pleath
Copy link
Contributor

pleath commented Sep 20, 2019

I had a feeling. So this is really about the way the stack is reconstructed.

@akroshg
Copy link
Contributor Author

akroshg commented Sep 20, 2019

the pidrefstack is ordered for block id. So we could not find out if the current symbol is used in the nested function.

@pleath
Copy link
Contributor

pleath commented Sep 20, 2019

Binding does find all the non-local references without walking the stack. If there’s a problem that only occurs with deferred parsing, it’s almost certainly because things are not set up correctly when we read the scope info. That could cause other problems besides this one.

@akroshg
Copy link
Contributor Author

akroshg commented Sep 20, 2019

Since we did not correctly find out that param scope and body scope need not merge - that put wrong information while saving the scope info. Later when restore when we did not restore the param scope.
Binding which finds out the non-local references happens later after FinishFncDecl. But the ResetBodyAndParamScopeMerged happens in the ParseFncDeclHelper and before FinishFncDecl.
The top ref in pidRefStack is not ordered based on the functionId so the only way I can find that out is to walk the stack. I thought of reconstructing the stack in the functionId order - but that will slow down the pushing part even in in the case where we don't have default arg.

@pleath
Copy link
Contributor

pleath commented Sep 20, 2019

Okay. That makes sense. So the problem is not with binding or discovery of non-local references, which we do eventually find. It’s having incomplete information when we save scope info. Is that right?

@akroshg
Copy link
Contributor Author

akroshg commented Sep 20, 2019

Yes. Moreover the ResetBodyandParamScopeMerge is using the incomplete information. Which eventually get stored in the scope info.

@pleath
Copy link
Contributor

pleath commented Sep 23, 2019

Is there a reason we can’t wait until the information is complete before saving scope info?

@akroshg
Copy link
Contributor Author

akroshg commented Sep 23, 2019

Looking at the code at ParseFncDeclHelper, it seems we make use of that information up-front to at the body scope creation and push those symbols to the body scope based on if they are needed to merge or not.
@aneeshdk if he can recollect why it was done before binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants