Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 14, 2025

Previously if you edited an AST struct, adding or removing fields, #[ast] macro would panic because the fields of the struct don't match what it's expecting from the STRUCTS metadata which is generated by oxc_ast_tools.

It would cover the whole struct with red squiggles, with a cryptic error message. This was really annoying.

Instead, make the macro output a compile_error! macro invocation. This makes IDE and cargo build show an error saying that you need to run just ast to re-run the codegen. Also, because the macro doesn't crash any more, you don't have to re-start Rust Analyser once you've fixed the problem.

This is less annoying for humans, and also the more helpful error message will hopefully point AI in the right direction.

Copy link
Member Author

overlookmotel commented Aug 14, 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 the C-bug Category - Bug label Aug 14, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 14, 2025

CodSpeed Instrumentation Performance Report

Merging #13102 will not alter performance

Comparing 08-14-fix_ast_macros_do_not_panic_in_macro (d676e04) with main (c138fad)1

Summary

✅ 34 untouched benchmarks

Footnotes

  1. No successful run was found on main (d676e04) during the generation of this report, so c138fad was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel marked this pull request as ready for review August 14, 2025 20:38
@overlookmotel overlookmotel marked this pull request as draft August 14, 2025 20:38
@overlookmotel overlookmotel marked this pull request as ready for review August 14, 2025 21:14
@graphite-app graphite-app bot changed the base branch from 08-14-refactor_ast_macros_simplify_code to graphite-base/13102 August 16, 2025 15:01
@graphite-app graphite-app bot force-pushed the graphite-base/13102 branch from e582c0a to c63c944 Compare August 16, 2025 15:06
@graphite-app graphite-app bot force-pushed the 08-14-fix_ast_macros_do_not_panic_in_macro branch from a9002da to abd344c Compare August 16, 2025 15:06
@graphite-app graphite-app bot changed the base branch from graphite-base/13102 to main August 16, 2025 15:07
@graphite-app graphite-app bot force-pushed the 08-14-fix_ast_macros_do_not_panic_in_macro branch from abd344c to 304011c Compare August 16, 2025 15:07
Copilot AI review requested due to automatic review settings August 16, 2025 17:30
@overlookmotel overlookmotel force-pushed the 08-14-fix_ast_macros_do_not_panic_in_macro branch from 304011c to edd0a0e Compare August 16, 2025 17:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves error handling in the #[ast] macro to provide better developer experience when AST structs are modified. Previously, the macro would panic with cryptic errors when struct fields didn't match the generated metadata, requiring IDE restarts. Now it generates helpful compile errors that guide users to run the codegen.

  • Replaced panic behavior with graceful error handling using compile_error! macro
  • Added better error messages directing users to run just ast for codegen
  • Improved robustness of the assert_generated_derives function by handling parsing failures gracefully

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Aug 18, 2025
Copy link
Member Author

overlookmotel commented Aug 18, 2025

Merge activity

@camc314 camc314 force-pushed the 08-14-fix_ast_macros_do_not_panic_in_macro branch from edd0a0e to 3c30069 Compare August 18, 2025 20:02
Previously if you edited an AST struct, adding or removing fields, `#[ast]` macro would panic because the fields of the struct don't match what it's expecting from the `STRUCTS` metadata which is generated by `oxc_ast_tools`.

It would cover the whole struct with red squiggles, with a cryptic error message. This was really annoying.

Instead, make the macro output a `compile_error!` macro invocation. This makes IDE and `cargo build` show an error saying that you need to run `just ast` to re-run the codegen. Also, because the macro doesn't crash any more, you don't have to re-start Rust Analyser once you've fixed the problem.

This is less annoying for humans, and also the more helpful error message will hopefully point AI in the right direction.
@graphite-app graphite-app bot force-pushed the 08-14-fix_ast_macros_do_not_panic_in_macro branch from 3c30069 to d676e04 Compare August 18, 2025 22:19
@graphite-app graphite-app bot merged commit d676e04 into main Aug 18, 2025
24 checks passed
@graphite-app graphite-app bot deleted the 08-14-fix_ast_macros_do_not_panic_in_macro branch August 18, 2025 22:25
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants