Truly independent web browser
LibJS/JIT: Build the compiler without std, so it cannot use the heap
Andreas Kling83e62ab2af41
diff --git a/Libraries/LibJS/JIT/Rust/build.rs b/Libraries/LibJS/JIT/Rust/build.rsindex 77da6f525fd..4381f2e900a 100644--- a/Libraries/LibJS/JIT/Rust/build.rs+++ b/Libraries/LibJS/JIT/Rust/build.rs@@ -11,9 +11,6 @@//! the `Instruction` enum and the field readers are shared with//! `Libraries/LibJS/Rust/build.rs` through `flapc::rust_bytecode`.-// NB: The rule against containers of the heap (see clippy.toml) is for the compiler. This script runs at build time.-#![allow(clippy::disallowed_types, clippy::disallowed_macros, clippy::disallowed_methods)]-use flapc::metadata::Field;use flapc::metadata::InstructionDefinition;use flapc::metadata::ParameterMode;diff --git a/Libraries/LibJS/JIT/Rust/clippy.toml b/Libraries/LibJS/JIT/Rust/clippy.tomldeleted file mode 100644index a5b32f55582..00000000000--- a/Libraries/LibJS/JIT/Rust/clippy.toml+++ /dev/null@@ -1,83 +0,0 @@-# NB: Clippy reads only the nearest clippy.toml, so this file repeats the list of /clippy.toml. Keep the two in sync.-disallowed-methods = [- { path = "std::slice::from_raw_parts", reason = "a null pointer is undefined behavior even for an empty slice, and an empty AK container lends one: use ak::slice_from_raw_parts" },- { path = "std::slice::from_raw_parts_mut", reason = "a null pointer is undefined behavior even for an empty slice, and an empty AK container lends one: use ak::slice_from_raw_parts_mut" },- { path = "f32::acos", reason = "the C library of each platform computes this differently: use ak::math::acos" },- { path = "f32::asin", reason = "the C library of each platform computes this differently: use ak::math::asin" },- { path = "f32::atan", reason = "the C library of each platform computes this differently: use ak::math::atan" },- { path = "f32::atan2", reason = "the C library of each platform computes this differently: use ak::math::atan2" },- { path = "f32::cbrt", reason = "the C library of each platform computes this differently: use ak::math::cbrt" },- { path = "f32::cos", reason = "the C library of each platform computes this differently: use ak::math::cos" },- { path = "f32::cosh", reason = "the C library of each platform computes this differently: use ak::math::cosh" },- { path = "f32::exp", reason = "the C library of each platform computes this differently: use ak::math::exp" },- { path = "f32::exp2", reason = "the C library of each platform computes this differently: use ak::math::exp2" },- { path = "f32::exp_m1", reason = "the C library of each platform computes this differently: use ak::math::expm1" },- { path = "f32::hypot", reason = "the C library of each platform computes this differently: use ak::math::hypot" },- { path = "f32::ln", reason = "the C library of each platform computes this differently: use ak::math::log" },- { path = "f32::ln_1p", reason = "the C library of each platform computes this differently: use ak::math::log1p" },- { path = "f32::log", reason = "the C library of each platform computes this differently: use ak::math::log(x) / log(base)" },- { path = "f32::log10", reason = "the C library of each platform computes this differently: use ak::math::log10" },- { path = "f32::log2", reason = "the C library of each platform computes this differently: use ak::math::log2" },- { path = "f32::powf", reason = "the C library of each platform computes this differently: use ak::math::pow" },- { path = "f32::sin", reason = "the C library of each platform computes this differently: use ak::math::sin" },- { path = "f32::sin_cos", reason = "the C library of each platform computes this differently: use ak::math::sincos" },- { path = "f32::sinh", reason = "the C library of each platform computes this differently: use ak::math::sinh" },- { path = "f32::tan", reason = "the C library of each platform computes this differently: use ak::math::tan" },- { path = "f32::tanh", reason = "the C library of each platform computes this differently: use ak::math::tanh" },- { path = "f32::asinh", reason = "the C library of each platform computes this differently: use ak::math::asinh" },- { path = "f32::acosh", reason = "the C library of each platform computes this differently: use ak::math::acosh" },- { path = "f32::atanh", reason = "the C library of each platform computes this differently: use ak::math::atanh" },- { path = "f64::acos", reason = "the C library of each platform computes this differently: use ak::math::acos" },- { path = "f64::asin", reason = "the C library of each platform computes this differently: use ak::math::asin" },- { path = "f64::atan", reason = "the C library of each platform computes this differently: use ak::math::atan" },- { path = "f64::atan2", reason = "the C library of each platform computes this differently: use ak::math::atan2" },- { path = "f64::cbrt", reason = "the C library of each platform computes this differently: use ak::math::cbrt" },- { path = "f64::cos", reason = "the C library of each platform computes this differently: use ak::math::cos" },- { path = "f64::cosh", reason = "the C library of each platform computes this differently: use ak::math::cosh" },- { path = "f64::exp", reason = "the C library of each platform computes this differently: use ak::math::exp" },- { path = "f64::exp2", reason = "the C library of each platform computes this differently: use ak::math::exp2" },- { path = "f64::exp_m1", reason = "the C library of each platform computes this differently: use ak::math::expm1" },- { path = "f64::hypot", reason = "the C library of each platform computes this differently: use ak::math::hypot" },- { path = "f64::ln", reason = "the C library of each platform computes this differently: use ak::math::log" },- { path = "f64::ln_1p", reason = "the C library of each platform computes this differently: use ak::math::log1p" },- { path = "f64::log", reason = "the C library of each platform computes this differently: use ak::math::log(x) / log(base)" },- { path = "f64::log10", reason = "the C library of each platform computes this differently: use ak::math::log10" },- { path = "f64::log2", reason = "the C library of each platform computes this differently: use ak::math::log2" },- { path = "f64::powf", reason = "the C library of each platform computes this differently: use ak::math::pow" },- { path = "f64::sin", reason = "the C library of each platform computes this differently: use ak::math::sin" },- { path = "f64::sin_cos", reason = "the C library of each platform computes this differently: use ak::math::sincos" },- { path = "f64::sinh", reason = "the C library of each platform computes this differently: use ak::math::sinh" },- { path = "f64::tan", reason = "the C library of each platform computes this differently: use ak::math::tan" },- { path = "f64::tanh", reason = "the C library of each platform computes this differently: use ak::math::tanh" },- { path = "f64::asinh", reason = "the C library of each platform computes this differently: use ak::math::asinh" },- { path = "f64::acosh", reason = "the C library of each platform computes this differently: use ak::math::acosh" },- { path = "f64::atanh", reason = "the C library of each platform computes this differently: use ak::math::atanh" },- { path = "slice::sort", reason = "a stable sort makes a block in the heap: use sort_unstable, with a key that has no ties" },- { path = "slice::sort_by", reason = "a stable sort makes a block in the heap: use sort_unstable_by, with a key that has no ties" },- { path = "slice::sort_by_key", reason = "a stable sort makes a block in the heap: use sort_unstable_by_key, with a key that has no ties" },- { path = "slice::sort_by_cached_key", reason = "this sort makes a block in the heap: use sort_unstable_by_key, with a key that has no ties" },- { path = "slice::to_vec", reason = "the compiler makes no block in the heap: use Zone::alloc_slice_copy, or ak::ZoneVec::from_slice_in" },- { path = "std::string::ToString::to_string", reason = "the compiler makes no block in the heap: show the value with Display, or write it into a crate::debug_text::DebugText" },- { path = "std::borrow::ToOwned::to_owned", reason = "the compiler makes no block in the heap: keep the reference, or copy into a zone" },-]--# The compiler keeps its data in zones (see ak::Zone), so that all the memory of a compile can go back to the system.-# A container of the heap would leave blocks behind in the heap of the process.-disallowed-types = [- { path = "std::vec::Vec", reason = "the compiler makes no block in the heap: use ak::ZoneVec, or a slice in a zone" },- { path = "std::collections::VecDeque", reason = "the compiler makes no block in the heap: use ak::ZoneVec" },- { path = "std::collections::BinaryHeap", reason = "the compiler makes no block in the heap: use ak::ZoneVec" },- { path = "std::collections::LinkedList", reason = "the compiler makes no block in the heap: use ak::ZoneVec" },- { path = "std::collections::HashMap", reason = "the compiler makes no block in the heap: use ak::ZoneMap" },- { path = "std::collections::HashSet", reason = "the compiler makes no block in the heap: use ak::ZoneSet" },- { path = "std::collections::BTreeMap", reason = "the compiler makes no block in the heap: use ak::ZoneMap, or a sorted ak::ZoneVec" },- { path = "std::collections::BTreeSet", reason = "the compiler makes no block in the heap: use ak::ZoneSet, or a sorted ak::ZoneVec" },- { path = "std::boxed::Box", reason = "the compiler makes no block in the heap: use Zone::alloc" },- { path = "std::rc::Rc", reason = "the compiler makes no block in the heap: share a reference into a zone" },- { path = "std::sync::Arc", reason = "the compiler makes no block in the heap: share a reference into a zone" },- { path = "std::string::String", reason = "the compiler makes no block in the heap: text is a Display value, or a crate::debug_text::DebugText in a zone" },-]-disallowed-macros = [- { path = "std::vec", reason = "the compiler makes no block in the heap: use a slice, or ak::ZoneVec" },- { path = "std::format", reason = "the compiler makes no block in the heap: write! into a Formatter or into a crate::debug_text::DebugText" },-]diff --git a/Libraries/LibJS/JIT/Rust/src/asm/executable_code.rs b/Libraries/LibJS/JIT/Rust/src/asm/executable_code.rsindex 4e78534d27c..bcd941ad8b2 100644--- a/Libraries/LibJS/JIT/Rust/src/asm/executable_code.rs+++ b/Libraries/LibJS/JIT/Rust/src/asm/executable_code.rs@@ -40,7 +40,7 @@ impl ExecutableCode {let address = ak::windows_code_memory::reserve(size);assert!(!address.is_null());assert!(ak::windows_code_memory::make_writable(address, size));- std::ptr::copy_nonoverlapping(code.as_ptr(), address, code.len());+ core::ptr::copy_nonoverlapping(code.as_ptr(), address, code.len());assert!(ak::windows_code_memory::make_executable(address, size));Self {address: address.cast(),@@ -52,7 +52,7 @@ impl ExecutableCode {// while the thread's write protection of it is off.unsafe {let address = libc::mmap(- std::ptr::null_mut(),+ core::ptr::null_mut(),size,libc::PROT_READ | libc::PROT_WRITE | libc::PROT_EXEC,libc::MAP_PRIVATE | libc::MAP_ANON | libc::MAP_JIT,@@ -61,7 +61,7 @@ impl ExecutableCode {);assert_ne!(address, libc::MAP_FAILED);pthread_jit_write_protect_np(0);- std::ptr::copy_nonoverlapping(code.as_ptr(), address.cast::<u8>(), code.len());+ core::ptr::copy_nonoverlapping(code.as_ptr(), address.cast::<u8>(), code.len());pthread_jit_write_protect_np(1);sys_icache_invalidate(address, code.len());Self { address, size }@@ -71,7 +71,7 @@ impl ExecutableCode {// made executable.unsafe {let address = libc::mmap(- std::ptr::null_mut(),+ core::ptr::null_mut(),size,libc::PROT_READ | libc::PROT_WRITE,libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,@@ -79,7 +79,7 @@ impl ExecutableCode {0,);assert_ne!(address, libc::MAP_FAILED);- std::ptr::copy_nonoverlapping(code.as_ptr(), address.cast::<u8>(), code.len());+ core::ptr::copy_nonoverlapping(code.as_ptr(), address.cast::<u8>(), code.len());assert_eq!(libc::mprotect(address, size, libc::PROT_READ | libc::PROT_EXEC), 0);__clear_cache(address.cast(), address.cast::<libc::c_char>().add(code.len()));Self { address, size }@@ -93,7 +93,7 @@ impl ExecutableCode {pub(crate) unsafe fn function<F: Copy>(&self) -> F {assert_eq!(size_of::<F>(), size_of::<*mut core::ffi::c_void>());// SAFETY: The caller guarantees `F` is a matching function pointer type.- unsafe { std::mem::transmute_copy(&self.address) }+ unsafe { core::mem::transmute_copy(&self.address) }}}diff --git a/Libraries/LibJS/JIT/Rust/src/asm/x86_64/sse.rs b/Libraries/LibJS/JIT/Rust/src/asm/x86_64/sse.rsindex 089547e9949..86c7fb1316a 100644--- a/Libraries/LibJS/JIT/Rust/src/asm/x86_64/sse.rs+++ b/Libraries/LibJS/JIT/Rust/src/asm/x86_64/sse.rs@@ -40,20 +40,55 @@ impl CpuFeatures {pub fn host() -> Self {#[cfg(target_arch = "x86_64")]{- static FEATURES: std::sync::OnceLock<CpuFeatures> = std::sync::OnceLock::new();- *FEATURES.get_or_init(|| Self {- avx: std::arch::is_x86_feature_detected!("avx"),- avx2: std::arch::is_x86_feature_detected!("avx2"),- bmi1: std::arch::is_x86_feature_detected!("bmi1"),- bmi2: std::arch::is_x86_feature_detected!("bmi2"),- lzcnt: std::arch::is_x86_feature_detected!("lzcnt"),- })+ host::features()}#[cfg(not(target_arch = "x86_64"))]Self::X86_64_V2}}+#[cfg(target_arch = "x86_64")]+mod host {+ // NB: The JS JIT crate has no `std`, so that its code cannot use the heap. Only this module has it, for the+ // detection of the features of the CPU, which also asks the OS whether it saves the extended registers.+ extern crate std;++ use super::CpuFeatures;+ use core::sync::atomic::{AtomicU8, Ordering};++ const AVX: u8 = 1 << 0;+ const AVX2: u8 = 1 << 1;+ const BMI1: u8 = 1 << 2;+ const BMI2: u8 = 1 << 3;+ const LZCNT: u8 = 1 << 4;+ const KNOWN: u8 = 1 << 7;++ /// The features of the host, with `KNOWN` set once they are detected.+ static FEATURES: AtomicU8 = AtomicU8::new(0);++ pub(super) fn features() -> CpuFeatures {+ let mut bits = FEATURES.load(Ordering::Relaxed);+ if bits & KNOWN == 0 {+ let bit = |detected: bool, bit: u8| if detected { bit } else { 0 };+ bits = KNOWN+ | bit(std::arch::is_x86_feature_detected!("avx"), AVX)+ | bit(std::arch::is_x86_feature_detected!("avx2"), AVX2)+ | bit(std::arch::is_x86_feature_detected!("bmi1"), BMI1)+ | bit(std::arch::is_x86_feature_detected!("bmi2"), BMI2)+ | bit(std::arch::is_x86_feature_detected!("lzcnt"), LZCNT);+ // NB: Each thread that detects the features gets the same bits, so a race does no harm.+ FEATURES.store(bits, Ordering::Relaxed);+ }+ CpuFeatures {+ avx: bits & AVX != 0,+ avx2: bits & AVX2 != 0,+ bmi1: bits & BMI1 != 0,+ bmi2: bits & BMI2 != 0,+ lzcnt: bits & LZCNT != 0,+ }+ }+}+impl VexOpcode {/// Only swap inputs whose complete results are identical in either order. Floating-point arithmetic may/// select a NaN payload by operand order, and scalar operations also copy upper lanes from the first input.@@ -498,7 +533,7 @@ mod tests {asm.ret();let code = ExecutableCode::new(&asm.finish().unwrap());let run: extern "sysv64" fn(*const u128, *const u128, *mut u128) =- unsafe { std::mem::transmute(code.address()) };+ unsafe { core::mem::transmute(code.address()) };let mut results = [0u128; 2];run(&raw const a, &raw const b, results.as_mut_ptr());assert_eq!(@@ -531,7 +566,7 @@ mod tests {asm.ret();let code = ExecutableCode::new(&asm.finish().unwrap());let run: extern "sysv64" fn(*const u128, *const u128, *mut u128) =- unsafe { std::mem::transmute(code.address()) };+ unsafe { core::mem::transmute(code.address()) };let a = (0x1234_5678_9abc_def0u128 << 64) | u128::from(7.5f64.to_bits());let b = (0xfedc_ba98_7654_3210u128 << 64) | u128::from(2.0f64.to_bits());let mut result = [0u128; 2];@@ -568,7 +603,7 @@ mod tests {asm.mov_rr(Width::W64, RAX, dst);asm.ret();let code = ExecutableCode::new(&asm.finish().unwrap());- let run: extern "sysv64" fn(u64) -> u64 = unsafe { std::mem::transmute(code.address()) };+ let run: extern "sysv64" fn(u64) -> u64 = unsafe { core::mem::transmute(code.address()) };for input in [0, 1, 2, 3, 1 << 31, 1 << 32, 1 << 63, u64::MAX] {let expected = match (op, width) {(BitCount::Lzcnt, Width::W32) => (input as u32).leading_zeros(),diff --git a/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs b/Libraries/LibJS/JIT/Rust/src/builder/inlining.rsindex 9a6f20ca53b..35f4aaac966 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs@@ -1314,8 +1314,8 @@ impl<'a, 'z> GraphBuilder<'a, 'z> {let Some(dst_slot) = self.function.layout.tracked_index(*dst) else {return Ok(None);};- let mut operands = std::iter::once(*callee)- .chain(std::iter::once(*this_value))+ let mut operands = core::iter::once(*callee)+ .chain(core::iter::once(*this_value)).chain(arguments.iter().copied());if self.graph.legacy_arguments.contains(&dst.raw())|| info.reads_whole_frame@@ -2274,7 +2274,7 @@ impl<'a, 'z> GraphBuilder<'a, 'z> {let derived_construct = construct.filter(|construct| construct.super_constructor.is_some());// NB: The callee's frame cannot hold the virtual arguments object:// the callee's generic instructions could not read it.- if std::iter::once(&this)+ if core::iter::once(&this).chain(arguments.iter()).any(|value| matches!(value, InlineValue::Operand(operand) if self.holds_virtual_arguments(*operand))){@@ -2458,14 +2458,14 @@ impl<'a, 'z> GraphBuilder<'a, 'z> {// NB: Walk the callee's bytecode, then continue in the caller.callee_function.start_walk();- let caller = std::mem::replace(&mut self.function, callee_function);+ let caller = core::mem::replace(&mut self.function, callee_function);self.callers.push(caller);self.frame = callee_frame;let call_block = self.block;self.enter_function(call_block);let result = self.build_function();let caller = self.callers.pop().expect("the caller was suspended");- let callee_function = std::mem::replace(&mut self.function, caller);+ let callee_function = core::mem::replace(&mut self.function, caller);result?;self.inlined_instructions += instruction_count;diff --git a/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rs b/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rsindex 127084e7978..dc44979a57c 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rs@@ -129,7 +129,7 @@ impl<'a> GraphBuilder<'a, '_> {let Some(feedback) = self.call_feedback(call_feedback) else {return Ok(None);};- if std::iter::once(&this_value)+ if core::iter::once(&this_value).chain(arguments).any(|operand| self.holds_virtual_arguments(*operand)){@@ -1009,9 +1009,9 @@ impl<'a> GraphBuilder<'a, '_> {}let mut slow_paths = self.start_slow_paths(Some(Repr::Tagged))?;let mut inputs = self.node_list();- let operands = std::iter::once(Some(*this_value))+ let operands = core::iter::once(Some(*this_value)).chain((0..call.arguments.len()).map(|index| arguments.get(index).copied()));- for (operand, kind) in operands.zip(std::iter::once(call.receiver).chain(call.arguments.iter().copied())) {+ for (operand, kind) in operands.zip(core::iter::once(call.receiver).chain(call.arguments.iter().copied())) {let input = match (operand, kind) {(Some(operand), HelperOperand::Value) => self.read(operand)?,(Some(operand), HelperOperand::String) => {diff --git a/Libraries/LibJS/JIT/Rust/src/builder/mod.rs b/Libraries/LibJS/JIT/Rust/src/builder/mod.rsindex 9ace6e1b25f..5a8a99e973a 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/mod.rs@@ -91,10 +91,10 @@ use ak::Zone;use ak::ZoneBitSet;use ak::ZoneMap;use ak::ZoneVec;+use core::cell::Cell;+use core::cell::OnceCell;pub(crate) use slow_paths::is_ssa_slow_path_output;pub(crate) use slow_paths::js_call_operands;-use std::cell::Cell;-use std::cell::OnceCell;/// Builds the IR for `snapshot.executables[0]`, with the graph and the work data of the build both in `zone`.#[cfg(test)]diff --git a/Libraries/LibJS/JIT/Rust/src/bytecode/cfg.rs b/Libraries/LibJS/JIT/Rust/src/bytecode/cfg.rsindex 2e358cd44b2..254075429e2 100644--- a/Libraries/LibJS/JIT/Rust/src/bytecode/cfg.rs+++ b/Libraries/LibJS/JIT/Rust/src/bytecode/cfg.rs@@ -26,7 +26,7 @@ use super::THIS_VALUE_REGISTER;use ak::Zone;use ak::ZoneBitSet;use ak::ZoneVec;-use std::ops::Range;+use core::ops::Range;pub type BlockIndex = usize;diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rsindex e956fd9dd99..3cb0ea34409 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs@@ -177,7 +177,7 @@ fn generate_stub<M: PortableMacroAssembler>(verify: false,emitting: None,requested_temps: &[],- undeclared_saves_area_uses: std::cell::RefCell::new(ZoneVec::new_in(&zone)),+ undeclared_saves_area_uses: core::cell::RefCell::new(ZoneVec::new_in(&zone)),};codegen.emit_call_stub(construct)?;codegen.masm.finish().map_err(super::assembly_failure)?;diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rsindex f70a068edf4..075c51a7e26 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs@@ -415,9 +415,9 @@ struct Codegen<'a, 'c, M: PortableMacroAssembler> {/// The node whose code (inline or out of line) is being emitted, if any.emitting: Option<NodeId>,/// How many temps each node's lowering took (see `temp()`).- requested_temps: &'a [std::cell::Cell<u8>],+ requested_temps: &'a [core::cell::Cell<u8>],/// The nodes whose code used the saves area without declaring it.- undeclared_saves_area_uses: std::cell::RefCell<ZoneVec<'a, NodeId>>,+ undeclared_saves_area_uses: core::cell::RefCell<ZoneVec<'a, NodeId>>,}/// The operands of the slow path of a `CallSlowPath` node that is a call,@@ -546,8 +546,8 @@ pub fn generate<'a, M: PortableMacroAssembler>(fused_probe_failure: None,verify: verify || cfg!(debug_assertions),emitting: None,- requested_temps: work.alloc_slice_from_iter(graph.nodes.iter().map(|_| std::cell::Cell::new(0))),- undeclared_saves_area_uses: std::cell::RefCell::new(ZoneVec::new_in(work)),+ requested_temps: work.alloc_slice_from_iter(graph.nodes.iter().map(|_| core::cell::Cell::new(0))),+ undeclared_saves_area_uses: core::cell::RefCell::new(ZoneVec::new_in(work)),};codegen.lay_out_frame()?;codegen.emit_prologue();diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rsindex cd424403dcd..96233c3d0a2 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs@@ -645,7 +645,7 @@ fn runtime() -> RuntimeInfo {set(OpCode::ConcatString, concat_string as *const () as u64);set(OpCode::NewArray, new_array as *const () as u64);RuntimeInfo {- slow_paths: slow_paths.into(),+ slow_paths: slow_paths.leak(),jit_call: jit_call as *const () as u64,jit_exit: jit_exit as *const () as u64,to_boolean: to_boolean as *const () as u64,@@ -1008,6 +1008,50 @@ fn compile_program_with((snapshot, compiled)}+#[test]+fn a_compile_makes_no_block_in_the_heap() {+ let program = assemble(|label| {+ vec![+ Instruction::Enter,+ Instruction::Mov { dst: l(0), src: c(0) },+ Instruction::Mov { dst: l(1), src: c(0) },+ Instruction::JumpLessThan {+ arith_feedback: 0,+ lhs: l(0),+ rhs: a(0),+ true_target: label(4),+ false_target: label(7),+ },+ Instruction::AddRhsInt32 {+ arith_feedback: 1,+ dst: l(0),+ lhs: l(0),+ rhs: 1,+ },+ Instruction::Add {+ arith_feedback: 2,+ dst: l(1),+ lhs: l(1),+ rhs: l(0),+ },+ Instruction::Jump { target: label(3) },+ Instruction::Return { value: l(1) },+ ]+ });+ let mut snapshot = crate::builder::tests::snapshot_for(&program, test_layout());+ snapshot.runtime = runtime();+ snapshot.executables[0].feedback.arith = snapshot.add(&[NUMBERS_AND_STRINGS_FEEDBACK; 3]);+ snapshot.options = crate::snapshot::CompileOptions::default();+ let mut scratch = crate::scratch::Scratch::new();+ let mut compiled = CompiledCode::new();+ crate::compile(&snapshot, &mut scratch, &mut compiled).unwrap();+ let mut result = Ok(());+ let blocks = crate::count_heap_blocks(|| result = crate::compile(&snapshot, &mut scratch, &mut compiled));+ assert_eq!(result, Ok(()));+ assert!(!compiled.code.is_empty());+ assert_eq!(blocks, 0);+}+#[cfg(target_arch = "x86_64")]/// The pc of the (only) loop back edge of `program`, which on-stack/// replacement entries start at.diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rsindex 80021cbd641..af101b50a68 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs@@ -218,8 +218,8 @@ fn set_marker_runtime(snapshot: &mut Snapshot) {use OpCode as O;let mut runtime = runtime();runtime.object_allocation.template = snapshot.add(&[PLAIN_OBJECT_CLASS]);- let mut set =- |opcode: OpCode, address: u64| std::sync::Arc::make_mut(&mut runtime.slow_paths)[opcode as usize] = address;+ let mut slow_paths = runtime.slow_paths.to_vec();+ let mut set = |opcode: OpCode, address: u64| slow_paths[opcode as usize] = address;for opcode in [O::Add,O::AddLhsInt32,@@ -326,6 +326,7 @@ fn set_marker_runtime(snapshot: &mut Snapshot) {for opcode in [O::Increment, O::Decrement, O::PostfixIncrement, O::PostfixDecrement] {set(opcode, marker_record as *const () as u64);}+ runtime.slow_paths = slow_paths.leak();snapshot.runtime = runtime;}@@ -2994,9 +2995,11 @@ fn every_fast_path_compiles_for_both_architectures() {});let mut snapshot = crate::builder::tests::snapshot_for(&program, layout());set_marker_runtime(&mut snapshot);+ let mut slow_paths = snapshot.runtime.slow_paths.to_vec();for opcode in [OpCode::InitializeVariableBinding, OpCode::SetLexicalBinding] {- std::sync::Arc::make_mut(&mut snapshot.runtime.slow_paths)[opcode as usize] = marker_put as *const () as u64;+ slow_paths[opcode as usize] = marker_put as *const () as u64;}+ snapshot.runtime.slow_paths = slow_paths.leak();let compiled =compile_for::<crate::asm::aarch64::MacroAssembler>(&snapshot, &|_| true, &mut crate::scratch::Scratch::new()).unwrap();diff --git a/Libraries/LibJS/JIT/Rust/src/ir/effects.rs b/Libraries/LibJS/JIT/Rust/src/ir/effects.rsindex c9764d0ef68..892613b643b 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/effects.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/effects.rs@@ -66,7 +66,7 @@ impl Locations {}}-impl std::ops::BitOr for Locations {+impl core::ops::BitOr for Locations {type Output = Self;fn bitor(self, other: Self) -> Self {@@ -74,7 +74,7 @@ impl std::ops::BitOr for Locations {}}-impl std::ops::BitOrAssign for Locations {+impl core::ops::BitOrAssign for Locations {fn bitor_assign(&mut self, other: Self) {*self = self.union(other);}diff --git a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs b/Libraries/LibJS/JIT/Rust/src/ir/mod.rsindex f7c6460eeb9..44719b2b4e6 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/mod.rs@@ -1485,7 +1485,7 @@ pub enum Successors<'z> {Cases(&'z [BlockId]),}-impl std::ops::Deref for Successors<'_> {+impl core::ops::Deref for Successors<'_> {type Target = [BlockId];fn deref(&self) -> &[BlockId] {@@ -1884,7 +1884,7 @@ impl<'z> Graph<'z> {/// A frame state and its callers' frame states, innermost first.pub fn frame_state_chain(&self, id: FrameStateId) -> impl Iterator<Item = FrameStateId> + Clone + '_ {- std::iter::successors(Some(id), |id| self.frame_state(*id).parent)+ core::iter::successors(Some(id), |id| self.frame_state(*id).parent)}/// The values `node` uses: its inputs, then the values of its frame@@ -1944,7 +1944,7 @@ impl<'z> Graph<'z> {work: &'a Zone,) -> impl Iterator<Item = (u32, NodeId)> + 'a {self.chain_values(id).chain(- std::iter::once_with(move || self.virtual_objects(id, work))+ core::iter::once_with(move || self.virtual_objects(id, work)).flatten().flat_map(|object| {self.node(object)@@ -1987,7 +1987,7 @@ impl<'z> Graph<'z> {/// The blocks code starts at: block 0, and the on-stack replacement/// entries.pub fn entries(&self) -> impl Iterator<Item = BlockId> + '_ {- std::iter::once(BlockId(0)).chain(self.osr_entries.iter().map(|(_, entry)| *entry))+ core::iter::once(BlockId(0)).chain(self.osr_entries.iter().map(|(_, entry)| *entry))}/// The control node ending `block`, which every block has once built.diff --git a/Libraries/LibJS/JIT/Rust/src/lib.rs b/Libraries/LibJS/JIT/Rust/src/lib.rsindex ffcb4f9cc98..863e261ca73 100644--- a/Libraries/LibJS/JIT/Rust/src/lib.rs+++ b/Libraries/LibJS/JIT/Rust/src/lib.rs@@ -11,14 +11,10 @@//! thread). It calls nothing in the runtime and has no access to the GC heap, so//! it can run on a worker thread.-// NB: The tests keep their own data in the heap.-#![cfg_attr(- test,- allow(clippy::disallowed_types, clippy::disallowed_macros, clippy::disallowed_methods)-)]+// NB: A compile makes no block in the heap: all its data is in zones (see `ak::Zone`). Without `std` (and without+// `alloc`), rustc rejects code of the compiler that would make one. The tests keep `std`.+#![cfg_attr(not(test), no_std)]-// NB: A module with `allow(clippy::disallowed_types)` still uses containers of the heap (see clippy.toml). It loses-// the `allow` when its data is in zones.pub mod artifact;pub mod asm;pub mod builder;@@ -31,7 +27,6 @@ pub mod ir;pub mod passes;pub mod regalloc;pub mod scratch;-#[allow(clippy::disallowed_types, clippy::disallowed_macros, clippy::disallowed_methods)]pub mod snapshot;pub mod tables;@@ -97,6 +92,67 @@ pub(crate) fn test_steps() -> [ak::Zone; 2] {[test_work(), test_work()]}+/// The allocator of the tests, which counts the blocks that `count_heap_blocks()` makes on its thread.+#[cfg(test)]+mod heap_counter {+ use std::alloc::{GlobalAlloc, Layout, System};+ use std::cell::Cell;++ struct CountingAllocator;++ std::thread_local! {+ static COUNTING: Cell<bool> = const { Cell::new(false) };+ static BLOCKS: Cell<usize> = const { Cell::new(0) };+ }++ fn count_block() {+ if COUNTING.with(Cell::get) {+ BLOCKS.with(|blocks| blocks.set(blocks.get() + 1));+ }+ }++ // SAFETY: Each method passes its call on to `System` as it is.+ unsafe impl GlobalAlloc for CountingAllocator {+ unsafe fn alloc(&self, layout: Layout) -> *mut u8 {+ count_block();+ // SAFETY: The caller keeps the contract of `GlobalAlloc::alloc`.+ unsafe { System.alloc(layout) }+ }++ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {+ count_block();+ // SAFETY: The caller keeps the contract of `GlobalAlloc::alloc_zeroed`.+ unsafe { System.alloc_zeroed(layout) }+ }++ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {+ count_block();+ // SAFETY: The caller keeps the contract of `GlobalAlloc::realloc`.+ unsafe { System.realloc(ptr, layout, new_size) }+ }++ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {+ // SAFETY: The caller keeps the contract of `GlobalAlloc::dealloc`.+ unsafe { System.dealloc(ptr, layout) }+ }+ }++ #[global_allocator]+ static ALLOCATOR: CountingAllocator = CountingAllocator;++ /// Runs `f`, and gives the number of blocks of the heap that it made or grew on this thread.+ pub(crate) fn count_heap_blocks(f: impl FnOnce()) -> usize {+ BLOCKS.with(|blocks| blocks.set(0));+ COUNTING.with(|counting| counting.set(true));+ f();+ COUNTING.with(|counting| counting.set(false));+ BLOCKS.with(Cell::get)+ }+}++#[cfg(test)]+pub(crate) use heap_counter::count_heap_blocks;+/// Compiles `snapshot.executables[0]` for the host architecture with the memory of `scratch`, into `compiled` in/// place of what it holds. After a failure, `compiled` holds no complete code.pub fn compile(snapshot: &Snapshot, scratch: &mut Scratch, compiled: &mut CompiledCode) -> Result<(), CompileFailure> {diff --git a/Libraries/LibJS/JIT/Rust/src/passes/branch_fusion.rs b/Libraries/LibJS/JIT/Rust/src/passes/branch_fusion.rsindex 3bc99ea9d27..aa1e8578050 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/branch_fusion.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/branch_fusion.rs@@ -151,7 +151,7 @@ fn thread_boolean_phis(graph: &mut Graph, uses: &[u32], work: &Zone) {(0..block_count).filter(|block| !threaded.contains(*block)).flat_map(|block| {- std::iter::once(BlockId::from_index(block)).chain(new_blocks[block].into_iter().flatten())+ core::iter::once(BlockId::from_index(block)).chain(new_blocks[block].into_iter().flatten())}),work,);diff --git a/Libraries/LibJS/JIT/Rust/src/passes/edit.rs b/Libraries/LibJS/JIT/Rust/src/passes/edit.rsindex f00c678ff2e..646377b58b1 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/edit.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/edit.rs@@ -176,7 +176,7 @@ fn reachable_blocks<'w>(graph: &Graph, work: &'w Zone) -> ZoneVec<'w, bool> {// predecessors if none of them was built, but is no entry.let mut pending = ZoneVec::from_iter_in(graph.entries().map(BlockId::index), work);while let Some(block) = pending.pop() {- if std::mem::replace(&mut reachable[block], true) {+ if core::mem::replace(&mut reachable[block], true) {continue;}pending.extend(@@ -450,7 +450,7 @@ pub fn remove_unused_frame_states(graph: &mut Graph, work: &Zone) {for node in block.nodes() {let mut frame_state = graph.nodes[node.index()].frame_state;while let Some(id) = frame_state {- if std::mem::replace(&mut used[id.index()], true) {+ if core::mem::replace(&mut used[id.index()], true) {break;}frame_state = graph.frame_states[id.index()].parent;diff --git a/Libraries/LibJS/JIT/Rust/src/passes/gvn.rs b/Libraries/LibJS/JIT/Rust/src/passes/gvn.rsindex 9542ee38008..03a4fa0a2d1 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/gvn.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/gvn.rs@@ -26,9 +26,9 @@ use crate::ir::Op;use ak::FastHasher;use ak::ZoneBitSet;use ak::ZoneMap;-use std::hash::Hash;-use std::hash::Hasher;-use std::mem::discriminant;+use core::hash::Hash;+use core::hash::Hasher;+use core::mem::discriminant;fn is_numbered(op: &Op) -> bool {let properties = op.properties();diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/coalescing.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/coalescing.rsindex f4f31dcf014..51bf39ef785 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/coalescing.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/coalescing.rs@@ -104,7 +104,7 @@ impl Interference<'_> {/// The values of the class of `value`, which starts with `value`.fn members(next: &[u32], value: u32) -> impl Iterator<Item = NodeId> + '_ {let mut member = Some(value);- std::iter::from_fn(move || {+ core::iter::from_fn(move || {let current = member?;let following = next[current as usize];member = (following != value).then_some(following);diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/loops.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/loops.rsindex f51fd5c65e8..aee6cc8614b 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/loops.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/loops.rs@@ -204,7 +204,7 @@ impl<'w> Loops<'w> {}let loops = &self.loops;self.by_size- .sort_unstable_by_key(|index| (std::cmp::Reverse(loops[*index as usize].block_count), *index));+ .sort_unstable_by_key(|index| (core::cmp::Reverse(loops[*index as usize].block_count), *index));for index in &self.by_size {let row = *index as usize * self.words_for_each_loop;let blocks = &self.blocks[row..row + self.words_for_each_loop];@@ -243,7 +243,7 @@ impl<'w> Loops<'w> {}/// The first of the use positions `uses[range]` (in order) that is in `loop_`.- pub fn first_use_in(&self, loop_: &Loop, uses: &[u32], range: std::ops::Range<usize>) -> Option<u32> {+ pub fn first_use_in(&self, loop_: &Loop, uses: &[u32], range: core::ops::Range<usize>) -> Option<u32> {loop_.first_use_in(self.blocks_of(loop_), uses, &self.position_blocks, range)}@@ -264,7 +264,7 @@ impl Loop {blocks: &[u64],uses: &[u32],position_blocks: &[u32],- range: std::ops::Range<usize>,+ range: core::ops::Range<usize>,) -> Option<u32> {let uses = &uses[range];let from = uses.partition_point(|position| *position < self.start);diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rsindex 96f5cf421c3..caeade65f7c 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rs@@ -787,7 +787,7 @@ impl<'w> Allocator<'_, 'w> {let victim = candidates().max_by_key(|register| {let value = self.contents[*register as usize].expect("no free register");- (self.next_use(value), std::cmp::Reverse(*register))+ (self.next_use(value), core::cmp::Reverse(*register))}).expect("a node needs more registers than the target has");self.evict(victim);@@ -1033,7 +1033,7 @@ impl<'w> Allocator<'_, 'w> {.iter().filter(|register| !taken.contains(*register));let first = free.next()?;- std::iter::once(first)+ core::iter::once(first).chain(free).find(|register| self.contents[*register as usize].is_none()).or(Some(first))diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/verify.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/verify.rsindex 300b8d486a7..f933bd1dafc 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/verify.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/verify.rs@@ -353,7 +353,7 @@ impl Verifier<'_, '_> {state.load(exit);for (phi, input) in phi_inputs_from(self.graph, *predecessor, block) {let output = self.allocation.node(phi).output.expect("phis have a location");- for location in std::iter::once(output).chain(self.filled_slot(phi)) {+ for location in core::iter::once(output).chain(self.filled_slot(phi)) {if self.read(&*state, location) == Some(self.content_of_value(input)) {state.insert(location, Content::Value(phi));} else {@@ -379,7 +379,7 @@ impl Verifier<'_, '_> {};for (phi, input) in phi_inputs_from(self.graph, predecessor, block) {let output = self.allocation.node(phi).output.expect("phis have a location");- for location in std::iter::once(output).chain(self.filled_slot(phi)) {+ for location in core::iter::once(output).chain(self.filled_slot(phi)) {let found = self.read(exit, location);if found != Some(self.content_of_value(input)) {self.error(format_args!(diff --git a/Libraries/LibJS/JIT/Rust/src/snapshot.rs b/Libraries/LibJS/JIT/Rust/src/snapshot.rsindex 0b2cb0896e2..953a4365a27 100644--- a/Libraries/LibJS/JIT/Rust/src/snapshot.rs+++ b/Libraries/LibJS/JIT/Rust/src/snapshot.rs@@ -20,7 +20,6 @@ use core::marker::PhantomData;use core::ops::{Deref, DerefMut, Index, IndexMut};use ak::{Column, RowBlock, Zone};-use std::sync::Arc;use crate::ir::Float64Function;use crate::ir::Locations;@@ -1077,7 +1076,7 @@ pub struct RuntimeInfo {/// The address of the slow path each generic opcode calls, indexed by/// opcode, or 0 if there is none. `codegen::slow_path_symbol()` names the/// function for each opcode and the calling convention it is called with.- pub slow_paths: Arc<[u64]>,+ pub slow_paths: &'static [u64],/// `i64 libjs_jit_call(VM*, ExecutionContext*, u32 pc)`: runs the call/// instruction at `pc` to completion, writes its result into its/// destination slot, and returns a slow path control word.@@ -1978,21 +1977,21 @@ impl<T: Row> IndexMut<List<T>> for Snapshot {/// A snapshot that is being captured, with what writes its lists row by row: `begin()`, `push()` and `end()`. A list/// that is ready is added in one go, with `Snapshot::add()`.-pub struct SnapshotWriter {- snapshot: Box<Snapshot>,+pub struct SnapshotWriter<'a> {+ snapshot: &'a mut Snapshot,lists: OpenLists,}-impl SnapshotWriter {+impl<'a> SnapshotWriter<'a> {/// Writes into `snapshot`, with the memory of `lists` for the lists that are written row by row.- pub fn new(snapshot: Box<Snapshot>, mut lists: OpenLists) -> Self {+ pub fn new(snapshot: &'a mut Snapshot, mut lists: OpenLists) -> Self {lists.reset();Self { snapshot, lists }}- /// The snapshot as it is now, and the memory for lists that are written row by row, for the next capture.- pub fn finish(self) -> (Box<Snapshot>, OpenLists) {- (self.snapshot, self.lists)+ /// The memory for lists that are written row by row, for the next capture. The snapshot keeps what was written.+ pub fn finish(self) -> OpenLists {+ self.lists}/// A zone for data that one step of the capture reads and then drops (see `Zone::scope()`). Its memory serves@@ -2039,17 +2038,17 @@ impl SnapshotWriter {}}-impl Deref for SnapshotWriter {+impl Deref for SnapshotWriter<'_> {type Target = Snapshot;fn deref(&self) -> &Snapshot {- &self.snapshot+ self.snapshot}}-impl DerefMut for SnapshotWriter {+impl DerefMut for SnapshotWriter<'_> {fn deref_mut(&mut self) -> &mut Snapshot {- &mut self.snapshot+ self.snapshot}}diff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rsindex dfc4f25aff7..92009835aba 100644--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs@@ -8,7 +8,7 @@//! and encodings of the fields it accesses, from the same layout types the interpreter is compiled against.use core::mem::offset_of;-use std::sync::Arc;+use std::sync::OnceLock;use libjs_abi::Builtin;use libjs_abi::value as nan_box;@@ -82,7 +82,7 @@ const _: () =pub struct RuntimeFunctionAddresses {/// The address of the slow path JIT code calls for each generic opcode, indexed by opcode, or 0 for opcodes/// without one (the compiler refuses to compile those generically).- slow_paths: Arc<[u64]>,+ slow_paths: &'static [u64],try_get_by_id_cache: u64,try_put_by_id_cache: u64,raw_native_exception: u64,@@ -101,11 +101,15 @@ impl RuntimeFunctionAddresses {.map(|(_, address)| *address as u64).unwrap_or_else(|| panic!("the runtime has no function {symbol}"))};+ // NB: The table holds addresses of functions, which are the same for every VM of the process.+ static SLOW_PATHS: OnceLock<Box<[u64]>> = OnceLock::new();Self {- slow_paths: (0..=u8::MAX)- .map_while(OpCode::from_u8)- .map(|opcode| slow_path_symbol(opcode).map_or(0, |symbol| address(&symbol.to_string())))- .collect(),+ slow_paths: SLOW_PATHS.get_or_init(|| {+ (0..=u8::MAX)+ .map_while(OpCode::from_u8)+ .map(|opcode| slow_path_symbol(opcode).map_or(0, |symbol| address(&symbol.to_string())))+ .collect()+ }),try_get_by_id_cache: address("asm_try_get_by_id_cache"),try_put_by_id_cache: address("asm_try_put_by_id_cache"),raw_native_exception: if RAW_NATIVE_FUNCTIONS_RETURN_IN_REGISTERS {@@ -521,7 +525,7 @@ pub fn runtime_info(};let mut info = RuntimeInfo {no_htmldda_objects: !vm.jit.htmldda_objects_exist(),- slow_paths: Arc::clone(&addresses.slow_paths),+ slow_paths: addresses.slow_paths,jit_call: jit_function_address!(super::calls::libjs_jit_call),call_forwarding_arguments: jit_function_address!(super::calls::libjs_jit_call_forwarding_arguments),finish_direct_call: jit_function_address!(super::calls::libjs_jit_finish_direct_call),diff --git a/Libraries/LibJS/Rust/src/jit/snapshot.rs b/Libraries/LibJS/Rust/src/jit/snapshot.rsindex 13d98af70f2..9e65abf1e4f 100644--- a/Libraries/LibJS/Rust/src/jit/snapshot.rs+++ b/Libraries/LibJS/Rust/src/jit/snapshot.rs@@ -103,7 +103,7 @@ struct SnapshotBuilder<'vm> {vm: &'vm Vm,defer_gc: &'vm DeferGc<'vm>,/// The snapshot that is being captured.- snapshot: SnapshotWriter,+ snapshot: SnapshotWriter<'vm>,cells: Vec<Gc<CellHeader>>,entries: Vec<Entry>,indices: HashMap<InlinedFunction, u32>,@@ -1568,10 +1568,8 @@ pub fn capture_snapshot<'d>(..FunctionFrameFields::default()},};- let mut snapshot = SnapshotWriter::new(- super::compile_queue::spare_snapshot(),- super::compile_queue::spare_open_lists(),- );+ let mut spare_snapshot = super::compile_queue::spare_snapshot();+ let mut snapshot = SnapshotWriter::new(&mut spare_snapshot, super::compile_queue::spare_open_lists());// NB: These allocate (and so may collect garbage), which they do before anything is captured.let allocation = allocation_infos(vm, realm, defer_gc, &mut snapshot);// NB: Closures that top-level code creates have its environments, which the code does not know.@@ -1680,8 +1678,8 @@ pub fn capture_snapshot<'d>(entries,..} = builder;- let (mut snapshot, open_lists) = snapshot.finish();- super::compile_queue::give_back_open_lists(open_lists);+ super::compile_queue::give_back_open_lists(snapshot.finish());+ let mut snapshot = spare_snapshot;snapshot.runtime = runtime;snapshot.options = {CompileOptions {diff --git a/Meta/Linters/check_rust_process_wide_state.py b/Meta/Linters/check_rust_process_wide_state.pyindex 97205bef711..43c9a66ae73 100755--- a/Meta/Linters/check_rust_process_wide_state.py+++ b/Meta/Linters/check_rust_process_wide_state.py@@ -37,6 +37,8 @@ ALLOWED = {"Libraries/LibJS/Flap/src/low_ir/lowering.rs:LABELS": "per-thread scratch buffer; a second copy costs memory, never an answer","Libraries/LibJS/JIT/Rust/src/asm/x86_64/sse.rs:FEATURES": "immutable CPU/OS feature cache; each copy computes the same supported instructions","Libraries/LibJS/JIT/Rust/src/codegen/tests.rs:REGION": "the fake heap region of JIT unit tests, in the cargo test binary that has no runtime",+ "Libraries/LibJS/JIT/Rust/src/lib.rs:BLOCKS": "per-thread count of the allocator of JIT unit tests, in the cargo test binary that has no runtime",+ "Libraries/LibJS/JIT/Rust/src/lib.rs:COUNTING": "per-thread switch of the allocator of JIT unit tests, in the cargo test binary that has no runtime","Libraries/LibRegex/Rust/src/vm.rs:INTERRUPT_FLAG": "per-thread, and only libjs_rust's copy sets it; the copy of LibURL's crate has no VM to interrupt, so it only ever sees null","Libraries/LibWeb/HTML/Parser/Rust/src/parser/test_host.rs:FAKE_DOM": "the fake DOM of tree builder unit tests, in the cargo test binary that has no C++ side","Libraries/LibWeb/HTML/Parser/Rust/src/token.rs:SPARE_ATTRIBUTE_LISTS": "per-thread allocation pool; a second copy costs memory, never an answer",