Skip to content

Commit 3c55574

Browse files
committed
Reduce usages of RubyLanguage#getCurrentContext()
1 parent a9dc560 commit 3c55574

File tree

6 files changed

+11
-22
lines changed

6 files changed

+11
-22
lines changed

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ protected RootCallTarget parse(ParsingRequest request) {
487487
? ParserContext.TOP_LEVEL_FIRST
488488
: ParserContext.TOP_LEVEL;
489489
final LexicalScope lexicalScope = contextIfSingleContext.map(RubyContext::getRootLexicalScope).orElse(null);
490-
return RubyLanguage.getCurrentContext().getCodeLoader().parse(
490+
return getCurrentContext().getCodeLoader().parse(
491491
rubySource,
492492
parserContext,
493493
null,

src/main/java/org/truffleruby/core/format/FormatEncoding.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.oracle.truffle.api.CompilerDirectives;
1919
import org.truffleruby.RubyContext;
20-
import org.truffleruby.RubyLanguage;
2120
import org.truffleruby.core.encoding.Encodings;
2221
import org.truffleruby.core.encoding.RubyEncoding;
2322
import org.truffleruby.language.control.RaiseException;
@@ -61,7 +60,7 @@ public static FormatEncoding find(Encoding encoding, Node currentNode) {
6160
}
6261

6362
// TODO (kjmenard 17-Oct-18): This entire enum needs to be rethought since a format string can take on any encoding, not just the 3 codified here.
64-
RubyContext context = RubyLanguage.getCurrentContext();
63+
RubyContext context = RubyContext.get(currentNode);
6564
throw new RaiseException(
6665
context,
6766
context.getCoreExceptions().runtimeError("Can't find format encoding for " + encoding, currentNode));

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.oracle.truffle.api.profiles.ConditionProfile;
2727
import com.oracle.truffle.api.profiles.LoopConditionProfile;
2828
import org.truffleruby.RubyContext;
29-
import org.truffleruby.RubyLanguage;
3029
import org.truffleruby.builtins.CoreMethod;
3130
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
3231
import org.truffleruby.builtins.CoreMethodNode;
@@ -473,8 +472,6 @@ private void createAccessors(RubyModule module, Object[] names, Accessor accesso
473472
private void createAccessor(RubyModule module, String name, Accessor accessor, Visibility visibility,
474473
SourceSection sourceSection) {
475474
assert accessor != BOTH;
476-
final RubyContext context = RubyLanguage.getCurrentContext();
477-
final RubyLanguage language = context.getLanguageSlow();
478475
final Arity arity = accessor == READER ? Arity.NO_ARGUMENTS : Arity.ONE_REQUIRED;
479476
final String ivar = "@" + name;
480477
final String accessorName = accessor == READER ? name : name + "=";
@@ -494,7 +491,7 @@ private void createAccessor(RubyModule module, String name, Accessor accessor, V
494491
: GeneratedWriterNodeFactory.getInstance();
495492

496493
final RubyRootNode reRaiseRootNode = new RubyRootNode(
497-
language,
494+
getLanguage(),
498495
sourceSection,
499496
null,
500497
sharedMethodInfo,
@@ -504,7 +501,7 @@ private void createAccessor(RubyModule module, String name, Accessor accessor, V
504501
final RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(reRaiseRootNode);
505502

506503
final InternalMethod method = new InternalMethod(
507-
context,
504+
getContext(),
508505
sharedMethodInfo,
509506
LexicalScope.IGNORE,
510507
DeclarationContext.NONE,
@@ -518,7 +515,7 @@ private void createAccessor(RubyModule module, String name, Accessor accessor, V
518515
null,
519516
nil);
520517

521-
module.fields.addMethod(context, this, method);
518+
module.fields.addMethod(getContext(), this, method);
522519
}
523520
}
524521

@@ -545,10 +542,7 @@ protected Object attr(
545542
private void warnObsoletedBooleanArgument() {
546543
final UncachedWarningNode warningNode = UncachedWarningNode.INSTANCE;
547544
if (warningNode.shouldWarn()) {
548-
final SourceSection sourceSection = RubyLanguage
549-
.getCurrentContext()
550-
.getCallStack()
551-
.getTopMostUserSourceSection();
545+
final SourceSection sourceSection = getContext().getCallStack().getTopMostUserSourceSection();
552546
warningNode.warningMessage(sourceSection, "optional boolean argument is obsoleted");
553547
}
554548
}

src/main/java/org/truffleruby/interop/TranslateInteropRubyExceptionNode.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
1313
import com.oracle.truffle.api.interop.UnknownKeyException;
14-
import org.truffleruby.RubyContext;
15-
import org.truffleruby.RubyLanguage;
1614
import org.truffleruby.core.cast.IntegerCastNode;
1715
import org.truffleruby.core.exception.RubyException;
1816
import org.truffleruby.language.RubyBaseNode;
@@ -166,12 +164,11 @@ protected AssertionError fallback(RaiseException exception, long index, String i
166164

167165
@TruffleBoundary
168166
protected AssertionError handleBadErrorType(InteropException e, RaiseException rubyException) {
169-
RubyContext context = RubyLanguage.getCurrentContext();
170-
final RubyException exception = context.getCoreExceptions().runtimeError(
167+
final RubyException exception = coreExceptions().runtimeError(
171168
Utils.concat("Wrong exception raised from a Ruby method implementing polyglot behavior: ", e),
172169
this);
173170
exception.cause = rubyException;
174-
throw new RaiseException(context, exception);
171+
throw new RaiseException(getContext(), exception);
175172
}
176173

177174
}

src/main/java/org/truffleruby/language/WarnNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ public static class UncachedWarnNode extends RubyBaseNode {
8484
}
8585

8686
public boolean shouldWarn() {
87-
return RubyLanguage.getCurrentContext().getCoreLibrary().warningsEnabled();
87+
return coreLibrary().warningsEnabled();
8888
}
8989

9090
public void warningMessage(SourceSection sourceSection, String message) {
9191
assert shouldWarn();
9292
WarnNode.callWarn(
93-
RubyLanguage.getCurrentContext(),
93+
getContext(),
9494
sourceSection,
9595
message,
9696
MakeStringNode.getUncached(),

src/main/java/org/truffleruby/language/WarningNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
package org.truffleruby.language;
1111

12-
import org.truffleruby.RubyLanguage;
1312

1413
/** Warns only if $VERBOSE is true. Corresponds to Kernel#warn(message, uplevel: 1) if $VERBOSE, but in Java with a
1514
* given SourceSection. */
@@ -30,7 +29,7 @@ private UncachedWarningNode() {
3029

3130
@Override
3231
public boolean shouldWarn() {
33-
return RubyLanguage.getCurrentContext().getCoreLibrary().isVerbose();
32+
return coreLibrary().isVerbose();
3433
}
3534
}
3635

0 commit comments

Comments
 (0)