Skip to content

Commit

Permalink
[Truffle] #initialize and #method_missing should be private.
Browse files Browse the repository at this point in the history
* And visibility checking for private with an explicit receiver is always false.
  • Loading branch information
eregon committed Oct 13, 2014
1 parent 4db3eb0 commit 0516e2f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
Expand Up @@ -15,6 +15,7 @@
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.dispatch.Dispatch;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
Expand Down Expand Up @@ -146,7 +147,7 @@ public boolean equal(Object a, Object b) {
}
}

@CoreMethod(names = "initialize", needsSelf = false, maxArgs = 0)
@CoreMethod(names = "initialize", needsSelf = false, maxArgs = 0, visibility = Visibility.PRIVATE)
public abstract static class InitializeNode extends CoreMethodNode {

public InitializeNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -199,7 +200,7 @@ public Object instanceEval(VirtualFrame frame, Object self, RubyProc block) {

}

@CoreMethod(names = "method_missing", needsBlock = true, isSplatted = true)
@CoreMethod(names = "method_missing", needsBlock = true, isSplatted = true, visibility = Visibility.PRIVATE)
public abstract static class MethodMissingNode extends CoreMethodNode {

public MethodMissingNode(RubyContext context, SourceSection sourceSection) {
Expand Down
Expand Up @@ -12,6 +12,7 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.nodes.dispatch.Dispatch;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyContext;
Expand Down Expand Up @@ -59,7 +60,7 @@ public abstract static class NewNode extends CoreMethodNode {

public NewNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
initialize = new DispatchHeadNode(context);
initialize = DispatchHeadNode.onSelf(context);
}

public NewNode(NewNode prev) {
Expand Down
Expand Up @@ -91,7 +91,7 @@ public Object dispatch(
ignoreVisibility, dispatchAction);

if (method == null) {
final RubyMethod missingMethod = lookup(callingSelf, receiverObject, "method_missing", ignoreVisibility,
final RubyMethod missingMethod = lookup(callingSelf, receiverObject, "method_missing", true,
dispatchAction);

if (missingMethod == null) {
Expand Down
Expand Up @@ -318,7 +318,7 @@ private DispatchNode createMethodMissingNode(
}

case CALL_METHOD_MISSING: {
final RubyMethod method = lookup(callingSelf, receiverObject, "method_missing", ignoreVisibility, dispatchAction);
final RubyMethod method = lookup(callingSelf, receiverObject, "method_missing", true, dispatchAction);

if (method == null) {
throw new RaiseException(getContext().getCoreLibrary().runtimeError(
Expand Down
Expand Up @@ -129,18 +129,8 @@ private boolean isVisibleToX(Node currentNode, ModuleChain module) {
return false;

case PRIVATE:
if (module == declaringModule) {
return true;
}

if (module.getSingletonClass(currentNode) == declaringModule) {
return true;
}

if (module.getParentModule() != null && isVisibleToX(currentNode, module.getParentModule())) {
return true;
}

// A private method may only be called with an implicit receiver,
// in which case the visibility must not be checked.
return false;

default:
Expand Down

0 comments on commit 0516e2f

Please sign in to comment.