Skip to content

Commit f9bf3d5

Browse files
committed
refactor(linter/plugins): use fixed-size allocators when ExternalLinter exists
1 parent 0285003 commit f9bf3d5

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

apps/oxlint/src/raw_fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use oxc_linter::RuntimeFileSystem;
1414
/// Identical to `OsFileSystem`, except that `read_to_arena_str` reads the file's contents into
1515
/// start of the allocator, instead of the end. This conforms to what raw transfer needs.
1616
///
17-
/// Must only be used in conjunction with `AllocatorPool` with `fixed_size` feature enabled,
17+
/// Must only be used in conjunction with `AllocatorPool` created with `new_fixed_size`,
1818
/// which wraps `Allocator`s with a custom `Drop` impl, which makes `read_to_arena_str` safe.
1919
///
2020
/// This is a temporary solution. When we replace `bumpalo` with our own allocator, all strings

crates/oxc_linter/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ description.workspace = true
1717
default = []
1818
ruledocs = ["oxc_macros/ruledocs"] # Enables the `ruledocs` feature for conditional compilation
1919
language_server = ["oxc_data_structures/rope"] # For the Runtime to support needed information for the language server
20-
oxlint2 = ["dep:oxc_ast_macros", "oxc_ast_visit/serialize", "tokio/rt-multi-thread"]
20+
oxlint2 = ["dep:oxc_ast_macros", "oxc_allocator/fixed_size", "oxc_ast_visit/serialize", "tokio/rt-multi-thread"]
2121
disable_oxlint2 = []
2222
force_test_reporter = []
2323

crates/oxc_linter/src/service/runtime.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,21 @@ impl Runtime {
265265
let _ = rayon::ThreadPoolBuilder::new().build_global();
266266

267267
let thread_count = rayon::current_num_threads();
268-
let allocator_pool = AllocatorPool::new(thread_count);
268+
269+
// If an external linter is used (JS plugins), we must use fixed-size allocators,
270+
// for compatibility with raw transfer
271+
let allocator_pool = if linter.has_external_linter() {
272+
#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
273+
{
274+
AllocatorPool::new_fixed_size(thread_count)
275+
}
276+
#[cfg(not(all(feature = "oxlint2", not(feature = "disable_oxlint2"))))]
277+
{
278+
panic!("`oxlint2` feature must be enabled when using external linters");
279+
}
280+
} else {
281+
AllocatorPool::new(thread_count)
282+
};
269283

270284
let resolver = options.cross_module.then(|| {
271285
Self::get_resolver(options.tsconfig.or_else(|| Some(options.cwd.join("tsconfig.json"))))

0 commit comments

Comments
 (0)