Skip to content

Commit

Permalink
rework how holey arrays are represented
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Nov 12, 2024
1 parent 5ca0c2f commit 3772340
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 559 deletions.
27 changes: 16 additions & 11 deletions crates/dash_vm/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ mod extract {
pub enum ArrayElement {
Single(Value),
Spread(Value, usize),
Hole(usize),
Hole(u32),
}

impl ExtractFront for ArrayElement {
Expand Down Expand Up @@ -561,7 +561,8 @@ mod handlers {
use crate::frame::{FrameState, This, TryBlock};
use crate::throw;
use crate::util::unlikely;
use crate::value::array::{Array, ArrayIterator, Element};
use crate::value::array::table::ArrayTable;
use crate::value::array::{Array, ArrayIterator};
use crate::value::function::r#async::AsyncFunction;
use crate::value::function::closure::Closure;
use crate::value::function::generator::GeneratorFunction;
Expand Down Expand Up @@ -1469,21 +1470,21 @@ mod handlers {
cx: &mut DispatchContext<'_>,
len: usize,
stack_values: usize,
mut fun: impl FnMut(Element<PropertyValue>),
mut fun: impl FnMut(ArrayElement),
) -> Result<(), Unrooted> {
let mut iter = ForwardSequence::<ArrayElement>::from_len(cx, len, stack_values);
while let Some(element) = iter.next_front(cx) {
match element? {
ArrayElement::Single(value) => fun(Element::Value(PropertyValue::static_default(value))),
ArrayElement::Single(value) => fun(ArrayElement::Single(value)),
ArrayElement::Spread(source, len) => {
for i in 0..len {
let i = cx.scope.intern_usize(i);

let value = source.get_property(&mut cx.scope, i.into())?.root(&mut cx.scope);
fun(Element::Value(PropertyValue::static_default(value)));
fun(ArrayElement::Single(value));
}
}
ArrayElement::Hole(count) => fun(Element::Hole { count }),
ArrayElement::Hole(count) => fun(ArrayElement::Hole(count)),
}
}
let truncate_to = cx.stack.len() - stack_values;
Expand All @@ -1494,17 +1495,21 @@ mod handlers {
}

fn arraylit_holey(cx: &mut DispatchContext<'_>, len: usize, stack_values: usize) -> Result<Array, Unrooted> {
let mut new_elements = Vec::with_capacity(stack_values);
with_arraylit_elements(cx, len, stack_values, |element| new_elements.push(element))?;
Ok(Array::from_possibly_holey(&cx.scope, new_elements))
let mut table = ArrayTable::new();
with_arraylit_elements(cx, len, stack_values, |element| match element {
ArrayElement::Single(value) => table.push(PropertyValue::static_default(value)),
ArrayElement::Hole(hole) => table.resize(table.len() + hole),
ArrayElement::Spread(..) => unreachable!(),
})?;
Ok(Array::from_table(&cx.scope, table))
}

fn arraylit_dense(cx: &mut DispatchContext<'_>, len: usize) -> Result<Array, Unrooted> {
// Dense implies len == stack_values
let mut new_elements = Vec::with_capacity(len);
with_arraylit_elements(cx, len, len, |element| match element {
Element::Hole { .. } => unreachable!(),
Element::Value(v) => new_elements.push(v),
ArrayElement::Single(value) => new_elements.push(PropertyValue::static_default(value)),
ArrayElement::Spread(..) | ArrayElement::Hole(_) => unreachable!(),
})?;
Ok(Array::from_vec(&cx.scope, new_elements))
}
Expand Down
1 change: 1 addition & 0 deletions crates/dash_vm/src/gc/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ unsafe impl Trace for dash_middle::compiler::constant::Function {
unsafe_empty_trace!(
usize,
u8,
u32,
u64,
f64,
bool,
Expand Down
245 changes: 0 additions & 245 deletions crates/dash_vm/src/value/array/holey.rs

This file was deleted.

Loading

0 comments on commit 3772340

Please sign in to comment.