oxc-project / backlog

backlog for collborators only
1 stars 0 forks source link

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

Open overlookmotel opened 2 months ago

overlookmotel commented 2 months ago

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 commented 2 months ago

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,
}