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(transfomer/using): remove use of child ids #9961

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

Conversation

camc314
Copy link
Contributor

@camc314 camc314 commented Mar 22, 2025

fixes #9744

@camc314 camc314 marked this pull request as ready for review March 22, 2025 00:08
@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Mar 22, 2025
Copy link
Contributor Author

camc314 commented Mar 22, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from d70450f to fd4b0c7 Compare March 22, 2025 00:11
Copy link

codspeed-hq bot commented Mar 22, 2025

CodSpeed Instrumentation Performance Report

Merging #9961 will not alter performance

Comparing c/03-22-fix_transfomer_using_remove_use_of_child_ids (021f76c) with main (2c53a72)

Summary

✅ 33 untouched benchmarks

@camc314 camc314 changed the base branch from c/03-22-fix_transformer_using_correctly_reparent_scopes_in_for_of_stmt to graphite-base/9961 March 22, 2025 00:33
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from fd4b0c7 to 9391d23 Compare March 22, 2025 11:12
@camc314 camc314 requested a review from Boshen as a code owner March 22, 2025 11:12
@camc314 camc314 force-pushed the graphite-base/9961 branch from 088e6a4 to 20ec38e Compare March 22, 2025 11:12
@camc314 camc314 changed the base branch from graphite-base/9961 to c/03-22-fix_transformer_using_correctly_reparent_scopes_in_for_of_stmt March 22, 2025 11:12
@github-actions github-actions bot added the A-semantic Area - Semantic label Mar 22, 2025
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from 9391d23 to 3cfc9f1 Compare March 22, 2025 11:15
@camc314 camc314 changed the base branch from c/03-22-fix_transformer_using_correctly_reparent_scopes_in_for_of_stmt to graphite-base/9961 March 22, 2025 11:16
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from 3cfc9f1 to f76a83b Compare March 22, 2025 11:20
@camc314 camc314 changed the base branch from graphite-base/9961 to c/03-22-fix_transformer_using_correctly_reparent_scopes_in_for_of_stmt March 22, 2025 11:20
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from f76a83b to 5973bbd Compare March 22, 2025 11:21
@camc314 camc314 force-pushed the c/03-22-fix_transformer_using_correctly_reparent_scopes_in_for_of_stmt branch from 20ec38e to 4c2e111 Compare March 22, 2025 11:21
@graphite-app graphite-app bot changed the base branch from c/03-22-fix_transformer_using_correctly_reparent_scopes_in_for_of_stmt to graphite-base/9961 March 24, 2025 11:41
@overlookmotel overlookmotel marked this pull request as draft March 24, 2025 11:46
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from 5973bbd to 7dffe96 Compare March 24, 2025 12:28
@github-actions github-actions bot added A-linter Area - Linter A-parser Area - Parser A-cli Area - CLI A-minifier Area - Minifier labels Mar 24, 2025
@github-actions github-actions bot added A-ast Area - AST A-codegen Area - Code Generation A-cfg Area - Control Flow Graph A-isolated-declarations Isolated Declarations A-ast-tools Area - AST tools A-editor Area - Editor and Language Server labels Mar 24, 2025
@camc314 camc314 marked this pull request as ready for review March 24, 2025 12:29
@camc314 camc314 requested a review from leaysgur as a code owner March 24, 2025 12:29
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from 7dffe96 to 3cdc653 Compare March 24, 2025 12:30
@camc314 camc314 force-pushed the graphite-base/9961 branch from 4c2e111 to 4eaf781 Compare March 24, 2025 12:30
@camc314 camc314 changed the base branch from graphite-base/9961 to c/03-22-fix_transformer_using_correctly_reparent_scopes_in_for_of_stmt March 24, 2025 12:30
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from 3cdc653 to 1c6f363 Compare March 24, 2025 12:40
@camc314 camc314 changed the base branch from c/03-22-fix_transformer_using_correctly_reparent_scopes_in_for_of_stmt to graphite-base/9961 March 24, 2025 12:41
@graphite-app graphite-app bot force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from 1c6f363 to fe95aeb Compare March 24, 2025 12:54
@graphite-app graphite-app bot force-pushed the graphite-base/9961 branch from 4eaf781 to 2c53a72 Compare March 24, 2025 12:54
@graphite-app graphite-app bot changed the base branch from graphite-base/9961 to main March 24, 2025 12:54
@graphite-app graphite-app bot force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from fe95aeb to 34ddbd7 Compare March 24, 2025 12:54
@camc314 camc314 removed A-linter Area - Linter A-parser Area - Parser A-cli Area - CLI A-minifier Area - Minifier A-ast Area - AST A-codegen Area - Code Generation A-cfg Area - Control Flow Graph A-isolated-declarations Isolated Declarations A-ast-tools Area - AST tools A-editor Area - Editor and Language Server labels Mar 24, 2025
@@ -677,6 +677,12 @@ impl Scoping {
});
}

pub fn remove_child_scope(&mut self, scope_id: ScopeId, child_scope_ids: ScopeId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn remove_child_scope(&mut self, scope_id: ScopeId, child_scope_ids: ScopeId) {
pub fn remove_child_scope(&mut self, scope_id: ScopeId, child_scope_id: ScopeId) {

Comment on lines 681 to 688
self.cell.with_dependent_mut(|_allocator, cell| {
cell.scope_child_ids[scope_id.index()].retain(|scope_id| *scope_id != child_scope_ids);
});
Copy link
Contributor

@overlookmotel overlookmotel Mar 24, 2025

Choose a reason for hiding this comment

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

What I was trying to say in previous comment is that this can be more efficient than remove_child_scopes, because you're only removing a single ID.

let child_ids = &mut cell.scope_child_ids[scope_id.index()];
let index = child_ids.iter().position(|&scope_id| scope_id == child_scope_id).unwrap();
child_ids.swap_remove(index);

Note that retain shifts up all following entries in the Vec (slow if there's lots of them), whereas swap_remove just moves 1 entry (same cheap cost, no matter how many entries in the Vec). And position will only search until it finds 1st match, whereas retain will carry on searching all the entries after its found a match (wasted work in this case because there can be only 1 match).

Warning: The unwrap() will panic if the ScopeId isn't found. That means this method must not be called unless the option to record child scope IDs is enabled. Method needs a comment to that effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahhh i see, thanks for explaining

Comment on lines 728 to 740
fn create_try_stmt(
body: BlockStatement<'a>,
catch: ArenaBox<'a, CatchClause<'a>>,
finally: ArenaBox<'a, BlockStatement<'a>>,
ctx: &TraverseCtx<'a>,
) -> Statement<'a> {
ctx.ast.statement_try(SPAN, body, Some(catch), Some(finally))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think more logic could be moved into this method - like generating the CatchClause and finally BlockStatement too. Unless I'm missing something, that logic looks identical across all the call sites too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah you're right. when i origannally looked, i thought there'd end up being a ton of args, but since the catch/finalizer are basically have the same args, it's not bad

@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from 34ddbd7 to 021f76c Compare March 24, 2025 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-semantic Area - Semantic A-transformer Area - Transformer / Transpiler C-bug Category - Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transformer: using crashes
2 participants