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

Implement runtime limits for recursion #2904

Merged
merged 4 commits into from
May 5, 2023
Merged

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented May 5, 2023

This Pull Request fixes/closes #809 and fixes/closes #1307 and related to #2350 .

It changes the following:

  • Adds runtime limits on recursion
  • Adds getter & setter to $boa.limits module for debugging
  • Add test and example

Like #2857 the recursion limit can be controlled through the .runtime_limits():

context.runtime_limits_mut().set_recursion_limit(123); // Set to an arbitrary number

Or using the $boa object for debugging:

$boa.limits.recursion = 123

function x() {
    x()
}

x() // RuntimeLimit: maximum recursion limit 123 exceeded

Tried different values 400 seemed to not cause a stack-overflow, while 500 did, so I set it to 400. This is in debug mode, In release we could probably set it to a higher value.

Removed "tail-call-optimization" feature from test262 ignore list, because it no longer causes a stack-overflow :)

Currently the way we do calls requires us to recurse in rust, this is not the ideal approach, we need to refactor it! That's why we are limited by our native stack size instead of heap size. This issue does not prevent this PR from being merged though.

I'll work on refactoring the way we call functions in a separate PR :)

@HalidOdat HalidOdat added enhancement New feature or request execution Issues or PRs related to code execution labels May 5, 2023
@HalidOdat HalidOdat added this to the v0.17.0 milestone May 5, 2023
@HalidOdat HalidOdat requested a review from a team May 5, 2023 19:07
@github-actions
Copy link

github-actions bot commented May 5, 2023

Test262 conformance changes

Test result main count PR count difference
Total 94,601 94,601 0
Passed 73,328 73,329 +1
Ignored 17,540 17,505 -35
Failed 3,733 3,767 +34
Panics 0 0 0
Conformance 77.51% 77.51% +0.00%
Fixed tests (1):
test/built-ins/Proxy/revocable/tco-fn-realm.js [strict mode] (previously Ignored)

@codecov
Copy link

codecov bot commented May 5, 2023

Codecov Report

Merging #2904 (07b64b5) into main (990e4df) will decrease coverage by 0.06%.
The diff coverage is 18.51%.

@@            Coverage Diff             @@
##             main    #2904      +/-   ##
==========================================
- Coverage   51.88%   51.82%   -0.06%     
==========================================
  Files         431      431              
  Lines       43230    43302      +72     
==========================================
+ Hits        22429    22443      +14     
- Misses      20801    20859      +58     
Impacted Files Coverage Δ
boa_cli/src/debug/limits.rs 0.00% <0.00%> (ø)
boa_examples/src/bin/runtime_limits.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/new/mod.rs 61.22% <16.66%> (-14.46%) ⬇️
boa_engine/src/vm/opcode/call/mod.rs 48.30% <33.33%> (-3.83%) ⬇️
boa_engine/src/vm/opcode/iteration/loop_ops.rs 100.00% <100.00%> (ø)
boa_engine/src/vm/runtime_limits.rs 73.33% <100.00%> (+9.69%) ⬆️

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.

It looks great to me! I'm only missing the test and example, as you mention :)

@HalidOdat HalidOdat requested a review from Razican May 5, 2023 20:09
@Razican Razican requested a review from a team May 5, 2023 20:42
Copy link
Member

@raskad raskad 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!

@raskad raskad added this pull request to the merge queue May 5, 2023
Merged via the queue into main with commit b4b77e7 May 5, 2023
@raskad raskad deleted the feature/recursion-runtime-limit branch May 5, 2023 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some Test262 tests can cause a stack overflow Implement call stack size tracking
3 participants