Truly independent web browser
LibJS/JIT: Keep the lists of a graph in a zone
Andreas Kling3469fc2dfe93
diff --git a/Libraries/LibJS/JIT/Rust/src/builder/allocation.rs b/Libraries/LibJS/JIT/Rust/src/builder/allocation.rsindex 4e89678b8c9..ffff67e142c 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/allocation.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/allocation.rs@@ -32,7 +32,7 @@ use crate::snapshot::ShapeSnapshot;/// `NewObject` without an object shape cache.const NO_OBJECT_SHAPE_CACHE: u32 = u32::MAX;-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {fn object_shape_cache(&self, cache: u32) -> Option<&ObjectShapeCacheSnapshot> {self.snapshot[self.function.executable.object_shape_caches].get(cache as usize)@@ -65,7 +65,7 @@ impl GraphBuilder<'_> {property_count,reserve: property_count,},- Vec::new(),+ &[],Some(Repr::Tagged),);self.write(dst, object)?;@@ -94,7 +94,7 @@ impl GraphBuilder<'_> {return Ok(false);};let value = self.read(src)?;- self.emit(Op::InitializeNamed { offset }, vec![object, value], None);+ self.emit(Op::InitializeNamed { offset }, &[object, value], None);Ok(true)}@@ -117,7 +117,7 @@ pub(super) enum ArrayElement {Constant(u64),}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Whether compiled code allocates arrays of `count` elements.pub(super) fn can_allocate_array(&self, count: usize) -> bool {// NB: The runtime always allocates arrays; the codegen tests of slow@@ -155,16 +155,16 @@ impl GraphBuilder<'_> {self.embed(shape);}let count = u32::try_from(values.len()).expect("array literals have fewer than 2^32 elements");- let array = self.emit(Op::AllocateArray { count }, Vec::new(), Some(Repr::Tagged));+ let array = self.emit(Op::AllocateArray { count }, &[], Some(Repr::Tagged));for (index, value) in (0u32..).zip(values) {- self.emit(Op::InitializeElement { index }, vec![array, value], None);+ self.emit(Op::InitializeElement { index }, &[array, value], None);}self.write(dst, array)?;Ok(true)}}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Builds `NewFunction` of the compiled function or an inlined one as an/// `AllocateFunction`, if it has a closure template and creates no/// method. Returns false, having built nothing, otherwise.@@ -206,7 +206,7 @@ impl GraphBuilder<'_> {sample,legacy_caller,},- vec![environment, private_environment],+ &[environment, private_environment],Some(Repr::Tagged),);self.write(dst, function)?;@@ -214,7 +214,7 @@ impl GraphBuilder<'_> {}}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Builds `CreateLexicalEnvironment` of the compiled function as an/// `AllocateEnvironment` that becomes the frame's lexical environment, if/// its shape cache has a template for environments with `capacity`@@ -244,10 +244,10 @@ impl GraphBuilder<'_> {let parent = self.read(parent)?;let environment = self.emit(Op::AllocateEnvironment { shape_cache, capacity },- vec![parent],+ &[parent],Some(Repr::Tagged),);- let address = self.emit(Op::SetLexicalEnvironment, vec![environment], Some(Repr::Pointer));+ let address = self.emit(Op::SetLexicalEnvironment, &[environment], Some(Repr::Pointer));self.frame.set_field(FrameField::LexicalEnvironment, address);self.write(dst, environment)?;Ok(true)@@ -297,7 +297,7 @@ mod tests {})}- fn ops(graph: &crate::ir::Graph) -> Vec<Op> {+ fn ops<'z>(graph: &crate::ir::Graph<'z>) -> Vec<Op<'z>> {graph.blocks.iter()@@ -329,7 +329,7 @@ mod tests {shape: EMPTY_SHAPE,property_count: 0,});- let graph = crate::builder::build_graph(&snapshot).unwrap();+ let graph = crate::builder::build_graph(&snapshot, crate::test_zone()).unwrap();assert_eq!(ops(&graph),vec![@@ -389,7 +389,7 @@ mod tests {};// NB: Cache 1 has no template.snapshot.executables[0].lexical_environment_templates = snapshot.add(&[Some(template), None]);- let graph = crate::builder::build_graph(&snapshot).unwrap();+ let graph = crate::builder::build_graph(&snapshot, crate::test_zone()).unwrap();let ops = graph.blocks.iter()@@ -431,7 +431,7 @@ mod tests {shape: EMPTY_SHAPE,property_count: 0,});- let graph = crate::builder::build_graph(&snapshot).unwrap();+ let graph = crate::builder::build_graph(&snapshot, crate::test_zone()).unwrap();let ops = ops(&graph);assert_eq!(ops.iter()diff --git a/Libraries/LibJS/JIT/Rust/src/builder/arguments.rs b/Libraries/LibJS/JIT/Rust/src/builder/arguments.rsindex 0398122ad86..195e85a4bda 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/arguments.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/arguments.rs@@ -147,7 +147,7 @@ pub(super) fn uses_virtual_arguments(graph: &Graph) -> bool {})}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Whether `node` is the virtual arguments object.pub(super) fn is_virtual_arguments(&self, node: NodeId) -> bool {self.graph@@ -260,7 +260,7 @@ impl GraphBuilder<'_> {self.write(dst, count)?;return Ok(true);}- let count = self.emit(Op::ArgumentCount, Vec::new(), Some(Repr::Tagged));+ let count = self.emit(Op::ArgumentCount, &[], Some(Repr::Tagged));self.write(dst, count)?;Ok(true)}@@ -291,7 +291,7 @@ impl GraphBuilder<'_> {}let index = self.read(property)?;let arguments_base = self.function.layout.arguments_base();- let argument = self.emit_checked(Op::LoadArgument { arguments_base }, vec![index], Some(Repr::Tagged));+ let argument = self.emit_checked(Op::LoadArgument { arguments_base }, &[index], Some(Repr::Tagged));self.write(dst, argument)?;Ok(true)}@@ -324,7 +324,7 @@ impl GraphBuilder<'_> {}let index = self.read(index)?;let arguments_base = self.function.layout.arguments_base();- let argument = self.emit_checked(Op::LoadArgument { arguments_base }, vec![index], Some(Repr::Tagged));+ let argument = self.emit_checked(Op::LoadArgument { arguments_base }, &[index], Some(Repr::Tagged));self.write(dst, argument)?;Ok(true)}@@ -386,7 +386,7 @@ impl GraphBuilder<'_> {if let Some(slice) = slice_check {self.check_callee(*this_value, slice)?;}- let array = self.emit_checked(Op::SliceArguments, vec![start], Some(Repr::Tagged));+ let array = self.emit_checked(Op::SliceArguments, &[start], Some(Repr::Tagged));self.write(*dst, array)?;Ok(Some(super::Flow::Continue))}diff --git a/Libraries/LibJS/JIT/Rust/src/builder/array_iterators.rs b/Libraries/LibJS/JIT/Rust/src/builder/array_iterators.rsindex 238ebcf01ee..0ac437d94c9 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/array_iterators.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/array_iterators.rs@@ -25,7 +25,7 @@ use crate::ir::value;/// The `hint` of a `GetIterator` for synchronous iteration.const SYNC_HINT: u8 = 0;-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// The builtin `%ArrayIteratorPrototype%.next` of the realm of the/// compiled code, if `%ArrayIteratorPrototype%` held it when the/// snapshot was taken.@@ -96,7 +96,7 @@ impl GraphBuilder<'_> {let started = self.start_next_case(&mut slow_paths);debug_assert!(started, "values that fail the checks go on to the next case");- let array = self.emit(Op::OpenArrayIteration, vec![iterable], Some(Repr::Tagged));+ let array = self.emit(Op::OpenArrayIteration, &[iterable], Some(Repr::Tagged));let array = self.branch_if_empty(&mut slow_paths, array);let outputs = self.join_paths(slow_paths, vec![first_index, array, not_done], |_, outputs| outputs);self.write(dst_iterator_object, outputs[0])?;@@ -150,8 +150,8 @@ impl GraphBuilder<'_> {let array = self.branch_to_slow_path(&mut slow_paths, BranchCondition::ElementsKind(kind), vec![array], true);let array = self.cell_address(array);let array = self.branch_to_slow_path(&mut slow_paths, BranchCondition::MagicalLength, vec![array], true);- let index = self.emit(Op::UnboxInt32, vec![index], Some(Repr::Int32));- let length = self.emit(Op::LoadElementsLength, vec![array], Some(Repr::Int32));+ let index = self.emit(Op::UnboxInt32, &[index], Some(Repr::Int32));+ let length = self.emit(Op::LoadElementsLength, &[array], Some(Repr::Int32));let (inside, outside) = self.branch_both_ways(BranchCondition::IndexInBounds, vec![index, length]);// NB: The done operand keeps the iteration done, also if the array@@ -164,12 +164,8 @@ impl GraphBuilder<'_> {let element = self.load_array_iteration_element(&mut slow_paths, kind, array, index);// NB: The index is below the capacity, so the next one is an int32 too.let one = self.int32_constant(1);- let next_index = self.emit_checked(- Op::Int32Binary { op: BinaryOp::Add },- vec![index, one],- Some(Repr::Int32),- );- let next_index = self.emit(Op::BoxInt32, vec![next_index], Some(Repr::Tagged));+ let next_index = self.emit_checked(Op::Int32Binary { op: BinaryOp::Add }, &[index, one], Some(Repr::Int32));+ let next_index = self.emit(Op::BoxInt32, &[next_index], Some(Repr::Tagged));self.end_hot_path(&mut slow_paths, vec![element, not_done, next_index, iterator_is_done]);// Array iterators. NB: Without them, the other values take the slow@@ -192,7 +188,7 @@ impl GraphBuilder<'_> {let object = self.branch_to_slow_path(&mut slow_paths, BranchCondition::ArrayIterator, vec![object], true);// NB: Done iterators no longer have an array.- let array = self.emit(Op::LoadArrayIteratorArray, vec![object], Some(Repr::Tagged));+ let array = self.emit(Op::LoadArrayIteratorArray, &[object], Some(Repr::Tagged));let (exhausted, live) = self.branch_both_ways(BranchCondition::Undefined, vec![array]);self.block = exhausted;self.end_hot_path(&mut slow_paths, vec![undefined, done, iterator, done]);@@ -204,25 +200,21 @@ impl GraphBuilder<'_> {// NB: Array iterators iterate array-likes up to their `length`,// which only arrays keep as the size of their elements.let array = self.branch_to_slow_path(&mut slow_paths, BranchCondition::MagicalLength, vec![array], true);- let index = self.emit(Op::LoadArrayIteratorIndex, vec![object], Some(Repr::Int32));- let length = self.emit(Op::LoadElementsLength, vec![array], Some(Repr::Int32));+ let index = self.emit(Op::LoadArrayIteratorIndex, &[object], Some(Repr::Int32));+ let length = self.emit(Op::LoadElementsLength, &[array], Some(Repr::Int32));let (inside, outside) = self.branch_both_ways(BranchCondition::IndexInBounds, vec![index, length]);// NB: The array has no element at the index, so the iterator is done.self.block = outside;- self.emit(Op::FinishArrayIterator, vec![object], None);+ self.emit(Op::FinishArrayIterator, &[object], None);self.end_hot_path(&mut slow_paths, vec![undefined, done, iterator, done]);self.block = inside;let index = self.refine(BranchCondition::IndexInBounds, true, vec![index, length]);let element = self.load_array_iteration_element(&mut slow_paths, kind, array, index);let one = self.int32_constant(1);- let next_index = self.emit_checked(- Op::Int32Binary { op: BinaryOp::Add },- vec![index, one],- Some(Repr::Int32),- );- self.emit(Op::StoreArrayIteratorIndex, vec![object, next_index], None);+ let next_index = self.emit_checked(Op::Int32Binary { op: BinaryOp::Add }, &[index, one], Some(Repr::Int32));+ self.emit(Op::StoreArrayIteratorIndex, &[object, next_index], None);let outputs = self.join_paths(slow_paths,vec![element, not_done, iterator, iterator_is_done],@@ -244,7 +236,7 @@ impl GraphBuilder<'_> {// NB: Holey elements below the length may be past the capacity.// Elements are accessed through the array (see// `element_storage_and_bound()`).- let capacity = self.emit(Op::LoadElementsCapacity, vec![array], Some(Repr::Int32));+ let capacity = self.emit(Op::LoadElementsCapacity, &[array], Some(Repr::Int32));let index = self.branch_to_slow_path(slow_paths, BranchCondition::IndexInBounds, vec![index, capacity], true);let element = self.load_element(kind, array, index);self.branch_if_empty(slow_paths, element)diff --git a/Libraries/LibJS/JIT/Rust/src/builder/caches.rs b/Libraries/LibJS/JIT/Rust/src/builder/caches.rsindex 01714952817..0de1af97874 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/caches.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/caches.rs@@ -231,7 +231,7 @@ impl CacheEntry {}}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// The entries of property lookup cache `cache` in their guard and/// action form, if the cache is monomorphic or polymorphic and compiled/// code can apply every entry.@@ -344,18 +344,25 @@ impl GraphBuilder<'_> {let mut cases = Vec::with_capacity(shapes.len());for shape in shapes {let block = self.graph.add_block(Block {- predecessors: vec![source],- ..Block::default()+ predecessors: self.graph.list(&[source]),+ ..self.graph.new_block()});self.order.push(block);self.embed(shape.shape);cases.push((*shape, block));}let address = self.cell_address(object);- let switch = self.set_control(Op::ShapeSwitch { cases: cases.clone() }, vec![object, address]);+ let zone = self.graph.zone;+ let switch = self.set_control(+ Op::ShapeSwitch {+ shapes: zone.alloc_slice_from_iter(cases.iter().map(|(shape, _)| *shape)),+ targets: zone.alloc_slice_from_iter(cases.iter().map(|(_, block)| *block)),+ },+ &[object, address],+ );self.graph.nodes[switch.index()].frame_state = Some(frame_state);- let join = self.graph.add_block(Block::default());+ let join = self.graph.add_block(self.graph.new_block());let mut results = Vec::new();let mut case_shapes = Vec::with_capacity(cases.len());for (index, (shape, block)) in cases.iter().enumerate() {@@ -364,7 +371,7 @@ impl GraphBuilder<'_> {let refined = self.refine(BranchCondition::Shape(*shape), true, vec![object, address]);results.push(case(self, index, refined));debug_assert_eq!(self.frame.slots, frame.slots, "cases do not change frame slots");- self.set_control(Op::Jump { target: join }, Vec::new());+ self.set_control(Op::Jump { target: join }, &[]);self.graph.blocks[join.index()].predecessors.push(self.block);case_shapes.push(std::mem::take(&mut self.frame.fresh_shapes));}@@ -378,6 +385,6 @@ impl GraphBuilder<'_> {if results.iter().all(|result| *result == results[0]) {return Some(results[0]);}- Some(self.add_phi(results))+ Some(self.add_phi(&results))}}diff --git a/Libraries/LibJS/JIT/Rust/src/builder/checks.rs b/Libraries/LibJS/JIT/Rust/src/builder/checks.rsindex a4912c52dd3..cabc1e8f783 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/checks.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/checks.rs@@ -30,7 +30,7 @@ use crate::ir::NodeId;use crate::ir::Op;use crate::ir::value;-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Builds an instruction whose handling is `Handling::Expanded`.pub(super) fn build_expanded(&mut self,@@ -154,7 +154,7 @@ impl GraphBuilder<'_> {let (next, cold) = self.branch_with_cold_side(condition, inputs, !throws_when);self.block = cold;self.emit_call_slow_path(slow_path_inputs, frame_state, None);- self.set_control(Op::Unreachable, Vec::new());+ self.set_control(Op::Unreachable, &[]);self.block = next;Ok(Flow::Continue)}@@ -165,7 +165,7 @@ impl GraphBuilder<'_> {/// there before, or if the value is known to be uninitialized.pub(super) fn check_initialized(&mut self, value: NodeId) -> Result<NodeId, CompileFailure> {if self.graph.constant_value(value) != Some(value::EMPTY) && self.may_speculate(ExitKind::Uninitialized) {- return Ok(self.emit_checked(Op::CheckInitialized, vec![value], None));+ return Ok(self.emit_checked(Op::CheckInitialized, &[value], None));}let empty = self.constant(value::EMPTY);let condition = BranchCondition::TaggedEquals { equal: true };@@ -189,7 +189,7 @@ impl GraphBuilder<'_> {self.block = cold;let converted = self.emit_call_slow_path(slow_path_inputs, frame_state, Some(Repr::Tagged));self.join_blocks(vec![hot, cold]);- let result = self.add_phi(vec![value, converted]);+ let result = self.add_phi(&[value, converted]);self.write(dst, result)?;Ok(Flow::Continue)}@@ -227,7 +227,7 @@ impl GraphBuilder<'_> {// NB: The slow path's value is the this value it resolved.let resolved = self.emit_call_slow_path(Vec::new(), frame_state, Some(Repr::Tagged));self.join_blocks(vec![hot, cold]);- let result = self.add_phi(vec![this_value, resolved]);+ let result = self.add_phi(&[this_value, resolved]);self.frame.slots[slot] = SlotState { node: result, in_sync };Ok(Flow::Continue)}@@ -253,7 +253,7 @@ impl GraphBuilder<'_> {let join = self.start_new_block(predecessors.clone());for block in predecessors {self.block = block;- self.set_control(Op::Jump { target: join }, Vec::new());+ self.set_control(Op::Jump { target: join }, &[]);}self.block = join;join@@ -297,7 +297,7 @@ impl GraphBuilder<'_> {pc: self.function.pc,saves_registers: true,},- inputs,+ &inputs,repr,);self.graph.nodes[node.index()].frame_state = Some(frame_state);@@ -409,7 +409,7 @@ impl GraphBuilder<'_> {/// where it is `holds` reaches (see `Op::Refine`).pub(super) fn refine(&mut self, condition: BranchCondition, holds: bool, inputs: Vec<NodeId>) -> NodeId {let repr = self.graph.node(inputs[0]).repr;- self.emit(Op::Refine { condition, holds }, inputs, repr)+ self.emit(Op::Refine { condition, holds }, &inputs, repr)}/// Ends the current block as one of several paths that completed the@@ -439,7 +439,7 @@ impl GraphBuilder<'_> {if_true,if_false,},- inputs,+ &inputs,);(hot, cold)}@@ -456,7 +456,7 @@ impl GraphBuilder<'_> {if_true,if_false,},- inputs,+ &inputs,);(if_true, if_false)}@@ -496,7 +496,7 @@ impl GraphBuilder<'_> {let frame_state = self.eager_frame_state();let (hot, cold) = self.branch_with_cold_side(condition, vec![value, empty], false);self.block = cold;- let exit = self.set_control(Op::Exit { kind }, Vec::new());+ let exit = self.set_control(Op::Exit { kind }, &[]);self.graph.nodes[exit.index()].frame_state = Some(frame_state);self.block = hot;self.refine(condition, false, vec![value, empty])@@ -588,7 +588,7 @@ impl GraphBuilder<'_> {return inputs[0];}let repr = self.graph.node(value).repr;- let phi = self.add_phi(inputs);+ let phi = self.add_phi(&inputs);self.graph.nodes[phi.index()].repr = repr;phi})@@ -602,7 +602,7 @@ impl GraphBuilder<'_> {if let Some(kind) = slow_paths.exits {for edge in &slow_paths.cold {self.block = *edge;- let exit = self.set_control(Op::Exit { kind }, Vec::new());+ let exit = self.set_control(Op::Exit { kind }, &[]);self.graph.nodes[exit.index()].frame_state = Some(slow_paths.frame_state);}return None;@@ -621,7 +621,7 @@ impl GraphBuilder<'_> {let mut outputs = vec![call];for index in 1..slow_paths.output_count {let index = u8::try_from(index).expect("slow paths have few outputs");- outputs.push(self.emit(Op::SlowPathOutput { index }, vec![call], Some(Repr::Tagged)));+ outputs.push(self.emit(Op::SlowPathOutput { index }, &[call], Some(Repr::Tagged)));}Some((slow, outputs))}diff --git a/Libraries/LibJS/JIT/Rust/src/builder/elements.rs b/Libraries/LibJS/JIT/Rust/src/builder/elements.rsindex 9f951ea3d6b..f8f6f24a0e4 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/elements.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/elements.rs@@ -31,7 +31,7 @@ use crate::snapshot::keyed_feedback_bits::TYPED_ARRAY_SHIFT;const PACKED_AND_HOLEY: u32 = PACKED | HOLEY;-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// The bits of the keyed feedback of `instruction`, if it has a slot.pub(super) fn keyed_feedback_bits(&self, instruction: &Instruction) -> Option<u32> {let slot = instruction.feedback_slots().keyed?;@@ -98,12 +98,12 @@ impl GraphBuilder<'_> {/// checked offset: with a constant index, the bounds check folds away,/// and the check of the offset is all that keeps them behind it.pub(super) fn element_storage_and_bound(&mut self, kind: ElementsKind, address: NodeId) -> (NodeId, NodeId) {- let count = |builder: &mut Self, op| builder.emit(op, vec![address], Some(Repr::Int32));+ let count = |builder: &mut Self, op| builder.emit(op, &[address], Some(Repr::Int32));match kind {ElementsKind::Packed | ElementsKind::Holey => {let length = count(self, Op::LoadElementsLength);let capacity = count(self, Op::LoadElementsCapacity);- let bound = self.emit(Op::Uint32Min, vec![length, capacity], Some(Repr::Int32));+ let bound = self.emit(Op::Uint32Min, &[length, capacity], Some(Repr::Int32));(address, bound)}ElementsKind::TypedArray(_) => {@@ -118,14 +118,14 @@ impl GraphBuilder<'_> {.fixed_length});let offset =- |builder: &mut Self| builder.emit(Op::LoadTypedArrayDataOffset, vec![address], Some(Repr::Pointer));+ |builder: &mut Self| builder.emit(Op::LoadTypedArrayDataOffset, &[address], Some(Repr::Pointer));let data = |builder: &mut Self, offset| {- builder.emit(Op::TypedArrayDataAddress, vec![offset], Some(Repr::Pointer))+ builder.emit(Op::TypedArrayDataAddress, &[offset], Some(Repr::Pointer))};match fixed_length {Some(length) if self.may_speculate(ExitKind::OutOfBounds) => {let offset = offset(self);- let offset = self.emit_checked(Op::CheckTypedArrayStorage, vec![offset], Some(Repr::Pointer));+ let offset = self.emit_checked(Op::CheckTypedArrayStorage, &[offset], Some(Repr::Pointer));(data(self, offset), self.int32_constant(length as i32))}_ => {@@ -141,13 +141,9 @@ impl GraphBuilder<'_> {/// The element at `index` of the elements of `kind` with the `storage`/// that `element_storage_and_bound()` gave, with doubles boxed.pub(super) fn load_element(&mut self, kind: ElementsKind, storage: NodeId, index: NodeId) -> NodeId {- let element = self.emit(- Op::LoadElementAt { kind },- vec![storage, index],- Some(kind.loaded_repr()),- );+ let element = self.emit(Op::LoadElementAt { kind }, &[storage, index], Some(kind.loaded_repr()));match kind.loaded_repr() {- Repr::Float64 => self.emit(Op::BoxFloat64, vec![element], Some(Repr::Tagged)),+ Repr::Float64 => self.emit(Op::BoxFloat64, &[element], Some(Repr::Tagged)),_ => element,}}@@ -155,7 +151,7 @@ impl GraphBuilder<'_> {/// Stores `value` at the checked `index` of the elements of `kind` with/// the `storage` that `element_storage_and_bound()` gave.pub(super) fn store_element(&mut self, kind: ElementsKind, storage: NodeId, index: NodeId, value: NodeId) {- self.emit(Op::StoreElementAt { kind }, vec![storage, index, value], None);+ self.emit(Op::StoreElementAt { kind }, &[storage, index, value], None);}/// The storage of the checked object (see@@ -171,10 +167,10 @@ impl GraphBuilder<'_> {let object = self.read(base)?;let index = self.read_value(property)?;let index = self.int32(index);- let object = self.emit_checked(Op::CheckElements { kind }, vec![object], None);+ let object = self.emit_checked(Op::CheckElements { kind }, &[object], None);let address = self.cell_address(object);let (storage, bound) = self.element_storage_and_bound(kind, address);- let index = self.emit_checked(Op::CheckBounds, vec![index, bound], Some(Repr::Int32));+ let index = self.emit_checked(Op::CheckBounds, &[index, bound], Some(Repr::Int32));Ok((storage, index))}@@ -194,7 +190,7 @@ impl GraphBuilder<'_> {let (storage, index) = self.element_access(kind, base, property)?;let mut value = self.load_element(kind, storage, index);if kind == ElementsKind::Holey {- value = self.emit_checked(Op::CheckNotHole, vec![value], Some(Repr::Tagged));+ value = self.emit_checked(Op::CheckNotHole, &[value], Some(Repr::Tagged));}self.write(dst, value)?;Ok(true)@@ -216,7 +212,7 @@ impl GraphBuilder<'_> {let value = self.read_value(src)?;let value = match (kind.stored_repr(), self.graph.node(value).repr) {(Repr::Int32, Some(Repr::Int32)) => value,- (Repr::Float64, Some(Repr::Int32)) => self.emit(Op::Int32ToFloat64, vec![value], Some(Repr::Float64)),+ (Repr::Float64, Some(Repr::Int32)) => self.emit(Op::Int32ToFloat64, &[value], Some(Repr::Float64)),(Repr::Int32, _) if self.may_speculate(ExitKind::BadType) => {let number = self.number(value);let conversion = if kind == ElementsKind::TypedArray(TypedArrayElement::Uint8Clamped) {@@ -224,7 +220,7 @@ impl GraphBuilder<'_> {} else {Op::Float64ToInt32};- self.emit(conversion, vec![number], Some(Repr::Int32))+ self.emit(conversion, &[number], Some(Repr::Int32))}(Repr::Float64, _) if self.may_speculate(ExitKind::BadType) => self.number(value),(Repr::Tagged, _) => self.tagged(value),@@ -233,8 +229,8 @@ impl GraphBuilder<'_> {let (storage, index) = self.element_access(kind, base, property)?;// NB: Holes are filled by the slow path.if kind == ElementsKind::Holey {- let old = self.emit(Op::LoadElementAt { kind }, vec![storage, index], Some(Repr::Tagged));- self.emit_checked(Op::CheckNotHole, vec![old], Some(Repr::Tagged));+ let old = self.emit(Op::LoadElementAt { kind }, &[storage, index], Some(Repr::Tagged));+ self.emit_checked(Op::CheckNotHole, &[old], Some(Repr::Tagged));}self.store_element(kind, storage, index, value);Ok(true)diff --git a/Libraries/LibJS/JIT/Rust/src/builder/environments.rs b/Libraries/LibJS/JIT/Rust/src/builder/environments.rsindex 6fa9eeb6dd3..210b45c7952 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/environments.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/environments.rs@@ -31,7 +31,7 @@ const INVALID_HOPS: u32 = 0xFFFF_FFFE;/// `JS::EnvironmentMode::Lexical`.const ENVIRONMENT_MODE_LEXICAL: u8 = 0;-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// `field` of the running execution context. Inlined callees need no/// function environment and never change their environments, so their/// execution contexts are constants.@@ -42,7 +42,7 @@ impl GraphBuilder<'_> {if let Some(value) = self.frame.field(field) {return Ok(value);}- let value = self.emit(Op::LoadFrameField { field }, Vec::new(), Some(Repr::Pointer));+ let value = self.emit(Op::LoadFrameField { field }, &[], Some(Repr::Pointer));self.frame.set_field(field, value);return Ok(value);}@@ -61,11 +61,7 @@ impl GraphBuilder<'_> {return Ok(self.graph.node(closure).inputs[usize::from(private)]);}let address = self.cell_address(closure);- return Ok(self.emit(- Op::LoadFunctionEnvironment { private },- vec![address],- Some(Repr::Pointer),- ));+ return Ok(self.emit(Op::LoadFunctionEnvironment { private }, &[address], Some(Repr::Pointer)));}}let executable = self.function.executable;@@ -140,7 +136,7 @@ impl GraphBuilder<'_> {}let mut environment = self.frame_field(field)?;for _ in 0..coordinate.hops {- environment = self.emit(Op::LoadOuterEnvironment, vec![environment], Some(Repr::Pointer));+ environment = self.emit(Op::LoadOuterEnvironment, &[environment], Some(Repr::Pointer));}Ok(Some(environment))}@@ -163,7 +159,7 @@ impl GraphBuilder<'_> {Op::LoadEnvironmentBinding {index: coordinate.index,},- vec![environment],+ &[environment],Some(Repr::Tagged),);// NB: Reading an uninitialized binding of a declarative environment@@ -222,7 +218,7 @@ impl GraphBuilder<'_> {Op::LoadEnvironmentBinding {index: coordinate.index,},- vec![environment],+ &[environment],Some(Repr::Tagged),);let empty = self.constant(value::EMPTY);@@ -236,7 +232,7 @@ impl GraphBuilder<'_> {Op::StoreEnvironmentBinding {index: coordinate.index,},- vec![environment, value],+ &[environment, value],None,);self.join_slow_paths(slow_paths, None);@@ -282,7 +278,7 @@ impl GraphBuilder<'_> {vec![environment],true,);- self.emit(Op::AppendEnvironmentBinding, vec![environment], None);+ self.emit(Op::AppendEnvironmentBinding, &[environment], None);self.join_slow_paths(slow_paths, None);Ok(Some(Flow::Continue))}@@ -304,7 +300,7 @@ impl GraphBuilder<'_> {Op::StoreEnvironmentBinding {index: coordinate.index,},- vec![environment, value],+ &[environment, value],None,);Ok(Some(Flow::Continue))diff --git a/Libraries/LibJS/JIT/Rust/src/builder/globals.rs b/Libraries/LibJS/JIT/Rust/src/builder/globals.rsindex 2736b46cc66..83facd06b6a 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/globals.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/globals.rs@@ -68,7 +68,7 @@ struct Globals {environment_serial: u64,}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// What global variable cache `cache` found, with the globals of the/// executable's realm, if code may access the variable directly.fn global_cache(&self, cache: u32) -> Option<(Globals, GlobalCacheSnapshot)> {@@ -111,11 +111,7 @@ impl GraphBuilder<'_> {}let environment = globals.declarative_environment;self.embed(environment);- let loaded = self.emit_checked(- Op::LoadGlobalBinding { environment, index },- Vec::new(),- Some(Repr::Tagged),- );+ let loaded = self.emit_checked(Op::LoadGlobalBinding { environment, index }, &[], Some(Repr::Tagged));match value {Some(value) => self.speculate_binding_value(loaded, value),None => loaded,@@ -175,7 +171,7 @@ impl GraphBuilder<'_> {let environment = globals.declarative_environment;self.embed(environment);let value = self.read(src)?;- self.emit_checked(Op::StoreGlobalBinding { environment, index }, vec![value], None);+ self.emit_checked(Op::StoreGlobalBinding { environment, index }, &[value], None);}GlobalCacheSnapshot::Property {shape,@@ -241,11 +237,7 @@ impl GraphBuilder<'_> {let mut slow_paths = self.start_slow_paths(Some(Repr::Tagged))?;let realm = self.frame_field(FrameField::Realm)?;let executable = self.frame_field(FrameField::Executable)?;- let value = self.emit(- Op::ProbeGlobalCache { cache },- vec![realm, executable],- Some(Repr::Tagged),- );+ let value = self.emit(Op::ProbeGlobalCache { cache }, &[realm, executable], Some(Repr::Tagged));let value = self.branch_if_empty(&mut slow_paths, value);let result = self.join_slow_paths(slow_paths, Some(value));self.write(dst, result.expect("GetGlobal has a value"))?;@@ -265,7 +257,7 @@ impl GraphBuilder<'_> {let executable = self.frame_field(FrameField::Executable)?;let stored = self.emit(Op::ProbeGlobalStore { cache },- vec![value, realm, executable],+ &[value, realm, executable],Some(Repr::Bool),);self.branch_to_slow_path(&mut slow_paths, BranchCondition::Bool, vec![stored], true);@@ -303,8 +295,8 @@ impl GraphBuilder<'_> {);let prototype = self.load_named(function, has_instance.prototype_offset);let value = self.read(lhs)?;- let result = self.emit_checked(Op::HasInPrototypeChain, vec![value, prototype], Some(Repr::Bool));- let boxed = self.emit(Op::BoxBool, vec![result], Some(Repr::Tagged));+ let result = self.emit_checked(Op::HasInPrototypeChain, &[value, prototype], Some(Repr::Bool));+ let boxed = self.emit(Op::BoxBool, &[result], Some(Repr::Tagged));self.write(dst, boxed)?;Ok(true)}@@ -368,7 +360,7 @@ impl GraphBuilder<'_> {expected: value.bits,kind: ExitKind::UnexpectedValue,},- vec![loaded],+ &[loaded],None,);self.global_constant(value)diff --git a/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs b/Libraries/LibJS/JIT/Rust/src/builder/inlining.rsindex ff48a1b1c19..6faba042fdc 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/inlining.rs@@ -419,7 +419,7 @@ impl InlinedCallSite {}}-impl<'a> GraphBuilder<'a> {+impl<'a, 'z> GraphBuilder<'a, 'z> {pub(super) fn boxed_object(&self, cell: CellId) -> u64 {(u64::from(value::OBJECT_TAG) << 48) | (cell.0 & self.runtime.heap_region_offset_mask)}@@ -430,15 +430,15 @@ impl<'a> GraphBuilder<'a> {/// frame memory. The destination of a `ResumeAfter` has the value it had/// before the instruction, which is what the frame needs if the/// instruction did not write it (see `ir::FrameState`).- pub(super) fn new_frame_state(&self, live: &BitSet, mode: ResumeMode) -> FrameState {+ pub(super) fn new_frame_state(&self, live: &BitSet, mode: ResumeMode) -> FrameState<'z> {let values = self.frame_state_values(live);let in_frame = self.frame_state_in_frame(live);FrameState {executable: self.function.index,pc: self.function.pc,mode,- values,- in_frame,+ values: self.graph.list(&values),+ in_frame: self.graph.list(&in_frame),parent: self.parent_frame_state(),passed_argument_count: None,legacy_arguments: self.legacy_argument_slots(),@@ -592,8 +592,9 @@ impl<'a> GraphBuilder<'a> {..self.new_frame_state(&self.function.liveness.live_out(last), ResumeMode::ResumeAt)};let frame_state = self.graph.add_frame_state(frame_state);- let guard = self.emit(Op::AssumeLegacyArgumentsUnread, Vec::new(), None);+ let guard = self.emit(Op::AssumeLegacyArgumentsUnread, &[], None);self.graph.nodes[guard.index()].frame_state = Some(frame_state);+ let nodes = self.graph.list(&nodes);self.graph.legacy_arguments_guards.push((guard, nodes));}@@ -851,7 +852,7 @@ impl<'a> GraphBuilder<'a> {Op::CheckClosure {shared_data: target.function.shared_data,},- vec![value],+ &[value],None,);return Ok(());@@ -899,7 +900,7 @@ impl<'a> GraphBuilder<'a> {fn build_call_without_inlined_frames(&mut self,instruction: &Instruction,- op: Op,+ op: Op<'z>,inputs: &[Operand],) -> Result<Flow, CompileFailure> {let input_nodes = inputs@@ -913,7 +914,7 @@ impl<'a> GraphBuilder<'a> {}});let destination = destination.expect("a call writes its destination");- let node = self.emit(op, input_nodes, Some(Repr::Tagged));+ let node = self.emit(op, &input_nodes, Some(Repr::Tagged));// NB: Resuming after the call, the frame's destination holds the// result already.let frame_state = self.resume_after_frame_state(destination.raw());@@ -1227,13 +1228,13 @@ impl<'a> GraphBuilder<'a> {.filter(|(predecessor, _)| edges.contains(predecessor)).map(|(_, input)| *input).collect::<Vec<_>>();- self.graph.nodes[callee_phi.index()].inputs = kept_inputs;- self.graph.blocks[join.index()].predecessors = edges.to_vec();+ self.graph.nodes[callee_phi.index()].inputs.assign(&kept_inputs);+ self.graph.blocks[join.index()].predecessors.assign(edges);return join;}let block = self.graph.add_block(Block {- predecessors: edges.to_vec(),- ..Block::default()+ predecessors: self.graph.list(edges),+ ..self.graph.new_block()});self.order.push(block);for predecessor in edges {@@ -1387,7 +1388,7 @@ impl<'a> GraphBuilder<'a> {let function = if functions.iter().all(|function| *function == functions[0]) {functions[0]} else {- self.add_phi(functions)+ self.add_phi(&functions)};self.frame.slots[callee_slot] = SlotState {node: function,@@ -1401,7 +1402,7 @@ impl<'a> GraphBuilder<'a> {let result = if values.iter().all(|value| *value == values[0]) {values[0]} else {- self.add_phi(values)+ self.add_phi(&values)};self.frame.fresh_shapes = AbstractFrame::common_fresh_shapes(case_shapes.iter().map(Vec::as_slice));self.write(*dst, result)?;@@ -1715,7 +1716,7 @@ impl<'a> GraphBuilder<'a> {expected,kind: ExitKind::UnexpectedValue,},- vec![super_constructor_value],+ &[super_constructor_value],None,);}@@ -1770,7 +1771,7 @@ impl<'a> GraphBuilder<'a> {Op::Exit {kind: ExitKind::BadCallTarget,},- Vec::new(),+ &[],);self.graph.nodes[exit.index()].frame_state = Some(frame_state);Ok(Some(Flow::Ended))@@ -1859,7 +1860,7 @@ impl<'a> GraphBuilder<'a> {shape,property_count: offset + 1,},- vec![object, value, address],+ &[object, value, address],None,);}@@ -2032,7 +2033,7 @@ impl<'a> GraphBuilder<'a> {property_count,reserve: construct.reserve.max(property_count),},- Vec::new(),+ &[],Some(Repr::Tagged),);// 10.2.2 [[Construct]] ( argumentsList, newTarget ), https://tc39.es/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget@@ -2040,7 +2041,7 @@ impl<'a> GraphBuilder<'a> {// NB: The fields have literal values, so this cannot throw, and `this` has their shape already.for &(offset, value) in fields {let value = self.constant(value);- self.emit(Op::InitializeNamed { offset }, vec![this, value], None);+ self.emit(Op::InitializeNamed { offset }, &[this, value], None);}this}@@ -2054,7 +2055,7 @@ impl<'a> GraphBuilder<'a> {InlineValue::FrameArgument(index) => {let index = self.constant(value::int32(index.cast_signed()));let arguments_base = self.function.layout.arguments_base();- Ok(self.emit_checked(Op::LoadArgument { arguments_base }, vec![index], Some(Repr::Tagged)))+ Ok(self.emit_checked(Op::LoadArgument { arguments_base }, &[index], Some(Repr::Tagged)))}}}@@ -2300,7 +2301,7 @@ impl<'a> GraphBuilder<'a> {Op::CheckClosure {shared_data: function.shared_data,},- vec![closure],+ &[closure],None,);}@@ -2326,13 +2327,13 @@ impl<'a> GraphBuilder<'a> {.iter().any(|argument| matches!(argument, InlineValue::FrameArgument(_))){- let count = self.emit(Op::ArgumentCount, Vec::new(), Some(Repr::Tagged));+ let count = self.emit(Op::ArgumentCount, &[], Some(Repr::Tagged));self.emit_checked(Op::CheckValue {expected: value::int32(passed_argument_count.cast_signed()),kind: ExitKind::UnexpectedValue,},- vec![count],+ &[count],None,);}@@ -2434,7 +2435,7 @@ impl<'a> GraphBuilder<'a> {let result = if values.iter().all(|value| *value == values[0]) {values[0]} else {- self.add_phi(values)+ self.add_phi(&values)};self.write(*dst, result)?;Ok(Some(Flow::Continue))@@ -2466,13 +2467,13 @@ impl<'a> GraphBuilder<'a> {match self.graph.constant_value(value) {Some(value::EMPTY) => self.constant(value::UNDEFINED),Some(_) => value,- None => self.emit(Op::EmptyToUndefined, vec![value], Some(Repr::Tagged)),+ None => self.emit(Op::EmptyToUndefined, &[value], Some(Repr::Tagged)),}};let continuation = match self.function.inline.as_ref().and_then(|call| call.continuation) {Some(continuation) => continuation,None => {- let continuation = self.graph.add_block(Block::default());+ let continuation = self.graph.add_block(self.graph.new_block());self.function.inline.as_mut()@@ -2488,7 +2489,7 @@ impl<'a> GraphBuilder<'a> {Some(shapes) => shapes.retain(|shape| fresh_shapes.contains(shape)),None => call.return_fresh_shapes = Some(fresh_shapes.clone()),}- self.set_control(Op::Jump { target: continuation }, Vec::new());+ self.set_control(Op::Jump { target: continuation }, &[]);self.graph.blocks[continuation.index()].predecessors.push(self.block);Ok(Flow::Ended)}diff --git a/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rs b/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rsindex d45bd61175f..d238c80cc55 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/intrinsics.rs@@ -48,7 +48,7 @@ const MAX_INLINE_SPLICED_VALUES: usize = crate::codegen::DIRECT_CALL_MAX_INPUTS/// How many arguments `try_build_math_min_max()` compares inline at most.const MAX_MIN_MAX_ARGUMENTS: usize = 8;-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Calls the packed-array splice helper without a native frame. It/// declines before doing anything observable for receivers or species/// constructors that require the ordinary call.@@ -98,7 +98,7 @@ impl GraphBuilder<'_> {value});}- let result = self.emit(Op::CallArraySplice, inputs, Some(Repr::Tagged));+ let result = self.emit(Op::CallArraySplice, &inputs, Some(Repr::Tagged));let result = self.branch_if_empty(&mut slow_paths, result);let result = self.join_slow_paths(slow_paths, Some(result))@@ -228,26 +228,26 @@ impl GraphBuilder<'_> {let result = if let Some(integer) = self.int32_value_of(argument) {self.build_int32_math_function(&mut slow_paths, op, integer)} else if let Some(double) = self.float64_value_of(argument) {- let result = self.emit(Op::Float64Unary { op }, vec![double], Some(Repr::Float64));- self.emit(Op::BoxFloat64, vec![result], Some(Repr::Tagged))+ let result = self.emit(Op::Float64Unary { op }, &[double], Some(Repr::Float64));+ self.emit(Op::BoxFloat64, &[result], Some(Repr::Tagged))} else {// NB: Int32 arguments, then doubles.let (int32, other) = self.branch_both_ways(BranchCondition::Int32Value, vec![argument]);self.block = other;let double = self.branch_to_slow_path(&mut slow_paths, BranchCondition::Double, vec![argument], true);- let double = self.emit(Op::UnboxDouble, vec![double], Some(Repr::Float64));- let result = self.emit(Op::Float64Unary { op }, vec![double], Some(Repr::Float64));- let double_result = self.emit(Op::BoxFloat64, vec![result], Some(Repr::Tagged));+ let double = self.emit(Op::UnboxDouble, &[double], Some(Repr::Float64));+ let result = self.emit(Op::Float64Unary { op }, &[double], Some(Repr::Float64));+ let double_result = self.emit(Op::BoxFloat64, &[result], Some(Repr::Tagged));let double = self.block;self.block = int32;let integer = self.refine(BranchCondition::Int32Value, true, vec![argument]);- let integer = self.emit(Op::UnboxInt32, vec![integer], Some(Repr::Int32));+ let integer = self.emit(Op::UnboxInt32, &[integer], Some(Repr::Int32));let int32_result = self.build_int32_math_function(&mut slow_paths, op, integer);let int32 = self.block;self.join_blocks(vec![int32, double]);- self.add_phi(vec![int32_result, double_result])+ self.add_phi(&[int32_result, double_result])};let result = self.join_slow_paths(slow_paths, Some(result))@@ -297,9 +297,9 @@ impl GraphBuilder<'_> {let numbers = arguments.into_iter().map(|argument| self.float64_of_number(&mut slow_paths, argument))- .collect();- let result = self.emit(Op::CallFloat64Function { function }, numbers, Some(Repr::Float64));- let result = self.emit(Op::BoxFloat64, vec![result], Some(Repr::Tagged));+ .collect::<Vec<_>>();+ let result = self.emit(Op::CallFloat64Function { function }, &numbers, Some(Repr::Float64));+ let result = self.emit(Op::BoxFloat64, &[result], Some(Repr::Tagged));let result = self.join_slow_paths(slow_paths, Some(result)).expect("the instruction has a value");@@ -333,7 +333,7 @@ impl GraphBuilder<'_> {pub(super) fn int32_to_float64(&mut self, integer: NodeId) -> NodeId {match self.graph.constant_value(integer) {Some(bits) => self.typed_constant(f64::from((bits as u32).cast_signed()).to_bits(), Repr::Float64),- None => self.emit(Op::Int32ToFloat64, vec![integer], Some(Repr::Float64)),+ None => self.emit(Op::Int32ToFloat64, &[integer], Some(Repr::Float64)),}}@@ -353,7 +353,7 @@ impl GraphBuilder<'_> {}let value = self.tagged(value);let refined = self.branch_to_slow_path(slow_paths, BranchCondition::Int32Value, vec![value], true);- self.emit(Op::UnboxInt32, vec![refined], Some(Repr::Int32))+ self.emit(Op::UnboxInt32, &[refined], Some(Repr::Int32))}/// Branches on whether the tagged `value` is an int32, and if not on@@ -388,18 +388,18 @@ impl GraphBuilder<'_> {let (int32_block, other) = self.branch_both_ways(integer, vec![value]);self.block = int32_block;let refined = self.refine(integer, true, vec![value]);- let integer = self.emit(Op::UnboxInt32, vec![refined], Some(Repr::Int32));+ let integer = self.emit(Op::UnboxInt32, &[refined], Some(Repr::Int32));let int32_value = int32(self, integer);let int32_end = self.block;self.block = other;let refined = otherwise(self, BranchCondition::Double, vec![value]);- let number = self.emit(Op::UnboxDouble, vec![refined], Some(Repr::Float64));+ let number = self.emit(Op::UnboxDouble, &[refined], Some(Repr::Float64));let double_value = double(self, number);let double_end = self.block;self.join_blocks(vec![int32_end, double_end]);- let phi = self.add_phi(vec![int32_value, double_value]);+ let phi = self.add_phi(&[int32_value, double_value]);self.graph.nodes[phi.index()].repr = Some(repr);phi}@@ -415,7 +415,7 @@ impl GraphBuilder<'_> {Float64UnaryOp::Abs if self.may_speculate(ExitKind::Overflow) => {let zero = self.int32_constant(0);let negated = self.int32_binary(BinaryOp::Sub, zero, integer);- let result = self.emit(Op::Int32Max, vec![integer, negated], Some(Repr::Int32));+ let result = self.emit(Op::Int32Max, &[integer, negated], Some(Repr::Int32));self.tagged(result)}Float64UnaryOp::Abs => {@@ -426,13 +426,13 @@ impl GraphBuilder<'_> {vec![integer, smallest],false,);- let result = self.emit(Op::Int32Abs, vec![integer], Some(Repr::Int32));+ let result = self.emit(Op::Int32Abs, &[integer], Some(Repr::Int32));self.tagged(result)}Float64UnaryOp::Sqrt | Float64UnaryOp::Negate => {let double = self.int32_to_float64(integer);- let result = self.emit(Op::Float64Unary { op }, vec![double], Some(Repr::Float64));- self.emit(Op::BoxFloat64, vec![result], Some(Repr::Tagged))+ let result = self.emit(Op::Float64Unary { op }, &[double], Some(Repr::Float64));+ self.emit(Op::BoxFloat64, &[result], Some(Repr::Tagged))}}}@@ -464,7 +464,7 @@ impl GraphBuilder<'_> {let index = self.int32_or_slow_path(&mut slow_paths, index);let code_unit = self.string_code_unit(&mut slow_paths, string, index);let result = match character {- StringCharacter::CodeUnit => self.emit(Op::BoxInt32, vec![code_unit], Some(Repr::Tagged)),+ StringCharacter::CodeUnit => self.emit(Op::BoxInt32, &[code_unit], Some(Repr::Tagged)),StringCharacter::String => self.ascii_character_string(&mut slow_paths, code_unit),};let result = self@@ -479,11 +479,11 @@ impl GraphBuilder<'_> {/// characters can be read and the index is in its bounds.pub(super) fn string_code_unit(&mut self, slow_paths: &mut SlowPaths, string: NodeId, index: NodeId) -> NodeId {let string = self.branch_to_slow_path(slow_paths, BranchCondition::String, vec![string], true);- let address = self.emit(Op::StringAddress, vec![string], Some(Repr::Pointer));+ let address = self.emit(Op::StringAddress, &[string], Some(Repr::Pointer));let readable = self.branch_to_slow_path(slow_paths, BranchCondition::ResolvedString, vec![address], true);- let length = self.emit(Op::StringLength, vec![address], Some(Repr::Int32));+ let length = self.emit(Op::StringLength, &[address], Some(Repr::Int32));let index = self.branch_to_slow_path(slow_paths, BranchCondition::IndexInBounds, vec![index, length], true);- self.emit(Op::LoadStringCodeUnit, vec![readable, index], Some(Repr::Int32))+ self.emit(Op::LoadStringCodeUnit, &[readable, index], Some(Repr::Int32))}/// The VM's string of `code_unit`, taking a slow path of `slow_paths`@@ -496,7 +496,7 @@ impl GraphBuilder<'_> {vec![code_unit, limit],true,);- self.emit(Op::SingleCharacterString, vec![code_unit], Some(Repr::Tagged))+ self.emit(Op::SingleCharacterString, &[code_unit], Some(Repr::Tagged))}/// Builds `array.push(...values)`, a `Call` of up to@@ -537,10 +537,10 @@ impl GraphBuilder<'_> {.collect::<Result<Vec<_>, _>>()?;self.embed(self.runtime.array_prototype);self.embed(self.runtime.object_prototype);- let receiver = self.emit_checked(Op::CheckAppendableArray, vec![receiver], Some(Repr::Tagged));+ let receiver = self.emit_checked(Op::CheckAppendableArray, &[receiver], Some(Repr::Tagged));let array = self.cell_address(receiver);- let length = self.emit(Op::LoadElementsLength, vec![array], Some(Repr::Int32));- let capacity = self.emit(Op::LoadElementsCapacity, vec![array], Some(Repr::Int32));+ let length = self.emit(Op::LoadElementsLength, &[array], Some(Repr::Int32));+ let capacity = self.emit(Op::LoadElementsCapacity, &[array], Some(Repr::Int32));// NB: One value fits where the length is below the capacity, compared// unsigned so that lengths above i32::MAX (negative as int32// values) never fit. More values need that much room between@@ -550,7 +550,7 @@ impl GraphBuilder<'_> {} else {let room = self.emit_checked(Op::Int32Binary { op: BinaryOp::Sub },- vec![capacity, length],+ &[capacity, length],Some(Repr::Int32),);let count = self.int32_constant(values.len() as i32);@@ -560,7 +560,7 @@ impl GraphBuilder<'_> {self.block = cold;let mut pushed = None;for value in &values {- pushed = Some(self.emit(Op::CallArrayPush, vec![receiver, *value], Some(Repr::Tagged)));+ pushed = Some(self.emit(Op::CallArrayPush, &[receiver, *value], Some(Repr::Tagged)));}let pushed = pushed.expect("there are values to push");let cold = self.block;@@ -571,12 +571,12 @@ impl GraphBuilder<'_> {length};for value in values {- new_length = self.emit(Op::AppendElement, vec![array, new_length, value], Some(Repr::Int32));+ new_length = self.emit(Op::AppendElement, &[array, new_length, value], Some(Repr::Int32));}- let new_length = self.emit(Op::BoxInt32, vec![new_length], Some(Repr::Tagged));+ let new_length = self.emit(Op::BoxInt32, &[new_length], Some(Repr::Tagged));let hot = self.block;self.join_blocks(vec![hot, cold]);- let length = self.add_phi(vec![new_length, pushed]);+ let length = self.add_phi(&[new_length, pushed]);self.write(*dst, length)?;Ok(Some(Flow::Continue))}@@ -641,9 +641,9 @@ impl GraphBuilder<'_> {.map(|value| self.int32(value)).collect::<Vec<_>>().into_iter()- .reduce(|result, value| self.emit(op.clone(), vec![result, value], Some(Repr::Int32)))+ .reduce(|result, value| self.emit(op.clone(), &[result, value], Some(Repr::Int32))).expect("there are arguments");- self.emit(Op::BoxInt32, vec![result], Some(Repr::Tagged))+ self.emit(Op::BoxInt32, &[result], Some(Repr::Tagged))} else {let op = if max { Op::Float64Max } else { Op::Float64Min };let result = values@@ -651,9 +651,9 @@ impl GraphBuilder<'_> {.map(|value| self.number(value)).collect::<Vec<_>>().into_iter()- .reduce(|result, number| self.emit(op.clone(), vec![result, number], Some(Repr::Float64)))+ .reduce(|result, number| self.emit(op.clone(), &[result, number], Some(Repr::Float64))).expect("there are arguments");- self.emit(Op::BoxFloat64, vec![result], Some(Repr::Tagged))+ self.emit(Op::BoxFloat64, &[result], Some(Repr::Tagged))};self.write(dst, result)?;Ok(Some(Flow::Continue))@@ -696,10 +696,10 @@ impl GraphBuilder<'_> {let [lhs, rhs] = values.map(|value| self.int32(value));let product = self.emit(Op::Int32WrappingBinary { op: BinaryOp::Mul },- vec![lhs, rhs],+ &[lhs, rhs],Some(Repr::Int32),);- let result = self.emit(Op::BoxInt32, vec![product], Some(Repr::Tagged));+ let result = self.emit(Op::BoxInt32, &[product], Some(Repr::Tagged));self.write(dst, result)?;Ok(Some(Flow::Continue))}@@ -739,7 +739,7 @@ impl GraphBuilder<'_> {expected: expected_bits,kind: ExitKind::BadCallTarget,},- vec![value],+ &[value],None,);Ok(())@@ -764,12 +764,12 @@ impl GraphBuilder<'_> {// values elements.let length =self.branch_to_slow_path(&mut slow_paths, BranchCondition::NonNegativeInt32, vec![length], true);- self.emit(Op::UnboxInt32, vec![length], Some(Repr::Int32))+ self.emit(Op::UnboxInt32, &[length], Some(Repr::Int32))}None => self.int32_constant(0),};let function = self.read(callee)?;- let array = self.emit(Op::ArrayCreate, vec![length, function], Some(Repr::Tagged));+ let array = self.emit(Op::ArrayCreate, &[length, function], Some(Repr::Tagged));let array = self.branch_if_empty(&mut slow_paths, array);let array = self.join_slow_paths(slow_paths, Some(array))@@ -904,8 +904,8 @@ impl GraphBuilder<'_> {let (int32, other) = self.branch_both_ways(BranchCondition::Int32Value, vec![value]);self.block = int32;let integer = self.refine(BranchCondition::Int32Value, true, vec![value]);- let unboxed = self.emit(Op::UnboxInt32, vec![integer], Some(Repr::Int32));- let cached = self.emit(Op::IntegerToString, vec![unboxed], Some(Repr::Tagged));+ let unboxed = self.emit(Op::UnboxInt32, &[integer], Some(Repr::Int32));+ let cached = self.emit(Op::IntegerToString, &[unboxed], Some(Repr::Tagged));let empty = self.constant(crate::ir::value::EMPTY);let missing = BranchCondition::TaggedEquals { equal: true };let (miss, hit) = self.branch_both_ways(missing, vec![cached, empty]);@@ -913,11 +913,11 @@ impl GraphBuilder<'_> {let cached = self.refine(missing, false, vec![cached, empty]);self.end_hot_path(&mut slow_paths, vec![cached]);self.block = miss;- let string = self.emit(Op::PrimitiveToString, vec![integer], Some(Repr::Tagged));+ let string = self.emit(Op::PrimitiveToString, &[integer], Some(Repr::Tagged));self.end_hot_path(&mut slow_paths, vec![string]);self.block = other;let primitive = self.branch_to_slow_path(&mut slow_paths, BranchCondition::Object, vec![value], false);- self.emit(Op::PrimitiveToString, vec![primitive], Some(Repr::Tagged))+ self.emit(Op::PrimitiveToString, &[primitive], Some(Repr::Tagged))} else {// 20.1.1.1 Object ( [ value ] ), https://tc39.es/ecma262/#sec-object-valuelet (object, other) = self.branch_both_ways(BranchCondition::Object, vec![value]);@@ -927,7 +927,7 @@ impl GraphBuilder<'_> {self.block = other;let primitive = self.branch_to_slow_path(&mut slow_paths, BranchCondition::Nullish, vec![value], false);let function = self.read(*callee)?;- let object = self.emit(Op::ToObject, vec![primitive, function], Some(Repr::Tagged));+ let object = self.emit(Op::ToObject, &[primitive, function], Some(Repr::Tagged));self.branch_if_empty(&mut slow_paths, object)};self.end_hot_path(&mut slow_paths, vec![result]);@@ -1012,10 +1012,10 @@ impl GraphBuilder<'_> {};inputs.push(input);}- let result = self.emit(Op::CallIntrinsic { intrinsic }, inputs, Some(call.result.repr()));+ let result = self.emit(Op::CallIntrinsic { intrinsic }, &inputs, Some(call.result.repr()));let result = match call.result {- HelperResult::Int32 => self.emit(Op::BoxInt32, vec![result], Some(Repr::Tagged)),- HelperResult::Bool => self.emit(Op::BoxBool, vec![result], Some(Repr::Tagged)),+ HelperResult::Int32 => self.emit(Op::BoxInt32, &[result], Some(Repr::Tagged)),+ HelperResult::Bool => self.emit(Op::BoxBool, &[result], Some(Repr::Tagged)),HelperResult::String => result,HelperResult::Value => self.branch_if_empty(&mut slow_paths, result),};@@ -1051,7 +1051,7 @@ impl GraphBuilder<'_> {Op::Int32Binary {op: BinaryOp::BitwiseAnd,},- vec![code, mask],+ &[code, mask],Some(Repr::Int32),);let ascii_limit = self.int32_constant(0x80);@@ -1061,7 +1061,7 @@ impl GraphBuilder<'_> {vec![code_unit, ascii_limit],true,);- let string = self.emit(Op::SingleCharacterString, vec![code_unit], Some(Repr::Tagged));+ let string = self.emit(Op::SingleCharacterString, &[code_unit], Some(Repr::Tagged));let result = self.join_slow_paths(slow_paths, Some(string)).expect("calls have a value");@@ -1122,7 +1122,7 @@ impl GraphBuilder<'_> {// elements packed, which the slow path does.builder.branch_to_slow_path(slow_paths, BranchCondition::Extensible, vec![address], true);let (_, index) = builder.element_index_in_bounds(slow_paths, kind, address, index);- let length = builder.emit(Op::LoadElementsLength, vec![address], Some(Repr::Int32));+ let length = builder.emit(Op::LoadElementsLength, &[address], Some(Repr::Int32));let one = builder.int32_constant(1);let last = builder.int32_binary(BinaryOp::Sub, length, one);builder.branch_to_slow_path(@@ -1132,7 +1132,7 @@ impl GraphBuilder<'_> {true,)};- builder.emit(Op::StoreElementAt { kind }, vec![address, index, value], None);+ builder.emit(Op::StoreElementAt { kind }, &[address, index, value], None);builder.end_hot_path(slow_paths, Vec::new());},);diff --git a/Libraries/LibJS/JIT/Rust/src/builder/keyed.rs b/Libraries/LibJS/JIT/Rust/src/builder/keyed.rsindex 5ee5f19be08..23711bb1c28 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/keyed.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/keyed.rs@@ -63,7 +63,7 @@ struct KeyPaths {named: Option<(BlockId, NodeId)>,}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// What the keyed feedback of `instruction` saw, or everything if it saw/// nothing.fn keyed_access_bits(&self, instruction: &Instruction) -> u32 {@@ -125,7 +125,7 @@ impl GraphBuilder<'_> {paths.named = Some((self.block, key));return Some(paths);};- let index = self.emit(Op::UnboxInt32, vec![integer], Some(Repr::Int32));+ let index = self.emit(Op::UnboxInt32, &[integer], Some(Repr::Int32));paths.indexed = Some((self.block, index));Some(paths)}@@ -158,14 +158,14 @@ impl GraphBuilder<'_> {index: NodeId,value: NodeId,) -> NodeId {- let length = self.emit(Op::LoadElementsLength, vec![address], Some(Repr::Int32));+ let length = self.emit(Op::LoadElementsLength, &[address], Some(Repr::Int32));let (inside, outside) = self.branch_both_ways(BranchCondition::IndexInBounds, vec![index, length]);self.block = outside;let next = BranchCondition::Int32(Comparison::StrictlyEquals);let next_index = self.branch_to_slow_path(slow_paths, next, vec![index, length], true);- let array = self.emit_checked(Op::CheckAppendableArray, vec![object], None);+ let array = self.emit_checked(Op::CheckAppendableArray, &[object], None);let array_address = self.cell_address(array);- let capacity = self.emit(Op::LoadElementsCapacity, vec![array_address], Some(Repr::Int32));+ let capacity = self.emit(Op::LoadElementsCapacity, &[array_address], Some(Repr::Int32));// NB: Lengths above i32::MAX are negative as int32 values, which an// unsigned comparison keeps from passing as room for an element.// Appends without room grow the elements through the runtime,@@ -178,20 +178,20 @@ impl GraphBuilder<'_> {let nonnegative = BranchCondition::Int32(Comparison::GreaterThanEquals);self.branch_to_slow_path(slow_paths, nonnegative, vec![next_index, zero], true);self.graph.blocks[self.block.index()].is_cold = true;- self.emit(Op::CallArrayPush, vec![array, value], Some(Repr::Tagged));+ self.emit(Op::CallArrayPush, &[array, value], Some(Repr::Tagged));self.end_hot_path(slow_paths, Vec::new());self.block = hot;let next_index = self.refine(room, true, vec![next_index, capacity]);self.emit(Op::AppendElement,- vec![array_address, next_index, value],+ &[array_address, next_index, value],Some(Repr::Int32),);self.end_hot_path(slow_paths, Vec::new());self.block = inside;let index = self.refine(BranchCondition::IndexInBounds, true, vec![index, length]);- let capacity = self.emit(Op::LoadElementsCapacity, vec![address], Some(Repr::Int32));+ let capacity = self.emit(Op::LoadElementsCapacity, &[address], Some(Repr::Int32));self.branch_to_slow_path(slow_paths, BranchCondition::IndexInBounds, vec![index, capacity], true)}@@ -318,7 +318,7 @@ impl GraphBuilder<'_> {let executable = self.function.index;let value = self.emit(Op::ProbeKeyedCache { executable, cache },- vec![object, key],+ &[object, key],Some(Repr::Tagged),);let value = self.branch_if_empty(&mut slow_paths, value);@@ -417,7 +417,7 @@ impl GraphBuilder<'_> {let executable = self.function.index;let stored = self.emit(Op::ProbeKeyedStore { executable, cache },- vec![object, key, value],+ &[object, key, value],Some(Repr::Bool),);self.branch_to_slow_path(&mut slow_paths, BranchCondition::Bool, vec![stored], true);@@ -436,10 +436,10 @@ impl GraphBuilder<'_> {fn store_holey_element(&mut self, slow_paths: &mut SlowPaths, address: NodeId, index: NodeId, value: NodeId) {let kind = ElementsKind::Holey;let in_bounds = BranchCondition::IndexInBounds;- let length = self.emit(Op::LoadElementsLength, vec![address], Some(Repr::Int32));+ let length = self.emit(Op::LoadElementsLength, &[address], Some(Repr::Int32));let index = self.branch_to_slow_path(slow_paths, in_bounds, vec![index, length], true);// NB: Elements made with a length, like `new Array(length)`, have no room yet, and grow as they get filled.- let capacity = self.emit(Op::LoadElementsCapacity, vec![address], Some(Repr::Int32));+ let capacity = self.emit(Op::LoadElementsCapacity, &[address], Some(Repr::Int32));let (room, no_room) = self.branch_with_cold_side(in_bounds, vec![index, capacity], true);self.block = no_room;// NB: Lengths above i32::MAX let negative int32 keys, which are no indices, pass as below the length.@@ -449,12 +449,12 @@ impl GraphBuilder<'_> {self.graph.blocks[self.block.index()].is_cold = true;let array = self.branch_to_slow_path(slow_paths, BranchCondition::HoleFillableArray, vec![address], true);self.graph.blocks[self.block.index()].is_cold = true;- self.emit(Op::CallStoreHoleyElement, vec![array, element_index, value], None);+ self.emit(Op::CallStoreHoleyElement, &[array, element_index, value], None);self.end_hot_path(slow_paths, Vec::new());self.block = room;let index = self.refine(in_bounds, true, vec![index, capacity]);- let old = self.emit(Op::LoadElementAt { kind }, vec![address, index], Some(Repr::Tagged));+ let old = self.emit(Op::LoadElementAt { kind }, &[address, index], Some(Repr::Tagged));let empty = self.constant(value::EMPTY);let (hole, element) = self.branch_both_ways(BranchCondition::TaggedEquals { equal: true }, vec![old, empty]);@@ -466,12 +466,12 @@ impl GraphBuilder<'_> {let one = self.int32_constant(1);let last = self.emit(Op::Int32WrappingBinary { op: BinaryOp::Sub },- vec![length, one],+ &[length, one],Some(Repr::Int32),);let (before_last, at_last) = self.branch_with_cold_side(in_bounds, vec![index, last], true);self.block = at_last;- self.emit(Op::CallStoreHoleyElement, vec![array, index, value], None);+ self.emit(Op::CallStoreHoleyElement, &[array, index, value], None);self.end_hot_path(slow_paths, Vec::new());self.block = before_last;let index_before_last = self.refine(in_bounds, true, vec![index, last]);@@ -497,7 +497,7 @@ impl GraphBuilder<'_> {} else {Op::Float64ToInt32};- self.emit(conversion, vec![number], Some(Repr::Int32))+ self.emit(conversion, &[number], Some(Repr::Int32))}(Repr::Float64, None) => self.float64_of_number(slow_paths, value),_ => self.tagged(value),@@ -589,6 +589,6 @@ impl GraphBuilder<'_> {fn probe_has_property(&mut self, own: bool, object: Operand, key: Operand) -> Result<NodeId, CompileFailure> {let object = self.read(object)?;let key = self.read(key)?;- Ok(self.emit(Op::ProbeHasProperty { own }, vec![object, key], Some(Repr::Tagged)))+ Ok(self.emit(Op::ProbeHasProperty { own }, &[object, key], Some(Repr::Tagged)))}}diff --git a/Libraries/LibJS/JIT/Rust/src/builder/mod.rs b/Libraries/LibJS/JIT/Rust/src/builder/mod.rsindex 13059db09d4..1cad96bff05 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/mod.rs@@ -79,7 +79,6 @@ use crate::ir::FrameField;use crate::ir::FrameStateId;use crate::ir::Graph;use crate::ir::Locations;-use crate::ir::Node;use crate::ir::NodeId;use crate::ir::Op;use crate::ir::SuspendKind;@@ -90,19 +89,24 @@ use crate::snapshot::ExecutableSnapshot;use crate::snapshot::Intrinsic;use crate::snapshot::RuntimeInfo;use crate::snapshot::Snapshot;+use ak::Zone;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]`.-pub fn build_graph(snapshot: &Snapshot) -> Result<Graph, CompileFailure> {- build_graph_with_feedback(snapshot, &|pc| {- snapshot- .executables- .first()- .is_none_or(|executable| has_run(snapshot, executable, pc))- })+pub fn build_graph<'z>(snapshot: &Snapshot, zone: &'z Zone) -> Result<Graph<'z>, CompileFailure> {+ build_graph_with_feedback(+ snapshot,+ &|pc| {+ snapshot+ .executables+ .first()+ .is_none_or(|executable| has_run(snapshot, executable, pc))+ },+ zone,+ )}/// Whether the instruction at `pc` ever ran in the interpreter, as far as the@@ -138,7 +142,11 @@ pub fn has_run(snapshot: &Snapshot, executable: &ExecutableSnapshot, pc: u32) ->/// Like `build_graph()`, with the "did this instruction ever run" oracle/// given by the caller.-pub fn build_graph_with_feedback(snapshot: &Snapshot, has_run: &dyn Fn(u32) -> bool) -> Result<Graph, CompileFailure> {+pub fn build_graph_with_feedback<'z>(+ snapshot: &Snapshot,+ has_run: &dyn Fn(u32) -> bool,+ zone: &'z Zone,+) -> Result<Graph<'z>, CompileFailure> {let decoded = (0..snapshot.executables.len()).map(|_| OnceCell::new()).collect::<Vec<_>>();@@ -154,6 +162,7 @@ pub fn build_graph_with_feedback(snapshot: &Snapshot, has_run: &dyn Fn(u32) -> binlined_callees_virtualized: &virtualized_inlined_arguments,},build_osr_entries,+ zone,)?.build()};@@ -522,13 +531,13 @@ impl<'a> Function<'a> {}}-struct GraphBuilder<'a> {+struct GraphBuilder<'a, 'z> {snapshot: &'a Snapshot,runtime: &'a RuntimeInfo,has_run: &'a dyn Fn(u32) -> bool,decoded: &'a [OnceCell<Result<DecodedFunction, CompileFailure>>],- graph: Graph,+ graph: Graph<'z>,/// The blocks in linear order, as they are started.order: Vec<BlockId>,/// The constant node of each value and representation.@@ -560,13 +569,14 @@ struct GraphBuilder<'a> {has_instance: HashMap<u64, crate::snapshot::OrdinaryHasInstanceSnapshot>,}-impl<'a> GraphBuilder<'a> {+impl<'a, 'z> GraphBuilder<'a, 'z> {fn new(snapshot: &'a Snapshot,has_run: &'a dyn Fn(u32) -> bool,decoded: &'a [OnceCell<Result<DecodedFunction, CompileFailure>>],virtualize_arguments: ArgumentsVirtualization<'a>,build_osr_entries: bool,+ zone: &'z Zone,) -> Result<Self, CompileFailure> {let executable = snapshot.executables.first().ok_or(CompileFailure::InvalidBytecode {pc: 0,@@ -594,7 +604,7 @@ impl<'a> GraphBuilder<'a> {decoded,graph: Graph {legacy_arguments,- ..Graph::default()+ ..Graph::new_in(zone)},order: Vec::new(),constants: HashMap::default(),@@ -613,7 +623,7 @@ impl<'a> GraphBuilder<'a> {})}- fn build(mut self) -> Result<Graph, CompileFailure> {+ fn build(mut self) -> Result<Graph<'z>, CompileFailure> {// NB: The entry block has no predecessors and jumps to the first bytecode// block, which may be a loop header.let entry = self.start_new_block(Vec::new());@@ -628,7 +638,7 @@ impl<'a> GraphBuilder<'a> {index.is_some_and(|index| self.can_build_osr_entry(index))});if self.snapshot.options.runs_once && self.build_osr_entries && builds_entry_at_osr_pc {- self.set_control(Op::Unreachable, Vec::new());+ self.set_control(Op::Unreachable, &[]);} else {self.load_entry_slots();self.enter_function(entry);@@ -716,7 +726,7 @@ impl<'a> GraphBuilder<'a> {/// Loads a slot from frame memory, which then holds its value in sync.fn load_slot(&mut self, slot: usize) -> NodeId {let operand = self.function.layout.operand_for_tracked_index(slot);- let node = self.emit(Op::LoadSlot { slot: operand.raw() }, Vec::new(), Some(Repr::Tagged));+ let node = self.emit(Op::LoadSlot { slot: operand.raw() }, &[], Some(Repr::Tagged));self.frame.slots[slot] = SlotState { node, in_sync: true };node}@@ -727,7 +737,7 @@ impl<'a> GraphBuilder<'a> {let first_block = self.ir_block(0);self.function.incoming[0].push((from, self.frame.clone()));self.block = from;- self.set_control(Op::Jump { target: first_block }, Vec::new());+ self.set_control(Op::Jump { target: first_block }, &[]);}/// Builds the blocks of the function being walked, in reverse post order.@@ -747,7 +757,7 @@ impl<'a> GraphBuilder<'a> {if let Some(block) = self.function.ir_blocks[block_index] {return block;}- let block = self.graph.add_block(Block::default());+ let block = self.graph.add_block(self.graph.new_block());self.function.ir_blocks[block_index] = Some(block);block}@@ -756,8 +766,8 @@ impl<'a> GraphBuilder<'a> {/// The caller sets the abstract frame.fn start_new_block(&mut self, predecessors: Vec<BlockId>) -> BlockId {let block = self.graph.add_block(Block {- predecessors,- ..Block::default()+ predecessors: self.graph.list(&predecessors),+ ..self.graph.new_block()});self.order.push(block);self.block = block;@@ -783,7 +793,10 @@ impl<'a> GraphBuilder<'a> {self.block = block;{let block = &mut self.graph.blocks[block.index()];- block.predecessors = incoming.iter().map(|(predecessor, _)| *predecessor).collect();+ block.predecessors.clear();+ block+ .predecessors+ .extend(incoming.iter().map(|(predecessor, _)| *predecessor));block.bytecode_start = Some(self.function.instructions[first_instruction].pc);block.is_loop_header = is_loop_header;}@@ -871,15 +884,15 @@ impl<'a> GraphBuilder<'a> {});let node = match shared {Some(node) => node,- None if reloads => self.emit(Op::LoadSlot { slot: operand.raw() }, Vec::new(), Some(Repr::Tagged)),+ None if reloads => self.emit(Op::LoadSlot { slot: operand.raw() }, &[], Some(Repr::Tagged)),None => {// NB: Phis start out tagged; representation selection unboxes them later.let inputs = incoming.iter().zip(&values).map(|((predecessor, _), value)| self.tagged_at_end_of(*predecessor, value.node))- .collect();- self.add_phi(inputs)+ .collect::<Vec<_>>();+ self.add_phi(&inputs)}};merged.slots[slot] = SlotState { node, in_sync };@@ -887,18 +900,22 @@ impl<'a> GraphBuilder<'a> {merged}- fn add_phi(&mut self, inputs: Vec<NodeId>) -> NodeId {- let phi = self- .graph- .add_node(Node::new(Op::Phi, inputs, Some(Repr::Tagged), self.function.pc));+ fn add_phi(&mut self, inputs: &[NodeId]) -> NodeId {+ let phi = self.graph.add(Op::Phi, inputs, Some(Repr::Tagged), self.function.pc);self.graph.blocks[self.block.index()].phis.push(phi);phi}/// Adds a node to the body of a block whose control node is already set.- fn append_to_finished_block(&mut self, block: BlockId, op: Op, inputs: Vec<NodeId>, repr: Option<Repr>) -> NodeId {+ fn append_to_finished_block(+ &mut self,+ block: BlockId,+ op: Op<'z>,+ inputs: &[NodeId],+ repr: Option<Repr>,+ ) -> NodeId {let pc = self.graph.control(block).pc;- let node = self.graph.add_node(Node::new(op, inputs, repr, pc));+ let node = self.graph.add(op, inputs, repr, pc);self.graph.blocks[block.index()].body.push(node);node}@@ -959,7 +976,7 @@ impl<'a> GraphBuilder<'a> {} else {self.function.incoming[target].push((self.block, self.frame.clone()));}- self.set_control(Op::Jump { target: target_block }, Vec::new());+ self.set_control(Op::Jump { target: target_block }, &[]);Ok(())}@@ -967,7 +984,7 @@ impl<'a> GraphBuilder<'a> {/// a fresh block for each successor.fn end_with_branch(&mut self,- make_op: impl FnOnce(BlockId, BlockId) -> Op,+ make_op: impl FnOnce(BlockId, BlockId) -> Op<'z>,inputs: Vec<NodeId>,if_true: BlockIndex,if_false: BlockIndex,@@ -975,16 +992,16 @@ impl<'a> GraphBuilder<'a> {let source = self.block;let frame = self.frame.clone();let true_edge = self.graph.add_block(Block {- predecessors: vec![source],- ..Block::default()+ predecessors: self.graph.list(&[source]),+ ..self.graph.new_block()});let false_edge = self.graph.add_block(Block {- predecessors: vec![source],- ..Block::default()+ predecessors: self.graph.list(&[source]),+ ..self.graph.new_block()});self.order.push(true_edge);self.order.push(false_edge);- self.set_control(make_op(true_edge, false_edge), inputs);+ self.set_control(make_op(true_edge, false_edge), &inputs);for (edge, target) in [(true_edge, if_true), (false_edge, if_false)] {self.block = edge;self.frame = frame.clone();@@ -1051,9 +1068,9 @@ impl<'a> GraphBuilder<'a> {// Nodes.- fn emit(&mut self, op: Op, inputs: Vec<NodeId>, repr: Option<Repr>) -> NodeId {+ fn emit(&mut self, op: Op<'z>, inputs: &[NodeId], repr: Option<Repr>) -> NodeId {debug_assert!(!op.is_control());- let node = self.graph.add_node(Node::new(op, inputs, repr, self.function.pc));+ let node = self.graph.add(op, inputs, repr, self.function.pc);self.graph.blocks[self.block.index()].body.push(node);self.note_shape_changes(node);node@@ -1097,9 +1114,9 @@ impl<'a> GraphBuilder<'a> {.map(|(_, shape)| *shape)}- fn set_control(&mut self, op: Op, inputs: Vec<NodeId>) -> NodeId {+ fn set_control(&mut self, op: Op<'z>, inputs: &[NodeId]) -> NodeId {debug_assert!(op.is_control());- let node = self.graph.add_node(Node::new(op, inputs, None, self.function.pc));+ let node = self.graph.add(op, inputs, None, self.function.pc);let block = &mut self.graph.blocks[self.block.index()];assert!(block.control.is_none(), "a block has one control node");block.control = Some(node);@@ -1114,9 +1131,7 @@ impl<'a> GraphBuilder<'a> {if let Some(node) = self.constants.get(&(bits, repr)) {return *node;}- let node = self- .graph- .add_node(Node::new(Op::Constant(bits), Vec::new(), Some(repr), 0));+ let node = self.graph.add(Op::Constant(bits), &[], Some(repr), 0);self.constants.insert((bits, repr), node);node}@@ -1128,7 +1143,7 @@ impl<'a> GraphBuilder<'a> {self.runtime.heap_region_base + (bits & self.runtime.heap_region_offset_mask),Repr::Pointer,),- None => self.emit(Op::CellAddress, vec![value], Some(Repr::Pointer)),+ None => self.emit(Op::CellAddress, &[value], Some(Repr::Pointer)),}}@@ -1148,9 +1163,9 @@ impl<'a> GraphBuilder<'a> {return self.constant(value::int32((bits as u32).cast_signed()));}if block == self.block {- return self.emit(Op::BoxInt32, vec![value], Some(Repr::Tagged));+ return self.emit(Op::BoxInt32, &[value], Some(Repr::Tagged));}- self.append_to_finished_block(block, Op::BoxInt32, vec![value], Some(Repr::Tagged))+ self.append_to_finished_block(block, Op::BoxInt32, &[value], Some(Repr::Tagged))}fn constant(&mut self, bits: u64) -> NodeId {@@ -1215,7 +1230,7 @@ impl<'a> GraphBuilder<'a> {let index = (operand.raw() - self.function.layout.constants_base()) as usize;if index < self.function.written_constants.capacity() && self.function.written_constants.contains(index){- return Ok(self.emit(Op::LoadSlot { slot: operand.raw() }, Vec::new(), Some(Repr::Tagged)));+ return Ok(self.emit(Op::LoadSlot { slot: operand.raw() }, &[], Some(Repr::Tagged)));}let bits = *self.snapshot[self.function.executable.constants].get(index).ok_or(CompileFailure::InvalidBytecode {@@ -1237,7 +1252,7 @@ impl<'a> GraphBuilder<'a> {}let Some(slot) = self.function.layout.tracked_index(operand) else {// NB: A written constant lives in frame memory.- self.emit(Op::StoreSlot { slot: operand.raw() }, vec![value], None);+ self.emit(Op::StoreSlot { slot: operand.raw() }, &[value], None);return Ok(());};// NB: Inlined frames have no memory to be out of sync with.@@ -1256,7 +1271,7 @@ impl<'a> GraphBuilder<'a> {.contains(slot);if !unchanged {if writes_memory {- self.emit(Op::StoreSlot { slot: operand.raw() }, vec![value], None);+ self.emit(Op::StoreSlot { slot: operand.raw() }, &[value], None);}self.frame.slots[slot] = SlotState {node: value,@@ -1271,7 +1286,7 @@ impl<'a> GraphBuilder<'a> {let SlotState { node, in_sync } = self.frame.slots[slot];if !in_sync {let operand = self.function.layout.operand_for_tracked_index(slot);- self.emit(Op::StoreSlot { slot: operand.raw() }, vec![node], None);+ self.emit(Op::StoreSlot { slot: operand.raw() }, &[node], None);self.frame.slots[slot].in_sync = true;}}@@ -1302,7 +1317,7 @@ impl<'a> GraphBuilder<'a> {Op::Exit {kind: ExitKind::NoFeedback,},- Vec::new(),+ &[],);self.graph.nodes[exit.index()].frame_state = Some(frame_state);return Ok(Flow::Ended);@@ -1312,7 +1327,7 @@ impl<'a> GraphBuilder<'a> {.instruction.clone();if osr::is_loop_back_edge(instruction.opcode()) {- self.emit_checked(Op::CheckInterrupt, Vec::new(), None);+ self.emit_checked(Op::CheckInterrupt, &[], None);}if replaces_environments(instruction.opcode()) {self.frame.forget_environments();@@ -1332,7 +1347,7 @@ impl<'a> GraphBuilder<'a> {Instruction::Enter => {// NB: Inlined frames are set up by the caller.if !self.function.is_virtual() {- self.emit(Op::InitializeFrame, Vec::new(), None);+ self.emit(Op::InitializeFrame, &[], None);}let empty = self.constant(value::EMPTY);for slot in RESERVED_REGISTER_COUNT as usize..self.function.layout.registers_and_locals_count as usize {@@ -1415,9 +1430,9 @@ impl<'a> GraphBuilder<'a> {let value = if self.graph.is_known_non_empty(value, arguments) {value} else {- self.emit(Op::EmptyToUndefined, vec![value], Some(Repr::Tagged))+ self.emit(Op::EmptyToUndefined, &[value], Some(Repr::Tagged))};- self.set_control(Op::Return, vec![value]);+ self.set_control(Op::Return, &[value]);return Ok(Some(Flow::Ended));}Instruction::End { value } => {@@ -1428,7 +1443,7 @@ impl<'a> GraphBuilder<'a> {if self.function.is_virtual() {return Ok(Some(self.build_inline_return(value, false)?));}- self.set_control(Op::Return, vec![value]);+ self.set_control(Op::Return, &[value]);return Ok(Some(Flow::Ended));}Instruction::Yield {@@ -1457,27 +1472,27 @@ impl<'a> GraphBuilder<'a> {}Instruction::GetLexicalEnvironment { dst } => {let address = self.frame_field(FrameField::LexicalEnvironment)?;- let environment = self.emit(Op::BoxCell, vec![address], Some(Repr::Tagged));+ let environment = self.emit(Op::BoxCell, &[address], Some(Repr::Tagged));self.write(dst, environment)?;}Instruction::SetLexicalEnvironment { environment } => {let environment = self.read(environment)?;- let address = self.emit(Op::SetLexicalEnvironment, vec![environment], Some(Repr::Pointer));+ let address = self.emit(Op::SetLexicalEnvironment, &[environment], Some(Repr::Pointer));self.frame.set_field(FrameField::LexicalEnvironment, address);}Instruction::LeavePrivateEnvironment => {- self.emit(Op::LeavePrivateEnvironment, Vec::new(), None);+ self.emit(Op::LeavePrivateEnvironment, &[], None);}Instruction::IsCallable { dst, value } => {let value = self.read(value)?;- let result = self.emit(Op::IsCallable, vec![value], Some(Repr::Tagged));+ let result = self.emit(Op::IsCallable, &[value], Some(Repr::Tagged));self.write(dst, result)?;}Instruction::GetArgumentCount { dst } => {// NB: An inlined callee was passed as many arguments as its call passed.let count = match &self.function.inline {Some(call) => self.constant(value::int32(call.passed_argument_count.cast_signed())),- None => self.emit(Op::ArgumentCount, Vec::new(), Some(Repr::Tagged)),+ None => self.emit(Op::ArgumentCount, &[], Some(Repr::Tagged)),};self.write(dst, count)?;}@@ -1654,7 +1669,7 @@ impl<'a> GraphBuilder<'a> {Instruction::Typeof { dst, src } if self.runtime.layout.typeof_strings.number != 0 => {let value = self.read(src)?;self.assume_no_htmldda_objects();- let result = self.emit(Op::Typeof, vec![value], Some(Repr::Tagged));+ let result = self.emit(Op::Typeof, &[value], Some(Repr::Tagged));self.write(dst, result)?;}Instruction::InstanceOf { dst, lhs, rhs } => {@@ -1673,7 +1688,7 @@ impl<'a> GraphBuilder<'a> {{let value = self.read(dst)?;self.assume_no_htmldda_objects();- let result = self.emit(Op::Typeof, vec![value], Some(Repr::Tagged));+ let result = self.emit(Op::Typeof, &[value], Some(Repr::Tagged));self.write(dst, result)?;}Instruction::SetGlobal { src, cache, .. } => {@@ -1787,17 +1802,17 @@ impl<'a> GraphBuilder<'a> {let value = if self.graph.is_known_non_empty(value, arguments) {value} else {- self.emit(Op::EmptyToUndefined, vec![value], Some(Repr::Tagged))+ self.emit(Op::EmptyToUndefined, &[value], Some(Repr::Tagged))};self.emit(Op::Suspend {continuation: continuation.map(|label| label.0),kind,},- Vec::new(),+ &[],None,);- self.set_control(Op::Return, vec![value]);+ self.set_control(Op::Return, &[value]);Ok(Flow::Ended)}@@ -1817,9 +1832,9 @@ impl<'a> GraphBuilder<'a> {let object = self.branch_to_slow_path(&mut slow_paths, BranchCondition::Object, vec![source], true);let object = self.cell_address(object);let generator = self.branch_to_slow_path(&mut slow_paths, BranchCondition::GeneratorObject, vec![object], true);- let completion_type = self.emit(Op::LoadGeneratorCompletionType, vec![generator], Some(Repr::Int32));- let completion_type = self.emit(Op::BoxInt32, vec![completion_type], Some(Repr::Tagged));- let value = self.emit(Op::LoadGeneratorCompletionValue, vec![generator], Some(Repr::Tagged));+ let completion_type = self.emit(Op::LoadGeneratorCompletionType, &[generator], Some(Repr::Int32));+ let completion_type = self.emit(Op::BoxInt32, &[completion_type], Some(Repr::Tagged));+ let value = self.emit(Op::LoadGeneratorCompletionValue, &[generator], Some(Repr::Tagged));let outputs = self.join_paths(slow_paths, vec![completion_type, value], |_, outputs| outputs);self.write(type_dst, outputs[0])?;self.write(value_dst, outputs[1])?;@@ -1883,8 +1898,8 @@ impl<'a> GraphBuilder<'a> {let frame = self.frame.clone();let [true_edge, false_edge, fallback] = [(); 3].map(|()| {let block = self.graph.add_block(Block {- predecessors: vec![source],- ..Block::default()+ predecessors: self.graph.list(&[source]),+ ..self.graph.new_block()});self.order.push(block);block@@ -1896,7 +1911,7 @@ impl<'a> GraphBuilder<'a> {if_false: false_edge,fallback,},- vec![value],+ &[value],);for (edge, target) in [(true_edge, if_true), (false_edge, if_false)] {self.block = edge;@@ -1905,7 +1920,7 @@ impl<'a> GraphBuilder<'a> {}self.block = fallback;self.frame = frame;- let boolean = self.emit(Op::ToBoolean, vec![value], Some(Repr::Bool));+ let boolean = self.emit(Op::ToBoolean, &[value], Some(Repr::Bool));self.end_with_branch(|if_true, if_false| Op::Branch {condition: BranchCondition::Bool,@@ -1932,11 +1947,11 @@ impl<'a> GraphBuilder<'a> {if_false: false_block,fallback,},- vec![value],+ &[value],);self.block = fallback;- let boolean = self.emit(Op::ToBoolean, vec![value], Some(Repr::Bool));+ let boolean = self.emit(Op::ToBoolean, &[value], Some(Repr::Bool));let (fallback_true_block, fallback_false_block) = self.branch_both_ways(BranchCondition::Bool, vec![boolean]);self.join_blocks(vec![true_block, false_block, fallback_true_block, fallback_false_block]);self.frame = frame;@@ -1948,7 +1963,7 @@ impl<'a> GraphBuilder<'a> {};let truthy = self.constant(truthy);let falsy = self.constant(falsy);- let result = self.add_phi(vec![truthy, falsy, truthy, falsy]);+ let result = self.add_phi(&[truthy, falsy, truthy, falsy]);self.write(dst, result)}@@ -1972,7 +1987,7 @@ impl<'a> GraphBuilder<'a> {&mut self,instruction: &Instruction,info: GenericInfo,- op: Op,+ op: Op<'z>,) -> Result<Flow, CompileFailure> {self.build_generic_node_with_inputs(instruction, info, op, &[], None)}@@ -1987,7 +2002,7 @@ impl<'a> GraphBuilder<'a> {&mut self,instruction: &Instruction,info: GenericInfo,- op: Op,+ op: Op<'z>,inputs: &[Operand],forwarded: Option<Operand>,) -> Result<Flow, CompileFailure> {@@ -2073,7 +2088,7 @@ impl<'a> GraphBuilder<'a> {} else {value_is_result.then_some(Repr::Tagged)};- let node = self.emit(op, input_nodes, repr);+ let node = self.emit(op, &input_nodes, repr);let mut destination = None;instruction.for_each_operand(|operand, role| {@@ -2131,7 +2146,7 @@ impl<'a> GraphBuilder<'a> {return Ok(Flow::Ended);}if !instruction.opcode().can_fall_through() {- self.set_control(Op::Unreachable, Vec::new());+ self.set_control(Op::Unreachable, &[]);return Ok(Flow::Ended);}Ok(Flow::Continue)diff --git a/Libraries/LibJS/JIT/Rust/src/builder/named.rs b/Libraries/LibJS/JIT/Rust/src/builder/named.rsindex 56399ca5eb7..ac0ee07c3c5 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/named.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/named.rs@@ -25,7 +25,7 @@ use crate::ir::Comparison;use crate::ir::NodeId;use crate::ir::Op;-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Builds `GetById` (`Handling::Expanded`): the property the cache has/// for the value (see `Op::ProbePropertyCache`).pub(super) fn build_get_by_id(&mut self, instruction: &Instruction) -> Result<Flow, CompileFailure> {@@ -71,7 +71,7 @@ impl GraphBuilder<'_> {cache,property,},- vec![object, value],+ &[object, value],Some(Repr::Bool),);self.branch_to_slow_path(&mut slow_paths, BranchCondition::Bool, vec![stored], true);@@ -141,7 +141,7 @@ impl GraphBuilder<'_> {cache,property,},- vec![object],+ &[object],Some(Repr::Tagged),);self.branch_if_empty(slow_paths, property)@@ -168,14 +168,14 @@ impl GraphBuilder<'_> {let (magical, named) = builder.branch_both_ways(BranchCondition::MagicalLength, vec![address]);builder.block = magical;let array = builder.refine(BranchCondition::MagicalLength, true, vec![address]);- let length = builder.emit(Op::LoadElementsLength, vec![array], Some(Repr::Int32));+ let length = builder.emit(Op::LoadElementsLength, &[array], Some(Repr::Int32));builder.end_with_length(slow_paths, length);builder.block = named;let length = builder.probe_property_cache(slow_paths, value, cache, u32::MAX);builder.end_hot_path(slow_paths, vec![length]);} else {- let address = builder.emit(Op::StringAddress, vec![value], Some(Repr::Pointer));- let length = builder.emit(Op::StringLength, vec![address], Some(Repr::Int32));+ let address = builder.emit(Op::StringAddress, &[value], Some(Repr::Pointer));+ let length = builder.emit(Op::StringLength, &[address], Some(Repr::Int32));builder.end_with_length(slow_paths, length);}},@@ -196,7 +196,7 @@ impl GraphBuilder<'_> {vec![length, zero],true,);- let length = self.emit(Op::BoxInt32, vec![length], Some(Repr::Tagged));+ let length = self.emit(Op::BoxInt32, &[length], Some(Repr::Tagged));self.end_hot_path(slow_paths, vec![length]);}}diff --git a/Libraries/LibJS/JIT/Rust/src/builder/osr.rs b/Libraries/LibJS/JIT/Rust/src/builder/osr.rsindex d2815bc2ef1..ac44a74c34a 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/osr.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/osr.rs@@ -74,7 +74,7 @@ pub(crate) fn is_loop_back_edge(opcode: OpCode) -> bool {)}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Whether the instruction with the given index is a back edge that an on-stack replacement entry can be built at.pub(super) fn can_build_osr_entry(&self, index: usize) -> bool {let pc = self.function.instructions[index].pc;diff --git a/Libraries/LibJS/JIT/Rust/src/builder/property_access.rs b/Libraries/LibJS/JIT/Rust/src/builder/property_access.rsindex 5db2feeb990..c7e73a71040 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/property_access.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/property_access.rs@@ -63,7 +63,7 @@ pub(super) struct KeyCheck {/// Cache entries of a keyed access for one key, and the check of the key.type KeyedEntries = (Vec<CacheEntry>, Option<KeyCheck>);-impl GraphBuilder<'_> {+impl<'z> GraphBuilder<'_, 'z> {/// The speculation gate: whether the current instruction may speculate/// in a way that exits with `kind`. A speculation that already failed at/// the same place is never made again.@@ -85,7 +85,7 @@ impl GraphBuilder<'_> {/// Emits a node that may exit with the current instruction's eager frame/// state. The value of a check is the input it refines (see/// `Op::refined_input()`).- pub(super) fn emit_checked(&mut self, op: Op, inputs: Vec<NodeId>, repr: Option<Repr>) -> NodeId {+ pub(super) fn emit_checked(&mut self, op: Op<'z>, inputs: &[NodeId], repr: Option<Repr>) -> NodeId {let repr = repr.or_else(|| self.graph.node(inputs[op.refined_input()?]).repr);let frame_state = self.eager_frame_state();let node = self.emit(op, inputs, repr);@@ -102,7 +102,7 @@ impl GraphBuilder<'_> {) {return value;}- self.emit_checked(Op::CheckObject, vec![value], None)+ self.emit_checked(Op::CheckObject, &[value], None)}/// `object`, refined: known to have one of `shapes`, or the code exits.@@ -113,9 +113,9 @@ impl GraphBuilder<'_> {let address = self.cell_address(object);self.emit_checked(Op::CheckShape {- shapes: shapes.to_vec(),+ shapes: self.graph.zone.alloc_slice_copy(shapes),},- vec![object, address],+ &[object, address],None,)}@@ -129,7 +129,7 @@ impl GraphBuilder<'_> {self.assume(Dependency::WatchpointSetValid(validity));return;}- self.emit_checked(Op::CheckPrototypeChainValid { validity }, Vec::new(), None);+ self.emit_checked(Op::CheckPrototypeChainValid { validity }, &[], None);}/// Makes the code depend on no `[[IsHTMLDDA]]` object existing, if none@@ -147,7 +147,7 @@ impl GraphBuilder<'_> {/// the current instruction on.pub(super) fn assume(&mut self, dependency: Dependency) {self.graph.depend_on(dependency);- self.emit_checked(Op::AssumeValid, Vec::new(), None);+ self.emit_checked(Op::AssumeValid, &[], None);}pub(super) fn load_named(&mut self, object: NodeId, offset: u32) -> NodeId {@@ -160,9 +160,9 @@ impl GraphBuilder<'_> {let address = self.cell_address(object);let op = Op::LoadNamed { offset, holds_data };if holds_data {- return self.emit(op, vec![object, address], Some(Repr::Tagged));+ return self.emit(op, &[object, address], Some(Repr::Tagged));}- self.emit_checked(op, vec![object, address], Some(Repr::Tagged))+ self.emit_checked(op, &[object, address], Some(Repr::Tagged))}pub(super) fn store_named(&mut self, object: NodeId, offset: u32, value: NodeId) {@@ -175,17 +175,17 @@ impl GraphBuilder<'_> {let address = self.cell_address(object);let op = Op::StoreNamed { offset, holds_data };if holds_data {- self.emit(op, vec![object, value, address], None);+ self.emit(op, &[object, value, address], None);return;}- self.emit_checked(op, vec![object, value, address], None);+ self.emit_checked(op, &[object, value, address], None);}/// Loads the property a `Get` entry describes, from the object itself or/// from the prototype holding it.pub(super) fn load_entry(&mut self, object: NodeId, entry: &CacheEntry) -> NodeId {if let Action::GetMissing { prototype_chain } = entry.action {- self.emit_checked(Op::CheckPropertyAbsenceCacheable, vec![object], None);+ self.emit_checked(Op::CheckPropertyAbsenceCacheable, &[object], None);if let Some((validity, valid)) = prototype_chain {self.check_prototype_chain(validity, valid);}@@ -244,7 +244,7 @@ impl GraphBuilder<'_> {expected,kind: ExitKind::UnexpectedValue,},- vec![loaded],+ &[loaded],None,);constant@@ -327,11 +327,11 @@ impl GraphBuilder<'_> {return Ok(false);}let object = self.read(base)?;- let array = self.emit_checked(Op::CheckArray, vec![object], Some(Repr::Tagged));+ let array = self.emit_checked(Op::CheckArray, &[object], Some(Repr::Tagged));let address = self.cell_address(array);- let length = self.emit(Op::LoadElementsLength, vec![address], Some(Repr::Int32));- let length = self.emit_checked(Op::CheckNonNegativeInt32, vec![length], Some(Repr::Int32));- let boxed = self.emit(Op::BoxInt32, vec![length], Some(Repr::Tagged));+ let length = self.emit(Op::LoadElementsLength, &[address], Some(Repr::Int32));+ let length = self.emit_checked(Op::CheckNonNegativeInt32, &[length], Some(Repr::Int32));+ let boxed = self.emit(Op::BoxInt32, &[length], Some(Repr::Tagged));self.write(dst, boxed)?;Ok(true)}@@ -382,9 +382,9 @@ impl GraphBuilder<'_> {self.exit_instead_of_slow_path(&mut slow_paths);let (object, checked_getter) = self.check_accessor_call(base, &entries, AccessorPart::Getter)?;debug_assert!(checked_getter.is_none(), "all entries have the same checked getter");- let typed_array = self.emit_checked(Op::CheckTypedArray, vec![object], Some(Repr::Tagged));+ let typed_array = self.emit_checked(Op::CheckTypedArray, &[object], Some(Repr::Tagged));let address = self.cell_address(typed_array);- let length = self.emit(Op::LoadTypedArrayLength, vec![address], Some(Repr::Int32));+ let length = self.emit(Op::LoadTypedArrayLength, &[address], Some(Repr::Int32));let zero = self.int32_constant(0);let length = self.branch_to_slow_path(&mut slow_paths,@@ -392,7 +392,7 @@ impl GraphBuilder<'_> {vec![length, zero],true,);- let length = self.emit(Op::BoxInt32, vec![length], Some(Repr::Tagged));+ let length = self.emit(Op::BoxInt32, &[length], Some(Repr::Tagged));let result = self.join_slow_paths(slow_paths, Some(length));self.write(dst, result.expect("GetLength has a value"))?;Ok(true)@@ -477,7 +477,7 @@ impl GraphBuilder<'_> {part,target,};- let node = self.emit(op, inputs, Some(Repr::Tagged));+ let node = self.emit(op, &inputs, Some(Repr::Tagged));let frame_state = self.resume_after_frame_state(dst);self.graph.nodes[node.index()].frame_state = Some(frame_state);node@@ -588,14 +588,14 @@ impl GraphBuilder<'_> {self.embed(function);self.emit_checked(Op::CheckAccessorFunction { offset, part, function },- vec![holder, address],+ &[holder, address],None,);return Ok((object, None));}let function = self.emit_checked(Op::LoadAccessorFunction { offset, part },- vec![holder, address],+ &[holder, address],Some(Repr::Tagged),);Ok((object, Some(function)))@@ -730,7 +730,7 @@ impl GraphBuilder<'_> {expected: check.expected,kind: ExitKind::UnexpectedValue,},- vec![check.key],+ &[check.key],None,);}diff --git a/Libraries/LibJS/JIT/Rust/src/builder/property_additions.rs b/Libraries/LibJS/JIT/Rust/src/builder/property_additions.rsindex 70386a2d403..32f1b61f720 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/property_additions.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/property_additions.rs@@ -27,7 +27,7 @@ use crate::bytecode::Operand;use crate::code::ExitKind;use crate::ir::Op;-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Builds `base.property = src` as `AddNamed` and `StoreNamed` nodes, if/// its property cache saw additions (and writes of existing own data/// properties) on shapes that are no dictionaries, and its object is an@@ -110,7 +110,7 @@ impl GraphBuilder<'_> {shape,property_count: offset + 1,},- vec![object, value, address],+ &[object, value, address],None,);}diff --git a/Libraries/LibJS/JIT/Rust/src/builder/property_iterator.rs b/Libraries/LibJS/JIT/Rust/src/builder/property_iterator.rsindex 66cd42c3f15..178d7334a0d 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/property_iterator.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/property_iterator.rs@@ -17,7 +17,7 @@ use crate::ir::Comparison;use crate::ir::Op;use crate::ir::value;-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// Builds `ObjectPropertyIteratorNext`, the next key of a for-in loop/// over `receiver`: while the property iterator cache `keys` still holds/// the receiver's keys and the cursor is an int32, the key at the cursor,@@ -56,28 +56,24 @@ impl GraphBuilder<'_> {vec![cursor_value],true,);- let index = self.emit(Op::UnboxInt32, vec![cursor_index], Some(Repr::Int32));- let count = self.emit(Op::LoadPropertyIteratorKeyCount, vec![keys], Some(Repr::Int32));+ let index = self.emit(Op::UnboxInt32, &[cursor_index], Some(Repr::Int32));+ let count = self.emit(Op::LoadPropertyIteratorKeyCount, &[keys], Some(Repr::Int32));let (more, finished) = self.branch_both_ways(BranchCondition::Int32(Comparison::LessThan), vec![index, count]);self.block = more;let index = self.refine(BranchCondition::Int32(Comparison::LessThan), true, vec![index, count]);- let key = self.emit(Op::LoadPropertyIteratorKey, vec![keys, index], Some(Repr::Tagged));+ let key = self.emit(Op::LoadPropertyIteratorKey, &[keys, index], Some(Repr::Tagged));// NB: The index is below the count, so the next one is an int32 too.let one = self.int32_constant(1);- let next = self.emit_checked(- Op::Int32Binary { op: BinaryOp::Add },- vec![index, one],- Some(Repr::Int32),- );- let next = self.emit(Op::BoxInt32, vec![next], Some(Repr::Tagged));+ let next = self.emit_checked(Op::Int32Binary { op: BinaryOp::Add }, &[index, one], Some(Repr::Int32));+ let next = self.emit(Op::BoxInt32, &[next], Some(Repr::Tagged));let not_done = self.constant(value::FALSE);let done = self.constant(value::TRUE);self.join_blocks(vec![more, finished]);- let value = self.add_phi(vec![key, old_value]);- let is_done = self.add_phi(vec![not_done, done]);- let new_cursor = self.add_phi(vec![next, cursor_value]);+ let value = self.add_phi(&[key, old_value]);+ let is_done = self.add_phi(&[not_done, done]);+ let new_cursor = self.add_phi(&[next, cursor_value]);let outputs = self.join_paths(slow_paths, vec![value, is_done, new_cursor], |_, outputs| outputs);self.write(dst_value, outputs[0])?;diff --git a/Libraries/LibJS/JIT/Rust/src/builder/slow_paths.rs b/Libraries/LibJS/JIT/Rust/src/builder/slow_paths.rsindex 6c7c3b8fa38..1bdd257ee55 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/slow_paths.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/slow_paths.rs@@ -57,7 +57,7 @@ pub(crate) fn js_call_operands(instruction: &Instruction) -> SlowPathOperands {SlowPathOperands { inputs, outputs }}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// The operands of the slow path of the instruction being built.pub(super) fn slow_path_operands(&self) -> Result<SlowPathOperands, CompileFailure> {let opcode = self.function.instructions[self.function.instruction_index]@@ -159,7 +159,7 @@ impl GraphBuilder<'_> {pc: self.function.pc,saves_registers: false,},- inputs,+ &inputs,repr,);@@ -192,7 +192,7 @@ impl GraphBuilder<'_> {node} else {let index = u8::try_from(index).expect("slow paths have few outputs");- self.emit(Op::SlowPathOutput { index }, vec![node], Some(Repr::Tagged))+ self.emit(Op::SlowPathOutput { index }, &[node], Some(Repr::Tagged))};self.write(operand, value)?;}diff --git a/Libraries/LibJS/JIT/Rust/src/builder/speculation.rs b/Libraries/LibJS/JIT/Rust/src/builder/speculation.rsindex 7ff377ac616..ce14b2ec30a 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/speculation.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/speculation.rs@@ -235,7 +235,7 @@ impl Operation {}}-impl GraphBuilder<'_> {+impl GraphBuilder<'_, '_> {/// The arithmetic feedback of the instruction being built.fn arith_feedback(&self, instruction: &Instruction) -> Option<u8> {let slot = instruction.feedback_slots().arith?;@@ -340,11 +340,7 @@ impl GraphBuilder<'_> {Outcome::Value(_) => {let [result] = self.join_hot_paths_with(paths, |builder, outputs| {let truth = builder.constant(value::TRUE);- vec![builder.emit(- Op::TaggedEquals { equal: true },- vec![outputs[0], truth],- Some(Repr::Bool),- )]+ vec![builder.emit(Op::TaggedEquals { equal: true }, &[outputs[0], truth], Some(Repr::Bool))]})[..] else {unreachable!("comparisons have one value")};@@ -357,7 +353,7 @@ impl GraphBuilder<'_> {Op::Int32Compare {comparison: Comparison::StrictlyEquals,},- vec![outputs[0], true_pc],+ &[outputs[0], true_pc],Some(Repr::Bool),)]})[..] else {@@ -392,16 +388,16 @@ impl GraphBuilder<'_> {outputs.into_iter().map(|output| {- let number = self.emit(Op::CheckNumber, vec![output], Some(Repr::Float64));+ let number = self.emit(Op::CheckNumber, &[output], Some(Repr::Float64));self.graph.nodes[number.index()].frame_state = Some(frame_state);- self.emit(Op::BoxFloat64, vec![number], Some(Repr::Tagged))+ self.emit(Op::BoxFloat64, &[number], Some(Repr::Tagged))}).collect()}fn box_number_result(&mut self, value: NodeId) -> NodeId {if self.graph.node(value).repr == Some(Repr::Float64) {- self.emit(Op::BoxFloat64, vec![value], Some(Repr::Tagged))+ self.emit(Op::BoxFloat64, &[value], Some(Repr::Tagged))} else {self.tagged(value)}@@ -416,7 +412,7 @@ impl GraphBuilder<'_> {return self.int32_to_float64(integer);}let value = self.tagged(value);- self.emit_checked(Op::CheckNumber, vec![value], Some(Repr::Float64))+ self.emit_checked(Op::CheckNumber, &[value], Some(Repr::Float64))}/// Builds numeric instructions that saw doubles with number guards,@@ -450,16 +446,16 @@ impl GraphBuilder<'_> {let lhs = self.number(lhs);let rhs = self.number(rhs);let result = if op.is_bitwise() {- let lhs = self.emit(Op::Float64ToInt32, vec![lhs], Some(Repr::Int32));- let rhs = self.emit(Op::Float64ToInt32, vec![rhs], Some(Repr::Int32));+ let lhs = self.emit(Op::Float64ToInt32, &[lhs], Some(Repr::Int32));+ let rhs = self.emit(Op::Float64ToInt32, &[rhs], Some(Repr::Int32));if op == BinaryOp::UnsignedRightShift {- let bits = self.emit(Op::Uint32ShiftRight, vec![lhs, rhs], Some(Repr::Int32));- self.emit(Op::Uint32ToFloat64, vec![bits], Some(Repr::Float64))+ let bits = self.emit(Op::Uint32ShiftRight, &[lhs, rhs], Some(Repr::Int32));+ self.emit(Op::Uint32ToFloat64, &[bits], Some(Repr::Float64))} else {self.int32_binary(op, lhs, rhs)}} else {- self.emit(Op::Float64Binary { op }, vec![lhs, rhs], Some(Repr::Float64))+ self.emit(Op::Float64Binary { op }, &[lhs, rhs], Some(Repr::Float64))};let result = self.box_number_result(result);self.write(dst, result)?;@@ -473,11 +469,11 @@ impl GraphBuilder<'_> {Op::Float64Unary {op: Float64UnaryOp::Negate,},- vec![number],+ &[number],Some(Repr::Float64),),UnaryOp::ToInt32 | UnaryOp::BitwiseNot => {- let integer = self.emit(Op::Float64ToInt32, vec![number], Some(Repr::Int32));+ let integer = self.emit(Op::Float64ToInt32, &[number], Some(Repr::Int32));if op == UnaryOp::BitwiseNot {let all_ones = self.int32_constant(-1);self.int32_binary(BinaryOp::BitwiseXor, integer, all_ones)@@ -495,7 +491,7 @@ impl GraphBuilder<'_> {let one = self.typed_constant(1f64.to_bits(), Repr::Float64);let result = self.emit(Op::Float64Binary { op: op.binary_op() },- vec![number, one],+ &[number, one],Some(Repr::Float64),);if let Some(dst) = old_value {@@ -514,7 +510,7 @@ impl GraphBuilder<'_> {let (lhs, rhs) = (self.read_value(lhs)?, self.read_input(rhs)?);let lhs = self.number(lhs);let rhs = self.number(rhs);- let result = self.emit(Op::Float64Compare { comparison }, vec![lhs, rhs], Some(Repr::Bool));+ let result = self.emit(Op::Float64Compare { comparison }, &[lhs, rhs], Some(Repr::Bool));return self.finish_comparison(result, outcome).map(Some);}}@@ -539,7 +535,7 @@ impl GraphBuilder<'_> {(_, Some(Repr::Int32)) => value,(Op::BoxInt32, _) => node.inputs[0],(Op::Constant(bits), _) if let Some(integer) = value::as_int32(*bits) => self.int32_constant(integer),- _ => self.emit_checked(Op::CheckInt32, vec![value], Some(Repr::Int32)),+ _ => self.emit_checked(Op::CheckInt32, &[value], Some(Repr::Int32)),}}@@ -565,7 +561,7 @@ impl GraphBuilder<'_> {/// `lhs op rhs` of two `Repr::Int32` values, which exits where the/// result is not an int32.pub(super) fn int32_binary(&mut self, op: BinaryOp, lhs: NodeId, rhs: NodeId) -> NodeId {- let node = self.emit(Op::Int32Binary { op }, vec![lhs, rhs], Some(Repr::Int32));+ let node = self.emit(Op::Int32Binary { op }, &[lhs, rhs], Some(Repr::Int32));if op.int32_can_overflow() {let frame_state = self.eager_frame_state();self.graph.nodes[node.index()].frame_state = Some(frame_state);@@ -648,7 +644,7 @@ impl GraphBuilder<'_> {}let lhs = self.read_int32(OperationInput::Operand(lhs))?;let rhs = self.read_int32(rhs)?;- let result = self.emit(Op::Int32Compare { comparison }, vec![lhs, rhs], Some(Repr::Bool));+ let result = self.emit(Op::Int32Compare { comparison }, &[lhs, rhs], Some(Repr::Bool));return self.finish_comparison(result, outcome).map(Some);}}@@ -692,7 +688,7 @@ impl GraphBuilder<'_> {// 1. If SameType(x, y) is true, then// a. Return IsStrictlyEqual(x, y).// NB: Objects are strictly equal only by identity.- let result = self.emit(Op::TaggedEquals { equal }, vec![lhs, rhs], Some(Repr::Bool));+ let result = self.emit(Op::TaggedEquals { equal }, &[lhs, rhs], Some(Repr::Bool));return self.finish_comparison(result, outcome).map(Some);}let lhs = self.read(lhs)?;@@ -713,9 +709,9 @@ impl GraphBuilder<'_> {if feedback == 0 || feedback & !identity_kinds != 0 || !self.may_speculate(ExitKind::BadType) {return Ok(None);}- self.emit_checked(Op::CheckIdentityComparable, vec![lhs, rhs], None)+ self.emit_checked(Op::CheckIdentityComparable, &[lhs, rhs], None)};- let result = self.emit(Op::TaggedEquals { equal }, vec![lhs, rhs], Some(Repr::Bool));+ let result = self.emit(Op::TaggedEquals { equal }, &[lhs, rhs], Some(Repr::Bool));self.finish_comparison(result, outcome).map(Some)}@@ -762,7 +758,7 @@ impl GraphBuilder<'_> {return Ok(None);};self.assume_no_htmldda_objects();- let result = self.emit(Op::TypeofIs { kind, equal }, vec![value], Some(Repr::Bool));+ let result = self.emit(Op::TypeofIs { kind, equal }, &[value], Some(Repr::Bool));self.finish_comparison(result, outcome).map(Some)}@@ -786,7 +782,7 @@ impl GraphBuilder<'_> {Ok(Flow::Ended)}Outcome::Value(dst) => {- let boolean = self.emit(Op::BoxBool, vec![result], Some(Repr::Tagged));+ let boolean = self.emit(Op::BoxBool, &[result], Some(Repr::Tagged));self.write(dst, boolean)?;Ok(Flow::Continue)}@@ -838,7 +834,7 @@ impl GraphBuilder<'_> {return self.int32_constant(integer);}let refined = self.branch_to_next_case(paths, BranchCondition::Int32Value, vec![value], true);- self.emit(Op::UnboxInt32, vec![refined], Some(Repr::Int32))+ self.emit(Op::UnboxInt32, &[refined], Some(Repr::Int32))}/// `value` as a `Repr::Float64`, where it is a number: tests send other@@ -897,14 +893,14 @@ impl GraphBuilder<'_> {};if !doubles {let refined = self.branch_to_next_case(paths, integer, vec![value], true);- return self.emit(Op::UnboxInt32, vec![refined], Some(Repr::Int32));+ return self.emit(Op::UnboxInt32, &[refined], Some(Repr::Int32));}self.on_integer_or_double(integer,value,Repr::Int32,|_, integer| integer,- |builder, number| builder.emit(Op::Float64ToInt32, vec![number], Some(Repr::Int32)),+ |builder, number| builder.emit(Op::Float64ToInt32, &[number], Some(Repr::Int32)),|builder, condition, inputs| builder.branch_to_next_case(paths, condition, inputs, true),)}@@ -948,8 +944,8 @@ impl GraphBuilder<'_> {return value;}let boolean = node.inputs[0];- let integer = self.emit(Op::BoolToInt32, vec![boolean], Some(Repr::Int32));- self.emit(Op::BoxInt32, vec![integer], Some(Repr::Tagged))+ let integer = self.emit(Op::BoolToInt32, &[boolean], Some(Repr::Int32));+ self.emit(Op::BoxInt32, &[integer], Some(Repr::Tagged))}// The paths of each kind of operation.@@ -985,9 +981,9 @@ impl GraphBuilder<'_> {let lhs = self.int32_of_operand_on_path(&mut paths, lhs, doubles, booleans);let rhs = self.int32_of_operand_on_path(&mut paths, rhs, doubles, booleans);let result = if op == BinaryOp::UnsignedRightShift && !int32_results {- let bits = self.emit(Op::Uint32ShiftRight, vec![lhs, rhs], Some(Repr::Int32));- let number = self.emit(Op::Uint32ToFloat64, vec![bits], Some(Repr::Float64));- self.emit(Op::BoxFloat64, vec![number], Some(Repr::Tagged))+ let bits = self.emit(Op::Uint32ShiftRight, &[lhs, rhs], Some(Repr::Int32));+ let number = self.emit(Op::Uint32ToFloat64, &[bits], Some(Repr::Float64));+ self.emit(Op::BoxFloat64, &[number], Some(Repr::Tagged))} else {let result = self.int32_binary(op, lhs, rhs);self.tagged(result)@@ -1029,8 +1025,8 @@ impl GraphBuilder<'_> {self.float64_on_path(&mut paths, lhs),self.float64_on_path(&mut paths, rhs),);- let result = self.emit(Op::Float64Binary { op }, vec![lhs, rhs], Some(Repr::Float64));- let result = self.emit(Op::BoxFloat64, vec![result], Some(Repr::Tagged));+ let result = self.emit(Op::Float64Binary { op }, &[lhs, rhs], Some(Repr::Float64));+ let result = self.emit(Op::BoxFloat64, &[result], Some(Repr::Tagged));self.end_hot_path(&mut paths, vec![result]);started = true;}@@ -1092,12 +1088,12 @@ impl GraphBuilder<'_> {self.block = other;let integer = self.int32_on_path(paths, value);- let converted = self.emit(Op::IntegerToString, vec![integer], Some(Repr::Tagged));+ let converted = self.emit(Op::IntegerToString, &[integer], Some(Repr::Tagged));let converted = self.test_not_empty(paths, converted);let converted_end = self.block;self.join_blocks(vec![string_end, converted_end]);- self.add_phi(vec![string, converted])+ self.add_phi(&[string, converted])}/// `value`, which is the empty value where only the slow path can make@@ -1113,11 +1109,7 @@ impl GraphBuilder<'_> {}fn finish_concatenation(&mut self, paths: &mut SlowPaths, lhs: NodeId, rhs: NodeId) {- let result = self.emit(- Op::ConcatenateStrings { key: false },- vec![lhs, rhs],- Some(Repr::Tagged),- );+ let result = self.emit(Op::ConcatenateStrings { key: false }, &[lhs, rhs], Some(Repr::Tagged));let result = self.test_not_empty(paths, result);self.end_hot_path(paths, vec![result]);}@@ -1178,10 +1170,10 @@ impl GraphBuilder<'_> {Op::Float64Unary {op: Float64UnaryOp::Negate,},- vec![number],+ &[number],Some(Repr::Float64),);- let result = self.emit(Op::BoxFloat64, vec![result], Some(Repr::Tagged));+ let result = self.emit(Op::BoxFloat64, &[result], Some(Repr::Tagged));self.end_hot_path(&mut paths, vec![result]);}}@@ -1236,10 +1228,10 @@ impl GraphBuilder<'_> {let one = self.typed_constant(1f64.to_bits(), Repr::Float64);let result = self.emit(Op::Float64Binary { op: op.binary_op() },- vec![number, one],+ &[number, one],Some(Repr::Float64),);- let result = self.emit(Op::BoxFloat64, vec![result], Some(Repr::Tagged));+ let result = self.emit(Op::BoxFloat64, &[result], Some(Repr::Tagged));self.end_hot_path(&mut paths, values(result));}Ok(Some(paths))@@ -1303,7 +1295,7 @@ impl GraphBuilder<'_> {let mut started = false;if int32s || strict_with_int32 {let (lhs, rhs) = (self.int32_on_path(&mut paths, lhs), self.int32_on_path(&mut paths, rhs));- let result = self.emit(Op::Int32Compare { comparison }, vec![lhs, rhs], Some(Repr::Bool));+ let result = self.emit(Op::Int32Compare { comparison }, &[lhs, rhs], Some(Repr::Bool));self.end_hot_path(&mut paths, vec![result]);started = true;}@@ -1312,7 +1304,7 @@ impl GraphBuilder<'_> {self.float64_on_path(&mut paths, lhs),self.float64_on_path(&mut paths, rhs),);- let result = self.emit(Op::Float64Compare { comparison }, vec![lhs, rhs], Some(Repr::Bool));+ let result = self.emit(Op::Float64Compare { comparison }, &[lhs, rhs], Some(Repr::Bool));self.end_hot_path(&mut paths, vec![result]);started = true;}@@ -1323,10 +1315,10 @@ impl GraphBuilder<'_> {let (lhs, rhs) = (self.tagged(lhs), self.tagged(rhs));let lhs = self.branch_to_next_case(&mut paths, BranchCondition::String, vec![lhs], true);let rhs = self.branch_to_next_case(&mut paths, BranchCondition::String, vec![rhs], true);- let result = self.emit(Op::StringsEqual, vec![lhs, rhs], Some(Repr::Tagged));+ let result = self.emit(Op::StringsEqual, &[lhs, rhs], Some(Repr::Tagged));let result = self.test_not_empty(&mut paths, result);let truth = self.constant(value::TRUE);- let result = self.emit(Op::TaggedEquals { equal }, vec![result, truth], Some(Repr::Bool));+ let result = self.emit(Op::TaggedEquals { equal }, &[result, truth], Some(Repr::Bool));self.end_hot_path(&mut paths, vec![result]);}if strict_with_int32 && self.start_next_case(&mut paths) {diff --git a/Libraries/LibJS/JIT/Rust/src/builder/tests.rs b/Libraries/LibJS/JIT/Rust/src/builder/tests.rsindex eed7638d8a2..18835a6eae7 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/tests.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/tests.rs@@ -41,20 +41,21 @@ pub(crate) fn snapshot_for(program: &Program, layout: FrameLayout) -> Snapshot {/// Builds the graph of `program` with `test_layout()`. The instructions with/// the indices in `never_ran` are treated as never having run.-pub(crate) fn build_with_layout(program: &Program, layout: FrameLayout, never_ran: &[usize]) -> Graph {+pub(crate) fn build_with_layout(program: &Program, layout: FrameLayout, never_ran: &[usize]) -> Graph<'static> {let snapshot = snapshot_for(program, layout);let never_ran_pcs = never_ran.iter().map(|index| program.offsets[*index]).collect::<Vec<_>>();- let mut graph = build_graph_with_feedback(&snapshot, &|pc| !never_ran_pcs.contains(&pc)).unwrap();+ let mut graph =+ build_graph_with_feedback(&snapshot, &|pc| !never_ran_pcs.contains(&pc), crate::test_zone()).unwrap();crate::passes::optimize(&mut graph, &layout, true, &mut Dominators::new()).unwrap();graph}/// Builds and optimizes the graph of `snapshot`, like compilation does.-pub(crate) fn optimized_graph(snapshot: &Snapshot) -> Graph {- let mut graph = build_graph(snapshot).unwrap();+pub(crate) fn optimized_graph(snapshot: &Snapshot) -> Graph<'static> {+ let mut graph = build_graph(snapshot, crate::test_zone()).unwrap();crate::passes::optimize(&mut graph,&snapshot.executables[0].layout,@@ -65,7 +66,7 @@ pub(crate) fn optimized_graph(snapshot: &Snapshot) -> Graph {graph}-pub(crate) fn build(program: &Program) -> Graph {+pub(crate) fn build(program: &Program) -> Graph<'static> {build_with_layout(program, test_layout(), &[])}@@ -410,7 +411,7 @@ fn unsupported_instructions_fail_cleanly() {]});let snapshot = snapshot_for(&program, test_layout());- let failure = build_graph(&snapshot).unwrap_err();+ let failure = build_graph(&snapshot, crate::test_zone()).unwrap_err();assert!(matches!(failure,CompileFailure::UnsupportedInstruction {@@ -1852,7 +1853,7 @@ pub(crate) mod inlining {}).collect();snapshot.executables[0].property_caches = add_caches(&mut snapshot, &[cache(entries)]);- let graph = build_graph(&snapshot).unwrap();+ let graph = build_graph(&snapshot, crate::test_zone()).unwrap();let frames = graph.frame_states.iter()diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rsindex 157f19a9fb6..13d4cf4e2cd 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs@@ -101,7 +101,9 @@ pub fn generate_construct_stub<M: PortableMacroAssembler>(/// Generates the code of the call stub, or with `construct` of the construct/// stub (see `Codegen::emit_call_stub()`).fn generate_stub<M: PortableMacroAssembler>(runtime: &RuntimeInfo, construct: bool) -> Result<Vec<u8>, CompileFailure> {- let graph = Graph::default();+ // NB: A stub has no graph to build: the graph stays empty, so its zone gives out nothing and takes no memory.+ let zone = ak::Zone::new(0, c"JIT stub graph");+ let graph = Graph::new_in(&zone);let allocation = Allocation::default();// NB: A stub is code for no executable. It reads no list of the runtime info.let snapshot = Snapshot::new();diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rsindex 70224a6e506..0222f4d747a 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs@@ -109,7 +109,7 @@ use crate::regalloc::Location;use crate::regalloc::Move;use crate::regalloc::RegisterMask;use crate::regalloc::RegisterSet;-use crate::scratch::Scratch;+use crate::scratch::Tables;use crate::snapshot::COMPRESSED_POINTER_SHIFT;use crate::snapshot::CellId;use crate::snapshot::ExecutableSnapshot;@@ -270,7 +270,7 @@ struct Locals {struct Codegen<'a, M: PortableMacroAssembler> {masm: M,- graph: &'a Graph,+ graph: &'a Graph<'a>,allocation: &'a Allocation,/// What the graph was built from. Executable 0 is the compiled function.snapshot: &'a Snapshot,@@ -416,22 +416,22 @@ struct LeaveStub {leave_arguments: Vec<(u32, bool)>,}-/// Generates code for `graph` with the register allocation in `scratch`, whose registers came from-/// `target_registers::<M>()`, and writes the sites of the code into the-/// tables of `scratch`. With `verify` (and in debug builds), checks that+/// Generates code for `graph` with the register allocation in `tables`, whose registers came from+/// `target_registers::<M>()`, and writes the sites of the code into+/// `tables`. With `verify` (and in debug builds), checks that/// every lowering matches its `lowering_info()`.pub fn generate<M: PortableMacroAssembler>(graph: &Graph,snapshot: &Snapshot,verify: bool,- scratch: &mut Scratch,+ tables: &mut Tables,) -> Result<GeneratedCode, CompileFailure> {- let Scratch {+ let Tables {artifact,sites,regalloc,..- } = scratch;+ } = tables;let allocation = ®alloc.allocation;let (_, pinned) = target_registers::<M>();let (gpr_dump_count, fpr_dump_count) = register_dump_counts::<M>();@@ -1810,10 +1810,10 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {self.masm.store64(&slot, self.input(node_id, 1));}Op::AddNamed { offset, shape, .. } => self.emit_add_named(node_id, *offset, *shape)?,- Op::ShapeSwitch { cases } => {+ Op::ShapeSwitch { shapes, targets } => {let exit = self.exit_site(node_id);self.emit_load_compressed_shape_of(node_id, self.pinned.scratch, 1);- for (shape, block) in cases {+ for (shape, block) in shapes.iter().zip(*targets) {let label = self.label(*block);self.emit_branch_on_shape(*shape, label, exit);}diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/sites.rs b/Libraries/LibJS/JIT/Rust/src/codegen/sites.rsindex 41c709488c4..b6f2a3142db 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/sites.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/sites.rs@@ -110,7 +110,7 @@ impl SiteScratch {/// Where a site of kind `kind` finds the values of the frame state of `node`, one after the other in the order of/// `Graph::frame_state_values()`.struct Locations<'a> {- graph: &'a Graph,+ graph: &'a Graph<'a>,allocation: &'a Allocation,kind: SiteKind,/// See `Graph::virtual_objects()`.@@ -169,7 +169,7 @@ impl Locations<'_> {/// What a site is written from.pub(crate) struct SiteSource<'a> {- pub graph: &'a Graph,+ pub graph: &'a Graph<'a>,pub allocation: &'a Allocation,/// The node whose frame state the site has.pub node: NodeId,diff --git a/Libraries/LibJS/JIT/Rust/src/ir/dump.rs b/Libraries/LibJS/JIT/Rust/src/ir/dump.rsindex 620263f1cd5..ce10df6e8c1 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/dump.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/dump.rs@@ -280,9 +280,10 @@ fn op_text(layout: &FrameLayout, op: &Op, inputs: &str) -> String {with_inputs(&format!("StoreNamed +{offset}")) + if *holds_data { " data" } else { "" }}Op::AddNamed { offset, shape, .. } => with_inputs(&format!("AddNamed +{offset} to {:#x}", shape.0)),- Op::ShapeSwitch { cases } => {- let cases = cases+ Op::ShapeSwitch { shapes, targets } => {+ let cases = shapes.iter()+ .zip(*targets).map(|(shape, block)| format!("{} -> {}", shapes_text(std::iter::once(shape)), block_name(*block))).collect::<Vec<_>>();format!("{} [{}]", with_inputs("ShapeSwitch"), cases.join(", "))diff --git a/Libraries/LibJS/JIT/Rust/src/ir/info.rs b/Libraries/LibJS/JIT/Rust/src/ir/info.rsindex 56a4c09619d..779b742cf44 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/info.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/info.rs@@ -230,7 +230,7 @@ impl OpInfo {}}-impl Op {+impl Op<'_> {/// What the compiler knows about the op.pub fn info(&self) -> OpInfo {use Inputs as I;diff --git a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs b/Libraries/LibJS/JIT/Rust/src/ir/mod.rsindex e4b7bbddebb..7b4518613eb 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/mod.rs@@ -28,6 +28,9 @@ pub use info::OpInfo;pub use dump::dump;pub use dump::node_text;+use ak::Zone;+use ak::ZoneVec;+use crate::bytecode::OpCode;use crate::code::ExitKind;use crate::code::Repr;@@ -436,7 +439,7 @@ pub enum VirtualObjectKind {macro_rules! define_ops {($(#[$attribute:meta])*- pub enum Op {+ pub enum Op<$zone:lifetime> {$($(#[$variant_attribute:meta])*$variant:ident $(($($tuple:ty),* $(,)?))? $({@@ -446,7 +449,7 @@ macro_rules! define_ops {}) => {$(#[$attribute])*- pub enum Op {+ pub enum Op<$zone> {$($(#[$variant_attribute])*$variant $(($($tuple),*))? $({@@ -455,7 +458,7 @@ macro_rules! define_ops {),*}- impl Op {+ impl Op<'_> {pub fn name(&self) -> &'static str {match self {$(Op::$variant { .. } => stringify!($variant)),*@@ -482,7 +485,7 @@ define_ops! {/// becomes a use of the value it refines (see `edit::remove_refinements()`)./// `CheckInt32` refines and unboxes its input at once.#[derive(Debug, Clone, PartialEq, Eq)]- pub enum Op {+ pub enum Op<'z> {/// A NaN-boxed constant.Constant(u64),/// Reads frame slot `slot` (a flat operand index).@@ -886,7 +889,7 @@ define_ops! {/// Exits unless the object in input 0 has one of `shapes`. An optional/// input 1 is the object's `CellAddress`.CheckShape {- shapes: Vec<ShapeCheck>,+ shapes: &'z [ShapeCheck],},/// Exits unless the `WatchpointSet` cell `validity` is still valid.CheckPrototypeChainValid {@@ -1004,11 +1007,13 @@ define_ops! {if_true: BlockId,if_false: BlockId,},- /// Continues at the block of the first case whose shape the object in- /// input 0 has, or exits if there is none. An optional input 1 is the- /// object's `CellAddress`.+ /// Continues at the block of `targets` for the first of `shapes` that the+ /// object in input 0 has, or exits if it has none of them. There is one+ /// block for each shape. An optional input 1 is the object's+ /// `CellAddress`.ShapeSwitch {- cases: Vec<(ShapeCheck, BlockId)>,+ shapes: &'z [ShapeCheck],+ targets: &'z [BlockId],},/// Returns input 0 from the function, as is: the `End` bytecode, and the/// `Return` bytecode of a value whose empty value became `undefined`.@@ -1394,9 +1399,9 @@ impl Float64Function {}}-impl Op {+impl<'z> Op<'z> {/// The blocks a control node can continue at.- pub fn successors(&self) -> Successors {+ pub fn successors(&self) -> Successors<'z> {let inline = |blocks: &[BlockId]| {let mut inline = [BlockId(0); 3];inline[..blocks.len()].copy_from_slice(blocks);@@ -1415,7 +1420,7 @@ impl Op {if_false,fallback,} => inline(&[*if_true, *if_false, *fallback]),- Op::ShapeSwitch { cases } => Successors::Cases(cases.iter().map(|(_, block)| *block).collect()),+ Op::ShapeSwitch { targets, .. } => Successors::Cases(targets),_ => inline(&[]),}}@@ -1437,8 +1442,8 @@ impl Op {visit(*if_false);visit(*fallback);}- Op::ShapeSwitch { cases } => {- for (_, block) in cases {+ Op::ShapeSwitch { targets, .. } => {+ for block in *targets {visit(*block);}}@@ -1446,32 +1451,41 @@ impl Op {}}- fn successors_mut(&mut self) -> Vec<&mut BlockId> {+ /// Makes a control node continue at `map(block)` where it continued at `block`. A shape switch that changes+ /// gets its new list of blocks from `zone`.+ fn map_successors(&mut self, zone: &'z Zone, map: impl Fn(BlockId) -> BlockId) {match self {- Op::Jump { target } => vec![target],+ Op::Jump { target } => *target = map(*target),Op::Branch { if_true, if_false, .. } | Op::BranchOnPc { if_true, if_false, .. } => {- vec![if_true, if_false]+ *if_true = map(*if_true);+ *if_false = map(*if_false);}Op::BranchTruthy {if_true,if_false,fallback,- } => vec![if_true, if_false, fallback],- Op::ShapeSwitch { cases } => cases.iter_mut().map(|(_, block)| block).collect(),- _ => Vec::new(),+ } => {+ *if_true = map(*if_true);+ *if_false = map(*if_false);+ *fallback = map(*fallback);+ }+ Op::ShapeSwitch { targets, .. } if targets.iter().any(|block| map(*block) != *block) => {+ *targets = zone.alloc_slice_from_iter(targets.iter().map(|block| map(*block)));+ }+ _ => {}}}}/// The blocks a control node can continue at (see `Op::successors()`):/// those of jumps and branches inline, and the cases of shape switches.-#[derive(Debug, Clone, PartialEq, Eq)]-pub enum Successors {+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum Successors<'z> {Inline { blocks: [BlockId; 3], count: u8 },- Cases(Vec<BlockId>),+ Cases(&'z [BlockId]),}-impl std::ops::Deref for Successors {+impl std::ops::Deref for Successors<'_> {type Target = [BlockId];fn deref(&self) -> &[BlockId] {@@ -1482,11 +1496,11 @@ impl std::ops::Deref for Successors {}}-impl IntoIterator for Successors {+impl<'z> IntoIterator for Successors<'z> {type Item = BlockId;- type IntoIter = SuccessorsIntoIter;+ type IntoIter = SuccessorsIntoIter<'z>;- fn into_iter(self) -> SuccessorsIntoIter {+ fn into_iter(self) -> SuccessorsIntoIter<'z> {SuccessorsIntoIter {successors: self,next: 0,@@ -1494,12 +1508,12 @@ impl IntoIterator for Successors {}}-pub struct SuccessorsIntoIter {- successors: Successors,+pub struct SuccessorsIntoIter<'z> {+ successors: Successors<'z>,next: usize,}-impl Iterator for SuccessorsIntoIter {+impl Iterator for SuccessorsIntoIter<'_> {type Item = BlockId;fn next(&mut self) -> Option<BlockId> {@@ -1510,9 +1524,9 @@ impl Iterator for SuccessorsIntoIter {}#[derive(Debug, Clone)]-pub struct Node {- pub op: Op,- pub inputs: Vec<NodeId>,+pub struct Node<'z> {+ pub op: Op<'z>,+ pub inputs: ZoneVec<'z, NodeId>,/// The representation of the value this node produces, if it produces one.pub repr: Option<Repr>,/// The interpreter state to rebuild if this node exits.@@ -1521,9 +1535,9 @@ pub struct Node {pub pc: u32,}-impl Node {+impl<'z> Node<'z> {/// A node without a frame state.- pub fn new(op: Op, inputs: Vec<NodeId>, repr: Option<Repr>, pc: u32) -> Self {+ pub fn new(op: Op<'z>, inputs: ZoneVec<'z, NodeId>, repr: Option<Repr>, pc: u32) -> Self {Self {op,inputs,@@ -1534,11 +1548,11 @@ impl Node {}}-#[derive(Debug, Clone, Default)]-pub struct Block {- pub predecessors: Vec<BlockId>,- pub phis: Vec<NodeId>,- pub body: Vec<NodeId>,+#[derive(Debug, Clone)]+pub struct Block<'z> {+ pub predecessors: ZoneVec<'z, BlockId>,+ pub phis: ZoneVec<'z, NodeId>,+ pub body: ZoneVec<'z, NodeId>,/// The control node ending this block. Every finished block has one.pub control: Option<NodeId>,/// The bytecode offset of the first instruction, for blocks that start a@@ -1558,7 +1572,21 @@ pub struct Block {pub start_frame_state: Option<FrameStateId>,}-impl Block {+impl<'z> Block<'z> {+ /// A block with no nodes and no predecessors, whose lists are in `zone`.+ pub fn new_in(zone: &'z Zone) -> Self {+ Self {+ predecessors: ZoneVec::new_in(zone),+ phis: ZoneVec::new_in(zone),+ body: ZoneVec::new_in(zone),+ control: None,+ bytecode_start: None,+ is_loop_header: false,+ is_cold: false,+ start_frame_state: None,+ }+ }+/// The block's nodes, in order: its phis, its body and its control node.pub fn nodes(&self) -> impl Iterator<Item = NodeId> + '_ {self.phis.iter().chain(&self.body).chain(&self.control).copied()@@ -1567,7 +1595,7 @@ impl Block {/// The interpreter state of a frame at a point where compiled code may exit.#[derive(Debug, Clone, PartialEq, Eq)]-pub struct FrameState {+pub struct FrameState<'z> {/// Index into `Snapshot::executables`.pub executable: u32,pub pc: u32,@@ -1575,7 +1603,7 @@ pub struct FrameState {/// The SSA value of every live frame slot (a flat operand index) whose/// frame memory does not already hold it, in slot order. Frames of/// inlined calls have no memory, so they list every live slot.- pub values: Vec<(u32, NodeId)>,+ pub values: ZoneVec<'z, (u32, NodeId)>,/// The live frame slots whose value frame memory holds: the compiled/// function's slots that are in sync, and the slots a slow path in an/// inlined callee wrote into the frames pushed for it. With `values`,@@ -1584,7 +1612,7 @@ pub struct FrameState {/// where the instruction did not continue (it threw, or its callee runs/// in the interpreter and writes it when it returns), that is what the/// frame needs. Exits after the instruction keep what it wrote.- pub in_frame: Vec<u32>,+ pub in_frame: ZoneVec<'z, u32>,/// For frames of inlined calls, the frame state of the caller: resuming/// after its `Call` instruction, with the call's result in `dst`.pub parent: Option<FrameStateId>,@@ -1598,29 +1626,33 @@ pub struct FrameState {pub legacy_arguments: core::ops::Range<u32>,}-#[derive(Debug, Clone, Default)]-pub struct Graph {- pub nodes: Vec<Node>,+/// The memory of all the lists of a graph is in one zone (see `ak::Zone`): a graph makes no block of the heap, and+/// all of it goes away when its zone is reset.+#[derive(Debug, Clone)]+pub struct Graph<'z> {+ /// Where the lists of the graph are, and where its nodes, blocks and frame states get their lists.+ pub zone: &'z Zone,+ pub nodes: ZoneVec<'z, Node<'z>>,/// Blocks in linear order. Block 0 is the entry, and every block comes/// after all its predecessors except those reaching it over a loop back/// edge, and cold ones once the passes moved cold blocks last.- pub blocks: Vec<Block>,- pub frame_states: Vec<FrameState>,+ pub blocks: ZoneVec<'z, Block<'z>>,+ pub frame_states: ZoneVec<'z, FrameState<'z>>,/// Cells the graph compares against or reads from (shapes, prototype/// holders, validity cells, inlined functions). The code is only valid/// while they live.- pub embedded_cells: Vec<CellId>,+ pub embedded_cells: ZoneVec<'z, CellId>,/// What the code assumes keeps holding where it has `Op::AssumeValid`/// nodes (see `Dependency`).- pub dependencies: Vec<crate::code::Dependency>,+ pub dependencies: ZoneVec<'z, crate::code::Dependency>,/// The shapes from the snapshot that were stable, which check/// elimination may make the code depend on.- pub stable_shapes: Vec<CellId>,+ pub stable_shapes: ZoneVec<'z, CellId>,/// Immutable properties of embedded typed arrays. Their fixed lengths/// require a valid cached storage offset before each access.- pub typed_array_constants: Vec<(u64, crate::snapshot::TypedArraySnapshot)>,+ pub typed_array_constants: ZoneVec<'z, (u64, crate::snapshot::TypedArraySnapshot)>,/// The targets of `Op::CallDirect` nodes that call function constants.- pub direct_call_targets: Vec<crate::snapshot::DirectCallTarget>,+ pub direct_call_targets: ZoneVec<'z, crate::snapshot::DirectCallTarget>,/// The most bytes of interpreter stack that materializing the frames of/// inlined calls, and the frames of direct and native calls on top of/// them, take at once. Compiled code checks at entry that they fit.@@ -1630,35 +1662,35 @@ pub struct Graph {/// each one starts at: a loop back edge, the continuation of a generator,/// or the instruction after the `Catch` of an exception handler. The frame/// holds every value.- pub osr_entries: Vec<(u32, BlockId)>,+ pub osr_entries: ZoneVec<'z, (u32, BlockId)>,/// The pcs of the loop back edges in the loops of the on-stack/// replacement entries (including those of the entries), from where a/// frame running in the interpreter reaches an entry.- pub osr_loop_back_edges: Vec<u32>,+ pub osr_loop_back_edges: ZoneVec<'z, u32>,/// The pcs of the loop back edges in the loops around the loops of the/// on-stack replacement entries, from where a frame running in the/// interpreter may reach an entry on a later iteration.- pub osr_outer_loop_back_edges: Vec<u32>,+ pub osr_outer_loop_back_edges: ZoneVec<'z, u32>,/// The pcs of the `Catch` of the exception handlers that got no catch/// entry because they never caught an exception before the compile (see/// `builder::osr`). A compile after they caught gives them one.- pub uncaught_handlers: Vec<u32>,+ pub uncaught_handlers: ZoneVec<'z, u32>,/// The register-saving `CallSlowPath` nodes that may run before the/// frame is initialized, and so initialize it first if it is not.- pub slow_paths_initializing_frame: Vec<NodeId>,+ pub slow_paths_initializing_frame: ZoneVec<'z, NodeId>,/// Where exits of each executable were taken before, as (executable,/// pc, kind), for passes that must not repeat a failed speculation.- pub exit_sites: Vec<(u32, u32, ExitKind)>,+ pub exit_sites: ZoneVec<'z, (u32, u32, ExitKind)>,/// The nodes that loop invariant code motion moved out of blocks that not/// every iteration of their loop runs, which exit with/// `ExitKind::Hoisted` instead of their own kind of exit.- pub speculatively_hoisted: Vec<NodeId>,+ pub speculatively_hoisted: ZoneVec<'z, NodeId>,/// The argument slots of the compiled function that its legacy/// `arguments` shows. Empty for functions without legacy `arguments`.pub legacy_arguments: core::ops::Range<u32>,/// The `AssumeLegacyArgumentsUnread` nodes, each with the nodes of its/// instruction that run code.- pub legacy_arguments_guards: Vec<(NodeId, Vec<NodeId>)>,+ pub legacy_arguments_guards: ZoneVec<'z, (NodeId, ZoneVec<'z, NodeId>)>,/// The slots of the compiled function (as operands) whose frame memory holds the value the function started with/// wherever its code runs: the arguments and the `this` value register, unless an instruction writes them. Nothing/// stores to them (the verifier enforces this), so the register allocator reloads what was loaded from them from@@ -1666,7 +1698,49 @@ pub struct Graph {pub unwritten_slots: crate::bitset::BitSet,}-impl Graph {+impl<'z> Graph<'z> {+ /// A graph with nothing in it, whose lists are in `zone`.+ pub fn new_in(zone: &'z Zone) -> Self {+ Self {+ zone,+ nodes: ZoneVec::new_in(zone),+ blocks: ZoneVec::new_in(zone),+ frame_states: ZoneVec::new_in(zone),+ embedded_cells: ZoneVec::new_in(zone),+ dependencies: ZoneVec::new_in(zone),+ stable_shapes: ZoneVec::new_in(zone),+ typed_array_constants: ZoneVec::new_in(zone),+ direct_call_targets: ZoneVec::new_in(zone),+ materialized_frame_bytes: 0,+ osr_entries: ZoneVec::new_in(zone),+ osr_loop_back_edges: ZoneVec::new_in(zone),+ osr_outer_loop_back_edges: ZoneVec::new_in(zone),+ uncaught_handlers: ZoneVec::new_in(zone),+ slow_paths_initializing_frame: ZoneVec::new_in(zone),+ exit_sites: ZoneVec::new_in(zone),+ speculatively_hoisted: ZoneVec::new_in(zone),+ legacy_arguments: 0..0,+ legacy_arguments_guards: ZoneVec::new_in(zone),+ unwritten_slots: crate::bitset::BitSet::default(),+ }+ }++ /// A list of `values` in the memory of the graph.+ pub fn list<T: Clone>(&self, values: &[T]) -> ZoneVec<'z, T> {+ ZoneVec::from_slice_in(values, self.zone)+ }++ /// A block with no nodes and no predecessors, whose lists are in the memory of the graph.+ pub fn new_block(&self) -> Block<'z> {+ Block::new_in(self.zone)+ }++ /// Adds a node with `inputs` and no frame state.+ pub fn add(&mut self, op: Op<'z>, inputs: &[NodeId], repr: Option<Repr>, pc: u32) -> NodeId {+ let inputs = self.list(inputs);+ self.add_node(Node::new(op, inputs, repr, pc))+ }+/// Records that the code relies on `dependency`, which makes the/// runtime discard the code once it no longer holds.pub fn depend_on(&mut self, dependency: crate::code::Dependency) {@@ -1675,7 +1749,7 @@ impl Graph {}}- pub fn node(&self, id: NodeId) -> &Node {+ pub fn node(&self, id: NodeId) -> &Node<'z> {&self.nodes[id.index()]}@@ -1704,11 +1778,11 @@ impl Graph {true}- pub fn block(&self, id: BlockId) -> &Block {+ pub fn block(&self, id: BlockId) -> &Block<'z> {&self.blocks[id.index()]}- pub fn frame_state(&self, id: FrameStateId) -> &FrameState {+ pub fn frame_state(&self, id: FrameStateId) -> &FrameState<'z> {&self.frame_states[id.index()]}@@ -1735,7 +1809,11 @@ impl Graph {/// The values that code `node` runs may read through the legacy/// `arguments` of the frames of its frame state chain for which/// `frames` holds.- pub fn legacy_argument_values_read_by(&self, node: NodeId, frames: impl Fn(&FrameState) -> bool) -> Vec<NodeId> {+ pub fn legacy_argument_values_read_by(+ &self,+ node: NodeId,+ frames: impl Fn(&FrameState<'z>) -> bool,+ ) -> Vec<NodeId> {let data = self.node(node);let Some(frame_state) = data.frame_state.filter(|_| data.op.properties().runs_code) else {return Vec::new();@@ -1821,27 +1899,27 @@ impl Graph {self.block(block).control.expect("finished blocks have a control node")}- pub fn control(&self, block: BlockId) -> &Node {+ pub fn control(&self, block: BlockId) -> &Node<'z> {self.node(self.control_id(block))}- pub fn successors(&self, block: BlockId) -> Successors {+ pub fn successors(&self, block: BlockId) -> Successors<'z> {self.control(block).op.successors()}- pub fn add_node(&mut self, node: Node) -> NodeId {+ pub fn add_node(&mut self, node: Node<'z>) -> NodeId {let id = NodeId::from_index(self.nodes.len());self.nodes.push(node);id}- pub fn add_block(&mut self, block: Block) -> BlockId {+ pub fn add_block(&mut self, block: Block<'z>) -> BlockId {let id = BlockId::from_index(self.blocks.len());self.blocks.push(block);id}- pub fn add_frame_state(&mut self, frame_state: FrameState) -> FrameStateId {+ pub fn add_frame_state(&mut self, frame_state: FrameState<'z>) -> FrameStateId {let id = FrameStateId(u32::try_from(self.frame_states.len()).expect("frame state count fits in u32"));self.frame_states.push(frame_state);id@@ -1857,11 +1935,10 @@ impl Graph {let control = self.blocks[block.index()].control.expect("finished blocks have a control node");- for successor in self.nodes[control.index()].op.successors_mut() {- if *successor == from {- *successor = to;- }- }+ let zone = self.zone;+ self.nodes[control.index()]+ .op+ .map_successors(zone, |successor| if successor == from { to } else { successor });}/// Reorders the blocks so that `order[i]` becomes block `i`. Blocks not@@ -1875,20 +1952,19 @@ impl Graph {assert!(new_index[block.index()].is_none(), "blocks appear once in the order");new_index[block.index()] = Some(BlockId::from_index(index));}- let remap = |block: &mut BlockId| {- *block = new_index[block.index()].expect("reordering keeps every referenced block");- };+ let new_id = |block: BlockId| new_index[block.index()].expect("reordering keeps every referenced block");+ let zone = self.zone;for block in order {let block = &mut self.blocks[block.index()];- block.predecessors.iter_mut().for_each(remap);+ for predecessor in &mut block.predecessors {+ *predecessor = new_id(*predecessor);+ }if let Some(control) = block.control {- for successor in self.nodes[control.index()].op.successors_mut() {- remap(successor);- }+ self.nodes[control.index()].op.map_successors(zone, new_id);}}for (_, block) in &mut self.osr_entries {- remap(block);+ *block = new_id(*block);}// Move each retained block to its destination, carrying the displaced// block's destination with it. Dropped blocks end up past the new end.@@ -1971,6 +2047,22 @@ impl Graph {}}+// NB: Tests make graphs and blocks with no zone at hand. They get the zone of their thread, which lives as long as+// the thread.+#[cfg(test)]+impl Default for Graph<'static> {+ fn default() -> Self {+ Self::new_in(crate::test_zone())+ }+}++#[cfg(test)]+impl Default for Block<'static> {+ fn default() -> Self {+ Self::new_in(crate::test_zone())+ }+}+#[cfg(test)]mod tests {use super::*;@@ -1980,8 +2072,8 @@ mod tests {executable: 0,pc: 0,mode: ResumeMode::ResumeAt,- values,- in_frame: Vec::new(),+ values: graph.list(&values),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent,passed_argument_count: None,legacy_arguments: 0..0,@@ -1998,7 +2090,7 @@ mod tests {..Block::default()});}- let control = graph.add_node(Node::new(Op::Jump { target: BlockId(2) }, Vec::new(), None, 0));+ let control = graph.add(Op::Jump { target: BlockId(2) }, &[], None, 0);graph.blocks[0].control = Some(control);graph.blocks[2].predecessors.push(BlockId(0));graph.osr_entries.push((10, BlockId(3)));@@ -2020,25 +2112,25 @@ mod tests {#[test]fn frame_state_values_keep_caller_and_nested_object_order() {let mut graph = Graph::default();- let value = graph.add_node(Node::new(Op::Constant(value::UNDEFINED), vec![], Some(Repr::Tagged), 0));- let inner = graph.add_node(Node::new(+ let value = graph.add(Op::Constant(value::UNDEFINED), &[], Some(Repr::Tagged), 0);+ let inner = graph.add(Op::VirtualObject {kind: VirtualObjectKind::Object { shape: CellId(1) },allocation: NodeId(0),},- vec![value],+ &[value],Some(Repr::Tagged),0,- ));- let outer = graph.add_node(Node::new(+ );+ let outer = graph.add(Op::VirtualObject {kind: VirtualObjectKind::Object { shape: CellId(2) },allocation: NodeId(1),},- vec![inner, value],+ &[inner, value],Some(Repr::Tagged),0,- ));+ );let parent = state(&mut graph, vec![(0, value), (1, inner)], None);let current = state(&mut graph, vec![(0, outer), (1, inner)], Some(parent));assert_eq!(graph.virtual_objects(current), [outer, inner]);diff --git a/Libraries/LibJS/JIT/Rust/src/lib.rs b/Libraries/LibJS/JIT/Rust/src/lib.rsindex 16336138409..b3e1397442f 100644--- a/Libraries/LibJS/JIT/Rust/src/lib.rs+++ b/Libraries/LibJS/JIT/Rust/src/lib.rs@@ -68,6 +68,15 @@ impl From<ak::ColumnFull> for CompileFailure {}}+/// The zone of the thread of a test, for the graphs that the test makes. It lives as long as the thread.+#[cfg(test)]+pub(crate) fn test_zone() -> &'static ak::Zone {+ thread_local! {+ static ZONE: &'static ak::Zone = Box::leak(Box::new(ak::Zone::new(1 << 30, c"test")));+ }+ ZONE.with(|zone| *zone)+}+/// 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> {@@ -107,26 +116,41 @@ fn compile_into<M: asm::PortableMacroAssembler>(has_run: &dyn Fn(u32) -> bool,scratch: &mut Scratch,compiled: &mut CompiledCode,+) -> Result<(), CompileFailure> {+ let result = run_stages::<M>(snapshot, has_run, scratch, compiled);+ scratch.end_compile();+ result+}++/// The stages of `compile_into()`, which leave their data in `scratch`.+fn run_stages<M: asm::PortableMacroAssembler>(+ snapshot: &Snapshot,+ has_run: &dyn Fn(u32) -> bool,+ scratch: &mut Scratch,+ compiled: &mut CompiledCode,) -> Result<(), CompileFailure> {compiled.clear();if !snapshot.is_complete() {return Err(CompileFailure::TooLarge);}- let mut graph = builder::build_graph_with_feedback(snapshot, has_run)?;+ let Scratch { zone, tables } = scratch;+ // NB: Nothing of the compile before this one is in use (see `Scratch`), and its graph is gone.+ zone.reset();+ let mut graph = builder::build_graph_with_feedback(snapshot, has_run, zone)?;let executable = &snapshot.executables[0];let pass_dumps = if snapshot.options.dump_passes {Some(passes::optimize_with_dumps(&mut graph,&executable.layout,snapshot.options.verify_ir,- &mut scratch.dominators,+ &mut tables.dominators,)?)} else {passes::optimize(&mut graph,&executable.layout,snapshot.options.verify_ir,- &mut scratch.dominators,+ &mut tables.dominators,)?;None};@@ -134,18 +158,18 @@ fn compile_into<M: asm::PortableMacroAssembler>(if snapshot.options.stress.few_registers {registers.allocatable_gprs = registers.few_registers(STRESS_EXTRA_REGISTERS);}- regalloc::allocate(&graph, ®isters, &mut scratch.regalloc, &mut scratch.dominators)?;+ regalloc::allocate(&graph, ®isters, &mut tables.regalloc, &mut tables.dominators)?;if snapshot.options.verify_ir- && let Err(errors) = regalloc::verify(&graph, ®isters, &scratch.regalloc.allocation)+ && let Err(errors) = regalloc::verify(&graph, ®isters, &tables.regalloc.allocation){panic!("invalid register allocation:\n{errors}\n{}",- regalloc::dump_allocation(&graph, &scratch.regalloc.allocation)+ regalloc::dump_allocation(&graph, &tables.regalloc.allocation));}- let mut generated = codegen::generate::<M>(&graph, snapshot, snapshot.options.verify_ir, scratch)?;+ let mut generated = codegen::generate::<M>(&graph, snapshot, snapshot.options.verify_ir, tables)?;generated.osr_entries.sort_unstable();- let layout = scratch.artifact.finish(+ let layout = tables.artifact.finish(&Tail {osr_entries: &generated.osr_entries,osr_loop_back_edges: &graph.osr_loop_back_edges,@@ -164,7 +188,7 @@ fn compile_into<M: asm::PortableMacroAssembler>(let mut text = pass_dumps.unwrap_or_default();if snapshot.options.dump_ir {text.push_str(&ir::dump(&graph, &executable.layout));- text.push_str(®alloc::dump_allocation(&graph, &scratch.regalloc.allocation));+ text.push_str(®alloc::dump_allocation(&graph, &tables.regalloc.allocation));}if snapshot.options.dump_asm {text.push_str(&codegen::dump_code(diff --git a/Libraries/LibJS/JIT/Rust/src/passes/bounds_check_elimination.rs b/Libraries/LibJS/JIT/Rust/src/passes/bounds_check_elimination.rsindex 905b65b8cb6..9cc797bbd82 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/bounds_check_elimination.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/bounds_check_elimination.rs@@ -113,7 +113,7 @@ impl Range {}struct Ranges<'a> {- graph: &'a Graph,+ graph: &'a Graph<'a>,dominators: &'a Dominators,/// The block of each phi.phi_blocks: &'a HashMap<NodeId, BlockId>,@@ -162,7 +162,7 @@ impl Ranges<'_> {}match node.op {Op::Phi if self.is_merge(value) => {- let inputs = node.inputs.clone();+ let inputs = node.inputs.to_vec();let mut range: Option<Range> = None;for input in inputs {let input = self.of(input)?;@@ -684,7 +684,7 @@ pub fn run(graph: &mut Graph, dominators: &mut Dominators) -> Result<(), ColumnFlet (frame_state, pc) = (graph.node(value).frame_state, graph.node(value).pc);let guard = graph.add_node(Node {op: Op::CheckBounds,- inputs: vec![value, count],+ inputs: graph.list(&[value, count]),repr: Some(Repr::Int32),frame_state,pc,@@ -708,12 +708,12 @@ pub fn run(graph: &mut Graph, dominators: &mut Dominators) -> Result<(), ColumnFvalue} else {let offset = constants.get_typed(graph, u64::from((offset as i32).cast_unsigned()), Repr::Int32);- let sum = graph.add_node(Node::new(+ let sum = graph.add(Op::Int32WrappingBinary { op: BinaryOp::Add },- vec![value, offset],+ &[value, offset],Some(Repr::Int32),graph.node(shift).pc,- ));+ );let body = &mut graph.blocks[block.index()].body;let position = body.iter()diff --git a/Libraries/LibJS/JIT/Rust/src/passes/branch_fusion.rs b/Libraries/LibJS/JIT/Rust/src/passes/branch_fusion.rsindex d2da4faa53e..3e2bc9675f3 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/branch_fusion.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/branch_fusion.rs@@ -22,7 +22,6 @@ use crate::ir::BlockId;use crate::ir::BranchCondition;use crate::ir::Comparison;use crate::ir::Graph;-use crate::ir::Node;use crate::ir::NodeId;use crate::ir::Op;@@ -80,7 +79,7 @@ fn thread_boolean_phis(graph: &mut Graph, uses: &[u32]) {continue;};let block_id = BlockId::from_index(block);- let predecessors = data.predecessors.clone();+ let predecessors = data.predecessors.to_vec();let jumps_here = |predecessor: &BlockId| {graph.control(*predecessor).op == Op::Jump { target: block_id } && predecessor.index() < block};@@ -95,7 +94,7 @@ fn thread_boolean_phis(graph: &mut Graph, uses: &[u32]) {continue;}let pc = graph.node(control).pc;- let inputs = graph.node(phi).inputs.clone();+ let inputs = graph.node(phi).inputs.to_vec();for (predecessor, input) in predecessors.into_iter().zip(inputs) {let truth = (graph.node(input).repr == Some(Repr::Bool)).then(|| graph.constant_value(input))@@ -110,11 +109,11 @@ fn thread_boolean_phis(graph: &mut Graph, uses: &[u32]) {let is_cold = graph.block(predecessor).is_cold;let edges = [if_true, if_false].map(|target| {let edge = graph.add_block(Block {- predecessors: vec![predecessor],+ predecessors: graph.list(&[predecessor]),is_cold,- ..Block::default()+ ..graph.new_block()});- let jump = graph.add_node(Node::new(Op::Jump { target }, Vec::new(), None, pc));+ let jump = graph.add(Op::Jump { target }, &[], None, pc);graph.blocks[edge.index()].control = Some(jump);add_predecessor(graph, target, edge, block_id);edge@@ -125,7 +124,7 @@ fn thread_boolean_phis(graph: &mut Graph, uses: &[u32]) {if_true: edges[0],if_false: edges[1],};- data.inputs = vec![input];+ data.inputs.assign(&[input]);new_blocks[predecessor.index()].extend(edges);}// NB: Nothing reaches the block anymore.diff --git a/Libraries/LibJS/JIT/Rust/src/passes/branch_splitting.rs b/Libraries/LibJS/JIT/Rust/src/passes/branch_splitting.rsindex 071d569f05b..24d55be3b2a 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/branch_splitting.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/branch_splitting.rs@@ -132,7 +132,7 @@ fn find_split(graph: &Graph, dominators: &Dominators, block: BlockId) -> Option<}}let moved: Vec<NodeId> = if branch_block == block {- data.body.clone()+ data.body.to_vec()} else {data.body.iter().chain(&branch_data.body).copied().collect()};@@ -284,8 +284,8 @@ fn split_one(graph: &mut Graph, dominators: &mut Dominators) -> Result<bool, Colcontinue;};- let block_phis = graph.block(split.block).phis.clone();- let predecessors = graph.block(split.block).predecessors.clone();+ let block_phis = graph.block(split.block).phis.to_vec();+ let predecessors = graph.block(split.block).predecessors.to_vec();let mut renames: [Vec<(NodeId, NodeId)>; 2] = std::array::from_fn(|side| {let predecessor = split.sides[side].0;let index = predecessors@@ -318,8 +318,8 @@ fn split_one(graph: &mut Graph, dominators: &mut Dominators) -> Result<bool, Colcopies.push(copy);}let body = &mut graph.blocks[target.index()].body;- copies.append(body);- *body = copies;+ copies.extend_from_slice(body);+ body.assign(&copies);}let rename = |side: usize, value: NodeId| renamed(&renames[side], value);@@ -357,7 +357,7 @@ fn split_one(graph: &mut Graph, dominators: &mut Dominators) -> Result<bool, Colfor side in 0..2 {let (predecessor, target) = split.sides[side];graph.replace_successor(predecessor, split.block, target);- graph.blocks[target.index()].predecessors = vec![predecessor];+ graph.blocks[target.index()].predecessors.assign(&[predecessor]);}graph.blocks[split.block.index()].predecessors.clear();for phi in block_phis {diff --git a/Libraries/LibJS/JIT/Rust/src/passes/check_elimination.rs b/Libraries/LibJS/JIT/Rust/src/passes/check_elimination.rsindex ab8a53792c5..d2cc1a63537 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/check_elimination.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/check_elimination.rs@@ -62,13 +62,24 @@ struct Decisions {replacements: Replacements,removed: BitSet,/// Control nodes to replace, with what.- controls: Vec<(NodeId, Op)>,+ controls: Vec<(NodeId, NewControl)>,/// Shape checks that become `AssumeValid` nodes.assumptions: Vec<NodeId>,/// The stable shapes the code relies on staying stable.stable_shapes: Vec<CellId>,}+/// What a control node is replaced with.+enum NewControl {+ Jump {+ target: BlockId,+ },+ /// A shape switch with fewer cases, each a shape and its target.+ ShapeSwitch {+ cases: Vec<(ShapeCheck, BlockId)>,+ },+}+impl Decisions {/// The value the analysis knows `value` as: what it is replaced by, and/// the value it refines (facts are about values, whatever refines them).@@ -156,10 +167,16 @@ pub fn run(graph: &mut Graph) {graph.depend_on(Dependency::StableShape(shape));}let changed_control_flow = !decisions.controls.is_empty();- for (node, op) in decisions.controls {- match op {- Op::Jump { target } => edit::make_jump(graph, node, target),- op => graph.nodes[node.index()].op = op,+ for (node, control) in decisions.controls {+ match control {+ NewControl::Jump { target } => edit::make_jump(graph, node, target),+ NewControl::ShapeSwitch { cases } => {+ let zone = graph.zone;+ graph.nodes[node.index()].op = Op::ShapeSwitch {+ shapes: zone.alloc_slice_from_iter(cases.iter().map(|(shape, _)| *shape)),+ targets: zone.alloc_slice_from_iter(cases.iter().map(|(_, target)| *target)),+ };+ }}}if changed_control_flow {@@ -271,7 +288,7 @@ fn visit_block(let value = decisions.value(graph, graph.node(control).inputs[0]);if let Some(holds) = facts.decides(graph, value, condition) {let target = if holds { if_true } else { if_false };- decisions.controls.push((control, Op::Jump { target }));+ decisions.controls.push((control, NewControl::Jump { target }));return vec![(target, facts)];}let mut passed = facts.clone();@@ -301,13 +318,13 @@ fn visit_block(&& facts.value_kind(inputs[0]).is_some(){let target = if equal { if_false } else { if_true };- decisions.controls.push((control, Op::Jump { target }));+ decisions.controls.push((control, NewControl::Jump { target }));return vec![(target, facts)];}if let Some(key) = BranchKey::of(graph, condition, &inputs) {if let Some(holds) = facts.branch_outcome(&key) {let target = if holds { if_true } else { if_false };- decisions.controls.push((control, Op::Jump { target }));+ decisions.controls.push((control, NewControl::Jump { target }));return vec![(target, facts)];}let mut passed = facts.clone();@@ -328,7 +345,7 @@ fn visit_block(return vec![(if_true, passed), (if_false, facts)];}}- let Op::ShapeSwitch { cases } = graph.node(control).op.clone() else {+ let Op::ShapeSwitch { shapes, targets } = graph.node(control).op else {let successors = graph.successors(block);let Some((last, others)) = successors.split_last() else {return Vec::new();@@ -346,20 +363,21 @@ fn visit_block(.shapes(object).filter(|_| !facts.is_unvalidated(object)).map(<[ShapeCheck]>::to_vec);- let possible = cases+ let possible = shapes.iter()- .filter(|(shape, _)| known.as_ref().is_none_or(|known| known.contains(shape))).copied()+ .zip(targets.iter().copied())+ .filter(|(shape, _)| known.as_ref().is_none_or(|known| known.contains(shape))).collect::<Vec<_>>();let covers_known = known.as_ref().is_some_and(|known| known.iter().all(|shape| possible.iter().any(|(case, _)| case == shape)));match possible.as_slice() {- [(_, target)] if covers_known => decisions.controls.push((control, Op::Jump { target: *target })),- _ if possible.len() < cases.len() && !possible.is_empty() => {+ [(_, target)] if covers_known => decisions.controls.push((control, NewControl::Jump { target: *target })),+ _ if possible.len() < shapes.len() && !possible.is_empty() => {decisions.controls.push((control,- Op::ShapeSwitch {+ NewControl::ShapeSwitch {cases: possible.clone(),},));@@ -435,7 +453,7 @@ fn visit_node(remove = removable && (is_object_constant || facts.is_object(value));facts.set_object(value);}- Op::CheckShape { ref shapes } => {+ Op::CheckShape { shapes } => {let object = input(0);remove = removable&& factsdiff --git a/Libraries/LibJS/JIT/Rust/src/passes/dce.rs b/Libraries/LibJS/JIT/Rust/src/passes/dce.rsindex 2a28fa7c873..8c49883b086 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/dce.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/dce.rs@@ -89,20 +89,20 @@ mod tests {fn unused_cycles_of_pure_values_are_removed() {let mut graph = Graph::default();graph.add_block(Block::default());- let constant = graph.add_node(crate::ir::Node::new(Op::Constant(1), vec![], Some(Repr::Int32), 0));- let phi = graph.add_node(crate::ir::Node::new(Op::Phi, vec![], Some(Repr::Int32), 0));- let add = graph.add_node(crate::ir::Node::new(+ let constant = graph.add(Op::Constant(1), &[], Some(Repr::Int32), 0);+ let phi = graph.add(Op::Phi, &[], Some(Repr::Int32), 0);+ let add = graph.add(Op::Int32Binary {op: BinaryOp::BitwiseOr,},- vec![phi, constant],+ &[phi, constant],Some(Repr::Int32),0,- ));- graph.nodes[phi.index()].inputs = vec![phi, add];+ );+ graph.nodes[phi.index()].inputs.assign(&[phi, add]);graph.blocks[0].phis.push(phi);graph.blocks[0].body.push(add);- let returned = graph.add_node(crate::ir::Node::new(Op::Return, vec![constant], None, 0));+ let returned = graph.add(Op::Return, &[constant], None, 0);graph.blocks[0].control = Some(returned);remove_dead_nodes(&mut graph);assert!(graph.blocks[0].phis.is_empty());@@ -114,44 +114,34 @@ mod tests {fn shared_frame_states_keep_nested_virtual_object_properties_alive() {let mut graph = Graph::default();graph.add_block(Block::default());- let constant = graph.add_node(crate::ir::Node::new(Op::Constant(1), vec![], Some(Repr::Int32), 0));- let boxed = graph.add_node(crate::ir::Node::new(- Op::BoxInt32,- vec![constant],- Some(Repr::Tagged),- 0,- ));- let object = graph.add_node(crate::ir::Node::new(+ let constant = graph.add(Op::Constant(1), &[], Some(Repr::Int32), 0);+ let boxed = graph.add(Op::BoxInt32, &[constant], Some(Repr::Tagged), 0);+ let object = graph.add(Op::VirtualObject {kind: crate::ir::VirtualObjectKind::Object { shape: CellId(1) },allocation: NodeId(0),},- vec![boxed],+ &[boxed],Some(Repr::Tagged),0,- ));+ );let frame = graph.add_frame_state(FrameState {executable: 0,pc: 0,mode: ResumeMode::ResumeAt,- values: vec![(0, object)],- in_frame: vec![],+ values: ak::ZoneVec::from_slice_in(&[(0, object)], crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,});graph.blocks[0].body.push(boxed);for _ in 0..2 {- let check = graph.add_node(crate::ir::Node::new(- Op::CheckObject,- vec![boxed],- Some(Repr::Tagged),- 0,- ));+ let check = graph.add(Op::CheckObject, &[boxed], Some(Repr::Tagged), 0);graph.nodes[check.index()].frame_state = Some(frame);graph.blocks[0].body.push(check);}- let returned = graph.add_node(crate::ir::Node::new(Op::Return, vec![constant], None, 0));+ let returned = graph.add(Op::Return, &[constant], None, 0);graph.blocks[0].control = Some(returned);remove_dead_nodes(&mut graph);assert!(graph.blocks[0].body.contains(&boxed));diff --git a/Libraries/LibJS/JIT/Rust/src/passes/dominators.rs b/Libraries/LibJS/JIT/Rust/src/passes/dominators.rsindex 05fb5023b9b..d2baaeb5392 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/dominators.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/dominators.rs@@ -292,7 +292,7 @@ fn intersect(#[cfg(test)]mod tests {use super::*;- use crate::ir::{Block, BranchCondition, Node, Op};+ use crate::ir::{Block, BranchCondition, Op};#[test]fn cyclic_graphs_with_multiple_entries_match_dominator_sets() {@@ -311,16 +311,16 @@ mod tests {BlockId::from_index(2 + (random >> 32) as usize % (count - 2))};let (a, b) = (target(), target());- let control = graph.add_node(Node::new(+ let control = graph.add(Op::Branch {condition: BranchCondition::Bool,if_true: a,if_false: b,},- vec![],+ &[],None,0,- ));+ );graph.blocks[block].control = Some(control);for successor in [a, b] {graph.blocks[successor.index()]diff --git a/Libraries/LibJS/JIT/Rust/src/passes/edit.rs b/Libraries/LibJS/JIT/Rust/src/passes/edit.rsindex b55b47c4436..ef537e15789 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/edit.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/edit.rs@@ -15,10 +15,8 @@ use crate::ir::BlockId;use crate::ir::FrameState;use crate::ir::FrameStateId;use crate::ir::Graph;-use crate::ir::Node;use crate::ir::NodeId;use crate::ir::Op;-use crate::ir::Successors;/// Values to replace by other values, as a pass decides them.pub struct Replacements {@@ -155,7 +153,7 @@ impl Constants {*self.nodes.entry((bits, repr))- .or_insert_with(|| graph.add_node(Node::new(Op::Constant(bits), Vec::new(), Some(repr), 0)))+ .or_insert_with(|| graph.add(Op::Constant(bits), &[], Some(repr), 0))}}@@ -198,7 +196,7 @@ pub fn clean_up_control_flow(graph: &mut Graph) {// Keep the predecessor entries (and their phi inputs) of reachable// blocks that still branch here, as many times as they do.let mut remaining_edges = (0..block_count)- .map(|block| graph.successors(BlockId::from_index(block)))+ .map(|block| graph.successors(BlockId::from_index(block)).to_vec()).collect::<Vec<_>>();for block in 0..block_count {if !reachable[block] {@@ -215,15 +213,7 @@ pub fn clean_up_control_flow(graph: &mut Graph) {let Some(index) = successors.iter().position(|successor| successor.index() == block) else {return false;};- match successors {- Successors::Inline { blocks, count } => {- *count -= 1;- blocks[index] = blocks[usize::from(*count)];- }- Successors::Cases(blocks) => {- blocks.swap_remove(index);- }- }+ successors.swap_remove(index);true}).collect::<InlineVec<bool, 4>>();@@ -322,7 +312,17 @@ pub fn fold_branches_to_one_target(graph: &mut Graph) -> bool {/// start of the bytecode block `block` with the values flowing into it from/// there, if `block` has a start frame state (see/// `Block::start_frame_state`).-pub fn frame_state_entering(graph: &Graph, block: BlockId, predecessor: BlockId) -> Option<FrameState> {+pub fn frame_state_entering<'z>(graph: &Graph<'z>, block: BlockId, predecessor: BlockId) -> Option<FrameState<'z>> {+ let (template, values) = values_entering(graph, block, predecessor)?;+ Some(frame_state_with_values(graph, template, &values))+}++/// The values of a frame state, with the frame state it is made from (see `values_entering()`).+pub type EnteringValues = (FrameStateId, Vec<(u32, NodeId)>);++/// The values of the frame state of `frame_state_entering()`, with the start frame state of `block` that it is made+/// from.+pub fn values_entering(graph: &Graph, block: BlockId, predecessor: BlockId) -> Option<EnteringValues> {let data = graph.block(block);let template = data.start_frame_state?;let entry_index = data@@ -331,8 +331,8 @@ pub fn frame_state_entering(graph: &Graph, block: BlockId, predecessor: BlockId).position(|block| *block == predecessor).expect("the predecessor enters the block");let phis = &data.phis;- let mut state: FrameState = graph.frame_state(template).clone();- for (_, value) in &mut state.values {+ let mut values = graph.frame_state(template).values.to_vec();+ for (_, value) in &mut values {if phis.contains(value) {*value = graph.node(*value).inputs[entry_index];} else if data.body.contains(value) {@@ -340,7 +340,26 @@ pub fn frame_state_entering(graph: &Graph, block: BlockId, predecessor: BlockId)return None;}}- Some(state)+ Some((template, values))+}++/// The frame state `template` with `values` in place of its values.+pub fn frame_state_with_values<'z>(+ graph: &Graph<'z>,+ template: FrameStateId,+ values: &[(u32, NodeId)],+) -> FrameState<'z> {+ let template = graph.frame_state(template);+ FrameState {+ executable: template.executable,+ pc: template.pc,+ mode: template.mode,+ values: graph.list(values),+ in_frame: template.in_frame.clone(),+ parent: template.parent,+ passed_argument_count: template.passed_argument_count,+ legacy_arguments: template.legacy_arguments.clone(),+ }}/// Moves the cold blocks after all other blocks, keeping the order of@@ -419,16 +438,15 @@ pub fn remove_unused_frame_states(graph: &mut Graph) {}}let remap = |id: FrameStateId| new_index[id.index()].expect("used frame states only refer to used ones");- let old = std::mem::take(&mut graph.frame_states);- graph.frame_states = old- .into_iter()- .zip(&used)- .filter(|(_, used)| **used)- .map(|(mut frame_state, _)| {+ let mut index = 0;+ graph.frame_states.retain_mut(|frame_state| {+ let used = used[index];+ index += 1;+ if used {frame_state.parent = frame_state.parent.map(remap);- frame_state- })- .collect();+ }+ used+ });for block in &graph.blocks {for node in block.nodes() {let node = &mut graph.nodes[node.index()];@@ -445,7 +463,7 @@ mod tests {fn replacements_allocate_lazily_and_follow_updated_chains() {let mut graph = Graph::default();for _ in 0..4 {- graph.add_node(Node::new(Op::Constant(0), vec![], Some(Repr::Tagged), 0));+ graph.add(Op::Constant(0), &[], Some(Repr::Tagged), 0);}let mut replacements = Replacements::new(&graph);assert_eq!(replacements.map.capacity(), 0);@@ -456,7 +474,7 @@ mod tests {assert_eq!(replacements.resolve(NodeId(0)), NodeId(2));replacements.replace(NodeId(1), NodeId(3));assert_eq!(replacements.resolve(NodeId(0)), NodeId(3));- let added = graph.add_node(Node::new(Op::Constant(0), vec![], Some(Repr::Tagged), 0));+ let added = graph.add(Op::Constant(0), &[], Some(Repr::Tagged), 0);replacements.replace(added, NodeId(0));assert_eq!(replacements.resolve(added), NodeId(3));assert!(!replacements.is_empty());diff --git a/Libraries/LibJS/JIT/Rust/src/passes/escape_analysis.rs b/Libraries/LibJS/JIT/Rust/src/passes/escape_analysis.rsindex a98efcc9300..1f703b75cbb 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/escape_analysis.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/escape_analysis.rs@@ -58,7 +58,6 @@ use crate::ir::BlockId;use crate::ir::FrameState;use crate::ir::FrameStateId;use crate::ir::Graph;-use crate::ir::Node;use crate::ir::NodeId;use crate::ir::Op;use crate::ir::VirtualObjectKind;@@ -430,7 +429,7 @@ fn resolve_legacy_arguments_guards(graph: &mut Graph) {placed.insert(node.index());}let mut removed = BitSet::new(graph.nodes.len());- for (guard, nodes) in std::mem::take(&mut graph.legacy_arguments_guards) {+ for (guard, nodes) in graph.legacy_arguments_guards.take() {let needed = nodes.iter().any(|node| placed.contains(node.index()) && graph.defers_legacy_argument_objects(*node));@@ -477,7 +476,7 @@ fn replace_objects(graph: &mut Graph, analysis: &Analysis) -> Result<(), Vec<Nodfor block_index in 0..block_count {let block = BlockId::from_index(block_index);- let predecessors = graph.block(block).predecessors.clone();+ let predecessors = graph.block(block).predecessors.to_vec();let forward = predecessors.iter().filter(|predecessor| predecessor.index() < block_index)@@ -521,7 +520,7 @@ fn replace_objects(graph: &mut Graph, analysis: &Analysis) -> Result<(), Vec<Nod.filter(|value| is_replaced(*value)).filter_map(|value| analysis.root(value)),);- let phi = graph.add_node(Node::new(Op::Phi, values, Some(Repr::Tagged), 0));+ let phi = graph.add(Op::Phi, &values, Some(Repr::Tagged), 0);graph.blocks[block_index].phis.push(phi);if has_back_edges {pending_phis.push((phi, block, key));@@ -538,8 +537,10 @@ fn replace_objects(graph: &mut Graph, analysis: &Analysis) -> Result<(), Vec<Nod.copied().collect::<Vec<_>>();for node in nodes {- let data = graph.node(node).clone();- if let Some(frame_state) = data.frame_state {+ let data = graph.node(node);+ let (node_op, node_inputs, node_repr, node_frame_state) =+ (data.op.clone(), data.inputs.to_vec(), data.repr, data.frame_state);+ if let Some(frame_state) = node_frame_state {let new_frame_state = virtualize_frame_state(graph,analysis,@@ -548,10 +549,10 @@ fn replace_objects(graph: &mut Graph, analysis: &Analysis) -> Result<(), Vec<Nod(&properties, &shapes),frame_state,);- graph.nodes[node.index()].frame_state = new_frame_state.or(data.frame_state);+ graph.nodes[node.index()].frame_state = new_frame_state.or(node_frame_state);}- let object = data.inputs.first().copied().filter(|object| is_replaced(*object));- match data.op {+ let object = node_inputs.first().copied().filter(|object| is_replaced(*object));+ match node_op {Op::AllocateObject {shape, property_count, ..} if is_replaced(node) => {@@ -573,7 +574,7 @@ fn replace_objects(graph: &mut Graph, analysis: &Analysis) -> Result<(), Vec<Nodlet root = analysis.root(object.expect("checked")).expect("replaced objects have roots");- properties.insert((root, offset), replacements.resolve(data.inputs[1]));+ properties.insert((root, offset), replacements.resolve(node_inputs[1]));shapes.insert(root, (shape, property_count));removed.insert(node.index());}@@ -581,7 +582,7 @@ fn replace_objects(graph: &mut Graph, analysis: &Analysis) -> Result<(), Vec<Nodlet root = analysis.root(object.expect("checked")).expect("replaced objects have roots");- properties.insert((root, offset), replacements.resolve(data.inputs[1]));+ properties.insert((root, offset), replacements.resolve(node_inputs[1]));removed.insert(node.index());}Op::LoadNamed { offset, .. } if object.is_some() => {@@ -596,8 +597,8 @@ fn replace_objects(graph: &mut Graph, analysis: &Analysis) -> Result<(), Vec<Nodif object.is_some() =>{// NB: What a removed check refined is the object itself.- if data.op.refined_input().is_some() && data.repr.is_some() {- replacements.replace(node, data.inputs[0]);+ if node_op.refined_input().is_some() && node_repr.is_some() {+ replacements.replace(node, node_inputs[0]);}removed.insert(node.index());}@@ -609,7 +610,7 @@ fn replace_objects(graph: &mut Graph, analysis: &Analysis) -> Result<(), Vec<Nod}for (phi, block, key) in pending_phis {- let predecessors = graph.block(block).predecessors.clone();+ let predecessors = graph.block(block).predecessors.to_vec();for (index, predecessor) in predecessors.iter().enumerate() {if predecessor.index() < block.index() {continue;@@ -678,12 +679,12 @@ fn virtualize_frame_state(} else {VirtualObjectKind::Object { shape }};- let object = graph.add_node(Node::new(+ let object = graph.add(Op::VirtualObject { kind, allocation: root },- Vec::new(),+ &[],Some(Repr::Tagged),graph.node(root).pc,- ));+ );objects.insert(root, object);object};@@ -712,8 +713,8 @@ fn virtualize_frame_state(.inputs.iter().map(|input| replacements.resolve(*input))- .collect();- graph.nodes[object.index()].inputs = inputs;+ .collect::<Vec<_>>();+ graph.nodes[object.index()].inputs.assign(&inputs);continue;}let (_, property_count) = shapes[&root];@@ -726,7 +727,7 @@ fn virtualize_frame_state(virtual_object(graph, &mut objects, property)}).collect::<Vec<_>>();- graph.nodes[object.index()].inputs = inputs;+ graph.nodes[object.index()].inputs.assign(&inputs);}parent}diff --git a/Libraries/LibJS/JIT/Rust/src/passes/facts.rs b/Libraries/LibJS/JIT/Rust/src/passes/facts.rsindex 7096f501156..6aa5379a3dd 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/facts.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/facts.rs@@ -932,7 +932,7 @@ mod tests {] {graph.add_node(crate::ir::Node {op: crate::ir::Op::LoadSlot { slot: 0 },- inputs: Vec::new(),+ inputs: ak::ZoneVec::new_in(crate::test_zone()),repr: Some(repr),frame_state: None,pc: 0,diff --git a/Libraries/LibJS/JIT/Rust/src/passes/frame_initialization.rs b/Libraries/LibJS/JIT/Rust/src/passes/frame_initialization.rsindex aa9a920d63a..8e1e1d4ef12 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/frame_initialization.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/frame_initialization.rs@@ -74,7 +74,7 @@ impl State {/// The node to put before a node with `need`, if any, and the state/// after both.- fn satisfy(self, need: &Need) -> (Option<Op>, State) {+ fn satisfy(self, need: &Need) -> (Option<Op<'static>>, State) {const INITIALIZED: State = State {published: Holds::Yes,initialized: Holds::Yes,@@ -234,8 +234,8 @@ pub fn run(graph: &mut Graph, layout: &FrameLayout) {// Insert from the back so earlier indices stay valid.insertions.sort_by_key(|(block, index, _)| (*block, *index));for (block, index, op) in insertions.into_iter().rev() {- let node = graph.add_node(Node::new(op, Vec::new(), None, entry_pc));+ let node = graph.add(op, &[], None, entry_pc);graph.blocks[block].body.insert(index, node);}- graph.slow_paths_initializing_frame = slow_paths;+ graph.slow_paths_initializing_frame.assign(&slow_paths);}diff --git a/Libraries/LibJS/JIT/Rust/src/passes/gvn.rs b/Libraries/LibJS/JIT/Rust/src/passes/gvn.rsindex ea569f39515..050bdefd8b5 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/gvn.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/gvn.rs@@ -159,14 +159,16 @@ mod tests {fn hash_collisions_do_not_make_different_nodes_equivalent() {let mut graph = Graph::default();graph.add_block(Block::default());- let a = graph.add_node(Node::new(Op::Constant(1), vec![], Some(Repr::Int32), 0));- let b = graph.add_node(Node::new(Op::Constant(2), vec![], Some(Repr::Int32), 0));- let first = graph.add_node(Node::new(Op::BoxInt32, vec![a], Some(Repr::Tagged), 0));- let different_input = graph.add_node(Node::new(Op::BoxInt32, vec![b], Some(Repr::Tagged), 0));- let different_operation = graph.add_node(Node::new(Op::Int32ToFloat64, vec![a], Some(Repr::Float64), 0));- let duplicate = graph.add_node(Node::new(Op::BoxInt32, vec![a], Some(Repr::Tagged), 0));- let returned = graph.add_node(Node::new(Op::Return, vec![duplicate], None, 0));- graph.blocks[0].body = vec![first, different_input, different_operation, duplicate];+ let a = graph.add(Op::Constant(1), &[], Some(Repr::Int32), 0);+ let b = graph.add(Op::Constant(2), &[], Some(Repr::Int32), 0);+ let first = graph.add(Op::BoxInt32, &[a], Some(Repr::Tagged), 0);+ let different_input = graph.add(Op::BoxInt32, &[b], Some(Repr::Tagged), 0);+ let different_operation = graph.add(Op::Int32ToFloat64, &[a], Some(Repr::Float64), 0);+ let duplicate = graph.add(Op::BoxInt32, &[a], Some(Repr::Tagged), 0);+ let returned = graph.add(Op::Return, &[duplicate], None, 0);+ graph.blocks[0]+ .body+ .assign(&[first, different_input, different_operation, duplicate]);graph.blocks[0].control = Some(returned);run_with_hash(&mut graph, &mut Dominators::new(), |_, _| 0).unwrap();assert_eq!(graph.blocks[0].body, [first, different_input, different_operation]);diff --git a/Libraries/LibJS/JIT/Rust/src/passes/licm.rs b/Libraries/LibJS/JIT/Rust/src/passes/licm.rsindex 6386150aab6..f2fdacfb4c3 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/licm.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/licm.rs@@ -36,7 +36,6 @@ use crate::ir::BlockId;use crate::ir::FrameStateId;use crate::ir::Graph;use crate::ir::Locations;-use crate::ir::Node;use crate::ir::Op;struct Loop {@@ -56,7 +55,7 @@ fn add_preheaders(graph: &mut Graph, dominators: &Dominators) -> bool {let count = graph.blocks.len();let mut order = Vec::new();for header in (0..count).map(BlockId::from_index) {- let predecessors = graph.block(header).predecessors.clone();+ let predecessors = graph.block(header).predecessors.to_vec();let (back_edge_sources, entries): (Vec<BlockId>, Vec<BlockId>) = predecessors.iter().partition(|predecessor| dominators.dominates(header, **predecessor));@@ -72,13 +71,14 @@ fn add_preheaders(graph: &mut Graph, dominators: &Dominators) -> bool {continue;}let preheader = graph.add_block(Block {- predecessors: entries.clone(),- ..Block::default()+ predecessors: graph.list(&entries),+ ..graph.new_block()});for entry in &entries {graph.replace_successor(*entry, header, preheader);}- for phi in graph.block(header).phis.clone() {+ let phis = graph.block(header).phis.to_vec();+ for phi in phis {let (back_inputs, entry_inputs): (Vec<_>, Vec<_>) = predecessors.iter().copied()@@ -88,28 +88,21 @@ fn add_preheaders(graph: &mut Graph, dominators: &Dominators) -> bool {let entering = if entry_inputs.iter().all(|input| *input == entry_inputs[0]) {entry_inputs[0]} else {- let merged = graph.add_node(Node::new(- Op::Phi,- entry_inputs,- graph.node(phi).repr,- graph.node(phi).pc,- ));+ let merged = graph.add(Op::Phi, &entry_inputs, graph.node(phi).repr, graph.node(phi).pc);graph.blocks[preheader.index()].phis.push(merged);merged};- let inputs = std::iter::once(entering)- .chain(back_inputs.into_iter().map(|(_, input)| input))- .collect();- graph.nodes[phi.index()].inputs = inputs;+ let inputs = &mut graph.nodes[phi.index()].inputs;+ inputs.clear();+ inputs.push(entering);+ inputs.extend(back_inputs.into_iter().map(|(_, input)| input));}- let jump = graph.add_node(Node::new(- Op::Jump { target: header },- Vec::new(),- None,- graph.control(header).pc,- ));+ let jump = graph.add(Op::Jump { target: header }, &[], None, graph.control(header).pc);graph.blocks[preheader.index()].control = Some(jump);- graph.blocks[header.index()].predecessors = std::iter::once(preheader).chain(back_edge_sources).collect();+ let header_predecessors = &mut graph.blocks[header.index()].predecessors;+ header_predecessors.clear();+ header_predecessors.push(preheader);+ header_predecessors.extend(back_edge_sources);order.push(preheader);order.push(header);}@@ -205,7 +198,8 @@ pub fn run(graph: &mut Graph, dominators: &mut Dominators) -> Result<(), ColumnFlet block_id = BlockId::from_index(block);let runs_every_iteration = dominators.runs_every_iteration(block_id, &loop_.back_edge_sources);let is_cold = graph.block(block_id).is_cold;- for node in graph.block(block_id).body.clone() {+ let body = graph.block(block_id).body.to_vec();+ for node in body {let data = graph.node(node);let mut properties = data.op.properties();// OPTIMIZATION: Nothing writes these slots, so their loads leave even loops that call, like thediff --git a/Libraries/LibJS/JIT/Rust/src/passes/loop_rotation.rs b/Libraries/LibJS/JIT/Rust/src/passes/loop_rotation.rsindex 11bde10bb60..4c3570fa3c1 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/loop_rotation.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/loop_rotation.rs@@ -19,6 +19,7 @@//! edges bring its values to those phis.use ak::ColumnFull;+use ak::ZoneVec;use super::dominators::Dominators;use super::edit;@@ -27,7 +28,6 @@ use crate::ir::Block;use crate::ir::BlockId;use crate::ir::FrameStateId;use crate::ir::Graph;-use crate::ir::Node;use crate::ir::NodeId;use crate::ir::Op;@@ -159,13 +159,14 @@ fn rotate(graph: &mut Graph, test: BlockId, region: &BitSet, sources: &[BlockId]bytecode_start: data.bytecode_start,is_cold: data.is_cold,start_frame_state: data.start_frame_state,- ..Block::default()+ ..graph.new_block()});block_copy[block.index()] = Some(copy);}let copied = |block: BlockId, block_copy: &[Option<BlockId>]| block_copy[block.index()].expect("in the region");let test_copy = copied(test, &block_copy);- for phi in graph.block(test).phis.clone() {+ let phis = graph.block(test).phis.to_vec();+ for phi in phis {let inputs = graph.node(phi).inputs@@ -178,7 +179,7 @@ fn rotate(graph: &mut Graph, test: BlockId, region: &BitSet, sources: &[BlockId]inputs[0]} else {let data = graph.node(phi);- let copy = graph.add_node(Node::new(Op::Phi, inputs, data.repr, data.pc));+ let copy = graph.add(Op::Phi, &inputs, data.repr, data.pc);graph.blocks[test_copy.index()].phis.push(copy);copy});@@ -186,12 +187,15 @@ fn rotate(graph: &mut Graph, test: BlockId, region: &BitSet, sources: &[BlockId]let mut copies = Vec::new();for &block in &blocks {let copy = copied(block, &block_copy);- let data = graph.block(block).clone();- let phis = if block == test { Vec::new() } else { data.phis.clone() };+ let data = graph.block(block);+ let phis = if block == test { Vec::new() } else { data.phis.to_vec() };+ let body = data.body.to_vec();+ let control = data.control;+ let predecessors = data.predecessors.to_vec();for (node, is_phi) in phis.iter().map(|node| (*node, true))- .chain(data.body.iter().chain(&data.control).map(|node| (*node, false)))+ .chain(body.iter().chain(&control).map(|node| (*node, false))){let new = graph.add_node(graph.node(node).clone());node_copy.resize(graph.nodes.len(), None);@@ -200,18 +204,16 @@ fn rotate(graph: &mut Graph, test: BlockId, region: &BitSet, sources: &[BlockId]let copy_data = &mut graph.blocks[copy.index()];if is_phi {copy_data.phis.push(new);- } else if Some(node) == data.control {+ } else if Some(node) == control {copy_data.control = Some(new);} else {copy_data.body.push(new);}}if block != test {- graph.blocks[copy.index()].predecessors = data- .predecessors- .iter()- .map(|predecessor| copied(*predecessor, &block_copy))- .collect();+ let copy_predecessors = &mut graph.blocks[copy.index()].predecessors;+ copy_predecessors.clear();+ copy_predecessors.extend(predecessors.iter().map(|predecessor| copied(*predecessor, &block_copy)));}}let map =@@ -228,16 +230,22 @@ fn rotate(graph: &mut Graph, test: BlockId, region: &BitSet, sources: &[BlockId]copied_parent = Some(copy);continue;}- let mut state = graph.frame_state(*id).clone();- for (_, value) in &mut state.values {- *value = map(*value, &node_copy);- }- if copied_parent.is_some() {- state.parent = copied_parent;- }- let copy = if state == *graph.frame_state(*id) {+ let original = graph.frame_state(*id);+ let values = original+ .values+ .iter()+ .map(|(slot, value)| (*slot, map(*value, &node_copy)))+ .collect::<Vec<_>>();+ let parent = if copied_parent.is_some() {+ copied_parent+ } else {+ original.parent+ };+ let copy = if original.values == values && original.parent == parent {*id} else {+ let mut state = edit::frame_state_with_values(graph, *id, &values);+ state.parent = parent;graph.add_frame_state(state)};frame_state_copy[id.index()] = Some(copy);@@ -246,13 +254,9 @@ fn rotate(graph: &mut Graph, test: BlockId, region: &BitSet, sources: &[BlockId]copied_parent.expect("the chain is not empty")};for © in &copies {- let inputs = graph- .node(copy)- .inputs- .iter()- .map(|input| map(*input, &node_copy))- .collect();- graph.nodes[copy.index()].inputs = inputs;+ for input in &mut graph.nodes[copy.index()].inputs {+ *input = map(*input, &node_copy);+ }if let Some(frame_state) = graph.node(copy).frame_state {graph.nodes[copy.index()].frame_state = Some(copy_frame_state(graph, frame_state));}@@ -293,7 +297,8 @@ fn rotate(graph: &mut Graph, test: BlockId, region: &BitSet, sources: &[BlockId].count();let position = positions[already];graph.blocks[successor.index()].predecessors.push(copy);- for phi in graph.block(successor).phis.clone() {+ let phis = graph.block(successor).phis.to_vec();+ for phi in phis {let input = map(graph.node(phi).inputs[position], &node_copy);graph.nodes[phi.index()].inputs.push(input);}@@ -312,25 +317,30 @@ fn rotate(graph: &mut Graph, test: BlockId, region: &BitSet, sources: &[BlockId]graph.blocks[test.index()].is_loop_header = false;// The predecessors that entered the test enter its copy instead, and the test keeps the others.- let predecessors = graph.block(test).predecessors.clone();+ let predecessors = graph.block(test).predecessors.to_vec();for (predecessor, entering) in predecessors.iter().zip(&entering) {if *entering {graph.replace_successor(*predecessor, test, test_copy);}}- graph.blocks[test_copy.index()].predecessors = predecessors+ let test_copy_predecessors = predecessors.iter().zip(&entering).filter(|(_, entering)| **entering).map(|(predecessor, _)| *predecessor)- .collect();- graph.blocks[test.index()].predecessors = predecessors+ .collect::<Vec<_>>();+ graph.blocks[test_copy.index()]+ .predecessors+ .assign(&test_copy_predecessors);+ let test_predecessors = predecessors.iter().zip(&entering).filter(|(_, entering)| !**entering).map(|(predecessor, _)| *predecessor)- .collect();- for phi in graph.block(test).phis.clone() {+ .collect::<Vec<_>>();+ graph.blocks[test.index()].predecessors.assign(&test_predecessors);+ let phis = graph.block(test).phis.to_vec();+ for phi in phis {let inputs = graph.node(phi).inputs@@ -338,16 +348,19 @@ fn rotate(graph: &mut Graph, test: BlockId, region: &BitSet, sources: &[BlockId].zip(&entering).filter(|(_, entering)| !**entering).map(|(input, _)| *input)- .collect();- graph.nodes[phi.index()].inputs = inputs;+ .collect::<Vec<_>>();+ graph.nodes[phi.index()].inputs.assign(&inputs);}- for (guard, nodes) in graph.legacy_arguments_guards.clone() {+ let zone = graph.zone;+ for index in 0..graph.legacy_arguments_guards.len() {+ let (guard, nodes) = &graph.legacy_arguments_guards[index];if let Some(copy) = node_copy.get(guard.index()).copied().flatten() {- let nodes = nodes.iter().map(|node| map(*node, &node_copy)).collect();+ let nodes = ZoneVec::from_iter_in(nodes.iter().map(|node| map(*node, &node_copy)), zone);graph.legacy_arguments_guards.push((copy, nodes));}}- for node in graph.slow_paths_initializing_frame.clone() {+ for index in 0..graph.slow_paths_initializing_frame.len() {+ let node = graph.slow_paths_initializing_frame[index];if let Some(copy) = node_copy.get(node.index()).copied().flatten() {graph.slow_paths_initializing_frame.push(copy);}diff --git a/Libraries/LibJS/JIT/Rust/src/passes/mod.rs b/Libraries/LibJS/JIT/Rust/src/passes/mod.rsindex e909b2bfbec..e267fc7512d 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/mod.rs@@ -213,7 +213,8 @@ fn run_passes(// On-stack replacement entries run once per entry, so they are cold// code too, which keeps the blocks they lead to from starting with// their register state.- for (_, block) in graph.osr_entries.clone() {+ let osr_entries = graph.osr_entries.to_vec();+ for (_, block) in osr_entries {graph.blocks[block.index()].is_cold = true;}edit::move_cold_blocks_last(graph);diff --git a/Libraries/LibJS/JIT/Rust/src/passes/representation.rs b/Libraries/LibJS/JIT/Rust/src/passes/representation.rsindex 3d24b92b5c4..8e9b21d01cd 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/representation.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/representation.rs@@ -26,7 +26,7 @@ use crate::bitset::BitSet;use crate::code::Repr;use crate::fast_hash::HashMap;use crate::ir::BlockId;-use crate::ir::FrameState;+use crate::ir::FrameStateId;use crate::ir::Graph;use crate::ir::Node;use crate::ir::NodeId;@@ -37,11 +37,11 @@ use crate::ir::value;struct Unboxed {repr: Repr,/// Boxes a value of the representation.- box_op: Op,+ box_op: Op<'static>,/// The unboxed bits of a tagged constant of the representation.constant: fn(u64) -> Option<u64>,/// Unboxes a tagged value, if it is of the representation.- check_op: Option<Op>,+ check_op: Option<Op<'static>>,/// Whether a user of a phi benefits from it being unboxed.wants_unboxed: fn(&Op) -> bool,/// Whether int32 values become values of the representation through@@ -171,7 +171,7 @@ fn checkable_inputs(graph: &Graph,unboxed: &Unboxed,checked: &BitSet,-) -> HashMap<NodeId, (BlockId, Vec<Option<FrameState>>)> {+) -> HashMap<NodeId, (BlockId, Vec<Option<edit::EnteringValues>>)> {let mut checkable = HashMap::default();for (index, block) in graph.blocks.iter().enumerate() {let block_id = BlockId::from_index(index);@@ -201,7 +201,7 @@ fn checkable_inputs(checkable.then(|| {entering[entry]- .get_or_insert_with(|| edit::frame_state_entering(graph, block_id, *predecessor))+ .get_or_insert_with(|| edit::values_entering(graph, block_id, *predecessor)).clone()}).flatten()@@ -290,9 +290,8 @@ fn unbox_phis(graph: &mut Graph, unboxed: &Unboxed) {for phi in candidates.iter() {let phi_id = NodeId::from_index(phi);let (block, states) = &checkable[&phi_id];- let inputs = graph.nodes[phi]- .inputs- .clone()+ let phi_inputs = graph.nodes[phi].inputs.to_vec();+ let inputs = phi_inputs.into_iter().enumerate().map(@@ -310,18 +309,18 @@ fn unbox_phis(graph: &mut Graph, unboxed: &Unboxed) {},None => {let predecessor = graph.block(*block).predecessors[index];- let state = states[index]- .clone()+ let (template, values) = states[index]+ .as_ref().expect("candidate phis only have unboxable inputs");*checks.entry((predecessor, input))- .or_insert_with(|| check_at_end(graph, unboxed, predecessor, input, state))+ .or_insert_with(|| check_at_end(graph, unboxed, predecessor, input, *template, values))}},)- .collect();+ .collect::<Vec<_>>();let node = &mut graph.nodes[phi];- node.inputs = inputs;+ node.inputs.assign(&inputs);node.repr = Some(unboxed.repr);}@@ -367,14 +366,16 @@ fn unbox_phis(graph: &mut Graph, unboxed: &Unboxed) {}/// Adds a check that unboxes `value` at the end of `predecessor`, exiting-/// with `state` where it fails.+/// with the frame state `template` with `values` where it fails.fn check_at_end(graph: &mut Graph,unboxed: &Unboxed,predecessor: BlockId,value: NodeId,- state: FrameState,+ template: FrameStateId,+ values: &[(u32, NodeId)],) -> NodeId {+ let state = edit::frame_state_with_values(graph, template, values);let pc = state.pc;let frame_state = Some(graph.add_frame_state(state));let check = graph.add_node(Node {@@ -382,7 +383,7 @@ fn check_at_end(.check_op.clone().expect("only checked representations check inputs"),- inputs: vec![value],+ inputs: graph.list(&[value]),repr: Some(unboxed.repr),frame_state,pc,@@ -409,12 +410,12 @@ fn convert_int32(graph: &mut Graph, integer: NodeId) -> NodeId {.map(|position| (index, position + 1))}).expect("values are in blocks");- let converted = graph.add_node(Node::new(+ let converted = graph.add(Op::Int32ToFloat64,- vec![integer],+ &[integer],Some(Repr::Float64),graph.node(integer).pc,- ));+ );graph.blocks[block].body.insert(position, converted);converted}@@ -426,12 +427,7 @@ fn box_phi(graph: &mut Graph, unboxed: &Unboxed, phi: NodeId) -> NodeId {.iter().position(|block| block.phis.contains(&phi)).expect("phis are in blocks");- let boxed = graph.add_node(Node::new(- unboxed.box_op.clone(),- vec![phi],- Some(Repr::Tagged),- graph.node(phi).pc,- ));+ let boxed = graph.add(unboxed.box_op.clone(), &[phi], Some(Repr::Tagged), graph.node(phi).pc);graph.blocks[block].body.insert(0, boxed);boxed}diff --git a/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs b/Libraries/LibJS/JIT/Rust/src/passes/simplify.rsindex d2be7e52408..e6e8f02af81 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs@@ -26,7 +26,6 @@ use crate::ir::BlockId;use crate::ir::BranchCondition;use crate::ir::Comparison;use crate::ir::Graph;-use crate::ir::Node;use crate::ir::NodeId;use crate::ir::Op;use crate::ir::value;@@ -171,12 +170,7 @@ fn build_int32_term(Int32Term::Binary(op, lhs, rhs) => {let (lhs, position) = build_int32_term(graph, constants, lhs, block, position, pc);let (rhs, position) = build_int32_term(graph, constants, rhs, block, position, pc);- let node = graph.add_node(Node::new(- Op::Int32WrappingBinary { op: *op },- vec![lhs, rhs],- Some(Repr::Int32),- pc,- ));+ let node = graph.add(Op::Int32WrappingBinary { op: *op }, &[lhs, rhs], Some(Repr::Int32), pc);graph.blocks[block.index()].body.insert(position, node);(node, position + 1)}@@ -527,19 +521,13 @@ fn simplify(graph: &mut Graph, dissolve_checks: bool) {let mut operands = Vec::new();for (input, double) in inputs.iter().zip(doubles) {operands.push(double.unwrap_or_else(|| {- let conversion =- graph.add_node(Node::new(Op::Int32ToFloat64, vec![*input], Some(Repr::Float64), pc));+ let conversion = graph.add(Op::Int32ToFloat64, &[*input], Some(Repr::Float64), pc);graph.blocks[block.index()].body.insert(index - 1, conversion);index += 1;conversion}));}- let compare = graph.add_node(Node::new(- Op::Float64Compare { comparison },- operands,- Some(Repr::Bool),- pc,- ));+ let compare = graph.add(Op::Float64Compare { comparison }, &operands, Some(Repr::Bool), pc);graph.blocks[block.index()].body.insert(index - 1, compare);index += 1;Some(compare)@@ -557,7 +545,7 @@ fn simplify(graph: &mut Graph, dissolve_checks: bool) {return Some(double);}let pc = graph.node(node).pc;- let conversion = graph.add_node(Node::new(Op::Int32ToFloat64, vec![integer], Some(Repr::Float64), pc));+ let conversion = graph.add(Op::Int32ToFloat64, &[integer], Some(Repr::Float64), pc);graph.blocks[block.index()].body.insert(index - 1, conversion);index += 1;Some(conversion)@@ -578,7 +566,7 @@ fn simplify(graph: &mut Graph, dissolve_checks: bool) {let double = boxing.inputs[0];let data = &mut graph.nodes[node.index()];data.op = Op::CheckFloat64Int32;- data.inputs = vec![double];+ data.inputs.assign(&[double]);continue;}// NB: Int32 operations take constant right-hand sides as@@ -588,7 +576,7 @@ fn simplify(graph: &mut Graph, dissolve_checks: bool) {&& int32_of(graph, inputs[0]).is_some()&& int32_of(graph, inputs[1]).is_none(){- graph.nodes[node.index()].inputs = vec![inputs[1], inputs[0]];+ graph.nodes[node.index()].inputs.assign(&[inputs[1], inputs[0]]);}}@@ -667,7 +655,7 @@ fn simplify(graph: &mut Graph, dissolve_checks: bool) {if let Some((op, inputs)) = new_op {let data = &mut graph.nodes[control.index()];data.op = op;- data.inputs = inputs;+ data.inputs.assign(&inputs);changed_control_flow = true;}}diff --git a/Libraries/LibJS/JIT/Rust/src/passes/tests.rs b/Libraries/LibJS/JIT/Rust/src/passes/tests.rsindex 941873fe7b3..35e01a0b89c 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/tests.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/tests.rs@@ -15,10 +15,10 @@ use crate::ir::Node;use crate::ir::NodeId;use crate::ir::Op;-fn node(graph: &mut Graph, op: Op, inputs: Vec<NodeId>, repr: Option<Repr>) -> NodeId {+fn node<'z>(graph: &mut Graph<'z>, op: Op<'z>, inputs: Vec<NodeId>, repr: Option<Repr>) -> NodeId {graph.add_node(Node {op,- inputs,+ inputs: graph.list(&inputs),repr,frame_state: None,pc: 0,@@ -27,11 +27,11 @@ fn node(graph: &mut Graph, op: Op, inputs: Vec<NodeId>, repr: Option<Repr>) -> N/// A diamond: b0 branches to b1 and b2, which join in b3 with a phi of the/// values they load.-fn diamond() -> (Graph, NodeId) {+fn diamond() -> (Graph<'static>, NodeId) {let mut graph = Graph::default();for predecessors in [vec![], vec![BlockId(0)], vec![BlockId(0)], vec![BlockId(1), BlockId(2)]] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -88,7 +88,7 @@ fn verifier_rejects_uses_of_values_from_blocks_that_do_not_dominate() {// The return uses b1's load, which b2 does not see.let load = graph.blocks[1].body[0];let ret = graph.blocks[3].control.unwrap();- graph.nodes[ret.index()].inputs = vec![load];+ graph.nodes[ret.index()].inputs.assign(&[load]);let errors = verify(&graph).unwrap_err();assert!(errors.contains("not defined before it"), "{errors}");}@@ -146,7 +146,7 @@ fn verifier_rejects_blocks_no_entry_reaches() {let (mut graph, _) = diamond();// b4 is a loop of its own that nothing enters.let block = graph.add_block(Block {- predecessors: vec![BlockId(4)],+ predecessors: ak::ZoneVec::from_slice_in(&[BlockId(4)], crate::test_zone()),is_loop_header: true,..Block::default()});@@ -174,8 +174,8 @@ fn verifier_rejects_slow_path_outputs_away_from_their_call() {executable: 0,pc: 0,mode: crate::code::ResumeMode::ResumeAt,- values: Vec::new(),- in_frame: Vec::new(),+ values: ak::ZoneVec::new_in(crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,@@ -212,15 +212,15 @@ fn simplification_removes_number_checks_of_numeric_constants() {executable: 0,pc: 0,mode: crate::code::ResumeMode::ResumeAt,- values: Vec::new(),- in_frame: Vec::new(),+ values: ak::ZoneVec::new_in(crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,}));let boxed = node(&mut graph, Op::BoxFloat64, vec![check], Some(Repr::Tagged));let ret = node(&mut graph, Op::Return, vec![boxed], None);- graph.blocks[0].body = vec![check, boxed];+ graph.blocks[0].body.assign(&[check, boxed]);graph.blocks[0].control = Some(ret);verify(&graph).unwrap();@@ -242,7 +242,7 @@ fn simplification_removes_int32_checks_that_number_checks_convert() {let mut graph = Graph::default();for predecessors in [vec![], vec![BlockId(0)], vec![BlockId(0)]] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -250,8 +250,8 @@ fn simplification_removes_int32_checks_that_number_checks_convert() {executable: 0,pc: 0,mode: crate::code::ResumeMode::ResumeAt,- values: Vec::new(),- in_frame: Vec::new(),+ values: ak::ZoneVec::new_in(crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,@@ -271,7 +271,7 @@ fn simplification_removes_int32_checks_that_number_checks_convert() {vec![boxed],None,);- graph.blocks[0].body = vec![boxed_double, check, boxed];+ graph.blocks[0].body.assign(&[boxed_double, check, boxed]);graph.blocks[0].control = Some(branch);// The number check sees the boxing through a refinement, which// simplification does not replace.@@ -288,7 +288,7 @@ fn simplification_removes_int32_checks_that_number_checks_convert() {graph.nodes[number.index()].frame_state = Some(frame_state);let result = node(&mut graph, Op::BoxFloat64, vec![number], Some(Repr::Tagged));let ret = node(&mut graph, Op::Return, vec![result], None);- graph.blocks[1].body = vec![refined, number, result];+ graph.blocks[1].body.assign(&[refined, number, result]);graph.blocks[1].control = Some(ret);let other_ret = node(&mut graph, Op::Return, vec![boxed], None);graph.blocks[2].control = Some(other_ret);@@ -310,7 +310,7 @@ fn element_counts_move_out_of_loops_that_only_store_elements() {let mut graph = Graph::default();for predecessors in [vec![], vec![BlockId(0), BlockId(1)], vec![BlockId(1)]] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -358,7 +358,7 @@ fn loads_of_slots_that_nothing_writes_move_out_of_loops_that_call() {let mut graph = Graph::default();for predecessors in [vec![], vec![BlockId(0), BlockId(1)], vec![BlockId(1)]] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -382,8 +382,8 @@ fn loads_of_slots_that_nothing_writes_move_out_of_loops_that_call() {executable: 0,pc: 0,mode: crate::code::ResumeMode::ResumeAt,- values: Vec::new(),- in_frame: Vec::new(),+ values: ak::ZoneVec::new_in(crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,@@ -469,8 +469,8 @@ fn typed_array_storage_offsets_are_reused_across_stores_but_not_calls() {executable: 0,pc: 0,mode: crate::code::ResumeMode::ResumeAt,- values: Vec::new(),- in_frame: Vec::new(),+ values: ak::ZoneVec::new_in(crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,@@ -503,7 +503,7 @@ fn typed_array_storage_metadata_moves_out_of_loops_that_only_store_elements() {let mut graph = Graph::default();for predecessors in [vec![], vec![BlockId(0), BlockId(1)], vec![BlockId(1)]] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -566,7 +566,7 @@ fn branches_on_known_kinds_fold() {vec![BlockId(1)],] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -612,7 +612,7 @@ fn branches_on_whether_values_of_known_kinds_are_empty_fold() {let mut graph = Graph::default();for predecessors in [vec![], vec![BlockId(0)], vec![BlockId(0)]] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -620,8 +620,8 @@ fn branches_on_whether_values_of_known_kinds_are_empty_fold() {executable: 0,pc: 0,mode: crate::code::ResumeMode::ResumeAt,- values: Vec::new(),- in_frame: Vec::new(),+ values: ak::ZoneVec::new_in(crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,@@ -645,7 +645,7 @@ fn branches_on_whether_values_of_known_kinds_are_empty_fold() {vec![value, empty],None,);- graph.blocks[0].body = vec![value, check];+ graph.blocks[0].body.assign(&[value, check]);graph.blocks[0].control = Some(branch);for block in [1, 2] {let ret = node(&mut graph, Op::Return, vec![value], None);@@ -677,7 +677,7 @@ fn check_elimination_keeps_checks_that_a_later_entry_reaches_blocks_before_it()vec![BlockId(0), BlockId(2)],] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -688,8 +688,8 @@ fn check_elimination_keeps_checks_that_a_later_entry_reaches_blocks_before_it()executable: 0,pc: 0,mode: crate::code::ResumeMode::ResumeAt,- values: Vec::new(),- in_frame: Vec::new(),+ values: ak::ZoneVec::new_in(crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,@@ -730,7 +730,7 @@ fn simplification_removes_integer_double_round_trips() {let integer = node(&mut graph, Op::Float64ToInt32, vec![double], Some(Repr::Int32));let boxed = node(&mut graph, Op::BoxInt32, vec![integer], Some(Repr::Tagged));let ret = node(&mut graph, Op::Return, vec![boxed], None);- graph.blocks[0].body = vec![double, integer, boxed];+ graph.blocks[0].body.assign(&[double, integer, boxed]);graph.blocks[0].control = Some(ret);verify(&graph).unwrap();@@ -752,7 +752,7 @@ fn simplification_tests_the_truthiness_of_boxed_int32_values_unboxed() {graph.add_block(Block::default());for _ in 1..4 {graph.add_block(Block {- predecessors: vec![BlockId(0)],+ predecessors: ak::ZoneVec::from_slice_in(&[BlockId(0)], crate::test_zone()),..Block::default()});}@@ -770,7 +770,7 @@ fn simplification_tests_the_truthiness_of_boxed_int32_values_unboxed() {vec![boxed],None,);- graph.blocks[0].body = vec![array, address, unboxed, boxed];+ graph.blocks[0].body.assign(&[array, address, unboxed, boxed]);graph.blocks[0].control = Some(branch);for block in 1..4 {let ret = node(&mut graph, Op::Return, vec![array], None);@@ -803,7 +803,7 @@ fn simplification_keeps_double_integer_round_trips() {let converted = node(&mut graph, Op::Int32ToFloat64, vec![integer], Some(Repr::Float64));let boxed = node(&mut graph, Op::BoxFloat64, vec![converted], Some(Repr::Tagged));let ret = node(&mut graph, Op::Return, vec![boxed], None);- graph.blocks[0].body = vec![load, double, integer, converted, boxed];+ graph.blocks[0].body.assign(&[load, double, integer, converted, boxed]);graph.blocks[0].control = Some(ret);verify(&graph).unwrap();@@ -837,7 +837,7 @@ fn simplification_converts_constant_doubles_to_integers() {let integer = node(&mut graph, op.clone(), vec![double], Some(Repr::Int32));let boxed = node(&mut graph, Op::BoxInt32, vec![integer], Some(Repr::Tagged));let ret = node(&mut graph, Op::Return, vec![boxed], None);- graph.blocks[0].body = vec![integer, boxed];+ graph.blocks[0].body.assign(&[integer, boxed]);graph.blocks[0].control = Some(ret);verify(&graph).unwrap();@@ -880,8 +880,8 @@ fn constant_bounds_checks_only_fold_when_the_unsigned_index_is_in_bounds() {executable: 0,pc: 0,mode: crate::code::ResumeMode::ResumeAt,- values: Vec::new(),- in_frame: Vec::new(),+ values: ak::ZoneVec::new_in(crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,@@ -933,7 +933,7 @@ fn frame_writes_after_slow_paths_that_may_initialize_the_frame_check_first() {None,);let ret = node(&mut graph, Op::Return, vec![call], None);- graph.blocks[0].body = vec![initialize, call, store];+ graph.blocks[0].body.assign(&[initialize, call, store]);graph.blocks[0].control = Some(ret);super::frame_initialization::run(&mut graph, &layout);@@ -957,7 +957,7 @@ fn hoisted_checks_gate_exits_by_the_loop_headers_executable() {let mut graph = Graph::default();for predecessors in [vec![], vec![BlockId(0), BlockId(1)], vec![BlockId(1)]] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -970,8 +970,8 @@ fn hoisted_checks_gate_exits_by_the_loop_headers_executable() {executable: 0,pc: 10,mode: ResumeMode::ResumeAfter { dst: 5 },- values: vec![(0, object)],- in_frame: vec![],+ values: ak::ZoneVec::from_slice_in(&[(0, object)], crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,@@ -980,8 +980,8 @@ fn hoisted_checks_gate_exits_by_the_loop_headers_executable() {executable: 1,pc: 77,mode: ResumeMode::ResumeAt,- values: vec![(0, object)],- in_frame: vec![],+ values: ak::ZoneVec::from_slice_in(&[(0, object)], crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: Some(parent),passed_argument_count: None,legacy_arguments: 0..0,@@ -1021,7 +1021,7 @@ fn control_flow_cleanup_preserves_duplicate_edges_and_phi_input_order() {let mut graph = Graph::default();graph.add_block(Block::default());graph.add_block(Block {- predecessors: vec![BlockId(0); 3],+ predecessors: ak::ZoneVec::from_elem_in(BlockId(0), 3, crate::test_zone()),..Block::default()});let values = (0..3)@@ -1073,7 +1073,7 @@ fn overflow_checks_removed_by_bounds_checks_check_the_counters_of_their_counts()vec![BlockId(3)],] {graph.add_block(Block {- predecessors,+ predecessors: graph.list(&predecessors),..Block::default()});}@@ -1083,8 +1083,8 @@ fn overflow_checks_removed_by_bounds_checks_check_the_counters_of_their_counts()executable: 0,pc: 7,mode: ResumeMode::ResumeAt,- values: Vec::new(),- in_frame: Vec::new(),+ values: ak::ZoneVec::new_in(crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,@@ -1095,7 +1095,7 @@ fn overflow_checks_removed_by_bounds_checks_check_the_counters_of_their_counts()let int32 = |graph: &mut Graph, value: i32| {node(graph, Op::Constant(u64::from(value as u32)), vec![], Some(Repr::Int32))};- let checked = |graph: &mut Graph, op: Op, inputs: Vec<NodeId>| {+ let checked = |graph: &mut Graph<'static>, op: Op<'static>, inputs: Vec<NodeId>| {let id = node(graph, op, inputs, Some(Repr::Int32));graph.nodes[id.index()].frame_state = Some(state);iddiff --git a/Libraries/LibJS/JIT/Rust/src/passes/truncation.rs b/Libraries/LibJS/JIT/Rust/src/passes/truncation.rsindex 5a9a030f9c2..1df75cfcd5e 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/truncation.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/truncation.rs@@ -162,7 +162,7 @@ fn compare_uint32_bits(graph: &mut Graph) {data.op = Op::Int32Compare {comparison: comparison.unsigned(),};- data.inputs = inputs.to_vec();+ data.inputs.assign(&inputs);}}}diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/coalescing.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/coalescing.rsindex de4053c426d..768093ac3b1 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/coalescing.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/coalescing.rs@@ -55,7 +55,7 @@ pub(super) struct Coalescing {}struct Interference<'a> {- graph: &'a Graph,+ graph: &'a Graph<'a>,liveness: &'a ValueLiveness,definitions: &'a [Definition],deaths: &'a Lists<(usize, u32)>,diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/liveness.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/liveness.rsindex d6b8717f521..3ff0032bccd 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/liveness.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/liveness.rs@@ -118,11 +118,11 @@ pub(super) fn state_predecessor(graph: &Graph, block: BlockId) -> Option<BlockId}/// The input of each phi of `successor` that flows in from `block`.-pub(super) fn phi_inputs_from(- graph: &Graph,+pub(super) fn phi_inputs_from<'g>(+ graph: &'g Graph<'g>,block: BlockId,successor: BlockId,-) -> impl Iterator<Item = (NodeId, NodeId)> + '_ {+) -> impl Iterator<Item = (NodeId, NodeId)> + 'g {let successor_block = graph.block(successor);let index = if successor_block.phis.is_empty() {0@@ -562,33 +562,33 @@ impl ValueLiveness {mod tests {use super::*;use crate::code::{Repr, ResumeMode};- use crate::ir::{Block, FrameState, Node};+ use crate::ir::{Block, FrameState};#[test]fn shared_frames_and_duplicate_uses_have_one_last_use_per_value() {let mut graph = Graph::default();graph.add_block(Block::default());- let value = graph.add_node(Node::new(Op::LoadSlot { slot: 0 }, vec![], Some(Repr::Tagged), 0));+ let value = graph.add(Op::LoadSlot { slot: 0 }, &[], Some(Repr::Tagged), 0);graph.blocks[0].body.push(value);let frame = graph.add_frame_state(FrameState {executable: 0,pc: 0,mode: ResumeMode::ResumeAt,- values: vec![(0, value), (1, value)],- in_frame: vec![],+ values: ak::ZoneVec::from_slice_in(&[(0, value), (1, value)], crate::test_zone()),+ in_frame: ak::ZoneVec::new_in(crate::test_zone()),parent: None,passed_argument_count: None,legacy_arguments: 0..0,});let mut checks = Vec::new();for _ in 0..2 {- let check = graph.add_node(Node::new(Op::CheckObject, vec![value], Some(Repr::Tagged), 0));+ let check = graph.add(Op::CheckObject, &[value], Some(Repr::Tagged), 0);graph.nodes[check.index()].frame_state = Some(frame);graph.blocks[0].body.push(check);checks.push(check);}- let constant = graph.add_node(Node::new(Op::Constant(0), vec![], Some(Repr::Tagged), 0));- let returned = graph.add_node(Node::new(Op::Return, vec![constant], None, 0));+ let constant = graph.add(Op::Constant(0), &[], Some(Repr::Tagged), 0);+ let returned = graph.add(Op::Return, &[constant], None, 0);graph.blocks[0].control = Some(returned);let mut liveness = ValueLiveness::new();liveness.compute(&graph).unwrap();@@ -606,29 +606,24 @@ mod tests {for index in 0..block_count {let mut block = Block::default();let value = if index == 0 {- graph.add_node(Node::new(Op::LoadSlot { slot: 0 }, vec![], Some(Repr::Tagged), 0))+ graph.add(Op::LoadSlot { slot: 0 }, &[], Some(Repr::Tagged), 0)} else {block.predecessors.push(BlockId::from_index(index - 1));- graph.add_node(Node::new(- Op::CheckObject,- vec![values[index - 1]],- Some(Repr::Tagged),- 0,- ))+ graph.add(Op::CheckObject, &[values[index - 1]], Some(Repr::Tagged), 0)};values.push(value);block.body.push(value);block.control = Some(if index + 1 == block_count {- graph.add_node(Node::new(Op::Return, vec![value], None, 0))+ graph.add(Op::Return, &[value], None, 0)} else {- graph.add_node(Node::new(+ graph.add(Op::Jump {target: BlockId::from_index(index + 1),},- vec![],+ &[],None,0,- ))+ )});graph.add_block(block);}diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rsindex 764e0d96dcc..ef72c46f7c0 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/mod.rs@@ -545,7 +545,7 @@ pub fn allocate(}struct Allocator<'a> {- graph: &'a Graph,+ graph: &'a Graph<'a>,registers: &'a RegisterSet,liveness: &'a ValueLiveness,allocation: &'a mut Allocation,diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/tests.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/tests.rsindex b510f849ddf..e75454de480 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/tests.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/tests.rs@@ -711,7 +711,7 @@ fn exits_find_constants_registers_and_spilled_values() {let allocation = allocate_and_verify(&graph);let exit = find_node(&graph, |node| matches!(node.op, Op::Exit { .. }));let mut scratch = crate::scratch::Scratch::new();- scratch.sites.begin(&graph).unwrap();+ scratch.tables.sites.begin(&graph).unwrap();SiteSource {graph: &graph,allocation: &allocation,@@ -720,10 +720,10 @@ fn exits_find_constants_registers_and_spilled_values() {stack_slot_offset: &|slot| -8 * (i32::try_from(slot).unwrap() + 1),saves: &[],}- .write(&mut scratch.sites, &mut scratch.artifact)+ .write(&mut scratch.tables.sites, &mut scratch.tables.artifact).unwrap();let mut words = ak::Column::new(crate::artifact::MAX_WORDS, c"test");- let layout = scratch.artifact.finish(&Tail::default(), &mut words).unwrap();+ let layout = scratch.tables.artifact.finish(&Tail::default(), &mut words).unwrap();let artifact = Artifact::new(&words, &layout);let argument = find_node(&graph, |node| node.op == Op::LoadSlot { slot: a(0).raw() });let Some(Location::Register(argument_register)) = allocation.node(argument).output else {@@ -834,18 +834,8 @@ fn the_verifier_finds_values_reloaded_from_frame_slots_that_do_not_hold_them() {// A store to the slot, which nothing may do, makes it hold another value.let mut stored = graph.clone();- let undefined = stored.add_node(crate::ir::Node::new(- Op::Constant(value::UNDEFINED),- vec![],- Some(Repr::Tagged),- 0,- ));- let store = stored.add_node(crate::ir::Node::new(- Op::StoreSlot { slot: a(0).raw() },- vec![undefined],- None,- 0,- ));+ let undefined = stored.add(Op::Constant(value::UNDEFINED), &[], Some(Repr::Tagged), 0);+ let store = stored.add(Op::StoreSlot { slot: a(0).raw() }, &[undefined], None, 0);let block = stored.blocks.iter()@@ -1248,7 +1238,7 @@ fn float64_values_get_floating_point_registers() {target_builtin: Some(13),..Default::default()}]);- let mut graph = crate::builder::build_graph_with_feedback(&snapshot, &|_| true).unwrap();+ let mut graph = crate::builder::build_graph_with_feedback(&snapshot, &|_| true, crate::test_zone()).unwrap();crate::passes::optimize(&mut graph,&snapshot.executables[0].layout,diff --git a/Libraries/LibJS/JIT/Rust/src/regalloc/verify.rs b/Libraries/LibJS/JIT/Rust/src/regalloc/verify.rsindex c4fab959ca0..079255b3362 100644--- a/Libraries/LibJS/JIT/Rust/src/regalloc/verify.rs+++ b/Libraries/LibJS/JIT/Rust/src/regalloc/verify.rs@@ -42,7 +42,7 @@ enum Content {type State = BTreeMap<Location, Content>;struct Verifier<'a> {- graph: &'a Graph,+ graph: &'a Graph<'a>,registers: &'a RegisterSet,allocation: &'a Allocation,/// Whether to report errors; off while the block states are still@@ -171,7 +171,8 @@ impl Verifier<'_> {}fn check_phi_inputs(&mut self, block: BlockId, exit_states: &[Option<State>]) {- for predecessor in self.graph.block(block).predecessors.clone() {+ let predecessors = self.graph.block(block).predecessors.to_vec();+ for predecessor in predecessors {let Some(exit) = &exit_states[predecessor.index()] else {continue;};diff --git a/Libraries/LibJS/JIT/Rust/src/scratch.rs b/Libraries/LibJS/JIT/Rust/src/scratch.rsindex d5ee4289cf0..013b5db2f96 100644--- a/Libraries/LibJS/JIT/Rust/src/scratch.rs+++ b/Libraries/LibJS/JIT/Rust/src/scratch.rs@@ -6,6 +6,8 @@//! The memory a thread compiles with.+use ak::Zone;+use crate::artifact::ArtifactWriter;use crate::codegen::sites::SiteScratch;use crate::passes::dominators::Dominators;@@ -16,6 +18,14 @@ use crate::regalloc::Regalloc;/// The memory is in a few ranges of address space that are the scratch's own, so all of it can go back to the system/// at any time between two compiles (see `release_memory()`), whatever else the process allocated since.pub struct Scratch {+ /// Where the graph of a compile is, with all the lists of its nodes, blocks and frame states. A compile starts+ /// with a zone that holds nothing.+ pub(crate) zone: Zone,+ pub(crate) tables: Tables,+}++/// The tables of a compile that are not part of its graph.+pub struct Tables {pub(crate) artifact: ArtifactWriter,pub(crate) sites: SiteScratch,pub(crate) regalloc: Regalloc,@@ -30,22 +40,38 @@ impl Default for Scratch {}}+/// The most bytes that the zone of a graph gives out. It is address space, which costs nothing before it is used, and+/// it is far above what a graph of the largest function that the builder accepts takes.+const GRAPH_ZONE_LIMIT: usize = 1 << 34;+impl Scratch {/// A scratch, which takes no memory before a compile uses it.pub fn new() -> Self {Self {- artifact: ArtifactWriter::new(),- sites: SiteScratch::new(),- regalloc: Regalloc::new(),- dominators: Dominators::new(),+ zone: Zone::new(GRAPH_ZONE_LIMIT, c"JIT graph"),+ tables: Tables {+ artifact: ArtifactWriter::new(),+ sites: SiteScratch::new(),+ regalloc: Regalloc::new(),+ dominators: Dominators::new(),+ },}}+ /// Drops the data of the compile that ended. The zone keeps its memory, so that the next compile of the thread+ /// does not take it from the system again: a thread that has no compile for a while gives it back (see+ /// `release_memory()`).+ pub(crate) fn end_compile(&mut self) {+ self.zone.reset();+ }+/// Gives the memory of the scratch back to the system. The next compile takes memory again.pub fn release_memory(&mut self) {- self.artifact.release_memory();- self.sites.release_memory();- self.regalloc.release_memory();- self.dominators.release_memory();+ self.zone.reset();+ self.zone.trim(0);+ self.tables.artifact.release_memory();+ self.tables.sites.release_memory();+ self.tables.regalloc.release_memory();+ self.tables.dominators.release_memory();}}