From af863fcfe180c54aac8fb5cc1f0211a3ad8664a4 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Tue, 23 Mar 2021 12:30:52 -0500 Subject: [PATCH] Remove RubyContext from Translator --- .../org/truffleruby/parser/BodyTranslator.java | 15 +++++++++------ .../parser/LoadArgumentsTranslator.java | 6 +++--- .../org/truffleruby/parser/MethodTranslator.java | 13 ++++++------- .../org/truffleruby/parser/ParseEnvironment.java | 5 +++++ .../parser/ReloadArgumentsTranslator.java | 6 +++--- .../java/org/truffleruby/parser/Translator.java | 7 ++----- .../org/truffleruby/parser/TranslatorDriver.java | 2 +- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/truffleruby/parser/BodyTranslator.java b/src/main/java/org/truffleruby/parser/BodyTranslator.java index d44ca0287f13..47d0bda18123 100644 --- a/src/main/java/org/truffleruby/parser/BodyTranslator.java +++ b/src/main/java/org/truffleruby/parser/BodyTranslator.java @@ -290,14 +290,14 @@ public class BodyTranslator extends Translator { protected String currentCallMethodName = null; public BodyTranslator( - RubyContext context, + RubyLanguage language, BodyTranslator parent, TranslatorEnvironment environment, Source source, ParserContext parserContext, Node currentNode, RubyDeferredWarnings rubyWarnings) { - super(context, source, parserContext, currentNode); + super(language, source, parserContext, currentNode); this.parent = parent; this.environment = environment; this.rubyWarnings = rubyWarnings; @@ -1032,7 +1032,7 @@ private RubyNode openModule(SourceIndexLength sourceSection, RubyNode defineOrGe modulePath); final BodyTranslator moduleTranslator = new BodyTranslator( - context, + language, this, newEnvironment, source, @@ -1482,7 +1482,7 @@ protected RubyNode translateMethodDefinition(SourceIndexLength sourceSection, Ru // ownScopeForAssignments is the same for the defined method as the current one. final MethodTranslator methodCompiler = new MethodTranslator( - context, + language, this, newEnvironment, false, @@ -1997,7 +1997,7 @@ private RubyNode translateBlockLikeNode(IterParseNode node, boolean isLambda) { TranslatorEnvironment.newFrameDescriptor(), environment.modulePath); final MethodTranslator methodCompiler = new MethodTranslator( - context, + language, this, newEnvironment, true, @@ -3097,7 +3097,10 @@ private RubyNode addNewlineIfNeeded(ParseNode jrubyNode, RubyNode node) { if (environment.getParseEnvironment().isCoverageEnabled()) { node.unsafeSetIsCoverageLine(); - context.getCoverageManager().setLineHasCode(source, current.toSourceSection(source).getStartLine()); + environment.getParseEnvironment().contextIfSingleContext + .get() + .getCoverageManager() + .setLineHasCode(source, current.toSourceSection(source).getStartLine()); } node.unsafeSetIsNewLine(); } diff --git a/src/main/java/org/truffleruby/parser/LoadArgumentsTranslator.java b/src/main/java/org/truffleruby/parser/LoadArgumentsTranslator.java index ebe8bbdbbb50..c8bae9a4a6d5 100644 --- a/src/main/java/org/truffleruby/parser/LoadArgumentsTranslator.java +++ b/src/main/java/org/truffleruby/parser/LoadArgumentsTranslator.java @@ -16,7 +16,7 @@ import java.util.List; import com.oracle.truffle.api.frame.FrameSlotKind; -import org.truffleruby.RubyContext; +import org.truffleruby.RubyLanguage; import org.truffleruby.core.IsNilNode; import org.truffleruby.core.array.ArrayIndexNodes; import org.truffleruby.core.array.ArrayLiteralNode; @@ -109,13 +109,13 @@ private enum State { public LoadArgumentsTranslator( Node currentNode, ArgsParseNode argsNode, - RubyContext context, + RubyLanguage language, Source source, ParserContext parserContext, boolean isProc, boolean isMethod, BodyTranslator methodBodyTranslator) { - super(context, source, parserContext, currentNode); + super(language, source, parserContext, currentNode); this.isProc = isProc; this.isMethod = isMethod; this.methodBodyTranslator = methodBodyTranslator; diff --git a/src/main/java/org/truffleruby/parser/MethodTranslator.java b/src/main/java/org/truffleruby/parser/MethodTranslator.java index d01f7b793034..b9c6864fcc42 100644 --- a/src/main/java/org/truffleruby/parser/MethodTranslator.java +++ b/src/main/java/org/truffleruby/parser/MethodTranslator.java @@ -12,7 +12,6 @@ import java.util.Arrays; import java.util.function.Supplier; -import org.truffleruby.RubyContext; import org.truffleruby.RubyLanguage; import org.truffleruby.collections.CachedSupplier; import org.truffleruby.core.IsNilNode; @@ -76,7 +75,7 @@ public class MethodTranslator extends BodyTranslator { private final String methodNameForBlock; public MethodTranslator( - RubyContext context, + RubyLanguage language, BodyTranslator parent, TranslatorEnvironment environment, boolean isBlock, @@ -86,7 +85,7 @@ public MethodTranslator( ArgsParseNode argsNode, String methodNameForBlock, RubyDeferredWarnings rubyWarnings) { - super(context, parent, environment, source, parserContext, currentNode, rubyWarnings); + super(language, parent, environment, source, parserContext, currentNode, rubyWarnings); this.isBlock = isBlock; this.argsNode = argsNode; this.methodNameForBlock = methodNameForBlock; @@ -121,7 +120,7 @@ public BlockDefinitionNode compileBlockNode(SourceIndexLength sourceSection, Par final RubyNode loadArguments = new LoadArgumentsTranslator( currentNode, argsNode, - context, + language, source, parserContext, !isStabbyLambda, @@ -217,7 +216,7 @@ private RubyNode preludeProc( final LoadArgumentsTranslator destructureArgumentsTranslator = new LoadArgumentsTranslator( currentNode, argsNode, - context, + language, source, parserContext, !isStabbyLambda, @@ -390,7 +389,7 @@ public RubyNode compileMethodBody(SourceIndexLength sourceSection, ParseNode bod final RubyNode loadArguments = new LoadArgumentsTranslator( currentNode, argsNode, - context, + language, source, parserContext, false, @@ -504,7 +503,7 @@ public RubyNode visitZSuperNode(ZSuperParseNode node) { } final ReloadArgumentsTranslator reloadTranslator = new ReloadArgumentsTranslator( - context, + language, source, parserContext, currentNode, diff --git a/src/main/java/org/truffleruby/parser/ParseEnvironment.java b/src/main/java/org/truffleruby/parser/ParseEnvironment.java index b2b34e9a5101..2807579b71f0 100644 --- a/src/main/java/org/truffleruby/parser/ParseEnvironment.java +++ b/src/main/java/org/truffleruby/parser/ParseEnvironment.java @@ -9,12 +9,15 @@ */ package org.truffleruby.parser; +import org.truffleruby.RubyContext; import org.truffleruby.RubyLanguage; import org.truffleruby.SuppressFBWarnings; import org.truffleruby.language.LexicalScope; import org.truffleruby.language.control.BreakID; import org.truffleruby.language.control.ReturnID; +import java.util.Optional; + /** Translator environment, unique per parse/translation. */ public class ParseEnvironment { @@ -23,10 +26,12 @@ public class ParseEnvironment { public boolean allowTruffleRubyPrimitives = false; private final String corePath; private final boolean coverageEnabled; + public final Optional contextIfSingleContext; public ParseEnvironment(RubyLanguage language) { corePath = language.corePath; coverageEnabled = language.contextIfSingleContext.map(c -> c.getCoverageManager().isEnabled()).orElse(false); + contextIfSingleContext = language.contextIfSingleContext; } public String getCorePath() { diff --git a/src/main/java/org/truffleruby/parser/ReloadArgumentsTranslator.java b/src/main/java/org/truffleruby/parser/ReloadArgumentsTranslator.java index eb400360be84..d350211b2871 100644 --- a/src/main/java/org/truffleruby/parser/ReloadArgumentsTranslator.java +++ b/src/main/java/org/truffleruby/parser/ReloadArgumentsTranslator.java @@ -12,7 +12,7 @@ import java.util.ArrayList; import java.util.List; -import org.truffleruby.RubyContext; +import org.truffleruby.RubyLanguage; import org.truffleruby.core.hash.ConcatHashLiteralNode; import org.truffleruby.core.hash.HashLiteralNode; import org.truffleruby.language.RubyNode; @@ -46,12 +46,12 @@ public class ReloadArgumentsTranslator extends Translator { private int restParameterIndex = -1; public ReloadArgumentsTranslator( - RubyContext context, + RubyLanguage language, Source source, ParserContext parserContext, Node currentNode, BodyTranslator methodBodyTranslator) { - super(context, source, parserContext, currentNode); + super(language, source, parserContext, currentNode); this.methodBodyTranslator = methodBodyTranslator; } diff --git a/src/main/java/org/truffleruby/parser/Translator.java b/src/main/java/org/truffleruby/parser/Translator.java index ebbbb6432aff..599a6efd70af 100644 --- a/src/main/java/org/truffleruby/parser/Translator.java +++ b/src/main/java/org/truffleruby/parser/Translator.java @@ -13,7 +13,6 @@ import java.util.Arrays; import java.util.List; -import org.truffleruby.RubyContext; import org.truffleruby.RubyLanguage; import org.truffleruby.language.RubyNode; import org.truffleruby.language.SourceIndexLength; @@ -37,15 +36,13 @@ public abstract class Translator extends AbstractNodeVisitor { - protected final RubyContext context; protected final Source source; protected final ParserContext parserContext; protected final Node currentNode; protected final RubyLanguage language; - public Translator(RubyContext context, Source source, ParserContext parserContext, Node currentNode) { - this.context = context; - this.language = context.getLanguageSlow(); + public Translator(RubyLanguage language, Source source, ParserContext parserContext, Node currentNode) { + this.language = language; this.source = source; this.parserContext = parserContext; this.currentNode = currentNode; diff --git a/src/main/java/org/truffleruby/parser/TranslatorDriver.java b/src/main/java/org/truffleruby/parser/TranslatorDriver.java index 9b132818939b..b17ec12eebd2 100644 --- a/src/main/java/org/truffleruby/parser/TranslatorDriver.java +++ b/src/main/java/org/truffleruby/parser/TranslatorDriver.java @@ -250,7 +250,7 @@ public RubyRootNode parse(RubySource rubySource, ParserContext parserContext, St } final BodyTranslator translator = new BodyTranslator( - context, + language, null, environment, source,