Truly independent web browser
LibJS: Use fast array mode for arrays in compiled code
Aliaksandr Kalenikb20f41c2f55a
diff --git a/Libraries/LibJS/JIT/ARCHITECTURE.md b/Libraries/LibJS/JIT/ARCHITECTURE.mdindex 974ce32834a..94c5716e08f 100644--- a/Libraries/LibJS/JIT/ARCHITECTURE.md+++ b/Libraries/LibJS/JIT/ARCHITECTURE.md@@ -185,7 +185,7 @@ Exits: E = eager, L = lazy. Every node that can exit has a frame state. "Call" m| ConcatenateStrings | The concatenation of two strings, a rope or a cached short string, or the empty value where only the slow path makes it. | | | | allocates || IntegerToString | The VM's cached string of an int32, or the empty value. | | | | cse || LoadPropertyIteratorKeyCount, LoadPropertyIteratorKey | The keys of a property iterator cache, at an index refined to be in bounds. The keys never change. | | | | cse |-| CreateArrayIterator | `GetIterator` of an array that iterates with `%Array.prototype.values%` and the builtin `next` (input 1), through a runtime call that preserves every register: a new array iterator over its values, or the empty value for anything else. | | Any | | allocates |+| OpenArrayIteration | `GetIterator` in fast array mode, through a runtime call that preserves every register: the iterable, if it is an array that iterates with `%Array.prototype.values%` and whose array iterators have the builtin `next`, or the empty value. The iteration then keeps the index of the next element in the iterator operand and the array in the next operand, and makes no iterator. | | Any | | || LoadArrayIteratorArray, LoadArrayIteratorIndex | The iterated array (`undefined` once done) and the low 32 bits of the next index of an array iterator (a `Repr::Pointer` that `BranchCondition::ArrayIterator` established is one). | | Iterators | | || StoreArrayIteratorIndex, FinishArrayIterator | Sets the next index of an array iterator, or makes it done. | | | Iterators | || LoadGlobalBinding | A binding of the global declarative environment; exits while uninitialized. | E | Global | | cse |@@ -274,7 +274,7 @@ the prologue's resumption in the interpreter publishes it inline.Compiled code may assume facts that hold until a rare runtime event (`code::Dependency`): aprototype chain stays valid, a shape stays stable, a global binding or a property of the globalobject is never assigned, the global declarative environment gets no bindings, no `[[IsHTMLDDA]]`-object exists.+object exists, a fuse of a realm stays intact (`runtime/realm_fuses.rs`).- The builder and check elimination record the dependencies they rely on in`Graph::dependencies`.diff --git a/Libraries/LibJS/JIT/Rust/src/builder/array_iterators.rs b/Libraries/LibJS/JIT/Rust/src/builder/array_iterators.rsindex a3ce8caf4b5..f93ba8eb3f3 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/array_iterators.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/array_iterators.rs@@ -4,10 +4,10 @@* SPDX-License-Identifier: BSD-2-Clause*/-//! Iteration over arrays, built as IR: `GetIterator` makes array iterators-//! without looking up and calling the iterator method of the array, and-//! `IteratorNextUnpack` steps them like `%ArrayIteratorPrototype%.next`-//! does. The slow paths of the instructions handle everything else.+//! Iteration over arrays, built as IR: `GetIterator` iterates arrays in fast+//! array mode, without an iterator, and `IteratorNextUnpack` steps that mode+//! and array iterators like `%ArrayIteratorPrototype%.next` does. The slow+//! paths of the instructions handle everything else.use super::Flow;use super::GraphBuilder;@@ -37,10 +37,9 @@ impl GraphBuilder<'_> {}/// Builds `GetIterator` (`Handling::Expanded`) of a synchronous iterator- /// as a new array iterator for arrays (see `Op::CreateArrayIterator`),- /// whose next method is the builtin one and which is not done yet.- /// Returns `None`, having built nothing, if the realm's array iterators- /// had another next method.+ /// in fast array mode, where the instruction allows it (see+ /// `Op::OpenArrayIteration`): the index 0, the array, and not done.+ /// Returns `None`, having built nothing, where it does not.pub(super) fn try_build_get_iterator(&mut self,dst_iterator_object: Operand,@@ -48,19 +47,18 @@ impl GraphBuilder<'_> {dst_iterator_done: Operand,iterable: Operand,hint: u32,+ fast_array_mode_allowed: bool,) -> Result<Option<Flow>, CompileFailure> {- if hint != SYNC_HINT {+ if hint != SYNC_HINT || !fast_array_mode_allowed {return Ok(None);}- let Some(next) = self.array_iterator_next() else {- return Ok(None);- };let iterable = self.read(iterable)?;let mut slow_paths = self.start_slow_paths(Some(Repr::Tagged))?;- let iterator = self.emit(Op::CreateArrayIterator, vec![iterable, next], Some(Repr::Tagged));- let iterator = self.branch_if_empty(&mut slow_paths, iterator);+ let array = self.emit(Op::OpenArrayIteration, vec![iterable], Some(Repr::Tagged));+ let array = self.branch_if_empty(&mut slow_paths, array);+ let first_index = self.constant(value::int32(0));let not_done = self.constant(value::FALSE);- let outputs = self.join_paths(slow_paths, vec![iterator, next, not_done], |_, outputs| outputs);+ let outputs = self.join_paths(slow_paths, vec![first_index, array, not_done], |_, outputs| outputs);self.write(dst_iterator_object, outputs[0])?;self.write(dst_iterator_next, outputs[1])?;self.write(dst_iterator_done, outputs[2])?;diff --git a/Libraries/LibJS/JIT/Rust/src/builder/checks.rs b/Libraries/LibJS/JIT/Rust/src/builder/checks.rsindex 4dfdf8184ab..6b2a955d63f 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/checks.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/checks.rs@@ -90,6 +90,7 @@ impl GraphBuilder<'_> {dst_iterator_done,iterable,hint,+ fast_array_mode_allowed,..} => match self.try_build_get_iterator(dst_iterator_object,@@ -97,6 +98,7 @@ impl GraphBuilder<'_> {dst_iterator_done,iterable,hint,+ fast_array_mode_allowed,)? {Some(flow) => Ok(flow),None => self.build_generic(instruction, info),diff --git a/Libraries/LibJS/JIT/Rust/src/builder/named.rs b/Libraries/LibJS/JIT/Rust/src/builder/named.rsindex 301550fedd8..947b17fdc8b 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/named.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/named.rs@@ -17,6 +17,7 @@ use super::GraphBuilder;use super::checks::SlowPaths;use crate::CompileFailure;use crate::bytecode::Instruction;+use crate::code::Dependency;use crate::code::Repr;use crate::ir::BranchCondition;use crate::ir::Comparison;@@ -71,6 +72,20 @@ impl GraphBuilder<'_> {};let mut slow_paths = self.start_slow_paths(None)?;let iterator = self.read(iterator_object)?;++ // NB: In fast array mode, the iterator operand holds the index of the+ // next element (see `try_build_get_iterator()`), and the return+ // fuse tells if array iterators have a return method.+ if let Some(return_fuse) = self.runtime.array_iterator_return_fuse {+ let (fast_array_mode, iterator_object) =+ self.branch_both_ways(BranchCondition::NonNegativeInt32, vec![iterator]);+ self.block = fast_array_mode;+ self.embed(return_fuse);+ self.assume(Dependency::Fuse(return_fuse));+ self.end_hot_path(&mut slow_paths, Vec::new());+ self.block = iterator_object;+ }+let return_method = self.probe_property_cache(&mut slow_paths, iterator, cache);self.branch_to_slow_path(&mut slow_paths, BranchCondition::Nullish, vec![return_method], true);self.join_slow_paths(slow_paths, None);diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/array_iterators.rs b/Libraries/LibJS/JIT/Rust/src/codegen/array_iterators.rsindex d0b9d0ad3c5..352a25301e3 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/array_iterators.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/array_iterators.rs@@ -19,22 +19,17 @@ use crate::ir::NodeId;use crate::ir::value;impl<M: PortableMacroAssembler> Codegen<'_, M> {- /// `CreateArrayIterator`: calls `RuntimeInfo::create_array_iterator`.- pub(in crate::codegen) fn emit_create_array_iterator(&mut self, node: NodeId) {- let (iterable, next, output) = (self.input(node, 0), self.input(node, 1), self.output(node));+ /// `OpenArrayIteration`: calls `RuntimeInfo::open_array_iteration`.+ pub(in crate::codegen) fn emit_open_array_iteration(&mut self, node: NodeId) {+ let (iterable, output) = (self.input(node, 0), self.output(node));let saved = slow_path_saved_registers::<M>().without(output).iter().collect::<Vec<_>>();self.emit_save_registers(&saved);- // NB: Either may be in the other's argument register.- let arguments: [Gpr; 3] = [M::ARGUMENT_GPRS[0], M::ARGUMENT_GPRS[1], M::ARGUMENT_GPRS[2]];- let scratch = self.pinned.scratch;- self.masm.move64(scratch, next);- self.masm.move64(arguments[1], iterable);- self.masm.move64(arguments[2], scratch);- self.masm.move64(arguments[0], self.pinned.vm);- self.masm.call_absolute(self.runtime.create_array_iterator);+ self.masm.move64(M::ARGUMENT_GPRS[1], iterable);+ self.masm.move64(M::ARGUMENT_GPRS[0], self.pinned.vm);+ self.masm.call_absolute(self.runtime.open_array_iteration);self.masm.move64(output, M::RETURN_GPRS[0]);self.emit_restore_registers(&saved, None);}diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rsindex 6ab2ecccf0d..2d05674590d 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs@@ -1687,7 +1687,7 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {Op::LoadElementsCapacity => self.emit_load_elements_capacity(node_id),Op::AppendElement => self.emit_append_element_node(node_id),Op::CallArrayPush => self.emit_call_array_push(node_id),- Op::CreateArrayIterator => self.emit_create_array_iterator(node_id),+ Op::OpenArrayIteration => self.emit_open_array_iteration(node_id),Op::LoadArrayIteratorArray => self.emit_load_array_iterator_array(node_id),Op::LoadArrayIteratorIndex => self.emit_load_array_iterator_index(node_id),Op::StoreArrayIteratorIndex => self.emit_store_array_iterator_index(node_id),diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/slow_path_calls.rs b/Libraries/LibJS/JIT/Rust/src/codegen/slow_path_calls.rsindex 5cefb58869c..853c97ef03b 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/slow_path_calls.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/slow_path_calls.rs@@ -180,7 +180,7 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {| Op::ProbePropertyStore { .. }| Op::ProbeKeyedStore { .. }| Op::CallArrayPush- | Op::CreateArrayIterator+ | Op::OpenArrayIteration| Op::AllocateObject { .. }| Op::AllocateArray { .. }| Op::AllocateFunction { .. }diff --git a/Libraries/LibJS/JIT/Rust/src/ir/dump.rs b/Libraries/LibJS/JIT/Rust/src/ir/dump.rsindex adb9d91c7b1..383b257f6b0 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/dump.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/dump.rs@@ -289,7 +289,7 @@ fn op_text(layout: &FrameLayout, op: &Op, inputs: &str) -> String {| Op::LoadElementsCapacity| Op::AppendElement| Op::CallArrayPush- | Op::CreateArrayIterator+ | Op::OpenArrayIteration| Op::LoadArrayIteratorArray| Op::LoadArrayIteratorIndex| Op::StoreArrayIteratorIndexdiff --git a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs b/Libraries/LibJS/JIT/Rust/src/ir/mod.rsindex 6c53cb8e1c8..d0ba9226ec6 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/mod.rs@@ -1013,13 +1013,11 @@ pub enum Op {CallArrayPush,// For-of loops over arrays.- /// `RuntimeInfo::create_array_iterator` of the tagged iterable input 0- /// and the builtin `next` method input 1: a new array iterator over the- /// values of the iterable, or the empty value where it is no array such- /// iterators can iterate. It saves the registers the call clobbers and- /// restores them afterwards, so it is no call for the register- /// allocator.- CreateArrayIterator,+ /// `RuntimeInfo::open_array_iteration` of the tagged iterable input 0:+ /// the iterable, where `GetIterator` iterates it in fast array mode, or+ /// the empty value. It saves the registers the call clobbers and restores+ /// them afterwards, so it is no call for the register allocator.+ OpenArrayIteration,/// The `[[IteratedArrayLike]]` of the array iterator at the/// `Repr::Pointer` input 0, as a tagged value: the array, or `undefined`/// once the iterator is done.@@ -1474,10 +1472,8 @@ impl Op {allocates: true,..P::PURE},- // NB: The new iterator is no location anything reads before.- Op::CreateArrayIterator => P {+ Op::OpenArrayIteration => P {reads: Locations::ALL,- allocates: true,..P::PURE},Op::LoadArrayIteratorArray | Op::LoadArrayIteratorIndex => P {@@ -1608,7 +1604,7 @@ impl Op {Op::LoadElementsCapacity => "LoadElementsCapacity",Op::AppendElement => "AppendElement",Op::CallArrayPush => "CallArrayPush",- Op::CreateArrayIterator => "CreateArrayIterator",+ Op::OpenArrayIteration => "OpenArrayIteration",Op::LoadArrayIteratorArray => "LoadArrayIteratorArray",Op::LoadArrayIteratorIndex => "LoadArrayIteratorIndex",Op::StoreArrayIteratorIndex => "StoreArrayIteratorIndex",diff --git a/Libraries/LibJS/JIT/Rust/src/passes/verify.rs b/Libraries/LibJS/JIT/Rust/src/passes/verify.rsindex 802e9ac631e..d9b506a482e 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/verify.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/verify.rs@@ -523,7 +523,7 @@ fn expected_input_reprs(graph: &Graph, node: NodeId) -> Option<Vec<Repr>> {Op::AppendElement => Some(vec![Repr::Pointer, Repr::Int32, Repr::Tagged]),Op::LoadElementsLength | Op::LoadElementsCapacity => Some(vec![Repr::Pointer]),Op::LoadPropertyIteratorKey => Some(vec![Repr::Tagged, Repr::Int32]),- Op::CreateArrayIterator => Some(tagged(2)),+ Op::OpenArrayIteration => Some(tagged(1)),Op::LoadArrayIteratorArray | Op::LoadArrayIteratorIndex | Op::FinishArrayIterator => Some(vec![Repr::Pointer]),Op::StoreArrayIteratorIndex => Some(vec![Repr::Pointer, Repr::Int32]),Op::BranchOnPc { .. } => Some(vec![Repr::Int32]),diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rsindex dc5e5541ac4..3f80e87c511 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rs@@ -102,7 +102,7 @@ pub fn saves_only_gprs(op: &Op) -> bool {saves_registers: true,..} | Op::CallArrayPush- | Op::CreateArrayIterator+ | Op::OpenArrayIteration| Op::AddNamed { .. }| Op::ProbeKeyedStore { .. }| Op::ProbePropertyCache { .. }diff --git a/Libraries/LibJS/JIT/Rust/src/snapshot.rs b/Libraries/LibJS/JIT/Rust/src/snapshot.rsindex 8621cac82e9..1247a4e03bc 100644--- a/Libraries/LibJS/JIT/Rust/src/snapshot.rs+++ b/Libraries/LibJS/JIT/Rust/src/snapshot.rs@@ -978,16 +978,19 @@ pub struct RuntimeInfo {/// `Array.prototype.slice.call(arguments, start)` with the arguments/// object of `frame`, which the code never created, as an array value.pub slice_arguments: u64,- /// `u64 libjs_jit_create_array_iterator(VM*, u64 iterable, u64 next)`:- /// `GetIterator` of an array whose iterator method is- /// `%Array.prototype.values%`, if the iterators it makes have the method- /// `next`, as a new array iterator over its values; the empty value,- /// having done nothing, otherwise.- pub create_array_iterator: u64,+ /// `u64 libjs_jit_open_array_iteration(VM*, u64 iterable)`:+ /// `GetIterator` in fast array mode: the iterable, if it is an array whose+ /// iterator method is `%Array.prototype.values%` and whose iterators have+ /// the builtin `next` method; the empty value otherwise.+ pub open_array_iteration: u64,/// The builtin `%ArrayIteratorPrototype%.next` of the realm of the/// compiled code, if `%ArrayIteratorPrototype%` holds it. Code that/// embeds it must list it in `CompiledCode::embedded_cells`.pub array_iterator_next: Option<CellId>,+ /// The fuse of the realm of the compiled code that stays intact while+ /// its array iterators have no `return` method, if it was intact. Code+ /// that depends on it must list it in `CompiledCode::embedded_cells`.+ pub array_iterator_return_fuse: Option<CellId>,/// The realm of the compiled code.pub realm: CellId,/// `%Array.prototype%` and `%Object.prototype%` of the realm of thediff --git a/Libraries/LibJS/Rust/src/bytecode/executable.rs b/Libraries/LibJS/Rust/src/bytecode/executable.rsindex ee77b5a25e4..d075fa4a973 100644--- a/Libraries/LibJS/Rust/src/bytecode/executable.rs+++ b/Libraries/LibJS/Rust/src/bytecode/executable.rs@@ -739,9 +739,8 @@ define_static_property_lookup_cache_sites! {IteratorValueValue,IteratorCloseReturn,ArrayAppendIteratorMethod,- CreateArrayIteratorOwnIteratorMethod,- CreateArrayIteratorIteratorMethod,- CreateArrayIteratorNextMethod,+ OpenArrayIterationOwnIteratorMethod,+ OpenArrayIterationIteratorMethod,ObjectPrototypeToStringToStringTag,ArrayFromIteratorMethod,ArraySpeciesCreateConstructor,diff --git a/Libraries/LibJS/Rust/src/jit/intrinsics.rs b/Libraries/LibJS/Rust/src/jit/intrinsics.rsindex a3bd9098e29..bb19560ca4b 100644--- a/Libraries/LibJS/Rust/src/jit/intrinsics.rs+++ b/Libraries/LibJS/Rust/src/jit/intrinsics.rs@@ -20,11 +20,10 @@ use crate::layout::cell::Gc;use crate::layout::object::Object;use crate::layout::value::Value;use crate::runtime::array::Array;-use crate::runtime::array_iterator::ArrayIterator;use crate::runtime::module_namespace_object::ModuleNamespaceObject;-use crate::runtime::object::PropertyKind;use crate::runtime::property_key::{PropertyKey, StringMayBeNumber};use crate::runtime::proxy_object::ProxyObject;+use crate::runtime::realm_fuses;use crate::runtime::string_object::StringObject;use crate::runtime::typed_array::{ContentType, TypedArrayBase};use crate::utf16::{has_fly_string_storage, to_utf16_fly_string};@@ -207,12 +206,13 @@ pub extern "C" fn libjs_jit_has_property(vm: &Vm, key: u64, object: u64) -> u64Value::FALSE.0}-/// `GetIterator(iterable, sync)` for an array whose iterator method is `%Array.prototype.values%`, whose iterators-/// have the method `next` (the builtin `%ArrayIteratorPrototype%.next` of the realm of JIT code, which it passes):-/// a new array iterator over the values of the array, made like `%Array.prototype.values%` makes it.+/// `GetIterator(iterable, sync)` in fast array mode (see `get_iterator()` in the interpreter's slow paths): the+/// iterable, if it is an array whose iterator method is `%Array.prototype.values%` of the realm of JIT code and whose+/// iterators have the builtin `next` method, so that nothing can observe the iterator GetIterator would make. The+/// empty value otherwise.////// JIT code calls this with its VM.-pub extern "C" fn libjs_jit_create_array_iterator(vm: &Vm, iterable: u64, next: u64) -> u64 {+pub extern "C" fn libjs_jit_open_array_iteration(vm: &Vm, iterable: u64) -> u64 {let iterable = Value(iterable);if !iterable.is_object() {return Value::EMPTY.0;@@ -221,10 +221,12 @@ pub extern "C" fn libjs_jit_create_array_iterator(vm: &Vm, iterable: u64, next:if array.downcast::<Array>().is_none() {return Value::EMPTY.0;}- // NB: The array inherits the iterator method from %Array.prototype%, which holds it as a data property, and- // array iterators inherit `next` from %ArrayIteratorPrototype%. The cached lookups of own properties run- // no code.+ // NB: The array inherits the iterator method from %Array.prototype%, which holds it as a data property. The cached+ // lookups of own properties run no code.let realm = vm.current_realm().expect("JIT code runs in a realm");+ if !realm_fuses::array_iterators_have_builtin_next(&realm) {+ return Value::EMPTY.0;+ }let array_prototype = realm.array_prototype();let iterator_key = PropertyKey::from(vm.well_known_symbols().iterator);let cache = |site| vm.static_property_lookup_cache(site);@@ -232,7 +234,7 @@ pub extern "C" fn libjs_jit_create_array_iterator(vm: &Vm, iterable: u64, next:|| get_own_property_without_side_effects(&array,&iterator_key,- cache(StaticPropertyLookupCacheSite::CreateArrayIteratorOwnIteratorMethod),+ cache(StaticPropertyLookupCacheSite::OpenArrayIterationOwnIteratorMethod),) != Value::EMPTY{return Value::EMPTY.0;@@ -241,15 +243,10 @@ pub extern "C" fn libjs_jit_create_array_iterator(vm: &Vm, iterable: u64, next:let iterator_method = get_own_property_without_side_effects(&array_prototype,&iterator_key,- cache(StaticPropertyLookupCacheSite::CreateArrayIteratorIteratorMethod),- );- let next_method = get_own_property_without_side_effects(- &realm.array_iterator_prototype(),- &vm.names.next,- cache(StaticPropertyLookupCacheSite::CreateArrayIteratorNextMethod),+ cache(StaticPropertyLookupCacheSite::OpenArrayIterationIteratorMethod),);- if iterator_method != values || next_method != Value(next) {+ if iterator_method != values {return Value::EMPTY.0;}- Value::from_object(ArrayIterator::create(vm, realm, iterable, PropertyKind::Value).upcast::<Object>()).0+ iterable.0}diff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rsindex a50b39a9c0d..4ff3bab6997 100644--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs@@ -454,9 +454,10 @@ pub fn runtime_info(vm: &Vm, realm: Gc<Realm>, allocation: AllocationInfos) -> R},array_push: super::calls::libjs_jit_array_push as *const () as u64,slice_arguments: super::calls::libjs_jit_slice_arguments as *const () as u64,- create_array_iterator: super::intrinsics::libjs_jit_create_array_iterator as *const () as u64,+ open_array_iteration: super::intrinsics::libjs_jit_open_array_iteration as *const () as u64,// NB: Filled in by capture_snapshot(), which lists it as an embedded cell.array_iterator_next: None,+ array_iterator_return_fuse: None,jit_exit: super::entry_exit::libjs_jit_exit as *const () as u64,to_boolean: addresses.to_boolean,primitive_to_string: super::calls::libjs_jit_primitive_to_string as *const () as u64,diff --git a/Libraries/LibJS/Rust/src/jit/snapshot.rs b/Libraries/LibJS/Rust/src/jit/snapshot.rsindex e0d9416873b..596a36bd9c0 100644--- a/Libraries/LibJS/Rust/src/jit/snapshot.rs+++ b/Libraries/LibJS/Rust/src/jit/snapshot.rs@@ -1170,6 +1170,8 @@ pub fn capture_snapshot(builder.cell(realm.array_prototype());builder.cell(realm.object_prototype());runtime.array_iterator_next = builder.optional_cell(array_iterator_next(vm, realm));+ runtime.array_iterator_return_fuse =+ builder.optional_cell(realm.array_iterator_return_fuse.get().filter(|fuse| fuse.is_intact()));let options = &vm.jit.options;let snapshot = Snapshot {executables,diff --git a/Tests/LibJS/JIT/ir/array-destructuring.js b/Tests/LibJS/JIT/ir/array-destructuring.jsnew file mode 100644index 00000000000..5173ec0fd9d--- /dev/null+++ b/Tests/LibJS/JIT/ir/array-destructuring.js@@ -0,0 +1,27 @@+// Array destructuring iterates arrays without array iterators, and closing+// such an iteration does nothing while array iterators have no return+// method.++function sumPair(pair) {+ const [first, second] = pair;+ return first + second;+}+jit.prepare(sumPair);+for (let i = 0; i < 10; ++i) sumPair([1, 2]);+jit.compile(sumPair);+if (sumPair([3, 4]) !== 7) throw new Error("wrong sum");++// CHECK-FUNCTION: sumPair+// CHECK-PASS: graph building+// CHECK: OpenArrayIteration+// CHECK-NOT: Allocate+// CHECK: CallSlowPath IteratorNextUnpack+// CHECK-NOT: Allocate+// CHECK: CallSlowPath IteratorNextUnpack+// CHECK-NOT: Allocate+// CHECK: BranchNonNegativeInt32 ([[ITERATOR:v\d+]]) -> [[FAST:b\d+]], [[OTHER:b\d+]]+// CHECK-NEXT: [[FAST]] <- {{b\d+}}:+// CHECK-NEXT: AssumeValid+// CHECK: [[OTHER]] <- {{b\d+}}:+// CHECK-NEXT: ProbePropertyCache cache {{\d+}} ([[ITERATOR]])+// CHECK: CallSlowPath IteratorClosediff --git a/Tests/LibJS/JIT/ir/array-iteration.js b/Tests/LibJS/JIT/ir/array-iteration.jsindex a29e48791c9..79497d64aea 100644--- a/Tests/LibJS/JIT/ir/array-iteration.js+++ b/Tests/LibJS/JIT/ir/array-iteration.js@@ -1,5 +1,6 @@-// For-of loops over arrays make array iterators without calling the-// iterator method, and step them inline.+// For-of loops over arrays iterate them without array iterators and without+// calling the iterator method, and step them inline: the iterator operand+// holds the index of the next element.function sum(array) {let total = 0;@@ -20,9 +21,8 @@ if (sum([4, 5]) !== 9) throw new Error("wrong sum");// CHECK-NOT: Uint32Min// CHECK: LoadElementAt Holey// CHECK-PASS: frame initialization-// CHECK: [[ITERATOR:v\d+]] = CreateArrayIterator-// CHECK: BranchArrayIterator-// CHECK: LoadArrayIteratorArray-// CHECK: LoadArrayIteratorIndex-// CHECK: LoadElementAt Holey-// CHECK: StoreArrayIteratorIndex+// CHECK: [[ARRAY:v\d+]] = OpenArrayIteration+// CHECK: BranchNonNegativeInt32+// CHECK: [[INDEX:v\d+]]:int32 = UnboxInt32+// CHECK: LoadElementAt Holey ({{v\d+}}, [[INDEX]])+// CHECK: BoxInt32