Skip to content

Commit

Permalink
[Truffle] Make sure to resolve only once a LazyRubyNode.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 10, 2017
1 parent 8dcc422 commit d87a727
Showing 1 changed file with 6 additions and 2 deletions.
Expand Up @@ -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;
Expand All @@ -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;
});
Expand Down

0 comments on commit d87a727

Please sign in to comment.