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
2 changes: 2 additions & 0 deletions .github/generated/ast_changes_watch_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ src:
- 'crates/oxc_formatter/src/generated/ast_nodes.rs'
- 'crates/oxc_formatter/src/generated/format.rs'
- 'crates/oxc_formatter/src/generated/format_write.rs'
- 'crates/oxc_linter/src/generated/assert_layouts.rs'
- 'crates/oxc_linter/src/lib.rs'
- 'crates/oxc_regular_expression/src/ast.rs'
- 'crates/oxc_regular_expression/src/generated/assert_layouts.rs'
- 'crates/oxc_regular_expression/src/generated/derive_clone_in.rs'
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

499 changes: 250 additions & 249 deletions crates/oxc_ast_macros/src/generated/structs.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion crates/oxc_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description.workspace = true
default = []
ruledocs = ["oxc_macros/ruledocs"] # Enables the `ruledocs` feature for conditional compilation
language_server = ["oxc_data_structures/rope"] # For the Runtime to support needed information for the language server
oxlint2 = ["tokio/rt-multi-thread"]
oxlint2 = ["dep:oxc_ast_macros", "tokio/rt-multi-thread"]
disable_oxlint2 = []
force_test_reporter = []

Expand All @@ -30,6 +30,7 @@ doctest = true
[dependencies]
oxc_allocator = { workspace = true }
oxc_ast = { workspace = true }
oxc_ast_macros = { workspace = true, optional = true }
oxc_ast_visit = { workspace = true }
oxc_cfg = { workspace = true }
oxc_codegen = { workspace = true }
Expand Down
31 changes: 31 additions & 0 deletions crates/oxc_linter/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/assert_layouts.rs`.

#![allow(unused_imports)]

use std::mem::{align_of, offset_of, size_of};

use crate::*;

#[cfg(target_pointer_width = "64")]
const _: () = {
// Padding: 3 bytes
assert!(size_of::<RawTransferMetadata2>() == 16);
assert!(align_of::<RawTransferMetadata2>() == 8);
assert!(offset_of!(RawTransferMetadata2, data_offset) == 8);
assert!(offset_of!(RawTransferMetadata2, is_ts) == 12);
assert!(offset_of!(RawTransferMetadata2, _padding) == 0);
};

#[cfg(target_pointer_width = "32")]
const _: () = {
// Padding: 3 bytes
assert!(size_of::<RawTransferMetadata2>() == 16);
assert!(align_of::<RawTransferMetadata2>() == 8);
assert!(offset_of!(RawTransferMetadata2, data_offset) == 8);
assert!(offset_of!(RawTransferMetadata2, is_ts) == 12);
assert!(offset_of!(RawTransferMetadata2, _padding) == 0);
};

#[cfg(not(any(target_pointer_width = "64", target_pointer_width = "32")))]
const _: () = panic!("Platforms with pointer width other than 64 or 32 bit are not supported");
36 changes: 36 additions & 0 deletions crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use std::{path::Path, rc::Rc, sync::Arc};
use oxc_allocator::Allocator;
use oxc_semantic::{AstNode, Semantic};

#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
use oxc_ast_macros::ast;

#[cfg(test)]
mod tester;

Expand All @@ -29,6 +32,12 @@ pub mod loader;
pub mod rules;
pub mod table;

#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
mod generated {
#[cfg(debug_assertions)]
pub mod assert_layouts;
}

pub use crate::{
config::{
BuiltinLintPlugins, Config, ConfigBuilderError, ConfigStore, ConfigStoreBuilder,
Expand Down Expand Up @@ -273,6 +282,33 @@ impl Linter {
}
}

#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
/// Metadata written to end of buffer.
///
/// Duplicate of `RawTransferMetadata` in `napi/parser/src/raw_transfer_types.rs`.
/// Any changes made here also need to be made there.
/// `oxc_ast_tools` checks that the 2 copies are identical.
#[ast]
struct RawTransferMetadata2 {
/// Offset of `RawTransferData` within buffer.
pub data_offset: u32,
/// `true` if AST is TypeScript.
pub is_ts: bool,
/// Padding to pad struct to size 16.
pub(crate) _padding: u64,
}

#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
use RawTransferMetadata2 as RawTransferMetadata;

#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
#[expect(dead_code)]
impl RawTransferMetadata {
pub fn new(data_offset: u32, is_ts: bool) -> Self {
Self { data_offset, is_ts, _padding: 0 }
}
}

#[cfg(test)]
mod test {
use super::Oxlintrc;
Expand Down
10 changes: 5 additions & 5 deletions napi/parser/generated/deserialize/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -5238,16 +5238,16 @@ function deserializeBoxTSExternalModuleReference(pos) {
return deserializeTSExternalModuleReference(uint32[pos >> 2]);
}

function deserializeOptionNameSpan(pos) {
if (uint32[(pos + 8) >> 2] === 0 && uint32[(pos + 12) >> 2] === 0) return null;
return deserializeNameSpan(pos);
}

function deserializeU64(pos) {
const pos32 = pos >> 2;
return uint32[pos32] + uint32[pos32 + 1] * 4294967296;
}

function deserializeOptionNameSpan(pos) {
if (uint32[(pos + 8) >> 2] === 0 && uint32[(pos + 12) >> 2] === 0) return null;
return deserializeNameSpan(pos);
}

function deserializeOptionU64(pos) {
if (uint8[pos] === 0) return null;
return deserializeU64(pos + 8);
Expand Down
10 changes: 5 additions & 5 deletions napi/parser/generated/deserialize/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5369,16 +5369,16 @@ function deserializeBoxTSExternalModuleReference(pos) {
return deserializeTSExternalModuleReference(uint32[pos >> 2]);
}

function deserializeOptionNameSpan(pos) {
if (uint32[(pos + 8) >> 2] === 0 && uint32[(pos + 12) >> 2] === 0) return null;
return deserializeNameSpan(pos);
}

function deserializeU64(pos) {
const pos32 = pos >> 2;
return uint32[pos32] + uint32[pos32 + 1] * 4294967296;
}

function deserializeOptionNameSpan(pos) {
if (uint32[(pos + 8) >> 2] === 0 && uint32[(pos + 12) >> 2] === 0) return null;
return deserializeNameSpan(pos);
}

function deserializeOptionU64(pos) {
if (uint8[pos] === 0) return null;
return deserializeU64(pos + 8);
Expand Down
10 changes: 5 additions & 5 deletions napi/parser/generated/lazy/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13752,17 +13752,17 @@ function constructBoxTSExternalModuleReference(pos, ast) {
return new TSExternalModuleReference(ast.buffer.uint32[pos >> 2], ast);
}

function constructOptionNameSpan(pos, ast) {
if (ast.buffer.uint32[(pos + 8) >> 2] === 0 && ast.buffer.uint32[(pos + 12) >> 2] === 0) return null;
return new NameSpan(pos, ast);
}

function constructU64(pos, ast) {
const { uint32 } = ast.buffer,
pos32 = pos >> 2;
return uint32[pos32] + uint32[pos32 + 1] * 4294967296;
}

function constructOptionNameSpan(pos, ast) {
if (ast.buffer.uint32[(pos + 8) >> 2] === 0 && ast.buffer.uint32[(pos + 12) >> 2] === 0) return null;
return new NameSpan(pos, ast);
}

function constructOptionU64(pos, ast) {
if (ast.buffer[pos] === 0) return null;
return constructU64(pos + 8, ast);
Expand Down
4 changes: 4 additions & 0 deletions napi/parser/src/raw_transfer_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub struct RawTransferData<'a> {
}

/// Metadata written to end of buffer.
///
/// Duplicated as `RawTransferMetadata2` in `crates/oxc_linter/src/lib.rs`.
/// Any changes made here also need to be made there.
/// `oxc_ast_tools` checks that the 2 copies are identical.
#[ast]
pub struct RawTransferMetadata {
/// Offset of `RawTransferData` within buffer.
Expand Down
27 changes: 24 additions & 3 deletions tasks/ast_tools/src/generators/raw_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,27 @@ fn generate_constants(consts: Constants) -> (String, TokenStream) {
/// Calculate constants.
fn get_constants(schema: &Schema) -> Constants {
let raw_metadata_struct = schema.type_by_name("RawTransferMetadata").as_struct().unwrap();
let raw_metadata2_struct = schema.type_by_name("RawTransferMetadata2").as_struct().unwrap();

// Check layout and fields of `RawTransferMetadata` and `RawTransferMetadata2` are identical
assert_eq!(raw_metadata_struct.layout, raw_metadata2_struct.layout);
assert_eq!(raw_metadata_struct.fields.len(), raw_metadata2_struct.fields.len());

let mut data_offset_field = None;
let mut is_ts_field = None;
for (field1, field2) in raw_metadata_struct.fields.iter().zip(&raw_metadata2_struct.fields) {
assert_eq!(field1.name(), field2.name());
assert_eq!(field1.type_id, field2.type_id);
assert_eq!(field1.offset_64(), field2.offset_64());
match field1.name() {
"data_offset" => data_offset_field = Some(field1),
"is_ts" => is_ts_field = Some(field1),
_ => {}
}
}
let data_offset_field = data_offset_field.unwrap();
let is_ts_field = is_ts_field.unwrap();

let raw_metadata_size = raw_metadata_struct.layout_64().size;

// Round up to multiple of `ALLOCATOR_CHUNK_END_ALIGN`
Expand All @@ -1068,10 +1089,10 @@ fn get_constants(schema: &Schema) -> Constants {

let buffer_size = BLOCK_SIZE - fixed_metadata_size;

// Get offsets of data within buffer
let raw_metadata_pos = buffer_size - raw_metadata_size;
let data_pointer_pos =
raw_metadata_pos + raw_metadata_struct.field_by_name("data_offset").offset_64();
let is_ts_pos = raw_metadata_pos + raw_metadata_struct.field_by_name("is_ts").offset_64();
let data_pointer_pos = raw_metadata_pos + data_offset_field.offset_64();
let is_ts_pos = raw_metadata_pos + is_ts_field.offset_64();

let program_offset = schema
.type_by_name("RawTransferData")
Expand Down
1 change: 1 addition & 0 deletions tasks/ast_tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ static SOURCE_PATHS: &[&str] = &[
"crates/oxc_ast/src/serialize/js.rs",
"crates/oxc_ast/src/serialize/jsx.rs",
"crates/oxc_ast/src/serialize/ts.rs",
"crates/oxc_linter/src/lib.rs",
"crates/oxc_syntax/src/lib.rs",
"crates/oxc_syntax/src/comment_node.rs",
"crates/oxc_syntax/src/module_record.rs",
Expand Down
Loading