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: 2 additions & 2 deletions crates/oxc_allocator/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const _: () = {
// Padding: 3 bytes
assert!(size_of::<FixedSizeAllocatorMetadata>() == 16);
assert!(align_of::<FixedSizeAllocatorMetadata>() == 8);
assert!(offset_of!(FixedSizeAllocatorMetadata, id) == 8);
assert!(offset_of!(FixedSizeAllocatorMetadata, alloc_ptr) == 0);
assert!(offset_of!(FixedSizeAllocatorMetadata, id) == 8);
assert!(offset_of!(FixedSizeAllocatorMetadata, is_double_owned) == 12);
};

Expand All @@ -22,8 +22,8 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
// Padding: 3 bytes
assert!(size_of::<FixedSizeAllocatorMetadata>() == 12);
assert!(align_of::<FixedSizeAllocatorMetadata>() == 4);
assert!(offset_of!(FixedSizeAllocatorMetadata, id) == 4);
assert!(offset_of!(FixedSizeAllocatorMetadata, alloc_ptr) == 0);
assert!(offset_of!(FixedSizeAllocatorMetadata, id) == 4);
assert!(offset_of!(FixedSizeAllocatorMetadata, is_double_owned) == 8);
};

Expand Down
908 changes: 454 additions & 454 deletions crates/oxc_ast/src/generated/assert_layouts.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/oxc_linter/src/generated/assert_layouts.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions crates/oxc_regular_expression/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const _: () = {
assert!(size_of::<LookAroundAssertion>() == 48);
assert!(align_of::<LookAroundAssertion>() == 8);
assert!(offset_of!(LookAroundAssertion, span) == 0);
assert!(offset_of!(LookAroundAssertion, kind) == 40);
assert!(offset_of!(LookAroundAssertion, body) == 8);
assert!(offset_of!(LookAroundAssertion, kind) == 40);

assert!(size_of::<LookAroundAssertionKind>() == 1);
assert!(align_of::<LookAroundAssertionKind>() == 1);
Expand All @@ -55,15 +55,15 @@ const _: () = {
assert!(offset_of!(Quantifier, span) == 0);
assert!(offset_of!(Quantifier, min) == 8);
assert!(offset_of!(Quantifier, max) == 16);
assert!(offset_of!(Quantifier, greedy) == 48);
assert!(offset_of!(Quantifier, body) == 32);
assert!(offset_of!(Quantifier, greedy) == 48);

// Padding: 3 bytes
assert!(size_of::<Character>() == 16);
assert!(align_of::<Character>() == 8);
assert!(offset_of!(Character, span) == 0);
assert!(offset_of!(Character, kind) == 12);
assert!(offset_of!(Character, value) == 8);
assert!(offset_of!(Character, kind) == 12);

assert!(size_of::<CharacterKind>() == 1);
assert!(align_of::<CharacterKind>() == 1);
Expand All @@ -81,10 +81,10 @@ const _: () = {
assert!(size_of::<UnicodePropertyEscape>() == 48);
assert!(align_of::<UnicodePropertyEscape>() == 8);
assert!(offset_of!(UnicodePropertyEscape, span) == 0);
assert!(offset_of!(UnicodePropertyEscape, negative) == 40);
assert!(offset_of!(UnicodePropertyEscape, strings) == 41);
assert!(offset_of!(UnicodePropertyEscape, name) == 8);
assert!(offset_of!(UnicodePropertyEscape, value) == 24);
assert!(offset_of!(UnicodePropertyEscape, negative) == 40);
assert!(offset_of!(UnicodePropertyEscape, strings) == 41);

// Padding: 0 bytes
assert!(size_of::<Dot>() == 8);
Expand All @@ -95,10 +95,10 @@ const _: () = {
assert!(size_of::<CharacterClass>() == 40);
assert!(align_of::<CharacterClass>() == 8);
assert!(offset_of!(CharacterClass, span) == 0);
assert!(offset_of!(CharacterClass, body) == 8);
assert!(offset_of!(CharacterClass, negative) == 32);
assert!(offset_of!(CharacterClass, strings) == 33);
assert!(offset_of!(CharacterClass, kind) == 34);
assert!(offset_of!(CharacterClass, body) == 8);

assert!(size_of::<CharacterClassContentsKind>() == 1);
assert!(align_of::<CharacterClassContentsKind>() == 1);
Expand All @@ -117,15 +117,15 @@ const _: () = {
assert!(size_of::<ClassStringDisjunction>() == 40);
assert!(align_of::<ClassStringDisjunction>() == 8);
assert!(offset_of!(ClassStringDisjunction, span) == 0);
assert!(offset_of!(ClassStringDisjunction, strings) == 32);
assert!(offset_of!(ClassStringDisjunction, body) == 8);
assert!(offset_of!(ClassStringDisjunction, strings) == 32);

// Padding: 7 bytes
assert!(size_of::<ClassString>() == 40);
assert!(align_of::<ClassString>() == 8);
assert!(offset_of!(ClassString, span) == 0);
assert!(offset_of!(ClassString, strings) == 32);
assert!(offset_of!(ClassString, body) == 8);
assert!(offset_of!(ClassString, strings) == 32);

// Padding: 0 bytes
assert!(size_of::<CapturingGroup>() == 56);
Expand Down Expand Up @@ -201,8 +201,8 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
assert!(size_of::<LookAroundAssertion>() == 36);
assert!(align_of::<LookAroundAssertion>() == 4);
assert!(offset_of!(LookAroundAssertion, span) == 0);
assert!(offset_of!(LookAroundAssertion, kind) == 32);
assert!(offset_of!(LookAroundAssertion, body) == 8);
assert!(offset_of!(LookAroundAssertion, kind) == 32);

assert!(size_of::<LookAroundAssertionKind>() == 1);
assert!(align_of::<LookAroundAssertionKind>() == 1);
Expand All @@ -213,15 +213,15 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
assert!(offset_of!(Quantifier, span) == 0);
assert!(offset_of!(Quantifier, min) == 8);
assert!(offset_of!(Quantifier, max) == 16);
assert!(offset_of!(Quantifier, greedy) == 44);
assert!(offset_of!(Quantifier, body) == 32);
assert!(offset_of!(Quantifier, greedy) == 44);

// Padding: 3 bytes
assert!(size_of::<Character>() == 16);
assert!(align_of::<Character>() == 4);
assert!(offset_of!(Character, span) == 0);
assert!(offset_of!(Character, kind) == 12);
assert!(offset_of!(Character, value) == 8);
assert!(offset_of!(Character, kind) == 12);

assert!(size_of::<CharacterKind>() == 1);
assert!(align_of::<CharacterKind>() == 1);
Expand All @@ -239,10 +239,10 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
assert!(size_of::<UnicodePropertyEscape>() == 28);
assert!(align_of::<UnicodePropertyEscape>() == 4);
assert!(offset_of!(UnicodePropertyEscape, span) == 0);
assert!(offset_of!(UnicodePropertyEscape, negative) == 24);
assert!(offset_of!(UnicodePropertyEscape, strings) == 25);
assert!(offset_of!(UnicodePropertyEscape, name) == 8);
assert!(offset_of!(UnicodePropertyEscape, value) == 16);
assert!(offset_of!(UnicodePropertyEscape, negative) == 24);
assert!(offset_of!(UnicodePropertyEscape, strings) == 25);

// Padding: 0 bytes
assert!(size_of::<Dot>() == 8);
Expand All @@ -253,10 +253,10 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
assert!(size_of::<CharacterClass>() == 28);
assert!(align_of::<CharacterClass>() == 4);
assert!(offset_of!(CharacterClass, span) == 0);
assert!(offset_of!(CharacterClass, body) == 8);
assert!(offset_of!(CharacterClass, negative) == 24);
assert!(offset_of!(CharacterClass, strings) == 25);
assert!(offset_of!(CharacterClass, kind) == 26);
assert!(offset_of!(CharacterClass, body) == 8);

assert!(size_of::<CharacterClassContentsKind>() == 1);
assert!(align_of::<CharacterClassContentsKind>() == 1);
Expand All @@ -275,15 +275,15 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
assert!(size_of::<ClassStringDisjunction>() == 28);
assert!(align_of::<ClassStringDisjunction>() == 4);
assert!(offset_of!(ClassStringDisjunction, span) == 0);
assert!(offset_of!(ClassStringDisjunction, strings) == 24);
assert!(offset_of!(ClassStringDisjunction, body) == 8);
assert!(offset_of!(ClassStringDisjunction, strings) == 24);

// Padding: 3 bytes
assert!(size_of::<ClassString>() == 28);
assert!(align_of::<ClassString>() == 4);
assert!(offset_of!(ClassString, span) == 0);
assert!(offset_of!(ClassString, strings) == 24);
assert!(offset_of!(ClassString, body) == 8);
assert!(offset_of!(ClassString, strings) == 24);

// Padding: 0 bytes
assert!(size_of::<CapturingGroup>() == 40);
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_syntax/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const _: () = {
// Padding: 0 bytes
assert!(size_of::<NameSpan>() == 24);
assert!(align_of::<NameSpan>() == 8);
assert!(offset_of!(NameSpan, name) == 8);
assert!(offset_of!(NameSpan, span) == 0);
assert!(offset_of!(NameSpan, name) == 8);

// Padding: 7 bytes
assert!(size_of::<ImportEntry>() == 96);
Expand All @@ -42,8 +42,8 @@ const _: () = {
// Padding: 7 bytes
assert!(size_of::<ExportEntry>() == 144);
assert!(align_of::<ExportEntry>() == 8);
assert!(offset_of!(ExportEntry, statement_span) == 8);
assert!(offset_of!(ExportEntry, span) == 0);
assert!(offset_of!(ExportEntry, statement_span) == 8);
assert!(offset_of!(ExportEntry, module_request) == 16);
assert!(offset_of!(ExportEntry, import_name) == 40);
assert!(offset_of!(ExportEntry, export_name) == 72);
Expand Down Expand Up @@ -112,8 +112,8 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
// Padding: 0 bytes
assert!(size_of::<NameSpan>() == 16);
assert!(align_of::<NameSpan>() == 4);
assert!(offset_of!(NameSpan, name) == 8);
assert!(offset_of!(NameSpan, span) == 0);
assert!(offset_of!(NameSpan, name) == 8);

// Padding: 3 bytes
assert!(size_of::<ImportEntry>() == 64);
Expand All @@ -130,8 +130,8 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
// Padding: 3 bytes
assert!(size_of::<ExportEntry>() == 96);
assert!(align_of::<ExportEntry>() == 4);
assert!(offset_of!(ExportEntry, statement_span) == 8);
assert!(offset_of!(ExportEntry, span) == 0);
assert!(offset_of!(ExportEntry, statement_span) == 8);
assert!(offset_of!(ExportEntry, module_request) == 16);
assert!(offset_of!(ExportEntry, import_name) == 32);
assert!(offset_of!(ExportEntry, export_name) == 52);
Expand Down
20 changes: 10 additions & 10 deletions napi/parser/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,38 @@ const _: () = {
assert!(size_of::<RawTransferMetadata>() == 16);
assert!(align_of::<RawTransferMetadata>() == 4);
assert!(offset_of!(RawTransferMetadata, data_offset) == 0);
assert!(offset_of!(RawTransferMetadata, tokens_offset) == 4);
assert!(offset_of!(RawTransferMetadata, tokens_len) == 8);
assert!(offset_of!(RawTransferMetadata, is_ts) == 12);
assert!(offset_of!(RawTransferMetadata, is_jsx) == 13);
assert!(offset_of!(RawTransferMetadata, has_bom) == 14);
assert!(offset_of!(RawTransferMetadata, tokens_offset) == 4);
assert!(offset_of!(RawTransferMetadata, tokens_len) == 8);

// Padding: 7 bytes
assert!(size_of::<Error>() == 80);
assert!(align_of::<Error>() == 8);
assert!(offset_of!(Error, severity) == 72);
assert!(offset_of!(Error, message) == 0);
assert!(offset_of!(Error, labels) == 16);
assert!(offset_of!(Error, help_message) == 40);
assert!(offset_of!(Error, codeframe) == 56);
assert!(offset_of!(Error, severity) == 72);

assert!(size_of::<ErrorSeverity>() == 1);
assert!(align_of::<ErrorSeverity>() == 1);

// Padding: 0 bytes
assert!(size_of::<ErrorLabel>() == 24);
assert!(align_of::<ErrorLabel>() == 8);
assert!(offset_of!(ErrorLabel, message) == 8);
assert!(offset_of!(ErrorLabel, span) == 0);
assert!(offset_of!(ErrorLabel, message) == 8);

// Padding: 7 bytes
assert!(size_of::<EcmaScriptModule>() == 104);
assert!(align_of::<EcmaScriptModule>() == 8);
assert!(offset_of!(EcmaScriptModule, has_module_syntax) == 96);
assert!(offset_of!(EcmaScriptModule, static_imports) == 0);
assert!(offset_of!(EcmaScriptModule, static_exports) == 24);
assert!(offset_of!(EcmaScriptModule, dynamic_imports) == 48);
assert!(offset_of!(EcmaScriptModule, import_metas) == 72);
assert!(offset_of!(EcmaScriptModule, has_module_syntax) == 96);

// Padding: 0 bytes
assert!(size_of::<StaticImport>() == 56);
Expand Down Expand Up @@ -82,38 +82,38 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
assert!(size_of::<RawTransferMetadata>() == 16);
assert!(align_of::<RawTransferMetadata>() == 4);
assert!(offset_of!(RawTransferMetadata, data_offset) == 0);
assert!(offset_of!(RawTransferMetadata, tokens_offset) == 4);
assert!(offset_of!(RawTransferMetadata, tokens_len) == 8);
assert!(offset_of!(RawTransferMetadata, is_ts) == 12);
assert!(offset_of!(RawTransferMetadata, is_jsx) == 13);
assert!(offset_of!(RawTransferMetadata, has_bom) == 14);
assert!(offset_of!(RawTransferMetadata, tokens_offset) == 4);
assert!(offset_of!(RawTransferMetadata, tokens_len) == 8);

// Padding: 3 bytes
assert!(size_of::<Error>() == 44);
assert!(align_of::<Error>() == 4);
assert!(offset_of!(Error, severity) == 40);
assert!(offset_of!(Error, message) == 0);
assert!(offset_of!(Error, labels) == 8);
assert!(offset_of!(Error, help_message) == 24);
assert!(offset_of!(Error, codeframe) == 32);
assert!(offset_of!(Error, severity) == 40);

assert!(size_of::<ErrorSeverity>() == 1);
assert!(align_of::<ErrorSeverity>() == 1);

// Padding: 0 bytes
assert!(size_of::<ErrorLabel>() == 16);
assert!(align_of::<ErrorLabel>() == 4);
assert!(offset_of!(ErrorLabel, message) == 8);
assert!(offset_of!(ErrorLabel, span) == 0);
assert!(offset_of!(ErrorLabel, message) == 8);

// Padding: 3 bytes
assert!(size_of::<EcmaScriptModule>() == 68);
assert!(align_of::<EcmaScriptModule>() == 4);
assert!(offset_of!(EcmaScriptModule, has_module_syntax) == 64);
assert!(offset_of!(EcmaScriptModule, static_imports) == 0);
assert!(offset_of!(EcmaScriptModule, static_exports) == 16);
assert!(offset_of!(EcmaScriptModule, dynamic_imports) == 32);
assert!(offset_of!(EcmaScriptModule, import_metas) == 48);
assert!(offset_of!(EcmaScriptModule, has_module_syntax) == 64);

// Padding: 0 bytes
assert!(size_of::<StaticImport>() == 40);
Expand Down
17 changes: 12 additions & 5 deletions tasks/ast_tools/src/generators/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
sync::atomic,
};

use itertools::Itertools;
use phf_codegen::Map as PhfMapGen;
use proc_macro2::TokenStream;
use quote::quote;
Expand All @@ -21,8 +22,8 @@ use crate::{
AST_MACROS_CRATE_PATH, Codegen, Generator,
output::{Output, output_path},
schema::{
Def, Discriminant, EnumDef, PointerKind, PrimitiveDef, Schema, StructDef, TypeDef, TypeId,
Visibility,
Def, Discriminant, EnumDef, FieldDef, PointerKind, PrimitiveDef, Schema, StructDef,
TypeDef, TypeId, Visibility,
extensions::layout::{GetLayout, GetOffset, Layout, Niche, Offset, PlatformLayout},
},
utils::{format_cow, number_lit},
Expand Down Expand Up @@ -578,6 +579,7 @@ fn generate_layout_assertions_for_struct<'s>(
) {
fn r#gen(
struct_def: &StructDef,
fields: &[&FieldDef],
is_64: bool,
struct_ident: &Ident,
schema: &Schema,
Expand All @@ -595,7 +597,7 @@ fn generate_layout_assertions_for_struct<'s>(

let size_align_assertions = generate_size_align_assertions(layout, struct_ident);

let offset_asserts = struct_def.fields.iter().filter_map(|field| {
let offset_asserts = fields.iter().map(|&field| {
if struct_def.is_foreign || field.visibility == Visibility::Private {
// Cannot create assertions for private fields (cant access them)
// or foreign types (we don't know what fields they have)
Expand All @@ -617,12 +619,17 @@ fn generate_layout_assertions_for_struct<'s>(
}
}

// Sort fields in offset order.
// `sort_by` not `sort_unstable_by` to maintain original field order for ZST fields.
let mut fields = struct_def.fields.iter().collect_vec();
fields.sort_by(|f1, f2| f1.offset.offset_64.cmp(&f2.offset.offset_64));

let (assertions_64, assertions_32) =
assertions.entry(struct_def.file(schema).krate()).or_default();

let ident = struct_def.ident();
assertions_64.extend(r#gen(struct_def, true, &ident, schema));
assertions_32.extend(r#gen(struct_def, false, &ident, schema));
assertions_64.extend(r#gen(struct_def, &fields, true, &ident, schema));
assertions_32.extend(r#gen(struct_def, &fields, false, &ident, schema));
}

/// Generate layout assertions for an enum.
Expand Down
Loading