Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 21, 2025

Remove the serialize_ts_element method added in #9913, and instead expose an INCLUDE_TS_FIELDS constant on Serializer trait.

Before:

if let Some(this_param) = &self.0.this_param {
    seq.serialize_ts_element(this_param);
}

After:

if S::INCLUDE_TS_FIELDS {
    if let Some(this_param) = &self.0.this_param {
        seq.serialize_element(this_param);
    }
}

This has one slight advantage. Because INCLUDE_TS_FIELDS is a constant, compiler will easily be able to prove that the code inside if S::INCLUDE_TS_FIELDS { ... } is dead code in the JS-only AST serializer, and remove it.

In this specific case, the TS-only logic is trivial, so compiler would probably see it could be optimized out anyway. But we may encounter other cases where more complex TS-only code is required, and compiler might not be able to prove that it's dead code in those cases.

Copy link
Member Author

overlookmotel commented Mar 21, 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.

@github-actions github-actions bot added A-ast Area - AST C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Mar 21, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 21, 2025

CodSpeed Instrumentation Performance Report

Merging #9943 will not alter performance

Comparing 03-21-refactor_ast_estree_expose_include_ts_fields_constant_on_serializer_ (dc3e725) with main (8228b74)

Summary

✅ 33 untouched benchmarks

@overlookmotel overlookmotel marked this pull request as ready for review March 21, 2025 07:42
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Mar 21, 2025
Copy link
Member Author

overlookmotel commented Mar 21, 2025

Merge activity

  • Mar 21, 3:45 AM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Mar 21, 3:45 AM EDT: A user added this pull request to the Graphite merge queue.
  • Mar 21, 3:54 AM EDT: A user merged this pull request with the Graphite merge queue.

…zer` (#9943)

Remove the `serialize_ts_element` method added in #9913, and instead expose an `INCLUDE_TS_FIELDS` constant on `Serializer` trait.

Before:

```rs
if let Some(this_param) = &self.0.this_param {
    seq.serialize_ts_element(this_param);
}
```

After:

```rs
if S::INCLUDE_TS_FIELDS {
    if let Some(this_param) = &self.0.this_param {
        seq.serialize_element(this_param);
    }
}
```

This has one slight advantage. Because `INCLUDE_TS_FIELDS` is a constant, compiler will easily be able to prove that the code inside `if S::INCLUDE_TS_FIELDS { ... }` is dead code in the JS-only AST serializer, and remove it.

In this specific case, the TS-only logic is trivial, so compiler would probably see it could be optimized out anyway. But we may encounter other cases where more complex TS-only code is required, and compiler might not be able to prove that it's dead code in those cases.
@graphite-app graphite-app bot force-pushed the 03-21-fix_ast_estree_fix_ts_type_def_for_tsthisparameter_ branch from d587d45 to 9d1035e Compare March 21, 2025 07:46
@graphite-app graphite-app bot force-pushed the 03-21-refactor_ast_estree_expose_include_ts_fields_constant_on_serializer_ branch from 14b2ebc to dc3e725 Compare March 21, 2025 07:46
Base automatically changed from 03-21-fix_ast_estree_fix_ts_type_def_for_tsthisparameter_ to main March 21, 2025 07:52
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 21, 2025
@graphite-app graphite-app bot merged commit dc3e725 into main Mar 21, 2025
26 checks passed
@graphite-app graphite-app bot deleted the 03-21-refactor_ast_estree_expose_include_ts_fields_constant_on_serializer_ branch March 21, 2025 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants