Skip to content

Commit

Permalink
[Truffle] getCallerFrame -> getCallerFrameIgnoringSend, rather than j…
Browse files Browse the repository at this point in the history
…ust keep that information in a comment
chrisseaton committed Feb 16, 2016

Unverified

This user has not yet uploaded their public signing key.
1 parent 500a642 commit c18b79f
Showing 11 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -316,7 +316,7 @@ public BindingNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public DynamicObject binding() {
// Materialize the caller's frame - false means don't use a slow path to get it - we want to optimize it
final MaterializedFrame callerFrame = getContext().getCallStack().getCallerFrame()
final MaterializedFrame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend()
.getFrame(FrameInstance.FrameAccess.MATERIALIZE, false).materialize();

return BindingNodes.createBinding(getContext(), callerFrame);
@@ -355,7 +355,7 @@ public CalleeNameNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject calleeName() {
CompilerDirectives.transferToInterpreter();
// the "called name" of a method.
return getSymbol(getContext().getCallStack().getCallingMethod().getName());
return getSymbol(getContext().getCallStack().getCallingMethodIgnoringSend().getName());
}
}

@@ -858,7 +858,7 @@ public String block() throws InterruptedException {

// Set the local variable $_ in the caller

final Frame caller = getContext().getCallStack().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_WRITE, true);
final Frame caller = getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameInstance.FrameAccess.READ_WRITE, true);

final FrameSlot slot = caller.getFrameDescriptor().findFrameSlot("$_");

@@ -1201,7 +1201,7 @@ public LambdaNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject lambda(NotProvided block) {
final Frame parentFrame = getContext().getCallStack().getCallerFrame().getFrame(FrameAccess.READ_ONLY, true);
final Frame parentFrame = getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameAccess.READ_ONLY, true);
final DynamicObject parentBlock = RubyArguments.getBlock(parentFrame.getArguments());

if (parentBlock == null) {
@@ -1236,7 +1236,7 @@ public LocalVariablesNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject localVariables() {
final Frame frame = getContext().getCallStack().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_ONLY, true);
final Frame frame = getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameInstance.FrameAccess.READ_ONLY, true);
return BindingNodes.LocalVariablesNode.listLocalVariables(getContext(), frame);
}

@@ -1253,7 +1253,7 @@ public MethodNameNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject methodName() {
CompilerDirectives.transferToInterpreter();
// the "original/definition name" of the method.
return getSymbol(getContext().getCallStack().getCallingMethod().getSharedMethodInfo().getName());
return getSymbol(getContext().getCallStack().getCallingMethodIgnoringSend().getSharedMethodInfo().getName());
}

}
@@ -1592,7 +1592,7 @@ public boolean require(DynamicObject featureString) {
}

private boolean callerIs(String caller) {
return getContext().getCallStack().getCallerFrame().getCallNode()
return getContext().getCallStack().getCallerFrameIgnoringSend().getCallNode()
.getEncapsulatingSourceSection().getSource().getName().endsWith(caller);
}
}
@@ -1615,7 +1615,7 @@ public boolean requireRelative(DynamicObject feature) {
if (featureLoader.isAbsolutePath(featureString)) {
featurePath = featureString;
} else {
final Source source = getContext().getCallStack().getCallerFrame().getCallNode().getEncapsulatingSourceSection().getSource();
final Source source = getContext().getCallStack().getCallerFrameIgnoringSend().getCallNode().getEncapsulatingSourceSection().getSource();
final String sourcePath = featureLoader.getSourcePath(source);

if (sourcePath == null) {
Original file line number Diff line number Diff line change
@@ -411,7 +411,7 @@ public DynamicObject generateAccessor(VirtualFrame frame, DynamicObject module,
final String name = nameToJavaStringNode.executeToJavaString(frame, nameObject);

CompilerDirectives.transferToInterpreter();
final FrameInstance callerFrame = getContext().getCallStack().getCallerFrame();
final FrameInstance callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend();
final SourceSection sourceSection = callerFrame.getCallNode().getEncapsulatingSourceSection();
final Visibility visibility = DeclarationContext.findVisibility(callerFrame.getFrame(FrameAccess.READ_ONLY, true));
final Arity arity = isGetter ? Arity.NO_ARGUMENTS : Arity.ONE_REQUIRED;
@@ -664,7 +664,7 @@ private Object classEvalSource(DynamicObject module, DynamicObject code, String
private Object classEvalSource(DynamicObject module, DynamicObject code, String file, int line) {
assert RubyGuards.isRubyString(code);

final MaterializedFrame callerFrame = getContext().getCallStack().getCallerFrame()
final MaterializedFrame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend()
.getFrame(FrameInstance.FrameAccess.MATERIALIZE, true).materialize();
Encoding encoding = Layouts.STRING.getRope(code).getEncoding();

@@ -1172,7 +1172,7 @@ public Object execute(VirtualFrame frame) {
private DynamicObject addMethod(DynamicObject module, String name, InternalMethod method) {
method = method.withName(name);

final Frame frame = getContext().getCallStack().getCallerFrame().getFrame(FrameAccess.READ_ONLY, true);
final Frame frame = getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameAccess.READ_ONLY, true);
final Visibility visibility = GetCurrentVisibilityNode.getVisibilityFromNameAndFrame(name, frame);
return addMethodNode.executeAddMethod(module, method, visibility);
}
@@ -1397,7 +1397,7 @@ public DynamicObject nesting() {

final List<DynamicObject> modules = new ArrayList<>();

InternalMethod method = getContext().getCallStack().getCallingMethod();
InternalMethod method = getContext().getCallStack().getCallingMethodIgnoringSend();
LexicalScope lexicalScope = method == null ? null : method.getSharedMethodInfo().getLexicalScope();
DynamicObject object = getContext().getCoreLibrary().getObjectClass();

@@ -1986,7 +1986,7 @@ public DynamicObject setVisibility(VirtualFrame frame, DynamicObject module, Obj
}

private void setCurrentVisibility(Visibility visibility) {
final Frame callerFrame = getContext().getCallStack().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_WRITE, true);
final Frame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameInstance.FrameAccess.READ_WRITE, true);
DeclarationContext.changeVisibility(callerFrame, visibility);
}

Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ public ProcNewNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public DynamicObject proc(VirtualFrame frame, DynamicObject procClass, Object[] args, NotProvided block) {
final Frame parentFrame = getContext().getCallStack().getCallerFrame().getFrame(FrameAccess.READ_ONLY, true);
final Frame parentFrame = getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameAccess.READ_ONLY, true);
final DynamicObject parentBlock = RubyArguments.getBlock(parentFrame.getArguments());

if (parentBlock == null) {
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ public static Object matchCommon(RubyContext context, RopeNodes.MakeSubstringNod
RegexpSetLastMatchPrimitiveNode.setLastMatch(context, nil);

if (setNamedCaptures && Layouts.REGEXP.getRegex(regexp).numberOfNames() > 0) {
final Frame frame = context.getCallStack().getCallerFrame().getFrame(FrameAccess.READ_WRITE, true);
final Frame frame = context.getCallStack().getCallerFrameIgnoringSend().getFrame(FrameAccess.READ_WRITE, true);
for (Iterator<NameEntry> i = Layouts.REGEXP.getRegex(regexp).namedBackrefIterator(); i.hasNext();) {
final NameEntry e = i.next();
final String name = new String(e.name, e.nameP, e.nameEnd - e.nameP, StandardCharsets.UTF_8).intern();
@@ -162,7 +162,7 @@ public static Object matchCommon(RubyContext context, RopeNodes.MakeSubstringNod
RegexpSetLastMatchPrimitiveNode.setLastMatch(context, matchObject);

if (setNamedCaptures && Layouts.REGEXP.getRegex(regexp).numberOfNames() > 0) {
final Frame frame = context.getCallStack().getCallerFrame().getFrame(FrameAccess.READ_WRITE, true);
final Frame frame = context.getCallStack().getCallerFrameIgnoringSend().getFrame(FrameAccess.READ_WRITE, true);
for (Iterator<NameEntry> i = Layouts.REGEXP.getRegex(regexp).namedBackrefIterator(); i.hasNext();) {
final NameEntry e = i.next();
final String name = new String(e.name, e.nameP, e.nameEnd - e.nameP, StandardCharsets.UTF_8).intern();
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public Object execute(VirtualFrame frame) {

// Rubinius expects $_ to be thread-local, rather than frame-local. If we see it in a method call, we need
// to look to the caller's frame to get the correct value, otherwise it will be nil.
final MaterializedFrame callerFrame = getContext().getCallStack().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_ONLY, true).materialize();
final MaterializedFrame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameInstance.FrameAccess.READ_ONLY, true).materialize();

// TODO CS 4-Jan-16 - but it could be in higher frames!
final FrameSlot slot = callerFrame.getFrameDescriptor().findFrameSlot("$_");
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public Object lastStringWrite(Object value) {

// Rubinius expects $_ to be thread-local, rather than frame-local. If we see it in a method call, we need
// to look to the caller's frame to get the correct value, otherwise it will be nil.
MaterializedFrame callerFrame = getContext().getCallStack().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_ONLY, true).materialize();
MaterializedFrame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameInstance.FrameAccess.READ_ONLY, true).materialize();

FrameSlot slot = callerFrame.getFrameDescriptor().findFrameSlot("$_");

Original file line number Diff line number Diff line change
@@ -140,7 +140,7 @@ public DynamicObject toProcUncached(VirtualFrame frame, DynamicObject symbol) {

protected DynamicObject createProc(VirtualFrame frame, DynamicObject symbol) {
CompilerDirectives.transferToInterpreter();
final SourceSection sourceSection = getContext().getCallStack().getCallerFrame()
final SourceSection sourceSection = getContext().getCallStack().getCallerFrameIgnoringSend()
.getCallNode().getEncapsulatingSourceSection();

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
Original file line number Diff line number Diff line change
@@ -297,7 +297,7 @@ public SimpleShellNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject simpleShell() {
new SimpleShell(getContext()).run(getContext().getCallStack().getCallerFrame().getFrame(FrameInstance.FrameAccess.MATERIALIZE, true).materialize(), this);
new SimpleShell(getContext()).run(getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameInstance.FrameAccess.MATERIALIZE, true).materialize(), this);
return nil();
}

Original file line number Diff line number Diff line change
@@ -37,9 +37,8 @@ public CallStackManager(RubyContext context) {
this.context = context;
}

/** Ignores Kernel#send and aliases */
@TruffleBoundary
public FrameInstance getCallerFrame() {
public FrameInstance getCallerFrameIgnoringSend() {
return Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<FrameInstance>() {
@Override
public FrameInstance visitFrame(FrameInstance frameInstance) {
@@ -55,8 +54,8 @@ public FrameInstance visitFrame(FrameInstance frameInstance) {
});
}

public InternalMethod getCallingMethod() {
return getMethod(getCallerFrame());
public InternalMethod getCallingMethodIgnoringSend() {
return getMethod(getCallerFrameIgnoringSend());
}

private InternalMethod getMethod(FrameInstance frame) {
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ private DispatchNode doDynamicObject(
if (ignoreVisibility) {
callerClass = null;
} else if (getDispatchAction() == DispatchAction.RESPOND_TO_METHOD) {
final Frame callerFrame = getContext().getCallStack().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_ONLY, true);
final Frame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameInstance.FrameAccess.READ_ONLY, true);
callerClass = getContext().getCoreLibrary().getMetaClass(RubyArguments.getSelf(callerFrame.getArguments()));
} else {
callerClass = getContext().getCoreLibrary().getMetaClass(RubyArguments.getSelf(frame.getArguments()));
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ public DynamicObject allocateTracing(DynamicObject classToAllocate, Object[] val
final Node allocatingNode;

if (useCallerFrame) {
allocatingFrameInstance = getContext().getCallStack().getCallerFrame();
allocatingFrameInstance = getContext().getCallStack().getCallerFrameIgnoringSend();
allocatingNode = getContext().getCallStack().getTopMostUserCallNode();
} else {
allocatingFrameInstance = Truffle.getRuntime().getCurrentFrame();

1 comment on commit c18b79f

@eregon
Copy link
Member

@eregon eregon commented on c18b79f Feb 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already a JavaDoc comment. This will make it less clear which one should be used. 99% of the cases it's this and not Truffle.getRuntime().getCallerFrame() for instance.

Sorry, something went wrong.

Please sign in to comment.