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 destructive for-of loop assignments #2803

Closed
wants to merge 2 commits into from

Conversation

raskad
Copy link
Member

@raskad raskad commented Apr 10, 2023

This Pull Request changes the following:

  • Fix the assignment of variables in destructive for-of initializers.
  • Fix the environment handling in the compilation of for-of/in loops.
  • Close iterators in destructive for-of loop assignments, when the code throws during the assignment.

@raskad raskad added bug Something isn't working execution Issues or PRs related to code execution labels Apr 10, 2023
@raskad raskad added this to the v0.17.0 milestone Apr 10, 2023
@github-actions
Copy link

github-actions bot commented Apr 10, 2023

Test262 conformance changes

Test result main count PR count difference
Total 94,781 94,781 0
Passed 71,403 71,489 +86
Ignored 17,824 17,824 0
Failed 5,554 5,468 -86
Panics 0 0 0
Conformance 75.33% 75.43% +0.09%
Fixed tests (86):
test/language/expressions/assignment/dstr/array-elem-trlg-iter-rest-thrw-close-err.js [strict mode] (previously Failed)
test/language/expressions/assignment/dstr/array-elem-trlg-iter-rest-thrw-close-err.js (previously Failed)
test/language/expressions/assignment/dstr/array-rest-iter-thrw-close-err.js [strict mode] (previously Failed)
test/language/expressions/assignment/dstr/array-rest-iter-thrw-close-err.js (previously Failed)
test/language/expressions/assignment/dstr/array-elem-iter-thrw-close.js [strict mode] (previously Failed)
test/language/expressions/assignment/dstr/array-elem-iter-thrw-close.js (previously Failed)
test/language/expressions/assignment/dstr/array-elem-trlg-iter-list-thrw-close.js [strict mode] (previously Failed)
test/language/expressions/assignment/dstr/array-elem-trlg-iter-list-thrw-close.js (previously Failed)
test/language/expressions/assignment/dstr/array-elem-trlg-iter-rest-thrw-close.js [strict mode] (previously Failed)
test/language/expressions/assignment/dstr/array-elem-trlg-iter-rest-thrw-close.js (previously Failed)
test/language/expressions/assignment/dstr/array-rest-iter-thrw-close.js [strict mode] (previously Failed)
test/language/expressions/assignment/dstr/array-rest-iter-thrw-close.js (previously Failed)
test/language/expressions/assignment/dstr/array-elem-trlg-iter-list-thrw-close-err.js [strict mode] (previously Failed)
test/language/expressions/assignment/dstr/array-elem-trlg-iter-list-thrw-close-err.js (previously Failed)
test/language/expressions/assignment/dstr/array-elem-iter-thrw-close-err.js [strict mode] (previously Failed)
test/language/expressions/assignment/dstr/array-elem-iter-thrw-close-err.js (previously Failed)
test/language/expressions/assignment/dstr/array-rest-lref-err.js [strict mode] (previously Failed)
test/language/expressions/assignment/dstr/array-rest-lref-err.js (previously Failed)
test/language/statements/for-of/dstr/array-elem-init-yield-expr.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-init-yield-expr.js (previously Failed)
test/language/statements/for-of/dstr/obj-id-put-unresolvable-strict.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-prop-nested-array-yield-expr.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-prop-nested-array-yield-expr.js (previously Failed)
test/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close-err.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close-err.js (previously Failed)
test/language/statements/for-of/dstr/obj-prop-nested-obj-yield-expr.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-prop-nested-obj-yield-expr.js (previously Failed)
test/language/statements/for-of/dstr/obj-id-put-const.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-id-put-const.js (previously Failed)
test/language/statements/for-of/dstr/obj-id-init-yield-expr.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-id-init-yield-expr.js (previously Failed)
test/language/statements/for-of/dstr/array-rest-iter-thrw-close-err.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-rest-iter-thrw-close-err.js (previously Failed)
test/language/statements/for-of/dstr/array-rest-nested-obj-yield-expr.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-rest-nested-obj-yield-expr.js (previously Failed)
test/language/statements/for-of/dstr/array-rest-put-let.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-rest-put-let.js (previously Failed)
test/language/statements/for-of/dstr/array-rest-put-unresolvable-strict.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-iter-thrw-close.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-iter-thrw-close.js (previously Failed)
test/language/statements/for-of/dstr/obj-prop-put-let.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-prop-put-let.js (previously Failed)
test/language/statements/for-of/dstr/obj-prop-put-unresolvable-strict.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close.js (previously Failed)
test/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close.js (previously Failed)
test/language/statements/for-of/dstr/array-elem-put-let.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-put-let.js (previously Failed)
test/language/statements/for-of/dstr/array-elem-put-const.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-put-const.js (previously Failed)
test/language/statements/for-of/dstr/obj-prop-put-const.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-prop-put-const.js (previously Failed)
test/language/statements/for-of/dstr/array-rest-iter-thrw-close.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-rest-iter-thrw-close.js (previously Failed)
test/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close-err.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close-err.js (previously Failed)
test/language/statements/for-of/dstr/obj-prop-elem-init-yield-expr.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-prop-elem-init-yield-expr.js (previously Failed)
test/language/statements/for-of/dstr/array-elem-iter-thrw-close-err.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-iter-thrw-close-err.js (previously Failed)
test/language/statements/for-of/dstr/obj-id-put-let.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-id-put-let.js (previously Failed)
test/language/statements/for-of/dstr/array-elem-put-unresolvable-strict.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-rest-put-const.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/obj-rest-put-const.js (previously Failed)
test/language/statements/for-of/dstr/array-elem-nested-obj-yield-expr.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-elem-nested-obj-yield-expr.js (previously Failed)
test/language/statements/for-of/dstr/array-rest-put-const.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-rest-put-const.js (previously Failed)
test/language/statements/for-of/dstr/array-rest-lref-err.js [strict mode] (previously Failed)
test/language/statements/for-of/dstr/array-rest-lref-err.js (previously Failed)
test/language/statements/for-await-of/async-func-decl-dstr-array-elem-put-const.js [strict mode] (previously Failed)
test/language/statements/for-await-of/async-func-decl-dstr-array-elem-put-const.js (previously Failed)
test/language/statements/for-await-of/async-func-decl-dstr-obj-prop-put-unresolvable-no-strict.js (previously Failed)
test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-put-const.js [strict mode] (previously Failed)
test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-put-const.js (previously Failed)
test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-put-unresolvable-strict.js [strict mode] (previously Failed)
test/language/statements/for-await-of/async-gen-decl-dstr-obj-prop-put-unresolvable-no-strict.js (previously Failed)
test/language/statements/for-await-of/async-func-decl-dstr-array-elem-put-unresolvable-strict.js [strict mode] (previously Failed)
test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-trlg-iter-rest-nrml-close-skip.js [strict mode] (previously Failed)
test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-trlg-iter-rest-nrml-close-skip.js (previously Failed)
test/language/statements/for-await-of/async-gen-decl-dstr-obj-id-put-unresolvable-no-strict.js (previously Failed)
test/language/statements/for-await-of/async-gen-decl-dstr-obj-id-simple-no-strict.js (previously Failed)
test/language/statements/for-await-of/async-func-decl-dstr-obj-id-put-unresolvable-no-strict.js (previously Failed)
test/language/statements/for-await-of/async-func-decl-dstr-obj-id-simple-no-strict.js (previously Failed)

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! Just a small suggestion.

Comment on lines +71 to +77
context
.vm
.frame_mut()
.iterators
.last_mut()
.expect("iterator on the call frame must exist")
.1 = done;
Copy link
Member

Choose a reason for hiding this comment

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

Seeing that we're now storing the current iterator directly in the vm frame, maybe we should leverage that and remove pushing the iterator to the stack?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I also thought about that. I would push that until we have figured out how this works in all scenarios. This current closing of iterators works because it is limited to the destructing assignment iterators. We have to extend this to the iterators of the for-of loop itself too. When doing that we have to adjust for async iterators and control flows.
When we have solved those issues, I think we should be able to just switch over the iterator objects from the stack to the frame.

@codecov
Copy link

codecov bot commented Apr 10, 2023

Codecov Report

Merging #2803 (8850f3b) into main (1e75fd0) will decrease coverage by 0.06%.
The diff coverage is 60.99%.

@@            Coverage Diff             @@
##             main    #2803      +/-   ##
==========================================
- Coverage   51.40%   51.34%   -0.06%     
==========================================
  Files         416      416              
  Lines       41080    41312     +232     
==========================================
+ Hits        21117    21213      +96     
- Misses      19963    20099     +136     
Impacted Files Coverage Δ
boa_engine/src/vm/code_block.rs 61.22% <ø> (ø)
boa_engine/src/vm/flowgraph/mod.rs 0.00% <ø> (ø)
boa_engine/src/vm/opcode/mod.rs 45.45% <ø> (ø)
...rc/bytecompiler/declaration/declaration_pattern.rs 26.63% <11.76%> (-2.39%) ⬇️
boa_engine/src/vm/opcode/control_flow/throw.rs 83.51% <50.00%> (-3.07%) ⬇️
boa_engine/src/vm/opcode/iteration/iterator.rs 65.76% <68.85%> (+4.65%) ⬆️
boa_engine/src/bytecompiler/statement/loop.rs 82.00% <94.59%> (+3.25%) ⬆️
boa_engine/src/vm/call_frame/mod.rs 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

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

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.

Got it! We can revisit this later when we have more information about the execution patterns of for loops :)

Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

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

Looks great! :)

Just a small suggestion

boa_engine/src/vm/call_frame/mod.rs Outdated Show resolved Hide resolved
@raskad
Copy link
Member Author

raskad commented Apr 11, 2023

bors r+

bors bot pushed a commit that referenced this pull request Apr 11, 2023
This Pull Request changes the following:

- Fix the assignment of variables in destructive for-of initializers.
- Fix the environment handling in the compilation of `for-of/in` loops.
- Close iterators in destructive for-of loop assignments, when the code throws during the assignment.
@bors
Copy link

bors bot commented Apr 11, 2023

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Fix destructive for-of loop assignments [Merged by Bors] - Fix destructive for-of loop assignments Apr 11, 2023
@bors bors bot closed this Apr 11, 2023
@bors bors bot deleted the fix-destructive-for-of-iterator-assignments branch April 11, 2023 21:30
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants