Skip to content

Commit

Permalink
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -9,18 +9,21 @@
*/
package org.jruby.truffle.language.control;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.AssumedValue;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

/**
* Executes a child node just once, and uses the same value each subsequent time the node is exeuted.
*/
public class OnceNode extends RubyNode {

@Child private RubyNode child;

// TODO(CS): need to always copy this with cloned nodes
private final AssumedValue<Object> valueMemo = new AssumedValue<>("OnceNode", null);
private final AssumedValue<Object> valueMemo = new AssumedValue<>(OnceNode.class.getName(), null);

public OnceNode(RubyContext context, SourceSection sourceSection, RubyNode child) {
super(context, sourceSection);
@@ -32,10 +35,12 @@ public Object execute(VirtualFrame frame) {
Object value = valueMemo.get();

if (value == null) {
CompilerDirectives.transferToInterpreter();

This comment has been minimized.

Copy link
@eregon

eregon Feb 24, 2016

Member

AndInvalidate() ? It would make it clearer that value cannot be compiled as null.

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Feb 24, 2016

Author Contributor

Technically that's done by the assumed value node, but I think you're arguing for it for code clarity. I disagree - the only thing that's required here is the transfer. If someone else has an @CompilationFinal and so needs to invalidate, that's their business to manage.

This comment has been minimized.

Copy link
@eregon

eregon Feb 24, 2016

Member

Indeed, I meant for clarity. Sounds fair.

value = child.execute(frame);
valueMemo.set(value);
}

return value;
}

}

0 comments on commit 6e3f361

Please sign in to comment.