-
Notifications
You must be signed in to change notification settings - Fork 645
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
Add with statement support #1571
base: static_h
Are you sure you want to change the base?
Conversation
This commit introduces support for the with statement via IR, by replacing the previous AST transformation with a more robust alternative. **Logic:** - Identifiers are replaced with a conditional chain that checks the presence of a key in the object properties. - We need to keep track of each `with` statement depth. Hermes also uses a task queue to lazily compile functions, and for this reason, we also need to copy the `with` depths when adding the declaration to the queue. - Compared to an AST transformation, `buildConditionalChain` any call to the Builder will be executed in the same called order. This means we cannot generate the nested conditional chain starting from the inner condition. **Test262 results:** 92.98%. Cooled by trossimel
Hi @trossimel-sc! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
While the output is correct, I've noticed that when running in debug mode, it occasionally fails with the following message:
And in this case the IR output seems to be incorrectly generated. This issue arises specifically when a store operation is present within the let e = 20;
with (obj) {
e = 30;
} Is there a straightforward way to handle this case? I'm not very familiar with Hermes IR, so I'm unsure why this failure occurs, while the output is still correct. Thank you for your help! Please feel free to respond once my CLA is signed, if needed. —I hope this process won't take much longer. 🫤 |
@trossimel-sc I haven't reviewed the PR, but I compiled it and looked at the IR output of your example:
You are calling a helper method to check if AFAICT, instruction BTW, I think that we probably want a new bytecode instruction for this instead of calling a helper, but we can do that incrementally. Also, the helper should just be a "builtin", which is safer and easier to call. But these are details that we can address when we start the review. (We don't want to start reviewing before we know that we can accept the PR, I hope you understand) |
Thanks for the response and the assistance @tmikov |
great work 🎉 adding Fixes: #1056 to description should link the issue to this PR (auto-close on merge) |
Summary
This PR introduces support for the with statement via IR
createConditionalChainImpl
The changes are designed to minimize disruption. The logic only activates when a with statement is present, and the bulk of the implementation is located in a separate file,
ESTreeIRGen-with
.Test Plan