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

Add explicit discriminants to all enums in #[ast] macro #123

Open
overlookmotel opened this issue Aug 3, 2024 · 1 comment
Open

Add explicit discriminants to all enums in #[ast] macro #123

overlookmotel opened this issue Aug 3, 2024 · 1 comment
Labels
A-ast Area - AST

Comments

@overlookmotel
Copy link

oxc-project/oxc#4614 made all AST types #[repr(C)]. To complete the work of making everything about the AST's in-memory representation predictable and guaranteed, we need to add explicit discriminants to all enums.

We can do this in the #[ast] macro rather than writing them out by hand. I think we can consider enum discriminants as an internal implementation detail, which does not need to be visible from reading the type defs. The discriminants we set will be the same as Rust compiler would set anyway.

e.g.:

#[ast]
pub enum PropertyKind {
    Init = 0,
    Get = 1,
    Set = 2,
}
@overlookmotel
Copy link
Author

Just to clarify, I mean that #[ast] macro will add the discriminants:

Type def in js.rs:

#[ast]
pub enum PropertyKind {
    Init,
    Get,
    Set,
}

after #[ast] macro expansion:

#[repr(u8)]
pub enum PropertyKind {
    Init = 0,
    Get = 1,
    Set = 2,
}

overlookmotel referenced this issue in oxc-project/oxc Aug 6, 2024
Related to #4622 but doesn't close it.
@Boshen Boshen unassigned rzvxa Oct 9, 2024
@Boshen Boshen transferred this issue from oxc-project/oxc Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast Area - AST
Projects
None yet
Development

No branches or pull requests

2 participants