Skip to content

Commit

Permalink
specialize intern_char
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Dec 27, 2023
1 parent 28f6817 commit b71cd5c
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 54 deletions.
5 changes: 2 additions & 3 deletions crates/dash_middle/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion crates/dash_rt_fs/src/promises.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion crates/dash_rt_fs/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
14 changes: 2 additions & 12 deletions crates/dash_vm/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -593,9 +591,8 @@ mod handlers {
is_constructor: bool,
call_ip: u16,
) -> Result<Option<HandleResult>, 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();
Expand All @@ -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 {
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion crates/dash_vm/src/eval.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/dash_vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions crates/dash_vm/src/js_std/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub fn values(cx: CallContext) -> Result<Value, Value> {

pub fn at(cx: CallContext) -> Result<Value, Value> {
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;
Expand All @@ -65,7 +65,7 @@ pub fn at(cx: CallContext) -> Result<Value, Value> {
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)
}

Expand Down
2 changes: 0 additions & 2 deletions crates/dash_vm/src/js_std/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value, Value> {
let value = cx.args.get(0).unwrap_or_undefined().to_js_string(cx.scope)?;
Expand Down
5 changes: 0 additions & 5 deletions crates/dash_vm/src/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<dyn Object>,
Expand Down Expand Up @@ -262,8 +259,6 @@ fn function(gc: &mut Gc, name: interner::Symbol, cb: NativeFunction) -> Handle<d

impl Statics {
pub fn new(gc: &mut Gc) -> Self {
let empty_str: Rc<str> = "".into();

Self {
function_proto: empty_object(gc),
function_ctor: function(gc, sym::Function, js_std::function::constructor),
Expand Down
1 change: 0 additions & 1 deletion crates/dash_vm/src/value/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion crates/dash_vm/src/value/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl Object for Function {
self.obj.get_prototype(sc)
}

fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
fn own_keys(&self, _: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
Ok(vec![Value::String(sym::length.into()), Value::String(sym::name.into())])
}

Expand Down
1 change: 0 additions & 1 deletion crates/dash_vm/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions crates/dash_vm/src/value/object.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions crates/dash_vm/src/value/ops/conversions.rs
Original file line number Diff line number Diff line change
@@ -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<PreferredType>) -> Result<Value, Value>;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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(),
Expand Down
24 changes: 11 additions & 13 deletions crates/dash_vm/src/value/primitive.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use std::any::Any;
use std::hash::{Hash, Hasher};
use std::rc::Rc;
use std::{fmt, iter};

use dash_middle::interner;
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;
Expand Down Expand Up @@ -63,7 +61,7 @@ impl Object for f64 {
self
}

fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
fn own_keys(&self, _: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
Ok(Vec::new())
}

Expand Down Expand Up @@ -115,7 +113,7 @@ impl Object for bool {
self
}

fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
fn own_keys(&self, _: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
Ok(Vec::new())
}

Expand Down Expand Up @@ -241,7 +239,7 @@ impl Object for Undefined {
self
}

fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
fn own_keys(&self, _: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
Ok(Vec::new())
}

Expand Down Expand Up @@ -293,7 +291,7 @@ impl Object for Null {
self
}

fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
fn own_keys(&self, _: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
Ok(Vec::new())
}

Expand Down Expand Up @@ -419,7 +417,7 @@ impl Object for Symbol {
self
}

fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
fn own_keys(&self, _: &mut LocalScope<'_>) -> Result<Vec<Value>, Value> {
Ok(Vec::new())
}

Expand Down Expand Up @@ -496,7 +494,7 @@ impl ValueConversion for f64 {
Ok(*self)
}

fn to_boolean(&self, sc: &mut LocalScope<'_>) -> Result<bool, Value> {
fn to_boolean(&self, _: &mut LocalScope<'_>) -> Result<bool, Value> {
Ok(*self != 0.0 && !self.is_nan())
}

Expand Down Expand Up @@ -571,7 +569,7 @@ impl ValueConversion for bool {
Ok(*self)
}

fn to_js_string(&self, sc: &mut LocalScope) -> Result<JsString, Value> {
fn to_js_string(&self, _: &mut LocalScope) -> Result<JsString, Value> {
Ok(if *self { sym::true_.into() } else { sym::false_.into() })
}

Expand Down Expand Up @@ -709,7 +707,7 @@ impl ValueConversion for Undefined {
Ok(false)
}

fn to_js_string(&self, sc: &mut LocalScope) -> Result<JsString, Value> {
fn to_js_string(&self, _: &mut LocalScope) -> Result<JsString, Value> {
Ok(sym::undefined.into())
}

Expand Down Expand Up @@ -771,7 +769,7 @@ impl ValueConversion for Null {
Ok(false)
}

fn to_js_string(&self, sc: &mut LocalScope) -> Result<JsString, Value> {
fn to_js_string(&self, _: &mut LocalScope) -> Result<JsString, Value> {
Ok(sym::null.into())
}

Expand Down Expand Up @@ -825,7 +823,7 @@ impl ValueConversion for Symbol {
throw!(sc, TypeError, "Cannot convert symbol to number");
}

fn to_boolean(&self, sc: &mut LocalScope<'_>) -> Result<bool, Value> {
fn to_boolean(&self, _: &mut LocalScope<'_>) -> Result<bool, Value> {
Ok(true)
}

Expand Down
8 changes: 4 additions & 4 deletions crates/dash_vm/src/value/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<super::Value, super::Value> {
fn strict_eq(&self, other: &Value, _: &mut LocalScope) -> Result<super::Value, super::Value> {
if let Value::String(other) = other {
Ok(Value::Boolean(self == other))
} else {
Expand All @@ -72,7 +72,7 @@ impl ValueEquality for JsString {
}

impl ValueConversion for JsString {
fn to_primitive(&self, sc: &mut LocalScope, preferred_type: Option<PreferredType>) -> Result<Value, Value> {
fn to_primitive(&self, _: &mut LocalScope, _: Option<PreferredType>) -> Result<Value, Value> {
Ok(Value::String(self.clone()))
}

Expand All @@ -84,7 +84,7 @@ impl ValueConversion for JsString {
Ok(!self.res(sc).is_empty())
}

fn to_js_string(&self, sc: &mut LocalScope) -> Result<JsString, Value> {
fn to_js_string(&self, _: &mut LocalScope) -> Result<JsString, Value> {
Ok(self.clone())
}

Expand Down Expand Up @@ -130,7 +130,7 @@ impl Object for JsString {
Ok(())
}

fn delete_property(&self, sc: &mut LocalScope, _: super::object::PropertyKey) -> Result<super::Unrooted, Value> {
fn delete_property(&self, _: &mut LocalScope, _: super::object::PropertyKey) -> Result<super::Unrooted, Value> {
Ok(Unrooted::new(Value::undefined()))
}

Expand Down

0 comments on commit b71cd5c

Please sign in to comment.