You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It prints 3 5 2 3 2 2 3 2 3. It seems that all the inner lambda calls are incorrectly reusing the argument 1 (the argument of the first call to add), which is not expected.
I am new to Truffle, but I find that this is possibly related to LambdaNode. The LambdaNode captures the virtualFrame on the first call to getMumblerFunction, and then the lambda function is returned with this virtual frame. However, the virtual frame may change during subsequent calls to getMumblerFunction, leading to incorrect behavior.
So I just remove the scopeSet flag in LambdaNode.java:
@Specialization
public Object getMumblerFunction(VirtualFrame virtualFrame) {
- MumblerFunction function = this.getFunction();+ MumblerFunction function = new MumblerFunction(this.getFunction().callTarget);- if (!isScopeSet()) {- CompilerDirectives.transferToInterpreterAndInvalidate();- function.setLexicalScope(virtualFrame.materialize());- this.scopeSet = true;- }+ function.setLexicalScope(virtualFrame.materialize());
return function;
}
It gives the correct output 3 7 6 7 8 9 6 7 8 9. Is this the correct way to implement closure? Or is there a better way to implement closure for better performance?
The text was updated successfully, but these errors were encountered:
The current implementation of closures is producing incorrect results when executing closure-related code. Here's an example:
It prints
3 5 2 3 2 2 3 2 3
. It seems that all the inner lambda calls are incorrectly reusing the argument 1 (the argument of the first call to add), which is not expected.I am new to Truffle, but I find that this is possibly related to
LambdaNode
. TheLambdaNode
captures thevirtualFrame
on the first call togetMumblerFunction
, and then the lambda function is returned with this virtual frame. However, the virtual frame may change during subsequent calls togetMumblerFunction
, leading to incorrect behavior.So I just remove the scopeSet flag in
LambdaNode.java
:It gives the correct output
3 7 6 7 8 9 6 7 8 9
. Is this the correct way to implement closure? Or is there a better way to implement closure for better performance?The text was updated successfully, but these errors were encountered: