Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all Value operations and add unsigned shift right #520

Merged
merged 13 commits into from
Jul 2, 2020

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Jun 23, 2020

What is the problem with the current implementation of Values operations?
The problem is that they are not spec compliant for objects, for example ToNumber (to_number) for objects it is supposed to call to_primitive and because it does not the code new Number(6) + 3 is broken and does not give the expected output 9. Also because to_number is called by Values operators, this means that the Value operations can throw exceptions and it requires context and should return a ResultValue.

It changes the following:

  • Removed Value::is_true() (this is a duplicate of to_boolean)
  • Added to_int32, to_uint32 and to_length to Interpreter
  • Made to_integer spec compliant
  • Made Value operators => functions (these functions take in an Interpreter, and can throw in certain cases, see example)
  • Made all Value operations spec compliant.
  • Added fast paths for all Value operations

The below code is fixed with this PR:

Number.prototype.valueOf = null;
Number.prototype.toString = null;

new Number(5) + 5 // this should throw, because it calls `to_primitive`

I'm not sure if I should move to_boolean to Interpreter, because it's the only one that can't throw and does not need context

@HalidOdat HalidOdat added bug Something isn't working technical debt execution Issues or PRs related to code execution labels Jun 23, 2020
@HalidOdat HalidOdat marked this pull request as draft June 23, 2020 10:25
@codecov
Copy link

codecov bot commented Jun 23, 2020

Codecov Report

Merging #520 into master will decrease coverage by 0.11%.
The diff coverage is 66.40%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #520      +/-   ##
==========================================
- Coverage   68.10%   67.99%   -0.12%     
==========================================
  Files         169      170       +1     
  Lines        9942    10322     +380     
==========================================
+ Hits         6771     7018     +247     
- Misses       3171     3304     +133     
Impacted Files Coverage Δ
boa/src/builtins/value/conversions.rs 54.54% <0.00%> (ø)
boa/src/builtins/value/operations.rs 30.41% <26.59%> (-28.97%) ⬇️
boa/src/builtins/number/conversions.rs 63.15% <63.15%> (ø)
boa/src/exec/operator/mod.rs 66.88% <65.90%> (ø)
boa/src/exec/mod.rs 68.53% <72.72%> (+1.61%) ⬆️
boa/src/builtins/array/mod.rs 80.90% <100.00%> (ø)
boa/src/builtins/boolean/tests.rs 100.00% <100.00%> (ø)
boa/src/builtins/number/mod.rs 65.48% <100.00%> (ø)
boa/src/builtins/value/display.rs 78.46% <100.00%> (ø)
boa/src/builtins/value/mod.rs 65.29% <100.00%> (+0.81%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b40e9e...e76d6e7. Read the comment docs.

@github-actions
Copy link

Benchmark for 62e6586

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 517.4±25.98ns 574.0±19.44ns -9.86%
Array access (Execution) 13.5±0.63µs 13.3±0.71µs +1.50%
Array creation (Execution) 3.8±0.12ms 3.8±0.17ms 0.00%
Array pop (Execution) 1421.1±64.64µs 1423.9±74.27µs -0.20%
Boolean Object Access (Execution) 5.1±0.26µs 5.1±0.33µs 0.00%
Create Realm 131.6±7.20µs 133.5±8.87µs -1.42%
Dynamic Object Property Access (Execution) 6.7±0.35µs 6.8±0.44µs -1.47%
Expression (Lexer) 2.0±0.09µs 2.0±0.08µs 0.00%
Expression (Parser) 5.0±0.30µs 4.9±0.38µs +2.04%
Fibonacci (Execution) 963.5±45.86µs 971.0±48.16µs -0.77%
For loop (Execution) 23.2±1.16µs 22.8±1.07µs +1.75%
For loop (Lexer) 5.0±0.41µs 5.3±1.09µs -5.66%
For loop (Parser) 13.2±0.86µs 13.2±0.55µs 0.00%
Hello World (Lexer) 907.9±85.26ns 920.9±57.85ns -1.41%
Hello World (Parser) 2.2±0.14µs 2.2±0.23µs 0.00%
Long file (Parser) 6.1±0.21ms 5.9±0.26ms +3.39%
Number Object Access (Execution) 4.1±0.22µs 4.1±0.22µs 0.00%
Object Creation (Execution) 6.2±0.26µs 6.2±0.29µs 0.00%
RegExp (Execution) 68.4±4.85µs 72.2±3.36µs -5.26%
RegExp Literal (Execution) 73.9±5.59µs 74.8±5.78µs -1.20%
RegExp Literal Creation (Execution) 70.7±3.24µs 72.7±4.51µs -2.75%
Static Object Property Access (Execution) 6.2±0.36µs 6.4±0.30µs -3.13%
String Object Access (Execution) 8.7±0.36µs 9.0±0.55µs -3.33%
String comparison (Execution) 6.8±0.40µs 6.7±0.40µs +1.49%
String concatenation (Execution) 5.8±0.22µs 5.8±0.27µs 0.00%
String copy (Execution) 4.6±0.26µs 4.5±0.20µs +2.22%
Symbols (Execution) 4.0±0.19µs 4.1±0.22µs -2.44%

@github-actions
Copy link

Benchmark for e586af4

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 417.9±24.32ns 482.6±28.12ns -13.41%
Array access (Execution) 12.4±0.75µs 12.2±0.85µs +1.64%
Array creation (Execution) 3.3±0.17ms 3.3±0.14ms 0.00%
Array pop (Execution) 1230.2±99.85µs 1262.9±115.30µs -2.59%
Boolean Object Access (Execution) 4.8±0.36µs 4.8±0.33µs 0.00%
Create Realm 126.7±9.26µs 119.9±7.57µs +5.67%
Dynamic Object Property Access (Execution) 6.8±0.58µs 6.5±0.43µs +4.62%
Expression (Lexer) 1811.7±102.85ns 1911.6±162.08ns -5.23%
Expression (Parser) 4.4±0.31µs 4.4±0.22µs 0.00%
Fibonacci (Execution) 924.4±42.44µs 935.9±46.97µs -1.23%
For loop (Execution) 20.8±1.58µs 21.2±1.46µs -1.89%
For loop (Lexer) 4.7±0.28µs 4.7±0.28µs 0.00%
For loop (Parser) 12.3±0.95µs 12.2±0.99µs +0.82%
Hello World (Lexer) 847.9±54.65ns 840.1±48.84ns +0.93%
Hello World (Parser) 1906.4±109.36ns 1963.0±125.83ns -2.88%
Long file (Parser) 5.5±0.22ms 5.6±0.24ms -1.79%
Number Object Access (Execution) 3.7±0.25µs 3.8±0.29µs -2.63%
Object Creation (Execution) 5.9±0.36µs 5.9±0.61µs 0.00%
RegExp (Execution) 73.4±6.02µs 69.4±3.58µs +5.76%
RegExp Literal (Execution) 75.9±4.94µs 74.6±5.48µs +1.74%
RegExp Literal Creation (Execution) 74.6±7.02µs 70.3±4.54µs +6.12%
Static Object Property Access (Execution) 6.0±0.38µs 5.9±0.35µs +1.69%
String Object Access (Execution) 8.1±0.59µs 8.1±0.55µs 0.00%
String comparison (Execution) 6.4±0.52µs 6.4±0.44µs 0.00%
String concatenation (Execution) 5.6±0.40µs 5.3±0.32µs +5.66%
String copy (Execution) 4.4±0.32µs 4.3±0.28µs +2.33%
Symbols (Execution) 4.3±0.36µs 3.7±0.24µs +16.22%

@Razican
Copy link
Member

Razican commented Jun 25, 2020

I'm not sure if I should move to_boolean to Interpreter, because it's the only one that can't throw and does not need context

I would move it. It makes sense having everything that's related working similarly and having the same endpoint. If not, it could get a bit messy.

@github-actions
Copy link

Benchmark for 5536c64

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 538.2±45.99ns 590.7±31.04ns -8.89%
Array access (Execution) 14.7±0.74µs 14.6±0.86µs +0.68%
Array creation (Execution) 4.1±0.15ms 3.9±0.15ms +5.13%
Array pop (Execution) 1527.3±55.88µs 1504.0±75.39µs +1.55%
Boolean Object Access (Execution) 5.6±0.26µs 5.7±0.30µs -1.75%
Create Realm 150.2±8.79µs 147.8±6.34µs +1.62%
Dynamic Object Property Access (Execution) 8.0±0.41µs 7.9±0.42µs +1.27%
Expression (Lexer) 2.3±0.11µs 2.3±0.14µs 0.00%
Expression (Parser) 5.2±0.22µs 5.2±0.28µs 0.00%
Fibonacci (Execution) 1129.7±44.96µs 1118.9±34.74µs +0.97%
For loop (Execution) 25.0±0.91µs 25.7±1.25µs -2.72%
For loop (Lexer) 5.5±0.21µs 5.6±0.29µs -1.79%
For loop (Parser) 14.7±0.61µs 15.2±0.80µs -3.29%
Hello World (Lexer) 1027.9±53.09ns 1000.9±38.18ns +2.70%
Hello World (Parser) 2.3±0.09µs 2.4±0.10µs -4.17%
Long file (Parser) 6.8±0.23ms 6.7±0.19ms +1.49%
Number Object Access (Execution) 4.5±0.31µs 4.4±0.22µs +2.27%
Object Creation (Execution) 7.1±0.24µs 7.0±0.39µs +1.43%
RegExp (Execution) 83.8±4.47µs 82.4±4.49µs +1.70%
RegExp Literal (Execution) 86.5±3.74µs 90.1±4.45µs -4.00%
RegExp Literal Creation (Execution) 82.1±3.78µs 85.4±3.91µs -3.86%
Static Object Property Access (Execution) 7.3±0.38µs 7.2±0.43µs +1.39%
String Object Access (Execution) 9.7±0.37µs 9.7±0.49µs 0.00%
String comparison (Execution) 7.8±0.42µs 7.7±0.60µs +1.30%
String concatenation (Execution) 6.5±0.33µs 6.3±0.24µs +3.17%
String copy (Execution) 5.3±0.22µs 5.2±0.26µs +1.92%
Symbols (Execution) 4.7±0.27µs 4.5±0.19µs +4.44%

@HalidOdat HalidOdat added this to the v0.10.0 milestone Jun 26, 2020
@HalidOdat HalidOdat force-pushed the deprecate/value-to-conversions branch from 932ba10 to 036c7d1 Compare June 26, 2020 09:06
@github-actions
Copy link

Benchmark for 5f3389e

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 491.4±46.84ns 545.2±28.01ns -9.87%
Array access (Execution) 13.2±0.53µs 13.4±0.77µs -1.49%
Array creation (Execution) 3.7±0.16ms 3.8±0.14ms -2.63%
Array pop (Execution) 1417.5±55.73µs 1414.9±72.77µs +0.18%
Boolean Object Access (Execution) 4.9±0.20µs 5.1±0.21µs -3.92%
Create Realm 130.0±5.64µs 136.3±9.24µs -4.62%
Dynamic Object Property Access (Execution) 6.9±0.33µs 6.8±0.28µs +1.47%
Expression (Lexer) 2.0±0.09µs 2.0±0.08µs 0.00%
Expression (Parser) 4.8±0.24µs 4.8±0.30µs 0.00%
Fibonacci (Execution) 960.5±47.02µs 924.9±38.75µs +3.85%
For loop (Execution) 22.5±1.08µs 21.7±1.04µs +3.69%
For loop (Lexer) 5.1±0.29µs 5.2±0.22µs -1.92%
For loop (Parser) 13.6±0.50µs 13.1±0.81µs +3.82%
Hello World (Lexer) 947.3±48.98ns 955.0±43.03ns -0.81%
Hello World (Parser) 2.1±0.10µs 2.1±0.13µs 0.00%
Long file (Parser) 6.0±0.17ms 5.8±0.17ms +3.45%
Number Object Access (Execution) 3.9±0.19µs 4.0±0.18µs -2.50%
Object Creation (Execution) 5.9±0.26µs 6.0±0.26µs -1.67%
RegExp (Execution) 70.0±4.68µs 72.3±4.92µs -3.18%
RegExp Literal (Execution) 74.0±3.86µs 74.2±3.66µs -0.27%
RegExp Literal Creation (Execution) 71.4±4.14µs 69.9±3.86µs +2.15%
Static Object Property Access (Execution) 6.3±0.44µs 6.2±0.31µs +1.61%
String Object Access (Execution) 8.5±0.44µs 8.5±0.35µs 0.00%
String comparison (Execution) 6.4±0.42µs 6.7±0.32µs -4.48%
String concatenation (Execution) 5.6±0.40µs 5.6±0.33µs 0.00%
String copy (Execution) 4.4±0.23µs 4.5±0.20µs -2.22%
Symbols (Execution) 4.0±0.28µs 4.1±0.18µs -2.44%

@github-actions
Copy link

Benchmark for aceb394

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 912.9±61.85ns 472.4±35.23ns +93.25%
Array access (Execution) 11.5±0.85µs 11.5±0.97µs 0.00%
Array creation (Execution) 3.1±0.17ms 3.2±0.22ms -3.13%
Array pop (Execution) 1179.9±72.60µs 1258.3±99.95µs -6.23%
Boolean Object Access (Execution) 4.3±0.34µs 4.5±0.40µs -4.44%
Create Realm 111.7±8.46µs 112.1±8.69µs -0.36%
Dynamic Object Property Access (Execution) 5.9±0.41µs 5.8±0.49µs +1.72%
Expression (Lexer) 1733.5±129.53ns 1687.0±122.63ns +2.76%
Expression (Parser) 4.1±0.32µs 4.3±0.33µs -4.65%
Fibonacci (Execution) 856.5±54.58µs 809.5±46.49µs +5.81%
For loop (Execution) 20.5±1.56µs 19.2±1.38µs +6.77%
For loop (Lexer) 4.3±0.32µs 4.7±0.40µs -8.51%
For loop (Parser) 11.3±0.85µs 11.3±1.50µs 0.00%
Hello World (Lexer) 760.0±66.23ns 786.8±60.88ns -3.41%
Hello World (Parser) 1864.1±168.55ns 1833.3±154.23ns +1.68%
Long file (Parser) 5.1±0.24ms 5.1±0.23ms 0.00%
Number Object Access (Execution) 3.6±0.30µs 3.4±0.22µs +5.88%
Object Creation (Execution) 5.4±0.59µs 5.2±0.41µs +3.85%
RegExp (Execution) 59.2±4.53µs 60.7±4.61µs -2.47%
RegExp Literal (Execution) 63.4±4.29µs 63.5±4.68µs -0.16%
RegExp Literal Creation (Execution) 58.6±4.06µs 59.0±4.64µs -0.68%
Static Object Property Access (Execution) 5.2±0.41µs 5.2±0.31µs 0.00%
String Object Access (Execution) 7.3±0.50µs 7.4±0.55µs -1.35%
String comparison (Execution) 5.8±0.39µs 5.7±0.40µs +1.75%
String concatenation (Execution) 4.8±0.34µs 4.9±0.48µs -2.04%
String copy (Execution) 3.9±0.28µs 3.8±0.29µs +2.63%
Symbols (Execution) 3.4±0.27µs 3.3±0.27µs +3.03%

@github-actions
Copy link

Benchmark for 6d6afb9

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 397.2±21.35ns 562.1±23.47ns -29.34%
Array access (Execution) 12.4±0.79µs 13.0±0.57µs -4.62%
Array creation (Execution) 3.5±0.17ms 3.6±0.13ms -2.78%
Array pop (Execution) 1333.1±80.97µs 1362.9±80.19µs -2.19%
Boolean Object Access (Execution) 5.1±0.15µs 4.8±0.30µs +6.25%
Create Realm 126.9±10.64µs 125.5±8.97µs +1.12%
Dynamic Object Property Access (Execution) 6.4±0.28µs 6.5±0.31µs -1.54%
Expression (Lexer) 1928.6±105.86ns 1977.7±71.63ns -2.48%
Expression (Parser) 4.6±0.30µs 4.8±0.26µs -4.17%
Fibonacci (Execution) 897.6±48.57µs 908.8±42.37µs -1.23%
For loop (Execution) 20.1±1.29µs 21.6±1.09µs -6.94%
For loop (Lexer) 5.0±0.29µs 4.9±0.33µs +2.04%
For loop (Parser) 12.7±0.67µs 12.4±0.86µs +2.42%
Hello World (Lexer) 854.3±52.53ns 876.3±63.07ns -2.51%
Hello World (Parser) 2.1±0.08µs 2.0±0.15µs +5.00%
Long file (Parser) 5.7±0.31ms 5.8±0.22ms -1.72%
Number Object Access (Execution) 3.9±0.19µs 4.1±0.29µs -4.88%
Object Creation (Execution) 5.9±0.30µs 5.6±0.32µs +5.36%
RegExp (Execution) 67.5±4.14µs 69.8±3.07µs -3.30%
RegExp Literal (Execution) 70.8±3.59µs 71.0±3.78µs -0.28%
RegExp Literal Creation (Execution) 67.1±5.52µs 67.4±4.78µs -0.45%
Static Object Property Access (Execution) 5.9±0.31µs 5.9±0.32µs 0.00%
String Object Access (Execution) 8.2±0.42µs 8.1±0.61µs +1.23%
String comparison (Execution) 6.5±0.27µs 6.5±0.51µs 0.00%
String concatenation (Execution) 5.3±0.37µs 5.4±0.31µs -1.85%
String copy (Execution) 4.3±0.15µs 4.3±0.16µs 0.00%
Symbols (Execution) 3.8±0.22µs 3.8±0.24µs 0.00%

@github-actions
Copy link

Benchmark for a5c1d76

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 398.9±22.84ns 542.8±30.53ns -26.51%
Array access (Execution) 12.8±0.81µs 12.8±0.72µs 0.00%
Array creation (Execution) 3.6±0.19ms 3.6±0.13ms 0.00%
Array pop (Execution) 1353.4±92.21µs 1331.6±59.77µs +1.64%
Boolean Object Access (Execution) 4.9±0.25µs 4.9±0.25µs 0.00%
Create Realm 127.9±9.98µs 127.0±6.77µs +0.71%
Dynamic Object Property Access (Execution) 6.7±0.37µs 6.5±0.33µs +3.08%
Expression (Lexer) 1938.8±92.40ns 1895.6±94.80ns +2.28%
Expression (Parser) 4.7±0.25µs 4.8±0.29µs -2.08%
Fibonacci (Execution) 915.4±40.72µs 932.1±43.60µs -1.79%
For loop (Execution) 21.2±0.92µs 21.4±1.25µs -0.93%
For loop (Lexer) 5.0±0.29µs 4.9±0.24µs +2.04%
For loop (Parser) 13.5±0.79µs 12.8±0.64µs +5.47%
Hello World (Lexer) 857.8±47.03ns 859.6±43.24ns -0.21%
Hello World (Parser) 2.1±0.12µs 2.1±0.10µs 0.00%
Long file (Parser) 5.8±0.18ms 5.7±0.19ms +1.75%
Number Object Access (Execution) 3.9±0.31µs 4.0±0.28µs -2.50%
Object Creation (Execution) 5.9±0.29µs 5.7±0.32µs +3.51%
RegExp (Execution) 67.5±4.33µs 66.0±4.29µs +2.27%
RegExp Literal (Execution) 72.1±4.99µs 69.7±3.91µs +3.44%
RegExp Literal Creation (Execution) 66.6±3.93µs 68.5±4.45µs -2.77%
Static Object Property Access (Execution) 5.9±0.32µs 5.9±0.34µs 0.00%
String Object Access (Execution) 8.1±0.39µs 8.1±0.43µs 0.00%
String comparison (Execution) 6.3±0.41µs 6.4±0.36µs -1.56%
String concatenation (Execution) 5.3±0.33µs 5.4±0.24µs -1.85%
String copy (Execution) 4.2±0.24µs 4.1±0.24µs +2.44%
Symbols (Execution) 3.8±0.22µs 3.7±0.21µs +2.70%

@HalidOdat HalidOdat changed the title Deprecate Values to_ conversions methods Fix Value operations Jun 27, 2020
@HalidOdat HalidOdat changed the title Fix Value operations Fix all Value operations and add unsigned shift right Jun 27, 2020
@HalidOdat HalidOdat marked this pull request as ready for review June 27, 2020 07:02
@HalidOdat
Copy link
Member Author

HalidOdat commented Jun 27, 2020

This PR fixes all Value operations, and adds unsigned shift left.

The Value to_ methods are still there but I removed there dependency from Value operations and in future PR I intead to remove them entirely.

This PR is ready, it would be nice to have fully working operators in v0.9

@github-actions
Copy link

Benchmark for efe1953

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 425.4±30.91ns 536.9±24.16ns -20.77%
Array access (Execution) 12.8±0.66µs 13.4±1.01µs -4.48%
Array creation (Execution) 3.7±0.12ms 3.7±0.11ms 0.00%
Array pop (Execution) 1352.8±78.82µs 1406.2±40.90µs -3.80%
Boolean Object Access (Execution) 5.0±0.20µs 5.1±0.13µs -1.96%
Create Realm 128.2±6.39µs 130.8±5.84µs -1.99%
Dynamic Object Property Access (Execution) 6.8±0.28µs 6.9±0.21µs -1.45%
Expression (Lexer) 2.1±0.06µs 1958.8±195.31ns +7.21%
Expression (Parser) 4.7±0.23µs 4.6±0.20µs +2.17%
Fibonacci (Execution) 914.2±35.93µs 960.6±34.76µs -4.83%
For loop (Execution) 20.6±1.23µs 22.9±1.19µs -10.04%
For loop (Lexer) 5.0±0.36µs 4.6±0.27µs +8.70%
For loop (Parser) 13.0±1.17µs 12.4±0.80µs +4.84%
Hello World (Lexer) 884.1±41.93ns 870.6±40.12ns +1.55%
Hello World (Parser) 2.1±0.12µs 1909.2±136.84ns +9.99%
Long file (Parser) 5.4±0.23ms 5.7±0.20ms -5.26%
Number Object Access (Execution) 4.0±0.17µs 4.1±0.16µs -2.44%
Object Creation (Execution) 5.8±0.33µs 5.9±0.25µs -1.69%
RegExp (Execution) 69.9±2.72µs 70.7±2.80µs -1.13%
RegExp Literal (Execution) 71.9±4.00µs 73.5±4.54µs -2.18%
RegExp Literal Creation (Execution) 70.2±3.99µs 69.8±2.10µs +0.57%
Static Object Property Access (Execution) 6.0±0.30µs 6.2±0.39µs -3.23%
String Object Access (Execution) 8.1±0.51µs 8.5±0.35µs -4.71%
String comparison (Execution) 6.7±0.32µs 6.8±0.11µs -1.47%
String concatenation (Execution) 5.7±0.22µs 5.7±0.26µs 0.00%
String copy (Execution) 4.5±0.26µs 4.3±0.17µs +4.65%
Symbols (Execution) 3.9±0.19µs 3.9±0.12µs 0.00%

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working execution Issues or PRs related to code execution technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected output in unsigned right shift
2 participants