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

feat(ast_tools): allow defining foreign types with #[ast(foreign = ...)] #8866

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Feb 3, 2025

Allow informing oxc_ast_tools about foreign types in AST (e.g. NonMaxU32) and other types which it otherwise can't parse (e.g. RegExpFlags, which is generated by bitflags! macro).

Mechanism is #[ast(foreign = ...)] attr on another type which acts as a "stand-in" for the real one, similar to serde's remote derive feature.

bitflags! {
    pub struct RegExpFlags: u8 { /* ... */ }
}

/// This dummy type tells `oxc_ast_tools` about `RegExpFlags`
#[ast(foreign = RegExpFlags)]
struct RegExpFlagsAlias(u8);

Copy link
Contributor Author

overlookmotel commented Feb 3, 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-tools Area - AST tools C-enhancement Category - New feature or request labels Feb 3, 2025
@overlookmotel overlookmotel marked this pull request as ready for review February 3, 2025 16:19
@overlookmotel overlookmotel force-pushed the 02-03-feat_ast_tools_support_nonzero_primitives branch from a9d48f2 to 3fd392f Compare February 3, 2025 18:52
@overlookmotel overlookmotel force-pushed the 02-03-feat_ast_tools_allow_defining_foreign_types_with_ast_foreign_._ branch from bd2f2e1 to 482836b Compare February 3, 2025 18:52
@overlookmotel overlookmotel force-pushed the 02-03-feat_ast_tools_support_nonzero_primitives branch from 3fd392f to c5841cf Compare February 3, 2025 20:21
@overlookmotel overlookmotel force-pushed the 02-03-feat_ast_tools_allow_defining_foreign_types_with_ast_foreign_._ branch from 482836b to dc0a998 Compare February 3, 2025 20:22
@overlookmotel overlookmotel force-pushed the 02-03-feat_ast_tools_support_nonzero_primitives branch from c5841cf to 7b2a5a2 Compare February 3, 2025 21:52
@overlookmotel overlookmotel force-pushed the 02-03-feat_ast_tools_allow_defining_foreign_types_with_ast_foreign_._ branch from dc0a998 to 534c4f8 Compare February 3, 2025 21:53
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Feb 4, 2025
Copy link

graphite-app bot commented Feb 4, 2025

Merge activity

…..)]` (#8866)

Allow informing `oxc_ast_tools` about foreign types in AST (e.g. `NonMaxU32`) and other types which it otherwise can't parse (e.g. `RegExpFlags`, which is generated by `bitflags!` macro).

Mechanism is `#[ast(foreign = ...)]` attr on another type which acts as a "stand-in" for the real one, similar to `serde`'s [remote derive feature](https://serde.rs/remote-derive.html).

```rs
bitflags! {
    pub struct RegExpFlags: u8 { /* ... */ }
}

/// This dummy type tells `oxc_ast_tools` about `RegExpFlags`
#[ast(foreign = RegExpFlags)]
struct RegExpFlagsAlias(u8);
```
@graphite-app graphite-app bot force-pushed the 02-03-feat_ast_tools_support_nonzero_primitives branch from 7b2a5a2 to 440a439 Compare February 4, 2025 02:48
@graphite-app graphite-app bot force-pushed the 02-03-feat_ast_tools_allow_defining_foreign_types_with_ast_foreign_._ branch from 534c4f8 to 9072f4c Compare February 4, 2025 02:49
graphite-app bot pushed a commit that referenced this pull request Feb 4, 2025
Add `#[ast]` attr to `ScopeId`, `SymbolId` and `ReferenceId` types. This makes them an "official" part of the AST, and removes the hacky "special case" logic from `oxc_ast_tools` which was previously working around that they weren't registered as part of the AST.

This uses the `#[ast(foreign = ...)]` feature introduced in #8866 to inform `oxc_ast_tools` about the foreign `NonMaxU32` type, enabling the ID types to be parsed and understood.
graphite-app bot pushed a commit that referenced this pull request Feb 4, 2025
…ith alias type (#8868)

Use `#[ast(foreign = RegExpFlags)]` (introduced in #8866) on a dummy type to tell `oxc_ast_tools` about the properties of the `RegExpFlags` type.
Base automatically changed from 02-03-feat_ast_tools_support_nonzero_primitives to main February 4, 2025 03:14
@graphite-app graphite-app bot merged commit 9072f4c into main Feb 4, 2025
16 checks passed
@graphite-app graphite-app bot deleted the 02-03-feat_ast_tools_allow_defining_foreign_types_with_ast_foreign_._ branch February 4, 2025 03:21
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-ast-tools Area - AST tools C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant