Skip to content

Commit

Permalink
refactor(ast)! move span to always be the first struct field
Browse files Browse the repository at this point in the history
For consistency. And maybe a small performance improvement when enum
bytes are aligned.
  • Loading branch information
Boshen committed Dec 12, 2024
1 parent 358d375 commit ff61017
Show file tree
Hide file tree
Showing 18 changed files with 253 additions and 240 deletions.
10 changes: 5 additions & 5 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,8 +1570,8 @@ pub struct BindingRestElement<'a> {
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash, ESTree)]
pub struct Function<'a> {
pub r#type: FunctionType,
pub span: Span,
pub r#type: FunctionType,
/// The function identifier. [`None`] for anonymous function expressions.
pub id: Option<BindingIdentifier<'a>>,
/// Is this a generator function?
Expand Down Expand Up @@ -1738,8 +1738,8 @@ pub struct YieldExpression<'a> {
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash, ESTree)]
pub struct Class<'a> {
pub r#type: ClassType,
pub span: Span,
pub r#type: ClassType,
/// Decorators applied to the class.
///
/// Decorators are currently a stage 3 proposal. Oxc handles both TC39 and
Expand Down Expand Up @@ -1879,11 +1879,11 @@ pub enum ClassElement<'a> {
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash, ESTree)]
pub struct MethodDefinition<'a> {
pub span: Span,
/// Method definition type
///
/// This will always be true when an `abstract` modifier is used on the method.
pub r#type: MethodDefinitionType,
pub span: Span,
#[ts]
pub decorators: Vec<'a, Decorator<'a>>,
pub key: PropertyKey<'a>,
Expand Down Expand Up @@ -1918,8 +1918,8 @@ pub enum MethodDefinitionType {
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash, ESTree)]
pub struct PropertyDefinition<'a> {
pub r#type: PropertyDefinitionType,
pub span: Span,
pub r#type: PropertyDefinitionType,
/// Decorators applied to the property.
///
/// See [`Decorator`] for more information.
Expand Down Expand Up @@ -2140,8 +2140,8 @@ pub enum AccessorPropertyType {
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash, ESTree)]
pub struct AccessorProperty<'a> {
pub r#type: AccessorPropertyType,
pub span: Span,
pub r#type: AccessorPropertyType,
/// Decorators applied to the accessor property.
///
/// See [`Decorator`] for more information.
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/ast_builder_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ impl<'a> AstBuilder<'a> {
let params =
self.formal_parameters(SPAN, FormalParameterKind::FormalParameter, self.vec(), NONE);
let empty_function = self.function(
FunctionType::FunctionDeclaration,
SPAN,
FunctionType::FunctionDeclaration,
None,
false,
false,
Expand Down Expand Up @@ -249,8 +249,8 @@ impl<'a> AstBuilder<'a> {
scope_id: ScopeId,
) -> Box<'a, Function<'a>> {
self.alloc_function_with_scope_id(
r#type,
span,
r#type,
id,
false,
false,
Expand Down
40 changes: 20 additions & 20 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ const _: () = {

assert!(size_of::<Function>() == 104usize);
assert!(align_of::<Function>() == 8usize);
assert!(offset_of!(Function, r#type) == 0usize);
assert!(offset_of!(Function, span) == 4usize);
assert!(offset_of!(Function, span) == 0usize);
assert!(offset_of!(Function, r#type) == 8usize);
assert!(offset_of!(Function, id) == 16usize);
assert!(offset_of!(Function, generator) == 48usize);
assert!(offset_of!(Function, r#async) == 49usize);
Expand Down Expand Up @@ -603,8 +603,8 @@ const _: () = {

assert!(size_of::<Class>() == 160usize);
assert!(align_of::<Class>() == 8usize);
assert!(offset_of!(Class, r#type) == 0usize);
assert!(offset_of!(Class, span) == 4usize);
assert!(offset_of!(Class, span) == 0usize);
assert!(offset_of!(Class, r#type) == 8usize);
assert!(offset_of!(Class, decorators) == 16usize);
assert!(offset_of!(Class, id) == 48usize);
assert!(offset_of!(Class, type_parameters) == 80usize);
Expand All @@ -629,8 +629,8 @@ const _: () = {

assert!(size_of::<MethodDefinition>() == 80usize);
assert!(align_of::<MethodDefinition>() == 8usize);
assert!(offset_of!(MethodDefinition, r#type) == 0usize);
assert!(offset_of!(MethodDefinition, span) == 4usize);
assert!(offset_of!(MethodDefinition, span) == 0usize);
assert!(offset_of!(MethodDefinition, r#type) == 8usize);
assert!(offset_of!(MethodDefinition, decorators) == 16usize);
assert!(offset_of!(MethodDefinition, key) == 48usize);
assert!(offset_of!(MethodDefinition, value) == 64usize);
Expand All @@ -646,8 +646,8 @@ const _: () = {

assert!(size_of::<PropertyDefinition>() == 104usize);
assert!(align_of::<PropertyDefinition>() == 8usize);
assert!(offset_of!(PropertyDefinition, r#type) == 0usize);
assert!(offset_of!(PropertyDefinition, span) == 4usize);
assert!(offset_of!(PropertyDefinition, span) == 0usize);
assert!(offset_of!(PropertyDefinition, r#type) == 8usize);
assert!(offset_of!(PropertyDefinition, decorators) == 16usize);
assert!(offset_of!(PropertyDefinition, key) == 48usize);
assert!(offset_of!(PropertyDefinition, value) == 64usize);
Expand Down Expand Up @@ -686,8 +686,8 @@ const _: () = {

assert!(size_of::<AccessorProperty>() == 104usize);
assert!(align_of::<AccessorProperty>() == 8usize);
assert!(offset_of!(AccessorProperty, r#type) == 0usize);
assert!(offset_of!(AccessorProperty, span) == 4usize);
assert!(offset_of!(AccessorProperty, span) == 0usize);
assert!(offset_of!(AccessorProperty, r#type) == 8usize);
assert!(offset_of!(AccessorProperty, decorators) == 16usize);
assert!(offset_of!(AccessorProperty, key) == 48usize);
assert!(offset_of!(AccessorProperty, value) == 64usize);
Expand Down Expand Up @@ -2105,8 +2105,8 @@ const _: () = {

assert!(size_of::<Function>() == 60usize);
assert!(align_of::<Function>() == 4usize);
assert!(offset_of!(Function, r#type) == 0usize);
assert!(offset_of!(Function, span) == 4usize);
assert!(offset_of!(Function, span) == 0usize);
assert!(offset_of!(Function, r#type) == 8usize);
assert!(offset_of!(Function, id) == 12usize);
assert!(offset_of!(Function, generator) == 32usize);
assert!(offset_of!(Function, r#async) == 33usize);
Expand Down Expand Up @@ -2165,8 +2165,8 @@ const _: () = {

assert!(size_of::<Class>() == 92usize);
assert!(align_of::<Class>() == 4usize);
assert!(offset_of!(Class, r#type) == 0usize);
assert!(offset_of!(Class, span) == 4usize);
assert!(offset_of!(Class, span) == 0usize);
assert!(offset_of!(Class, r#type) == 8usize);
assert!(offset_of!(Class, decorators) == 12usize);
assert!(offset_of!(Class, id) == 28usize);
assert!(offset_of!(Class, type_parameters) == 48usize);
Expand All @@ -2191,8 +2191,8 @@ const _: () = {

assert!(size_of::<MethodDefinition>() == 48usize);
assert!(align_of::<MethodDefinition>() == 4usize);
assert!(offset_of!(MethodDefinition, r#type) == 0usize);
assert!(offset_of!(MethodDefinition, span) == 4usize);
assert!(offset_of!(MethodDefinition, span) == 0usize);
assert!(offset_of!(MethodDefinition, r#type) == 8usize);
assert!(offset_of!(MethodDefinition, decorators) == 12usize);
assert!(offset_of!(MethodDefinition, key) == 28usize);
assert!(offset_of!(MethodDefinition, value) == 36usize);
Expand All @@ -2208,8 +2208,8 @@ const _: () = {

assert!(size_of::<PropertyDefinition>() == 60usize);
assert!(align_of::<PropertyDefinition>() == 4usize);
assert!(offset_of!(PropertyDefinition, r#type) == 0usize);
assert!(offset_of!(PropertyDefinition, span) == 4usize);
assert!(offset_of!(PropertyDefinition, span) == 0usize);
assert!(offset_of!(PropertyDefinition, r#type) == 8usize);
assert!(offset_of!(PropertyDefinition, decorators) == 12usize);
assert!(offset_of!(PropertyDefinition, key) == 28usize);
assert!(offset_of!(PropertyDefinition, value) == 36usize);
Expand Down Expand Up @@ -2248,8 +2248,8 @@ const _: () = {

assert!(size_of::<AccessorProperty>() == 56usize);
assert!(align_of::<AccessorProperty>() == 4usize);
assert!(offset_of!(AccessorProperty, r#type) == 0usize);
assert!(offset_of!(AccessorProperty, span) == 4usize);
assert!(offset_of!(AccessorProperty, span) == 0usize);
assert!(offset_of!(AccessorProperty, r#type) == 8usize);
assert!(offset_of!(AccessorProperty, decorators) == 12usize);
assert!(offset_of!(AccessorProperty, key) == 28usize);
assert!(offset_of!(AccessorProperty, value) == 36usize);
Expand Down
Loading

0 comments on commit ff61017

Please sign in to comment.