From b71cd5ce91cb120c14d8626e0dee04c61234c5a6 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Wed, 27 Dec 2023 06:35:00 +0100 Subject: [PATCH] specialize `intern_char` --- crates/dash_middle/src/interner.rs | 5 ++--- crates/dash_rt_fs/src/promises.rs | 2 +- crates/dash_rt_fs/src/sync.rs | 2 +- crates/dash_vm/src/dispatch.rs | 14 ++---------- crates/dash_vm/src/eval.rs | 1 - crates/dash_vm/src/frame.rs | 2 +- crates/dash_vm/src/js_std/array.rs | 6 +++--- crates/dash_vm/src/js_std/string.rs | 2 -- crates/dash_vm/src/statics.rs | 5 ----- crates/dash_vm/src/value/boxed.rs | 1 - crates/dash_vm/src/value/function/mod.rs | 2 +- crates/dash_vm/src/value/mod.rs | 1 - crates/dash_vm/src/value/object.rs | 2 -- crates/dash_vm/src/value/ops/conversions.rs | 6 +++--- crates/dash_vm/src/value/primitive.rs | 24 ++++++++++----------- crates/dash_vm/src/value/string.rs | 8 +++---- 16 files changed, 29 insertions(+), 54 deletions(-) diff --git a/crates/dash_middle/src/interner.rs b/crates/dash_middle/src/interner.rs index a6d601d4..cfd22883 100644 --- a/crates/dash_middle/src/interner.rs +++ b/crates/dash_middle/src/interner.rs @@ -350,9 +350,8 @@ impl StringInterner { } pub fn intern_char(&mut self, val: char) -> Symbol { - // for now this just calls `intern`, but we might want to specialize this - let string = val.to_string(); - self.intern(string.as_ref()) + let mut buf = [0; 4]; + self.intern(val.encode_utf8(&mut buf)) } pub fn mark(&self, sym: Symbol) { diff --git a/crates/dash_rt_fs/src/promises.rs b/crates/dash_rt_fs/src/promises.rs index b21bb4b6..0c9b54bf 100644 --- a/crates/dash_rt_fs/src/promises.rs +++ b/crates/dash_rt_fs/src/promises.rs @@ -3,7 +3,7 @@ use dash_vm::localscope::LocalScope; use dash_vm::value::error::Error; use dash_vm::value::function::native::CallContext; use dash_vm::value::function::{Function, FunctionKind}; -use dash_vm::value::object::{NamedObject, Object, PropertyKey, PropertyValue}; +use dash_vm::value::object::{NamedObject, Object, PropertyValue}; use dash_vm::value::ops::conversions::ValueConversion; use dash_vm::value::{Value, ValueContext}; diff --git a/crates/dash_rt_fs/src/sync.rs b/crates/dash_rt_fs/src/sync.rs index 9b634c6c..781f40fb 100644 --- a/crates/dash_rt_fs/src/sync.rs +++ b/crates/dash_rt_fs/src/sync.rs @@ -2,7 +2,7 @@ use dash_vm::localscope::LocalScope; use dash_vm::value::error::Error; use dash_vm::value::function::native::CallContext; use dash_vm::value::function::{Function, FunctionKind}; -use dash_vm::value::object::{NamedObject, Object, PropertyKey, PropertyValue}; +use dash_vm::value::object::{NamedObject, Object, PropertyValue}; use dash_vm::value::ops::conversions::ValueConversion; use dash_vm::value::{Value, ValueContext}; diff --git a/crates/dash_vm/src/dispatch.rs b/crates/dash_vm/src/dispatch.rs index b10771de..7304bedd 100755 --- a/crates/dash_vm/src/dispatch.rs +++ b/crates/dash_vm/src/dispatch.rs @@ -2,7 +2,6 @@ use dash_log::warn; use std::ops::{Deref, DerefMut}; -use std::rc::Rc; use std::vec::Drain; use crate::frame::Frame; @@ -200,7 +199,6 @@ mod handlers { use dash_middle::interner::sym; use if_chain::if_chain; use smallvec::SmallVec; - use std::borrow::Cow; use std::ops::{Add, Div, Mul, Rem, Sub}; use crate::frame::{Frame, FrameState, TryBlock}; @@ -593,9 +591,8 @@ mod handlers { is_constructor: bool, call_ip: u16, ) -> Result, Unrooted> { - let (args, refs) = { + let args = { let mut args = Vec::with_capacity(argc); - // let mut refs = Vec::new(); let len = cx.fetch_and_inc_ip(); let spread_indices: SmallVec<[_; 4]> = (0..len).map(|_| cx.fetch_and_inc_ip()).collect(); @@ -605,10 +602,6 @@ mod handlers { if len == 0 { // Fast path for no spread arguments for value in iter { - // if let Value::Object(handle) = &value { - // refs.push(handle.clone()); - // } - args.push(value); } } else { @@ -626,15 +619,12 @@ mod handlers { } indices_iter.next(); } else { - // if let Value::Object(handle) = &value { - // refs.push(handle.clone()); - // } args.push(value); } } } - (args, ()) + args }; cx.scope.add_many(&args); diff --git a/crates/dash_vm/src/eval.rs b/crates/dash_vm/src/eval.rs index eb5ceaee..08077918 100644 --- a/crates/dash_vm/src/eval.rs +++ b/crates/dash_vm/src/eval.rs @@ -1,7 +1,6 @@ use dash_compiler::FunctionCompiler; use dash_lexer::Lexer; use dash_middle::compiler::StaticImportKind; -use dash_middle::interner::StringInterner; use dash_optimizer::type_infer::TypeInferCtx; use dash_optimizer::OptLevel; use dash_parser::Parser; diff --git a/crates/dash_vm/src/frame.rs b/crates/dash_vm/src/frame.rs index 6afb5602..043ed4a0 100755 --- a/crates/dash_vm/src/frame.rs +++ b/crates/dash_vm/src/frame.rs @@ -86,7 +86,7 @@ impl LoopCounterMap { } unsafe impl Trace for LoopCounterMap { - fn trace(&self, cx: &mut TraceCtxt<'_>) {} + fn trace(&self, _: &mut TraceCtxt<'_>) {} } #[derive(Debug, Clone, Trace)] diff --git a/crates/dash_vm/src/js_std/array.rs b/crates/dash_vm/src/js_std/array.rs index 8714b90a..9d34e538 100644 --- a/crates/dash_vm/src/js_std/array.rs +++ b/crates/dash_vm/src/js_std/array.rs @@ -54,8 +54,8 @@ pub fn values(cx: CallContext) -> Result { pub fn at(cx: CallContext) -> Result { let this = Value::Object(cx.this.to_object(cx.scope)?); - let len = this.length_of_array_like(cx.scope)?; - let mut index = cx.args.first().unwrap_or_undefined().to_integer_or_infinity(cx.scope)? as usize; + let len = this.length_of_array_like(cx.scope)? as i64; + let mut index = cx.args.first().unwrap_or_undefined().to_integer_or_infinity(cx.scope)? as i64; if index < 0 { index += len; @@ -65,7 +65,7 @@ pub fn at(cx: CallContext) -> Result { return Ok(Value::undefined()); } - let index = cx.scope.intern_usize(index); + let index = cx.scope.intern_usize(index as usize); this.get_property(cx.scope, index.into()).root(cx.scope) } diff --git a/crates/dash_vm/src/js_std/string.rs b/crates/dash_vm/src/js_std/string.rs index c66a1c14..c6ba0a08 100644 --- a/crates/dash_vm/src/js_std/string.rs +++ b/crates/dash_vm/src/js_std/string.rs @@ -6,9 +6,7 @@ use crate::value::function::native::CallContext; use crate::value::object::PropertyValue; use crate::value::ops::conversions::ValueConversion; use crate::value::{Value, ValueContext}; -use std::borrow::Cow; use std::fmt::Write; -use std::rc::Rc; pub fn constructor(cx: CallContext) -> Result { let value = cx.args.get(0).unwrap_or_undefined().to_js_string(cx.scope)?; diff --git a/crates/dash_vm/src/statics.rs b/crates/dash_vm/src/statics.rs index cf9c4c41..038f24ee 100644 --- a/crates/dash_vm/src/statics.rs +++ b/crates/dash_vm/src/statics.rs @@ -9,7 +9,6 @@ use crate::value::function::{Function, FunctionKind}; use crate::value::map::Map; use crate::value::regex::RegExp; use crate::value::set::Set; -use crate::value::string::JsString; use crate::value::PureBuiltin; use super::value::array::{Array, ArrayIterator}; @@ -23,8 +22,6 @@ use super::value::function::native::NativeFunction; use super::value::object::{NamedObject, Object}; use super::value::primitive::Symbol; -use std::rc::Rc; - #[derive(Trace)] pub struct Statics { pub function_proto: Handle, @@ -262,8 +259,6 @@ fn function(gc: &mut Gc, name: interner::Symbol, cb: NativeFunction) -> Handle Self { - let empty_str: Rc = "".into(); - Self { function_proto: empty_object(gc), function_ctor: function(gc, sym::Function, js_std::function::constructor), diff --git a/crates/dash_vm/src/value/boxed.rs b/crates/dash_vm/src/value/boxed.rs index 1766272e..1d066fed 100644 --- a/crates/dash_vm/src/value/boxed.rs +++ b/crates/dash_vm/src/value/boxed.rs @@ -6,7 +6,6 @@ use crate::value::{JsString, PropertyKey, Unrooted}; use crate::{delegate, PropertyValue, Vm}; use dash_proc_macro::Trace; use std::any::Any; -use std::rc::Rc; use super::object::{NamedObject, Object}; use super::primitive::{PrimitiveCapabilities, Symbol as PrimitiveSymbol}; diff --git a/crates/dash_vm/src/value/function/mod.rs b/crates/dash_vm/src/value/function/mod.rs index 6dfadcb3..5bfac444 100755 --- a/crates/dash_vm/src/value/function/mod.rs +++ b/crates/dash_vm/src/value/function/mod.rs @@ -256,7 +256,7 @@ impl Object for Function { self.obj.get_prototype(sc) } - fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { + fn own_keys(&self, _: &mut LocalScope<'_>) -> Result, Value> { Ok(vec![Value::String(sym::length.into()), Value::String(sym::name.into())]) } diff --git a/crates/dash_vm/src/value/mod.rs b/crates/dash_vm/src/value/mod.rs index 555aed2a..777ae364 100755 --- a/crates/dash_vm/src/value/mod.rs +++ b/crates/dash_vm/src/value/mod.rs @@ -13,7 +13,6 @@ pub mod promise; pub mod regex; pub mod set; pub mod typedarray; -use std::rc::Rc; use dash_middle::compiler::constant::Constant; use dash_middle::compiler::external::External; diff --git a/crates/dash_vm/src/value/object.rs b/crates/dash_vm/src/value/object.rs index e16e9b96..6a6fcb26 100755 --- a/crates/dash_vm/src/value/object.rs +++ b/crates/dash_vm/src/value/object.rs @@ -1,8 +1,6 @@ use std::any::Any; -use std::borrow::Cow; use std::cell::RefCell; use std::fmt::Debug; -use std::ptr::addr_of; use crate::gc::interner::sym; use crate::gc::persistent::Persistent; diff --git a/crates/dash_vm/src/value/ops/conversions.rs b/crates/dash_vm/src/value/ops/conversions.rs index 24fa7c6e..bf07cb92 100755 --- a/crates/dash_vm/src/value/ops/conversions.rs +++ b/crates/dash_vm/src/value/ops/conversions.rs @@ -1,12 +1,12 @@ use crate::gc::handle::Handle; use crate::gc::interner::sym; use crate::localscope::LocalScope; +use crate::throw; use crate::value::boxed::{Boolean, Number as BoxedNumber, String as BoxedString, Symbol as BoxedSymbol}; use crate::value::object::Object; use crate::value::primitive::{Number, MAX_SAFE_INTEGERF}; use crate::value::string::JsString; use crate::value::{Root, Typeof, Value}; -use crate::{throw, Vm}; pub trait ValueConversion { fn to_primitive(&self, sc: &mut LocalScope, preferred_type: Option) -> Result; @@ -146,7 +146,7 @@ impl ValueConversion for Value { // b. If exoticToPrim is not undefined, then if let Some(exotic_to_prim) = exotic_to_prim { - let preferred_type = preferred_type.to_value(sc); + let preferred_type = preferred_type.to_value(); // iv. Let result be ? Call(exoticToPrim, input, « hint »). let result = exotic_to_prim.apply(sc, self.clone(), vec![preferred_type]).root(sc)?; @@ -198,7 +198,7 @@ pub enum PreferredType { } impl PreferredType { - pub fn to_value(&self, vm: &Vm) -> Value { + pub fn to_value(&self) -> Value { let st = match self { PreferredType::Default => sym::default.into(), PreferredType::String => sym::string.into(), diff --git a/crates/dash_vm/src/value/primitive.rs b/crates/dash_vm/src/value/primitive.rs index 232c45a0..b2515a22 100644 --- a/crates/dash_vm/src/value/primitive.rs +++ b/crates/dash_vm/src/value/primitive.rs @@ -1,6 +1,5 @@ use std::any::Any; use std::hash::{Hash, Hasher}; -use std::rc::Rc; use std::{fmt, iter}; use dash_middle::interner; @@ -8,12 +7,11 @@ use dash_proc_macro::Trace; use crate::gc::handle::Handle; use crate::gc::interner::sym; -use crate::gc::trace::{Trace, TraceCtxt}; use crate::localscope::LocalScope; use crate::throw; use crate::util::{format_f64, Captures}; -use super::boxed::{Boolean as BoxedBoolean, Number as BoxedNumber, String as BoxedString, Symbol as BoxedSymbol}; +use super::boxed::{Boolean as BoxedBoolean, Number as BoxedNumber, Symbol as BoxedSymbol}; use super::object::{Object, PropertyKey, PropertyValue}; use super::ops::conversions::{PreferredType, ValueConversion}; use super::ops::equality::ValueEquality; @@ -63,7 +61,7 @@ impl Object for f64 { self } - fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { + fn own_keys(&self, _: &mut LocalScope<'_>) -> Result, Value> { Ok(Vec::new()) } @@ -115,7 +113,7 @@ impl Object for bool { self } - fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { + fn own_keys(&self, _: &mut LocalScope<'_>) -> Result, Value> { Ok(Vec::new()) } @@ -241,7 +239,7 @@ impl Object for Undefined { self } - fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { + fn own_keys(&self, _: &mut LocalScope<'_>) -> Result, Value> { Ok(Vec::new()) } @@ -293,7 +291,7 @@ impl Object for Null { self } - fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { + fn own_keys(&self, _: &mut LocalScope<'_>) -> Result, Value> { Ok(Vec::new()) } @@ -419,7 +417,7 @@ impl Object for Symbol { self } - fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { + fn own_keys(&self, _: &mut LocalScope<'_>) -> Result, Value> { Ok(Vec::new()) } @@ -496,7 +494,7 @@ impl ValueConversion for f64 { Ok(*self) } - fn to_boolean(&self, sc: &mut LocalScope<'_>) -> Result { + fn to_boolean(&self, _: &mut LocalScope<'_>) -> Result { Ok(*self != 0.0 && !self.is_nan()) } @@ -571,7 +569,7 @@ impl ValueConversion for bool { Ok(*self) } - fn to_js_string(&self, sc: &mut LocalScope) -> Result { + fn to_js_string(&self, _: &mut LocalScope) -> Result { Ok(if *self { sym::true_.into() } else { sym::false_.into() }) } @@ -709,7 +707,7 @@ impl ValueConversion for Undefined { Ok(false) } - fn to_js_string(&self, sc: &mut LocalScope) -> Result { + fn to_js_string(&self, _: &mut LocalScope) -> Result { Ok(sym::undefined.into()) } @@ -771,7 +769,7 @@ impl ValueConversion for Null { Ok(false) } - fn to_js_string(&self, sc: &mut LocalScope) -> Result { + fn to_js_string(&self, _: &mut LocalScope) -> Result { Ok(sym::null.into()) } @@ -825,7 +823,7 @@ impl ValueConversion for Symbol { throw!(sc, TypeError, "Cannot convert symbol to number"); } - fn to_boolean(&self, sc: &mut LocalScope<'_>) -> Result { + fn to_boolean(&self, _: &mut LocalScope<'_>) -> Result { Ok(true) } diff --git a/crates/dash_vm/src/value/string.rs b/crates/dash_vm/src/value/string.rs index 2430c5a9..6e86785c 100644 --- a/crates/dash_vm/src/value/string.rs +++ b/crates/dash_vm/src/value/string.rs @@ -62,7 +62,7 @@ impl ValueEquality for JsString { Ok(Value::Boolean(*self == other.to_js_string(sc)?)) } - fn strict_eq(&self, other: &Value, sc: &mut LocalScope) -> Result { + fn strict_eq(&self, other: &Value, _: &mut LocalScope) -> Result { if let Value::String(other) = other { Ok(Value::Boolean(self == other)) } else { @@ -72,7 +72,7 @@ impl ValueEquality for JsString { } impl ValueConversion for JsString { - fn to_primitive(&self, sc: &mut LocalScope, preferred_type: Option) -> Result { + fn to_primitive(&self, _: &mut LocalScope, _: Option) -> Result { Ok(Value::String(self.clone())) } @@ -84,7 +84,7 @@ impl ValueConversion for JsString { Ok(!self.res(sc).is_empty()) } - fn to_js_string(&self, sc: &mut LocalScope) -> Result { + fn to_js_string(&self, _: &mut LocalScope) -> Result { Ok(self.clone()) } @@ -130,7 +130,7 @@ impl Object for JsString { Ok(()) } - fn delete_property(&self, sc: &mut LocalScope, _: super::object::PropertyKey) -> Result { + fn delete_property(&self, _: &mut LocalScope, _: super::object::PropertyKey) -> Result { Ok(Unrooted::new(Value::undefined())) }