From 101140f6cd4267e00a363fb78e2d675ca3805273 Mon Sep 17 00:00:00 2001 From: nd419 <5161147+neeldug@users.noreply.github.com> Date: Thu, 17 Jun 2021 18:09:23 +0100 Subject: [PATCH 1/4] fix cargo check errors - move constants to associated constants - format & lint --- boa/src/builtins/bigint/conversions.rs | 4 +-- boa/src/builtins/math/mod.rs | 15 ++++----- boa/src/builtins/string/mod.rs | 9 +++-- boa/src/object/internal_methods.rs | 2 +- .../parser/expression/assignment/mod.rs | 11 +++++-- .../primary/object_initializer/mod.rs | 6 ++-- boa/src/value/mod.rs | 3 +- boa/src/value/operations.rs | 6 ++-- boa_tester/src/exec.rs | 33 ++++++++++++------- 9 files changed, 52 insertions(+), 37 deletions(-) diff --git a/boa/src/builtins/bigint/conversions.rs b/boa/src/builtins/bigint/conversions.rs index 6cdb1f14f20..2c8dd37d6b6 100644 --- a/boa/src/builtins/bigint/conversions.rs +++ b/boa/src/builtins/bigint/conversions.rs @@ -53,10 +53,10 @@ impl BigInt { /// Converts the BigInt to a f64 type. /// - /// Returns `std::f64::INFINITY` if the BigInt is too big. + /// Returns `f64::INFINITY` if the BigInt is too big. #[inline] pub fn to_f64(&self) -> f64 { - self.0.to_f64().unwrap_or(std::f64::INFINITY) + self.0.to_f64().unwrap_or(f64::INFINITY) } #[inline] diff --git a/boa/src/builtins/math/mod.rs b/boa/src/builtins/math/mod.rs index ed177fef3a6..272418b3191 100644 --- a/boa/src/builtins/math/mod.rs +++ b/boa/src/builtins/math/mod.rs @@ -15,7 +15,6 @@ use crate::{ builtins::BuiltIn, object::ObjectInitializer, property::Attribute, BoaProfiler, Context, Result, Value, }; -use std::f64; #[cfg(test)] mod tests; @@ -36,14 +35,14 @@ impl BuiltIn for Math { let attribute = Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT; let object = ObjectInitializer::new(context) - .property("E", f64::consts::E, attribute) - .property("LN2", f64::consts::LN_2, attribute) - .property("LN10", f64::consts::LN_10, attribute) - .property("LOG2E", f64::consts::LOG2_E, attribute) - .property("LOG10E", f64::consts::LOG10_E, attribute) + .property("E", std::f64::consts::E, attribute) + .property("LN2", std::f64::consts::LN_2, attribute) + .property("LN10", std::f64::consts::LN_10, attribute) + .property("LOG2E", std::f64::consts::LOG2_E, attribute) + .property("LOG10E", std::f64::consts::LOG10_E, attribute) .property("SQRT1_2", 0.5_f64.sqrt(), attribute) - .property("SQRT2", f64::consts::SQRT_2, attribute) - .property("PI", f64::consts::PI, attribute) + .property("SQRT2", std::f64::consts::SQRT_2, attribute) + .property("PI", std::f64::consts::PI, attribute) .function(Self::abs, "abs", 1) .function(Self::acos, "acos", 1) .function(Self::acosh, "acosh", 1) diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index 9749b9516eb..03789672963 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -27,7 +27,6 @@ use regress::Regex; use std::{ char::{decode_utf16, from_u32}, cmp::{max, min}, - f64::NAN, string::String as StdString, }; @@ -314,7 +313,7 @@ impl String { // Fast path returning NaN when pos is obviously out of range if pos < 0 || pos >= primitive_val.len() as i32 { - return Ok(Value::from(NAN)); + return Ok(Value::from(f64::NAN)); } // Calling .len() on a string would give the wrong result, as they are bytes not the number of unicode code points @@ -323,7 +322,7 @@ impl String { if let Some(utf16_val) = primitive_val.encode_utf16().nth(pos as usize) { Ok(Value::from(f64::from(utf16_val))) } else { - Ok(Value::from(NAN)) + Ok(Value::from(f64::NAN)) } } @@ -1169,7 +1168,7 @@ impl String { // the number of code units from start to the end of the string, // which should always be smaller or equals to both +infinity and i32::max_value let end = if args.len() < 2 { - i32::max_value() + i32::MAX } else { args.get(1) .expect("Could not get argument") @@ -1247,7 +1246,7 @@ impl String { .get(1) .map(|arg| arg.to_integer(context).map(|limit| limit as usize)) .transpose()? - .unwrap_or(std::u32::MAX as usize); + .unwrap_or(u32::MAX as usize); let values: Vec = match separator { None if limit == 0 => vec![], diff --git a/boa/src/object/internal_methods.rs b/boa/src/object/internal_methods.rs index 0e0e56b047c..3892eee5db7 100644 --- a/boa/src/object/internal_methods.rs +++ b/boa/src/object/internal_methods.rs @@ -363,7 +363,7 @@ impl GcObject { return Ok(false); } if self.ordinary_define_own_property(key, desc) { - if index >= old_len && index < std::u32::MAX { + if index >= old_len && index < u32::MAX { let desc = PropertyDescriptor::Data(DataDescriptor::new( index + 1, old_len_data_desc.attributes(), diff --git a/boa/src/syntax/parser/expression/assignment/mod.rs b/boa/src/syntax/parser/expression/assignment/mod.rs index 0a7cf4c4d07..be30d52eebd 100644 --- a/boa/src/syntax/parser/expression/assignment/mod.rs +++ b/boa/src/syntax/parser/expression/assignment/mod.rs @@ -217,6 +217,13 @@ where /// [spec]: https://tc39.es/ecma262/#sec-assignment-operators-static-semantics-early-errors #[inline] pub(crate) fn is_assignable(node: &Node) -> bool { - matches!(node, Node::GetConstField(_) | Node::GetField(_) | Node::Assign(_) - | Node::Call(_) | Node::Identifier(_) | Node::Object(_)) + matches!( + node, + Node::GetConstField(_) + | Node::GetField(_) + | Node::Assign(_) + | Node::Call(_) + | Node::Identifier(_) + | Node::Object(_) + ) } diff --git a/boa/src/syntax/parser/expression/primary/object_initializer/mod.rs b/boa/src/syntax/parser/expression/primary/object_initializer/mod.rs index 0ae11c5dada..9a450c8cef2 100644 --- a/boa/src/syntax/parser/expression/primary/object_initializer/mod.rs +++ b/boa/src/syntax/parser/expression/primary/object_initializer/mod.rs @@ -208,8 +208,10 @@ where idn @ "get" | idn @ "set" if matches!( cursor.peek(0)?.map(|t| t.kind()), - Some(&TokenKind::Identifier(_)) | Some(&TokenKind::Keyword(_)) - | Some(&TokenKind::BooleanLiteral(_)) | Some(&TokenKind::NullLiteral) + Some(&TokenKind::Identifier(_)) + | Some(&TokenKind::Keyword(_)) + | Some(&TokenKind::BooleanLiteral(_)) + | Some(&TokenKind::NullLiteral) | Some(&TokenKind::NumericLiteral(_)) ) => { diff --git a/boa/src/value/mod.rs b/boa/src/value/mod.rs index 5e00b90674a..7239f9ddd9b 100644 --- a/boa/src/value/mod.rs +++ b/boa/src/value/mod.rs @@ -19,7 +19,6 @@ use serde_json::{Number as JSONNumber, Value as JSONValue}; use std::{ collections::HashSet, convert::TryFrom, - f64::NAN, fmt::{self, Display}, str::FromStr, }; @@ -91,7 +90,7 @@ impl Value { /// Creates a new number with `NaN` value. #[inline] pub fn nan() -> Self { - Self::number(NAN) + Self::number(f64::NAN) } /// Creates a new string value. diff --git a/boa/src/value/operations.rs b/boa/src/value/operations.rs index 44cc173f8b3..d7e0ac9341a 100644 --- a/boa/src/value/operations.rs +++ b/boa/src/value/operations.rs @@ -423,14 +423,14 @@ impl Value { #[inline] pub fn neg(&self, context: &mut Context) -> Result { Ok(match *self { - Self::Symbol(_) | Self::Undefined => Self::rational(NAN), + Self::Symbol(_) | Self::Undefined => Self::rational(f64::NAN), Self::Object(_) => Self::rational(match self.to_numeric_number(context) { Ok(num) => -num, - Err(_) => NAN, + Err(_) => f64::NAN, }), Self::String(ref str) => Self::rational(match f64::from_str(str) { Ok(num) => -num, - Err(_) => NAN, + Err(_) => f64::NAN, }), Self::Rational(num) => Self::rational(-num), Self::Integer(num) => Self::rational(-f64::from(num)), diff --git a/boa_tester/src/exec.rs b/boa_tester/src/exec.rs index aa011deec60..b362f923563 100644 --- a/boa_tester/src/exec.rs +++ b/boa_tester/src/exec.rs @@ -110,18 +110,27 @@ impl Test { && !IGNORED.contains_test(&self.name) && !IGNORED.contains_any_feature(&self.features) && (matches!(self.expected_outcome, Outcome::Positive) - || matches!(self.expected_outcome, Outcome::Negative { - phase: Phase::Parse, - error_type: _, - }) - || matches!(self.expected_outcome, Outcome::Negative { - phase: Phase::Early, - error_type: _, - }) - || matches!(self.expected_outcome, Outcome::Negative { - phase: Phase::Runtime, - error_type: _, - })) { + || matches!( + self.expected_outcome, + Outcome::Negative { + phase: Phase::Parse, + error_type: _, + } + ) + || matches!( + self.expected_outcome, + Outcome::Negative { + phase: Phase::Early, + error_type: _, + } + ) + || matches!( + self.expected_outcome, + Outcome::Negative { + phase: Phase::Runtime, + error_type: _, + } + )) { let res = panic::catch_unwind(|| match self.expected_outcome { Outcome::Positive => { // TODO: implement async and add `harness/doneprintHandle.js` to the includes. From a1450db30787dd3aabf0da7192400f615757a901 Mon Sep 17 00:00:00 2001 From: nd419 <5161147+neeldug@users.noreply.github.com> Date: Thu, 17 Jun 2021 18:20:14 +0100 Subject: [PATCH 2/4] remove superfluous use --- boa/src/builtins/math/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/boa/src/builtins/math/mod.rs b/boa/src/builtins/math/mod.rs index 3d6c4f3c697..73b27305e0d 100644 --- a/boa/src/builtins/math/mod.rs +++ b/boa/src/builtins/math/mod.rs @@ -31,8 +31,6 @@ impl BuiltIn for Math { } fn init(context: &mut Context) -> (&'static str, Value, Attribute) { - use std::f64; - let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let attribute = Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT; From b13505df2943b87277b8df78d06017342de06351 Mon Sep 17 00:00:00 2001 From: nd419 <5161147+neeldug@users.noreply.github.com> Date: Thu, 17 Jun 2021 18:27:18 +0100 Subject: [PATCH 3/4] use static constant in property --- boa/src/builtins/math/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boa/src/builtins/math/mod.rs b/boa/src/builtins/math/mod.rs index 73b27305e0d..0a01945752b 100644 --- a/boa/src/builtins/math/mod.rs +++ b/boa/src/builtins/math/mod.rs @@ -41,7 +41,7 @@ impl BuiltIn for Math { .property("LN10", std::f64::consts::LN_10, attribute) .property("LOG2E", std::f64::consts::LOG2_E, attribute) .property("LOG10E", std::f64::consts::LOG10_E, attribute) - .property("SQRT1_2", 0.5_f64.sqrt(), attribute) + .property("SQRT1_2", std::f64::consts::FRAC_1_SQRT_2, attribute) .property("SQRT2", std::f64::consts::SQRT_2, attribute) .property("PI", std::f64::consts::PI, attribute) .function(Self::abs, "abs", 1) From 3c3b389c4f18d1102dd32b9464849a491bbce882 Mon Sep 17 00:00:00 2001 From: nd419 <5161147+neeldug@users.noreply.github.com> Date: Fri, 18 Jun 2021 22:35:26 +0100 Subject: [PATCH 4/4] add parallelism to test262 conformance runs --- Cargo.lock | 1 + boa_tester/Cargo.toml | 1 + boa_tester/src/exec/mod.rs | 7 +++---- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc4a3596074..e44c43f6083 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,6 +104,7 @@ dependencies = [ "hex", "num-format", "once_cell", + "rayon", "regex", "serde", "serde_json", diff --git a/boa_tester/Cargo.toml b/boa_tester/Cargo.toml index 1bc9d6af066..6ce3128991a 100644 --- a/boa_tester/Cargo.toml +++ b/boa_tester/Cargo.toml @@ -25,3 +25,4 @@ git2 = "0.13.20" hex = "0.4.3" num-format = "0.4.0" gc = { version = "0.4.1", features = ["derive"] } +rayon = "1.5.1" diff --git a/boa_tester/src/exec/mod.rs b/boa_tester/src/exec/mod.rs index 82bb1a4886c..82634a69b84 100644 --- a/boa_tester/src/exec/mod.rs +++ b/boa_tester/src/exec/mod.rs @@ -8,6 +8,7 @@ use super::{ }; use boa::{parse, Context, Value}; use colored::Colorize; +use rayon::prelude::*; use std::panic; impl TestSuite { @@ -17,17 +18,15 @@ impl TestSuite { println!("Suite {}:", self.name); } - // TODO: in parallel let suites: Vec<_> = self .suites - .iter() + .par_iter() .map(|suite| suite.run(harness, verbose)) .collect(); - // TODO: in parallel let tests: Vec<_> = self .tests - .iter() + .par_iter() .map(|test| test.run(harness, verbose)) .flatten() .collect();