Skip to content

Commit de4a15c

Browse files
committed
wip
1 parent bf772bf commit de4a15c

File tree

9 files changed

+135
-6
lines changed

9 files changed

+135
-6
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ resolver = "2"
3535
[profile.release]
3636
lto = "fat"
3737
codegen-units = 1
38+
debug = true
3839

3940
[profile.dev]
4041
debug = true

crates/dash_compiler/src/instruction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl InstructionBuilder<'_, '_> {
254254
self.write_instr(Instruction::StaticPropAccess);
255255
self.writew(id);
256256
self.write(preserve_this.into());
257+
self.write_all(&1234123456u32.to_ne_bytes());
257258

258259
Ok(())
259260
}

crates/dash_decompiler/src/decompiler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ impl<'interner, 'buf> FunctionDecompiler<'interner, 'buf> {
220220
Instruction::StaticPropAccess => {
221221
let b = self.read_u16()?;
222222
let _preserve_this = self.read()?;
223+
for _ in 0..4 {
224+
self.read()?;
225+
}
223226
let ident = self
224227
.interner
225228
.resolve(self.constants.symbols[SymbolConstant(b)])

crates/dash_vm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ahash = "0.8.3"
2828
rustc-hash = "2.1.0"
2929
hashbrown = "0.15.0"
3030
if_chain = "1.0.2"
31+
rand = "0.9.1"
3132

3233
[dev-dependencies]
3334
criterion = "0.5.0"

crates/dash_vm/src/dispatch.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,17 +1626,58 @@ mod handlers {
16261626
}
16271627

16281628
pub fn staticpropertyaccess(mut cx: DispatchContext<'_>) -> Result<Option<HandleResult>, Unrooted> {
1629+
// let (id, cache) = {
1630+
// let frame = cx.active_frame_mut();
1631+
// let ip = frame.ip;
1632+
// frame.function.buffer.with(|buf| unsafe {
1633+
// let id = u16::from_ne_bytes(buf.get_unchecked(ip..ip + 2).try_into().unwrap());
1634+
// let cache = u32::from_ne_bytes(buf.get_unchecked(ip + 2..ip + 6).try_into().unwrap());
1635+
// frame.ip += 6;
1636+
// (id, cache)
1637+
// })
1638+
// };
16291639
let id = cx.fetchw_and_inc_ip();
1640+
16301641
let ident = JsString::from(cx.constants().symbols[SymbolConstant(id)]);
16311642

16321643
let preserve_this = cx.fetch_and_inc_ip() == 1;
1644+
let cache = cx.fetchw32_and_inc_ip();
16331645

16341646
let target = if preserve_this {
16351647
cx.peek_stack()
16361648
} else {
16371649
cx.pop_stack_rooted()
16381650
};
16391651

1652+
if ident.sym() == sym::length {
1653+
let k = sym::from.to_key(&mut cx.scope);
1654+
let i = std::time::Instant::now();
1655+
let c = 1000000;
1656+
let mut x = None;
1657+
let (data, fun) = match target.unpack() {
1658+
ValueKind::Object(object) => {
1659+
let data = object.data_ptr(&cx.scope);
1660+
let vt = object.vtable(&cx.scope);
1661+
// unsafe {
1662+
// ||
1663+
// }
1664+
(data, vt.js_get_property_descriptor)
1665+
}
1666+
_ => unreachable!(),
1667+
};
1668+
if let Some(target_) = target.extract::<OrdObject>(&cx.scope) {
1669+
for _ in 0..c {
1670+
x = unsafe { Some(fun(data, k, &mut cx.scope)) };
1671+
// x = Some(target.get_property_descriptor(k, &mut cx.scope).unwrap());
1672+
}
1673+
let e = i.elapsed();
1674+
dbg!(e / c);
1675+
// dbg!(x);
1676+
// assert!(x.unwrap().root(&mut cx.scope));
1677+
}
1678+
// dbg!(x.unwrap().root(&mut cx.scope).unpack());
1679+
}
1680+
16401681
let value = target.get_property(ident.to_key(&mut cx.scope), &mut cx.scope)?;
16411682
cx.push_stack(value);
16421683
Ok(None)

crates/dash_vm/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,21 @@ impl Vm {
12641264
u16::from_ne_bytes(value)
12651265
}
12661266

1267+
/// Fetches a wide value (16-bit) in the currently executing frame
1268+
/// and increments the instruction pointer
1269+
#[cfg_attr(dash_lints, dash_lints::trusted_no_gc)]
1270+
pub(crate) fn fetchw32_and_inc_ip(&mut self) -> u32 {
1271+
let frame = self.active_frame_mut();
1272+
let value: [u8; 4] = frame.function.buffer.with(|buf| {
1273+
buf[frame.ip..frame.ip + 4]
1274+
.try_into()
1275+
.expect("Failed to get wide instruction")
1276+
});
1277+
1278+
frame.ip += 4;
1279+
u32::from_ne_bytes(value)
1280+
}
1281+
12671282
#[cfg_attr(dash_lints, dash_lints::trusted_no_gc)]
12681283
pub(crate) fn get_frame_sp(&self) -> usize {
12691284
self.active_frame().sp

crates/dash_vm/src/value/mod.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,51 @@ unsafe impl Trace for Value {
219219
}
220220

221221
// TODO: can we just get rid of this impl if ExternalValue stores ValueId instead of ObjectId which should remove the need for having an object vtable for value
222+
#[warn(clippy::missing_trait_methods)]
222223
impl Object for Value {
224+
fn get_property(&self, this: This, key: PropertyKey, sc: &mut LocalScope<'_>) -> Result<Unrooted, Unrooted> {
225+
match self.unpack() {
226+
ValueKind::Object(o) => o.get_property(key, sc),
227+
ValueKind::Number(n) => n.get_property(this, key, sc),
228+
ValueKind::Boolean(b) => b.get_property(this, key, sc),
229+
ValueKind::String(s) => s.get_property(this, key, sc),
230+
ValueKind::External(e) => e.get_property(this, key, sc),
231+
ValueKind::Undefined(u) => u.get_property(this, key, sc),
232+
ValueKind::Null(n) => n.get_property(this, key, sc),
233+
ValueKind::Symbol(s) => s.get_property(this, key, sc),
234+
}
235+
}
236+
237+
fn get_own_property(&self, this: This, key: PropertyKey, sc: &mut LocalScope<'_>) -> Result<Unrooted, Unrooted> {
238+
match self.unpack() {
239+
ValueKind::Object(o) => o.get_own_property(key, sc),
240+
ValueKind::Number(n) => n.get_own_property(this, key, sc),
241+
ValueKind::Boolean(b) => b.get_own_property(this, key, sc),
242+
ValueKind::String(s) => s.get_own_property(this, key, sc),
243+
ValueKind::External(e) => e.get_own_property(this, key, sc),
244+
ValueKind::Undefined(u) => u.get_own_property(this, key, sc),
245+
ValueKind::Null(n) => n.get_own_property(this, key, sc),
246+
ValueKind::Symbol(s) => s.get_own_property(this, key, sc),
247+
}
248+
}
249+
250+
fn get_property_descriptor(
251+
&self,
252+
key: PropertyKey,
253+
sc: &mut LocalScope,
254+
) -> Result<Option<PropertyValue>, Unrooted> {
255+
match self.unpack() {
256+
ValueKind::Number(n) => n.get_property_descriptor(key, sc),
257+
ValueKind::Boolean(b) => b.get_property_descriptor(key, sc),
258+
ValueKind::String(s) => s.get_property_descriptor(key, sc),
259+
ValueKind::Undefined(u) => u.get_property_descriptor(key, sc),
260+
ValueKind::Null(n) => n.get_property_descriptor(key, sc),
261+
ValueKind::Symbol(s) => s.get_property_descriptor(key, sc),
262+
ValueKind::Object(o) => o.get_property_descriptor(key, sc),
263+
ValueKind::External(e) => e.get_property_descriptor(key, sc),
264+
}
265+
}
266+
223267
fn get_own_property_descriptor(
224268
&self,
225269
key: PropertyKey,

crates/dash_vm/src/value/object/ordinary.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,29 @@ impl OrdObject {
124124
}
125125

126126
impl Object for OrdObject {
127+
fn get_property_descriptor(
128+
&self,
129+
key: PropertyKey,
130+
sc: &mut LocalScope,
131+
) -> Result<Option<PropertyValue>, Unrooted> {
132+
if let Some(pv) = self.get_own_property_descriptor(key, sc)? {
133+
Ok(Some(pv))
134+
} else {
135+
#[cold]
136+
fn f() {}
137+
f();
138+
eprintln!("SLOW PATH!!! {key:?}");
139+
if let InnerOrdObject::Linear(l) = &*self.0.borrow() {
140+
let ks = l
141+
.raw_keys()
142+
.iter()
143+
.map(|v| sc.interner.resolve(interner::Symbol::from_raw(*v)))
144+
.collect::<Vec<_>>();
145+
println!("Keys: {ks:?}")
146+
}
147+
self.get_prototype(sc)?.get_property_descriptor(key, sc)
148+
}
149+
}
127150
fn get_own_property_descriptor(
128151
&self,
129152
key: PropertyKey,
@@ -860,7 +883,7 @@ impl PropertyVec {
860883
let descriptors = unsafe {
861884
align_ptr_mut(
862885
values
863-
.add(self.len() as usize)
886+
.add(self.capacity().get() as usize)
864887
.cast::<InternalLinearPropertyVecDescriptor>(),
865888
)
866889
};
@@ -880,7 +903,7 @@ impl PropertyVec {
880903
let descriptors = unsafe {
881904
align_ptr(
882905
values
883-
.add(self.len() as usize)
906+
.add(self.capacity().get() as usize)
884907
.cast::<InternalLinearPropertyVecDescriptor>(),
885908
)
886909
};

0 commit comments

Comments
 (0)