Closed
Bug 257128
Opened 20 years ago
Closed 20 years ago
Interpreter and tail call elimination
Categories
(Rhino Graveyard :: Core, enhancement)
Tracking
(Not tracked)
RESOLVED
FIXED
1.6R1
People
(Reporter: igor, Assigned: igor)
Details
Attachments
(2 files, 1 obsolete file)
201 bytes,
text/plain
|
Details | |
48.73 KB,
patch
|
Details | Diff | Splinter Review |
Given that interpreter do not use Java stack frames for JS (see bug 256339) it
is only natural to support at least minimal form of tail call elimination so
tail call recursion in JS would require only constant amount of memory.
Assignee | ||
Comment 1•20 years ago
|
||
The code generation of the patch is straightforward. It adds context flags to
visitExpression which defaults to 0 indicating generic context if node does not
know what to do about it. Then during generation of Token.RETURN the patch
calls visitExpression with ECF_TAIL flag to indicate the context. Then
Token.COMMA, Token.HOOK, Token.AND and Token.OR preserve the flag for tail call
operands and when Token.CALL gets the flag it uses Icode_TAIL_CALL instead of
Token.CALL to indicate tail call.
The runtime part was more tricky since initially I tries to implement state and
its stack arrays reuse. But this is too complex due to possible exceptions
during state reinitialization (see comments in the patch) )so at the end the
difference between tail and ordinary call in the patch is that the tail call
release its parent and would transfer control on return to its grandparent
instead.
Assignee | ||
Comment 2•20 years ago
|
||
Without tail call recursion eleimination the test case would create 20_000_000
JS stack frames and even stackless interpreter would give up with OutOfMemory.
With the patch applied the test case finishes after about 45s on my Athlon
1.2MHz Fedora box.
Assignee | ||
Comment 3•20 years ago
|
||
The previous patch contains a bug: Interpreter.interpret would use initial
state to extract interpretation result but after tail call that state was never
updated with the result. The solution is to return the final state for the
result extraction.
Attachment #157149 -
Attachment is obsolete: true
Assignee | ||
Comment 4•20 years ago
|
||
I committed the patch
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Target Milestone: --- → 1.5R6
You need to log in
before you can comment on or make changes to this bug.
Description
•