Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Make sure to resolve only once a LazyRubyNode.
Browse files Browse the repository at this point in the history
eregon committed Jan 10, 2017
1 parent 8dcc422 commit d87a727
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
public class LazyRubyNode extends RubyNode {

private final Supplier<RubyNode> resolver;
private RubyNode resolved = null;

public LazyRubyNode(Supplier<RubyNode> resolver) {
this.resolver = resolver;
@@ -42,13 +43,16 @@ protected boolean isTaggedWith(Class<?> tag) {

public RubyNode resolve() {
CompilerDirectives.transferToInterpreterAndInvalidate();

return atomic(() -> {
if (resolved != null) {
return resolved;
}

if (getContext().getOptions().LAZY_TRANSLATION_LOG) {
Log.LOGGER.info(() -> "lazy translating " + RubyLanguage.fileLine(getParent().getEncapsulatingSourceSection()));
}

final RubyNode resolved = resolver.get();
resolved = resolver.get();
replace(resolved, "lazy node resolved");
return resolved;
});

0 comments on commit d87a727

Please sign in to comment.