Skip to content

Commit d84da65

Browse files
committed
[GR-26844] Ignore refinements for Primitive.object_respond_to?
PullRequest: truffleruby/2080
2 parents e7a7f15 + 4fd9861 commit d84da65

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

src/main/.checkstyle_checks.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@
231231
<property name="format" value="CompilerDirectives\.transferToInterpreterAndInvalidate\(\);\s+\w+Node\s+=\s+(?!insert\()"/>
232232
<property name="message" value="Lazily initialized child nodes must be explicitly inserted into the AST."/>
233233
</module>
234+
<module name="RegexpMultiline">
235+
<property name="format" value="CompilerDirectives\.transferToInterpreterAndInvalidate\(\);\s+\w+\s+=\s+(?!insert\()\w+\.create\("/>
236+
<property name="message" value="Lazily initialized child nodes must be explicitly inserted into the AST."/>
237+
</module>
234238
<module name="RegexpHeader">
235239
<property name="header" value='/\*\n (\* Copyright \(c\) (20[0-9][0-9], )?20[0-9][0-9] Oracle and/or its affiliates\. All rights reserved\. This|\*\*\*\*\* BEGIN LICENSE BLOCK \*\*\*\*\*)\n (\* code is released under a tri EPL/GPL/LGPL license\. You can use it,|\* Version: EPL 2\.0/GPL 2\.0/LGPL 2\.1)\n (\* redistribute it and/or modify it under the terms of the:|\*)\n (\*|\* The contents of this file are subject to the Eclipse Public)\n (\* Eclipse Public License version 2\.0|\* License Version 2\.0 \(the "License"\); you may not use this file)\n (\* GNU General Public License version 2|\* except in compliance with the License\. You may obtain a copy of)\n (\* GNU Lesser General Public License version 2\.1|\* the License at http://www.eclipse.org/legal/epl-v20.html)\n (\*/|\*)\n'/>
236240
<property name="fileExtensions" value="java"/>

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ public abstract static class RespondToNode extends CoreMethodNode {
15591559
@Child private InternalRespondToNode dispatch;
15601560
@Child private InternalRespondToNode dispatchIgnoreVisibility;
15611561
@Child private InternalRespondToNode dispatchRespondToMissing;
1562-
@Child private ReadCallerFrameNode readCallerFrame = ReadCallerFrameNode.create();
1562+
@Child private ReadCallerFrameNode readCallerFrame;
15631563
@Child private DispatchNode respondToMissingNode;
15641564
@Child private BooleanCastNode booleanCastNode;
15651565
private final ConditionProfile ignoreVisibilityProfile = ConditionProfile.create();
@@ -1572,6 +1572,8 @@ public RespondToNode() {
15721572
dispatchRespondToMissing = InternalRespondToNode.create();
15731573
}
15741574

1575+
/** Callers should pass null for the frame here, unless they want to use refinements and can ensure the direct
1576+
* caller is a Ruby method */
15751577
public abstract boolean executeDoesRespondTo(VirtualFrame frame, Object object, Object name,
15761578
boolean includeProtectedAndPrivate);
15771579

@@ -1600,11 +1602,7 @@ protected boolean doesRespondToString(
16001602
return true;
16011603
} else if (respondToMissingProfile
16021604
.profile(dispatchRespondToMissing.execute(frame, object, "respond_to_missing?"))) {
1603-
return respondToMissing(
1604-
frame,
1605-
object,
1606-
getSymbol(name.rope),
1607-
includeProtectedAndPrivate);
1605+
return respondToMissing(object, getSymbol(name.rope), includeProtectedAndPrivate);
16081606
} else {
16091607
return false;
16101608
}
@@ -1630,14 +1628,13 @@ protected boolean doesRespondToSymbol(
16301628
return true;
16311629
} else if (respondToMissingProfile
16321630
.profile(dispatchRespondToMissing.execute(frame, object, "respond_to_missing?"))) {
1633-
return respondToMissing(frame, object, name, includeProtectedAndPrivate);
1631+
return respondToMissing(object, name, includeProtectedAndPrivate);
16341632
} else {
16351633
return false;
16361634
}
16371635
}
16381636

1639-
private boolean respondToMissing(VirtualFrame frame, Object object, RubySymbol name,
1640-
boolean includeProtectedAndPrivate) {
1637+
private boolean respondToMissing(Object object, RubySymbol name, boolean includeProtectedAndPrivate) {
16411638
if (respondToMissingNode == null) {
16421639
CompilerDirectives.transferToInterpreterAndInvalidate();
16431640
respondToMissingNode = insert(DispatchNode.create());
@@ -1654,6 +1651,10 @@ private boolean respondToMissing(VirtualFrame frame, Object object, RubySymbol n
16541651

16551652
private void useCallerRefinements(VirtualFrame frame) {
16561653
if (frame != null) {
1654+
if (readCallerFrame == null) {
1655+
CompilerDirectives.transferToInterpreterAndInvalidate();
1656+
readCallerFrame = insert(ReadCallerFrameNode.create());
1657+
}
16571658
DeclarationContext context = RubyArguments.getDeclarationContext(readCallerFrame.execute(frame));
16581659
RubyArguments.setDeclarationContext(frame, context);
16591660
}

src/main/java/org/truffleruby/core/string/StringNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,14 @@ protected boolean equal(RubyString a, RubyString b) {
465465
}
466466

467467
@Specialization(guards = "!isRubyString(b)")
468-
protected boolean equal(VirtualFrame frame, RubyString a, Object b) {
468+
protected boolean equal(RubyString a, Object b) {
469469
if (respondToNode == null) {
470470
CompilerDirectives.transferToInterpreterAndInvalidate();
471471
respondToNode = insert(KernelNodesFactory.RespondToNodeFactory.create(null, null, null));
472472
}
473473

474474
if (respondToNode
475-
.executeDoesRespondTo(frame, b, coreStrings().TO_STR.createInstance(getContext()), false)) {
475+
.executeDoesRespondTo(null, b, coreStrings().TO_STR.createInstance(getContext()), false)) {
476476
if (objectEqualNode == null) {
477477
CompilerDirectives.transferToInterpreterAndInvalidate();
478478
objectEqualNode = insert(DispatchNode.create());

src/main/java/org/truffleruby/core/support/TypeNodes.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import com.oracle.truffle.api.dsl.ImportStatic;
5656
import com.oracle.truffle.api.dsl.NodeChild;
5757
import com.oracle.truffle.api.dsl.Specialization;
58-
import com.oracle.truffle.api.frame.VirtualFrame;
5958
import com.oracle.truffle.api.library.CachedLibrary;
6059
import com.oracle.truffle.api.object.DynamicObjectLibrary;
6160
import com.oracle.truffle.api.object.HiddenKey;
@@ -83,8 +82,9 @@ public static abstract class ObjectRespondToNode extends PrimitiveArrayArguments
8382
.create(null, null, null);
8483

8584
@Specialization
86-
protected boolean objectRespondTo(VirtualFrame frame, Object object, Object name, boolean includePrivate) {
87-
return respondToNode.executeDoesRespondTo(frame, object, name, includePrivate);
85+
protected boolean objectRespondTo(Object object, Object name, boolean includePrivate) {
86+
// Do not pass a frame here, we want to ignore refinements and not need to read the caller frame
87+
return respondToNode.executeDoesRespondTo(null, object, name, includePrivate);
8888
}
8989

9090
}

0 commit comments

Comments
 (0)