Skip to content

Commit d8dd0c1

Browse files
author
Nicolas Laurent
committed
Remove boundaries & cleanup in RubyCallNode
1 parent 574d6bd commit d8dd0c1

File tree

3 files changed

+16
-35
lines changed

3 files changed

+16
-35
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,14 +1261,14 @@ protected RubyMethod method(VirtualFrame frame, Object self, Object name,
12611261
@Cached ConditionProfile respondToMissingProfile) {
12621262
final String normalizedName = nameToJavaStringNode.execute(name);
12631263
InternalMethod method = lookupMethodNode
1264-
.lookupPrivate(frame, self, normalizedName, dispatchConfig);
1264+
.lookup(frame, self, normalizedName, dispatchConfig);
12651265

12661266
if (notFoundProfile.profile(method == null)) {
12671267
final Object respondToMissing = respondToMissingNode
12681268
.call(self, "respond_to_missing?", name, dispatchConfig.ignoreVisibility);
12691269
if (respondToMissingProfile.profile(booleanCastNode.executeToBoolean(respondToMissing))) {
12701270
final InternalMethod methodMissing = lookupMethodNode
1271-
.lookupPrivate(frame, self, "method_missing", dispatchConfig);
1271+
.lookup(frame, self, "method_missing", dispatchConfig);
12721272
method = createMissingMethod(self, name, normalizedName, methodMissing);
12731273
} else {
12741274
throw new RaiseException(

src/main/java/org/truffleruby/language/dispatch/RubyCallNode.java

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,21 @@
1616
import org.truffleruby.core.cast.BooleanCastNodeGen;
1717
import org.truffleruby.core.cast.ProcOrNullNode;
1818
import org.truffleruby.core.cast.ProcOrNullNodeGen;
19-
import org.truffleruby.core.module.ModuleOperations;
2019
import org.truffleruby.core.proc.RubyProc;
2120
import org.truffleruby.core.symbol.RubySymbol;
2221
import org.truffleruby.language.RubyBaseNode;
2322
import org.truffleruby.language.RubyContextSourceNode;
2423
import org.truffleruby.language.RubyNode;
2524
import org.truffleruby.language.arguments.RubyArguments;
2625
import org.truffleruby.language.methods.BlockDefinitionNode;
27-
import org.truffleruby.language.methods.DeclarationContext;
2826
import org.truffleruby.language.methods.InternalMethod;
2927

3028
import com.oracle.truffle.api.CompilerDirectives;
31-
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3229
import com.oracle.truffle.api.frame.VirtualFrame;
3330
import com.oracle.truffle.api.nodes.ExplodeLoop;
3431
import com.oracle.truffle.api.profiles.BranchProfile;
3532
import com.oracle.truffle.api.profiles.ConditionProfile;
33+
import org.truffleruby.language.methods.LookupMethodOnSelfNode;
3634

3735
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE;
3836
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_RETURN_MISSING;
@@ -48,7 +46,7 @@ public class RubyCallNode extends RubyContextSourceNode {
4846
@Children private final RubyNode[] arguments;
4947

5048
private final boolean isSplatted;
51-
private final boolean ignoreVisibility;
49+
private final DispatchConfiguration dispatchConfig;
5250
private final boolean isVCall;
5351
private final boolean isSafeNavigation;
5452
private final boolean isAttrAssign;
@@ -73,7 +71,7 @@ public RubyCallNode(RubyCallNodeParameters parameters) {
7371
}
7472

7573
this.isSplatted = parameters.isSplatted();
76-
this.ignoreVisibility = parameters.isIgnoreVisibility();
74+
this.dispatchConfig = parameters.isIgnoreVisibility() ? PRIVATE : PROTECTED;
7775
this.isVCall = parameters.isVCall();
7876
this.isSafeNavigation = parameters.isSafeNavigation();
7977
this.isAttrAssign = parameters.isAttrAssign();
@@ -114,7 +112,7 @@ public Object executeWithArgumentsEvaluated(VirtualFrame frame, Object receiverO
114112
Object[] argumentsObjects) {
115113
if (dispatch == null) {
116114
CompilerDirectives.transferToInterpreterAndInvalidate();
117-
dispatch = insert(DispatchNode.create(ignoreVisibility ? PRIVATE : PROTECTED));
115+
dispatch = insert(DispatchNode.create(dispatchConfig));
118116
}
119117

120118
final Object returnValue = dispatch
@@ -183,8 +181,8 @@ private class DefinedNode extends RubyBaseNode {
183181
@Child private DispatchNode respondToMissing = DispatchNode.create(PRIVATE_RETURN_MISSING);
184182
@Child private BooleanCastNode respondToMissingCast = BooleanCastNodeGen.create(null);
185183

186-
// TODO CS-10-Apr-17 see below
187-
// @Child private LookupMethodNode lookupMethodNode = LookupMethodNodeGen.create(ignoreVisibility, false, null, null);
184+
185+
@Child private LookupMethodOnSelfNode lookupMethodNode = LookupMethodOnSelfNode.create();
188186

189187
private final ConditionProfile receiverDefinedProfile = ConditionProfile.create();
190188
private final BranchProfile argumentNotDefinedProfile = BranchProfile.create();
@@ -218,8 +216,7 @@ public Object isDefined(VirtualFrame frame, RubyContext context) {
218216
return nil;
219217
}
220218

221-
final DeclarationContext declarationContext = RubyArguments.getDeclarationContext(frame);
222-
final InternalMethod method = doLookup(receiverObject, declarationContext);
219+
final InternalMethod method = lookupMethodNode.lookup(frame, receiverObject, methodName, dispatchConfig);
223220
final Object self = RubyArguments.getSelf(frame);
224221

225222
if (methodNotFoundProfile.profile(method == null)) {
@@ -230,32 +227,16 @@ public Object isDefined(VirtualFrame frame, RubyContext context) {
230227
}
231228
} else if (methodUndefinedProfile.profile(method.isUndefined())) {
232229
return nil;
233-
} else if (methodNotVisibleProfile.profile(!ignoreVisibility && !isVisibleTo(method, self))) {
230+
} else if (methodNotVisibleProfile
231+
.profile(!dispatchConfig.ignoreVisibility && !isVisibleTo(method, self))) {
234232
return nil;
235233
}
236234

237235
return coreStrings().METHOD.createInstance();
238236
}
239237

240-
// TODO CS-10-Apr-17 remove this boundary
241-
242-
@TruffleBoundary
243-
private InternalMethod doLookup(Object receiverObject, DeclarationContext declarationContext) {
244-
// TODO CS-10-Apr-17 I'd like to use this but it doesn't give the same result
245-
// lookupMethodNode.executeLookupMethod(frame, coreLibrary().getMetaClass(receiverObject), methodName);
246-
247-
return ModuleOperations
248-
.lookupMethodUncached(coreLibrary().getMetaClass(receiverObject), methodName, declarationContext);
249-
}
250-
251-
// TODO CS-10-Apr-17 remove this boundary
252-
253-
@TruffleBoundary
254238
private boolean isVisibleTo(InternalMethod method, Object self) {
255239
return method.isVisibleTo(coreLibrary().getMetaClass(self));
256240
}
257-
258241
}
259-
260-
261242
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public static LookupMethodOnSelfNode create() {
2626
return LookupMethodOnSelfNodeGen.create();
2727
}
2828

29-
public InternalMethod lookupProtected(VirtualFrame frame, Object self, String name) {
30-
return execute(frame, self, name, DispatchConfiguration.PROTECTED);
31-
}
32-
33-
public InternalMethod lookupPrivate(
29+
public InternalMethod lookup(
3430
VirtualFrame frame, Object self, String name, DispatchConfiguration config) {
3531
return execute(frame, self, name, config);
3632
}
3733

34+
public InternalMethod lookupProtected(VirtualFrame frame, Object self, String name) {
35+
return execute(frame, self, name, DispatchConfiguration.PROTECTED);
36+
}
37+
3838
public InternalMethod lookupIgnoringVisibility(VirtualFrame frame, Object self, String name) {
3939
return execute(frame, self, name, DispatchConfiguration.PRIVATE);
4040
}

0 commit comments

Comments
 (0)