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

[Merged by Bors] - Fix order dependent execution in assignment. #2378

Closed
wants to merge 5 commits into from

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Oct 24, 2022

Fixes #1917 (fixes the code example given with the hashes)

Fixes the order dependent execution of assignment, so the following code works correctly:

function f(x) { console.log(x) } // used to check the order of execution
let a = [[]]

(f(1), a)[(f(2), 0)][(f(3), 0)] = (f(4), 123) // 🤮

Prints out:

1
2
3
4
123

As expected

This introduces some opcodes:

Besides the new opcodes, Some opcodes pop and push order of values on the stack have been changed. To eliminate many swaps and to make this change easier.

This PR is still a WIP and needs more refactoring

This is now ready for review/merge :)

@HalidOdat HalidOdat added bug Something isn't working execution Issues or PRs related to code execution vm Issues and PRs related to the Boa Virtual Machine. labels Oct 24, 2022
@HalidOdat HalidOdat marked this pull request as draft October 24, 2022 19:48
@github-actions
Copy link

github-actions bot commented Oct 24, 2022

Test262 conformance changes

Test result main count PR count difference
Total 93,789 93,789 0
Passed 69,271 69,279 +8
Ignored 18,352 18,352 0
Failed 6,166 6,158 -8
Panics 0 0 0
Conformance 73.86% 73.87% +0.01%
Fixed tests (8):
test/language/statements/for-await-of/async-gen-decl-dstr-obj-prop-elem-target-yield-expr.js [strict mode] (previously Failed)
test/language/statements/for-await-of/async-gen-decl-dstr-obj-prop-elem-target-yield-expr.js (previously Failed)
test/language/statements/class/super/in-constructor-superproperty-evaluation.js [strict mode] (previously Failed)
test/language/statements/class/super/in-constructor-superproperty-evaluation.js (previously Failed)
test/language/expressions/assignment/target-member-computed-reference-null.js [strict mode] (previously Failed)
test/language/expressions/assignment/target-member-computed-reference-null.js (previously Failed)
test/language/expressions/assignment/target-member-computed-reference-undefined.js [strict mode] (previously Failed)
test/language/expressions/assignment/target-member-computed-reference-undefined.js (previously Failed)

@codecov
Copy link

codecov bot commented Oct 24, 2022

Codecov Report

Merging #2378 (2e6f543) into main (18824ba) will increase coverage by 0.11%.
The diff coverage is 43.47%.

@@            Coverage Diff             @@
##             main    #2378      +/-   ##
==========================================
+ Coverage   39.59%   39.71%   +0.11%     
==========================================
  Files         307      307              
  Lines       23394    23437      +43     
==========================================
+ Hits         9264     9309      +45     
+ Misses      14130    14128       -2     
Impacted Files Coverage Δ
boa_engine/src/vm/opcode/define/class/getter.rs 0.00% <ø> (ø)
boa_engine/src/vm/opcode/define/class/method.rs 0.00% <ø> (ø)
boa_engine/src/vm/opcode/define/class/setter.rs 0.00% <ø> (ø)
boa_engine/src/vm/opcode/define/own_property.rs 86.66% <ø> (ø)
boa_engine/src/vm/opcode/delete/mod.rs 86.66% <ø> (ø)
boa_engine/src/vm/opcode/get/property.rs 70.00% <ø> (ø)
boa_engine/src/vm/opcode/mod.rs 66.66% <ø> (ø)
boa_engine/src/vm/opcode/set/private.rs 0.00% <0.00%> (ø)
boa_engine/src/bytecompiler/mod.rs 29.51% <41.90%> (+0.92%) ⬆️
boa_engine/src/vm/opcode/unary_ops/decrement.rs 76.92% <50.00%> (+7.69%) ⬆️
... and 33 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Razican Razican added this to the v0.17.0 milestone Oct 28, 2022
bors bot pushed a commit that referenced this pull request Oct 29, 2022
This Pull Request implements optional chains.

Example:

```Javascript
const adventurer = {
    name: 'Alice',
    cat: {
        name: 'Dinah'
    }
};

console.log(adventurer.cat?.name); // Dinah
console.log(adventurer.dog?.name); // undefined
```

Since I needed to implement `Opcode::RotateLeft`, and #2378 had an implementation for `Opcode::RotateRight`, I took the opportunity to integrate both ops into this PR (big thanks to @HalidOdat for the original implementation!).

This PR almost has 100% conformance for the `optional-chaining` test suite. However, there's this one [test](https://github.com/tc39/test262/blob/85373b4ce12a908f8fc517093d95cf2ed2f5ee6a/test/language/expressions/optional-chaining/member-expression.js) that can't be solved until we properly set function names for function expressions in object and class definitions.
@HalidOdat
Copy link
Member Author

Hopefully I can rebase and finish this by this weekend or next week.

@HalidOdat HalidOdat marked this pull request as ready for review October 30, 2022 12:24
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.

Looks good! This was a concerning issue that was blocking a 1.0 issue.

I would add a couple of tests. At least this one:

  arr[i++][i++] = i++;

Checking that the final length and the values in the array are correct. Also with the example in the PR, so that this doesn't break again :)

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.

Thank you!

Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Nice work!

@jedel1043
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Oct 30, 2022
Fixes #1917 (fixes the code example given with  the hashes)

Fixes the order dependent execution of assignment, so the following code works correctly:
```javascript
function f(x) { console.log(x) } // used to check the order of execution
let a = [[]]

(f(1), a)[(f(2), 0)][(f(3), 0)] = (f(4), 123) // 🤮
```
Prints out:
```bash
1
2
3
4
123
```
As expected

This introduces some opcodes:
 - ~~`Swap3`:  currently used only to keep some previous code working that needs refactoring.~~
 - ~~`RotateRight n`: Rotates the `n` top values from the top of the stack to the right by `1`.~~ Already added by #2390 

~~Besides the new opcodes,~~ Some opcodes pop and push order of values on the stack have been changed. To eliminate many swaps and to make this change easier.

~~This PR is still a WIP and needs more refactoring~~

This is now ready for review/merge :)
@bors
Copy link

bors bot commented Oct 30, 2022

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Fix order dependent execution in assignment. [Merged by Bors] - Fix order dependent execution in assignment. Oct 30, 2022
@bors bors bot closed this Oct 30, 2022
@bors bors bot deleted the fix/order-of-execution branch October 30, 2022 17:27
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 vm Issues and PRs related to the Boa Virtual Machine.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange issue with postfix increment and array indexing
5 participants