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

fix(oxc_transform): overlap replacement #7621

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

IWANABETHATGUY
Copy link
Contributor

@IWANABETHATGUY IWANABETHATGUY commented Dec 3, 2024

Copy link

graphite-app bot commented Dec 3, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link
Contributor Author

IWANABETHATGUY commented Dec 3, 2024

@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Dec 3, 2024
@IWANABETHATGUY IWANABETHATGUY force-pushed the 12-04-fix_overlap_replacement branch from ded4b7b to 04312f6 Compare December 3, 2024 16:43
Copy link
Contributor Author

Since TraverseCtxt has no functionality to skip visit sub tree(Fix me if I am wrong, I don't find the usage in codebase).
Need to lock the sub tree if one ast node is replaced by some value.
TODO:
if overlap appears in AssignmentExpr the output should still be wrong, since we can't get address of AssignmentExpression for now.

@overlookmotel any chance to implement ToAddress for AssignmentExpression ?

@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review December 3, 2024 16:47
Copy link

codspeed-hq bot commented Dec 3, 2024

CodSpeed Performance Report

Merging #7621 will not alter performance

Comparing 12-04-fix_overlap_replacement (f7d41dd) with main (ac910ee)

Summary

✅ 29 untouched benchmarks

@overlookmotel
Copy link
Contributor

overlookmotel commented Dec 4, 2024

Since TraverseCtxt has no functionality to skip visit sub tree(Fix me if I am wrong, I don't find the usage in codebase).

Correct. Traverse has no facility to skip visiting sub tree at present. We could look at adding that, but it might cause quite a performance regression, as it'd introduce an extra check and branch after every single AST node.

The way you are handling it here seems like a good option in meantime, especially as the subtree is likely small, so not a great cost to visiting it.

TODO: if overlap appears in AssignmentExpr the output should still be wrong, since we can't get address of AssignmentExpression for now.

@overlookmotel any chance to implement ToAddress for AssignmentExpression ?

I'm not familiar with the define plugin, so not sure what you mean by "overlap". Can you give an example showing the problem with AssignmentExpression?

@IWANABETHATGUY
Copy link
Contributor Author

Since TraverseCtxt has no functionality to skip visit sub tree(Fix me if I am wrong, I don't find the usage in codebase).

Correct. Traverse has no facility to skip visiting sub tree at present. We could look at adding that, but it might cause quite a performance regression, as it'd introduce an extra check and branch after every single AST node.

The way you are handling it here seems like a good option in meantime, especially as the subtree is likely small, so not a great cost to visiting it.

TODO: if overlap appears in AssignmentExpr the output should still be wrong, since we can't get address of AssignmentExpression for now.
@overlookmotel any chance to implement ToAddress for AssignmentExpression ?

I'm not familiar with the define plugin, so not sure what you mean by "overlap". Can you give an example showing the problem with AssignmentExpression?

Here is one, https://esbuild.github.io/try/#dAAwLjI0LjAAewogIGRlZmluZTogewogICAgJ2ltcG9ydC5tZXRhLmVudi5GT08nOiAnaW1wb3J0Lm1ldGEuZW52LkZPTycsCiAgICAnaW1wb3J0Lm1ldGEuZW52JzogJ19fZm9vX18nLAogIH0sCn0ACmNvbnNvbGUubG9nKAoJW2ltcG9ydC5tZXRhLmVudi5GT08gPSAwXQopCg, you could see
both
import.meta.env.FOO and import.meta.env matched part of import.meta.env.FOO
for esbuild it will replace import.meta.env.FOO to import.meta.env.FOO and skip visit sub tree.

but for us,
we first replace import.meta.env.FOO to import.meta.env.FOO, then visit the child import.meta.env, and replace it to
__foo__, so the final output should be __foo__.FOO

@IWANABETHATGUY IWANABETHATGUY force-pushed the 12-04-fix_overlap_replacement branch from 04312f6 to 4fce07e Compare December 5, 2024 02:20
@IWANABETHATGUY IWANABETHATGUY changed the title fix overlap replacement fix(oxc_transform): overlap replacement Dec 5, 2024
@github-actions github-actions bot added the C-bug Category - Bug label Dec 5, 2024
@IWANABETHATGUY IWANABETHATGUY force-pushed the 12-04-fix_overlap_replacement branch 5 times, most recently from e5cde8b to f6c6399 Compare December 5, 2024 13:21
Copy link
Contributor

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the comments I've made, looks good.

But could you please add some comments about what ast_node_lock is and how it works?

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Dec 6, 2024
Copy link
Contributor

overlookmotel commented Dec 6, 2024

Merge activity

  • Dec 6, 10:26 AM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Dec 6, 10:26 AM EST: A user added this pull request to the Graphite merge queue.
  • Dec 6, 10:33 AM EST: A user merged this pull request with the Graphite merge queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-transformer Area - Transformer / Transpiler C-bug Category - Bug
Projects
None yet
2 participants