fix(vm): make loop iteration limit consistent across loop kinds - #5464
Open
mansiverma897993 wants to merge 1 commit into
Open
fix(vm): make loop iteration limit consistent across loop kinds#5464mansiverma897993 wants to merge 1 commit into
mansiverma897993 wants to merge 1 commit into
Conversation
With `set_loop_iteration_limit(10)`, a `for` loop body ran 12 times and a `while` loop body 11 times before the limit error was raised. Two bugs compounded: - `IncrementLoopIteration` only errored when the counter was strictly greater than the limit, allowing one extra iteration. - `for` loops jumped over the `IncrementLoopIteration` opcode on the first iteration, so it was never counted. Emit `IncrementLoopIteration` after the condition/done check and before the body in all loop kinds (for, while, do-while, for-in, for-of), and error once the counter reaches the limit. A limit of N now allows exactly N body executions for every loop kind, and loops that finish within the limit never raise a limit error. Fixes boa-dev#5461
Test262 conformance changes
Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5464 +/- ##
===========================================
+ Coverage 47.24% 62.88% +15.63%
===========================================
Files 476 530 +54
Lines 46892 59102 +12210
===========================================
+ Hits 22154 37166 +15012
+ Misses 24738 21936 -2802 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request fixes/closes #5461.
With
set_loop_iteration_limit(10), aforloop body ran 12 times and awhileloop body ran 11 times before theRuntimeLimiterror was raised. Two bugs compounded:IncrementLoopIterationonly raised the error when the counter was strictly greater than the limit, which allows one extra iteration for every loop kind.forloops jumped over theirIncrementLoopIterationopcode on the first pass (the initial jump into the loop lands after it, since it must skip the per-iteration binding copy and the final expression), so the first iteration was never counted.It changes the following:
IncrementLoopIterationnow raises the limit error when the counter reaches the limit instead of one past it.IncrementLoopIterationafter the condition/done check and right before the loop body for all loop kinds (for,while,do-while,for-in,for-of). This means the limit counts actual body executions: a limit of N allows exactly N body executions for every loop kind, and loops that finish within the limit (e.g.for (let i = 0; i < 10; ++i)with limit 10, or afor-ofover a 10-element array) never raise a limit error.limitbody executions and agree with each other, and regenerates the affectedinsta-bytecodesnapshots.