Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/oxc_ast/src/generated/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,10 @@ impl GetSpan for AstKind<'_> {
}

impl GetAddress for AstKind<'_> {
/// Get [`Address`] of an [`AstKind`].
// This boils down to 1 instruction.
// In all cases, it gets the pointer from the reference in the `AstKind`.
#[inline]
fn address(&self) -> Address {
match *self {
Self::Program(it) => it.unstable_address(),
Expand Down
15 changes: 6 additions & 9 deletions tasks/ast_tools/src/generators/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ impl Generator for AstKindGenerator {
for type_def in &schema.types {
let has_kind = match type_def {
TypeDef::Struct(struct_def) => struct_def.kind.has_kind,
TypeDef::Enum(enum_def) => enum_def.kind.has_kind,
_ => false,
};
if !has_kind {
Expand All @@ -101,12 +100,7 @@ impl Generator for AstKindGenerator {

span_match_arms.extend(quote!( Self::#type_ident(it) => it.span(), ));

let get_address = match type_def {
TypeDef::Struct(_) => quote!(it.unstable_address()),
TypeDef::Enum(_) => quote!(it.address()),
_ => unreachable!(),
};
address_match_arms.extend(quote!( Self::#type_ident(it) => #get_address, ));
address_match_arms.extend(quote!( Self::#type_ident(it) => it.unstable_address(), ));

let set_node_id = match type_def {
TypeDef::Struct(struct_def)
Expand Down Expand Up @@ -224,8 +218,11 @@ impl Generator for AstKindGenerator {

///@@line_break
impl GetAddress for AstKind<'_> {
// TODO: Once only structs have `AstKind`s (https://github.com/oxc-project/oxc/issues/11490),
// mark this method `#[inline]`, because then it'll be boiled down to a single instruction.
///@@line_break
/// Get [`Address`] of an [`AstKind`].
///@ This boils down to 1 instruction.
///@ In all cases, it gets the pointer from the reference in the `AstKind`.
#[inline]
fn address(&self) -> Address {
match *self {
#address_match_arms
Expand Down
Loading