Skip to content

Commit ab586f8

Browse files
committed
Remove usages of lookupContextReference()
1 parent d69729e commit ab586f8

File tree

8 files changed

+22
-55
lines changed

8 files changed

+22
-55
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import com.oracle.truffle.api.frame.FrameDescriptor;
1414
import com.oracle.truffle.api.nodes.RootNode;
1515
import com.oracle.truffle.api.source.SourceSection;
16+
import org.truffleruby.RubyContext;
17+
import org.truffleruby.RubyLanguage;
1618
import org.truffleruby.core.CoreLibrary;
1719

1820
public abstract class RubyBaseRootNode extends RootNode {
@@ -48,4 +50,12 @@ public boolean countsTowardsStackTraceLimit() {
4850
// Entries with a java source section should not count towards the limit, even though they're not internal.
4951
return !isInternal() && sourceSection != CoreLibrary.JAVA_CORE_SOURCE_SECTION;
5052
}
53+
54+
public final RubyLanguage getLanguage() {
55+
return RubyLanguage.get(this);
56+
}
57+
58+
public final RubyContext getContext() {
59+
return RubyContext.get(this);
60+
}
5161
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.truffleruby.language;
1111

1212
import com.oracle.truffle.api.CompilerAsserts;
13-
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
1413
import com.oracle.truffle.api.nodes.Node;
1514
import org.truffleruby.RubyContext;
1615
import org.truffleruby.RubyLanguage;
@@ -56,28 +55,24 @@ protected void checkArity(VirtualFrame frame) {
5655
arityForCheck,
5756
RubyArguments.getArgumentsCount(frame),
5857
checkArityProfile,
59-
getContextReference(),
6058
this);
6159
} else {
62-
checkKeywordArityNode.checkArity(frame, arityForCheck, checkArityProfile, language, getContextReference());
60+
checkKeywordArityNode.checkArity(frame, arityForCheck, checkArityProfile);
6361
}
6462
}
6563

6664
public static void checkArity(Arity arity, int given,
6765
BranchProfile checkFailedProfile,
68-
ContextReference<RubyContext> contextRef,
6966
Node currentNode) {
7067
CompilerAsserts.partialEvaluationConstant(arity);
7168
if (!arity.check(given)) {
7269
checkFailedProfile.enter();
73-
checkArityError(arity, given, contextRef, currentNode);
70+
checkArityError(arity, given, currentNode);
7471
}
7572
}
7673

77-
private static void checkArityError(Arity arity, int given,
78-
ContextReference<RubyContext> contextRef,
79-
Node currentNode) {
80-
final RubyContext context = contextRef.get();
74+
private static void checkArityError(Arity arity, int given, Node currentNode) {
75+
final RubyContext context = RubyContext.get(currentNode);
8176
if (arity.hasRest()) {
8277
throw new RaiseException(
8378
context,

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

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

12-
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
1312
import org.jcodings.specific.UTF8Encoding;
1413
import org.truffleruby.RubyContext;
1514
import org.truffleruby.RubyLanguage;
@@ -19,16 +18,13 @@
1918
import org.truffleruby.core.string.StringOperations;
2019
import org.truffleruby.language.backtrace.InternalRootNode;
2120

22-
import com.oracle.truffle.api.CompilerDirectives;
23-
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
2421
import com.oracle.truffle.api.frame.VirtualFrame;
2522
import com.oracle.truffle.api.source.Source;
2623

2724
public class RubyEvalInteractiveRootNode extends RubyBaseRootNode implements InternalRootNode {
2825

2926
private final Rope sourceRope;
3027

31-
@CompilationFinal private ContextReference<RubyContext> contextReference;
3228
private final RubyLanguage language;
3329

3430
public RubyEvalInteractiveRootNode(RubyLanguage language, Source source) {
@@ -39,11 +35,7 @@ public RubyEvalInteractiveRootNode(RubyLanguage language, Source source) {
3935

4036
@Override
4137
public Object execute(VirtualFrame frame) {
42-
if (contextReference == null) {
43-
CompilerDirectives.transferToInterpreterAndInvalidate();
44-
contextReference = lookupContextReference(RubyLanguage.class);
45-
}
46-
final RubyContext context = contextReference.get();
38+
final RubyContext context = getContext();
4739

4840
// Just do Truffle::Boot::INTERACTIVE_BINDING.eval(code) for interactive sources.
4941
// It's the semantics we want and takes care of caching correctly based on the Binding's FrameDescriptor.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public RubyLambdaRootNode(
6666

6767
public RubyLambdaRootNode copyRootNode(SharedMethodInfo newSharedMethodInfo, RubyNode newBody) {
6868
return new RubyLambdaRootNode(
69-
language,
69+
getLanguage(),
7070
getSourceSection(),
7171
getFrameDescriptor(),
7272
newSharedMethodInfo,

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

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

12-
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
1312
import org.truffleruby.RubyContext;
1413
import org.truffleruby.RubyLanguage;
1514
import org.truffleruby.language.arguments.RubyArguments;
@@ -32,14 +31,12 @@
3231

3332
public class RubyParsingRequestNode extends RubyBaseRootNode implements InternalRootNode {
3433

35-
private final ContextReference<RubyContext> contextReference;
3634
private final RootCallTarget callTarget;
3735

3836
@Child private DirectCallNode callNode;
3937

4038
public RubyParsingRequestNode(RubyLanguage language, RubyContext context, Source source, String[] argumentNames) {
4139
super(language, null, null);
42-
this.contextReference = lookupContextReference(RubyLanguage.class);
4340

4441
final RubySource rubySource = new RubySource(source, language.getSourcePath(source));
4542

@@ -59,8 +56,8 @@ public RubyParsingRequestNode(RubyLanguage language, RubyContext context, Source
5956

6057
@Override
6158
public Object execute(VirtualFrame frame) {
62-
final RubyLanguage language = getLanguage(RubyLanguage.class);
63-
final RubyContext context = contextReference.get();
59+
final RubyLanguage language = getLanguage();
60+
final RubyContext context = getContext();
6461

6562
final SharedMethodInfo sharedMethodInfo = RubyRootNode.of(callTarget).getSharedMethodInfo();
6663
assert sharedMethodInfo.getStaticLexicalScopeOrNull() == context.getRootLexicalScope() ||

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
*/
1010
package org.truffleruby.language;
1111

12-
import com.oracle.truffle.api.CompilerDirectives;
13-
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
1412
import com.oracle.truffle.api.RootCallTarget;
15-
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
1613
import com.oracle.truffle.api.dsl.NodeFactory;
1714
import com.oracle.truffle.api.nodes.NodeUtil;
18-
import org.truffleruby.RubyContext;
1915
import org.truffleruby.RubyLanguage;
2016
import org.truffleruby.builtins.ReRaiseInlinedExceptionNode;
2117
import org.truffleruby.language.control.ReturnID;
@@ -32,9 +28,6 @@ public static RubyRootNode of(RootCallTarget callTarget) {
3228
return (RubyRootNode) callTarget.getRootNode();
3329
}
3430

35-
protected final RubyLanguage language;
36-
@CompilationFinal private ContextReference<RubyContext> contextReference;
37-
3831
private final SharedMethodInfo sharedMethodInfo;
3932
private Split split;
4033
public final ReturnID returnID;
@@ -53,7 +46,6 @@ public RubyRootNode(
5346
assert sourceSection != null;
5447
assert body != null;
5548

56-
this.language = language;
5749
this.sharedMethodInfo = sharedMethodInfo;
5850
this.body = body;
5951
this.split = split;
@@ -112,17 +104,4 @@ public RubyNode copyBody() {
112104
return NodeUtil.cloneNode(body);
113105
}
114106

115-
public final ContextReference<RubyContext> getContextReference() {
116-
if (contextReference == null) {
117-
CompilerDirectives.transferToInterpreterAndInvalidate();
118-
contextReference = lookupContextReference(RubyLanguage.class);
119-
}
120-
121-
return contextReference;
122-
}
123-
124-
public final RubyContext getContext() {
125-
return getContextReference().get();
126-
}
127-
128107
}

src/main/java/org/truffleruby/language/arguments/CheckKeywordArityNode.java

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

1212
import com.oracle.truffle.api.CompilerAsserts;
1313
import com.oracle.truffle.api.CompilerDirectives;
14-
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
15-
import org.truffleruby.RubyContext;
1614
import org.truffleruby.RubyLanguage;
1715
import org.truffleruby.core.hash.RubyHash;
1816
import org.truffleruby.core.hash.library.HashStoreLibrary;
@@ -42,9 +40,7 @@ public CheckKeywordArityNode(Arity arity) {
4240
}
4341

4442
public void checkArity(VirtualFrame frame, Arity arity,
45-
BranchProfile basicArityCheckFailedProfile,
46-
RubyLanguage language,
47-
ContextReference<RubyContext> contextRef) {
43+
BranchProfile basicArityCheckFailedProfile) {
4844
CompilerAsserts.partialEvaluationConstant(arity);
4945

5046
final RubyHash keywordArguments = readUserKeywordsHashNode.execute(frame);
@@ -59,13 +55,11 @@ public void checkArity(VirtualFrame frame, Arity arity,
5955

6056
if (!arity.basicCheck(given)) {
6157
basicArityCheckFailedProfile.enter();
62-
throw new RaiseException(
63-
contextRef.get(),
64-
contextRef.get().getCoreExceptions().argumentError(given, arity.getRequired(), this));
58+
throw new RaiseException(getContext(), coreExceptions().argumentError(given, arity.getRequired(), this));
6559
}
6660

6761
if (!arity.hasKeywordsRest() && keywordArguments != null) {
68-
checkKeywordArguments(argumentsCount, keywordArguments, arity, language);
62+
checkKeywordArguments(argumentsCount, keywordArguments, arity, getLanguage());
6963
}
7064
}
7165

src/main/java/org/truffleruby/language/methods/CallInternalMethodNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected Object alwaysInlined(
9090

9191
try {
9292
RubyCheckArityRootNode
93-
.checkArity(cachedArity, args.length, checkArityProfile, contextRef, alwaysInlinedNode);
93+
.checkArity(cachedArity, args.length, checkArityProfile, alwaysInlinedNode);
9494

9595
return alwaysInlinedNode.execute(frame, self, args, block, cachedCallTarget);
9696
} catch (RaiseException e) {

0 commit comments

Comments
 (0)