Skip to content
Snippets Groups Projects
Commit 26d90709 authored by Florian Angerer's avatar Florian Angerer
Browse files

Added missing guard.

parent 09bead24
Branches
No related tags found
No related merge requests found
...@@ -17,8 +17,8 @@ import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.foreign; ...@@ -17,8 +17,8 @@ import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.foreign;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX;
import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.TruffleObject; import com.oracle.truffle.api.interop.TruffleObject;
...@@ -44,6 +44,11 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; ...@@ -44,6 +44,11 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
@RBuiltin(name = "@", kind = PRIMITIVE, parameterNames = {"", ""}, nonEvalArgs = 1, behavior = COMPLEX) @RBuiltin(name = "@", kind = PRIMITIVE, parameterNames = {"", ""}, nonEvalArgs = 1, behavior = COMPLEX)
public abstract class Slot extends RBuiltinNode.Arg2 { public abstract class Slot extends RBuiltinNode.Arg2 {
private static final int UNINITIALIZED = 0;
private static final int IS_LHS = 1;
private static final int IS_NOT_LHS = 2;
@CompilationFinal private int isLhsState = UNINITIALIZED;
@Child private UpdateShareableChildValueNode sharedAttrUpdate = UpdateShareableChildValueNode.create(); @Child private UpdateShareableChildValueNode sharedAttrUpdate = UpdateShareableChildValueNode.create();
@Child private AccessSlotNode accessSlotNode = AccessSlotNodeGen.create(true); @Child private AccessSlotNode accessSlotNode = AccessSlotNodeGen.create(true);
...@@ -71,24 +76,28 @@ public abstract class Slot extends RBuiltinNode.Arg2 { ...@@ -71,24 +76,28 @@ public abstract class Slot extends RBuiltinNode.Arg2 {
return unwrapParent instanceof RSyntaxCall && ((RSyntaxCall) unwrapParent).getSyntaxLHS() == n; return unwrapParent instanceof RSyntaxCall && ((RSyntaxCall) unwrapParent).getSyntaxLHS() == n;
} }
protected boolean isForeignObject(Object obj) { private boolean isLhsOfCall() {
return RRuntime.isForeignObject(obj); if (isLhsState == UNINITIALIZED) {
CompilerDirectives.transferToInterpreterAndInvalidate();
Node unwrapParent = RASTUtils.unwrapParent(this);
assert ((BuiltinCallNode) unwrapParent).getBuiltin() == this;
if (unwrapParent instanceof BuiltinCallNode && isLhsOfSyntaxCall(((RBaseNode) unwrapParent).asRSyntaxNode())) {
isLhsState = IS_LHS;
} else {
isLhsState = IS_NOT_LHS;
}
}
return isLhsState == IS_LHS;
} }
protected boolean isLhsOfCall() { protected boolean isLhsOfForeignCall(Object o) {
CompilerAsserts.neverPartOfCompilation(); return RRuntime.isForeignObject(o) && isLhsOfCall();
Node unwrapParent = RASTUtils.unwrapParent(this);
assert ((BuiltinCallNode) unwrapParent).getBuiltin() == this;
return unwrapParent instanceof BuiltinCallNode && isLhsOfSyntaxCall(((RBaseNode) unwrapParent).asRSyntaxNode());
} }
@Specialization(guards = {"isForeignObject(object)", "lhsOfCall"}) @Specialization(guards = "isLhsOfForeignCall(object)")
protected Object getSlot(TruffleObject object, Object nameObj, protected Object getSlot(TruffleObject object, Object nameObj,
@Cached("isLhsOfCall()") boolean lhsOfCall,
@Cached("createClassProfile()") ValueProfile nameObjProfile) { @Cached("createClassProfile()") ValueProfile nameObjProfile) {
assert lhsOfCall;
String name = getName(nameObjProfile.profile(nameObj)); String name = getName(nameObjProfile.profile(nameObj));
assert Utils.isInterned(name); assert Utils.isInterned(name);
...@@ -96,7 +105,7 @@ public abstract class Slot extends RBuiltinNode.Arg2 { ...@@ -96,7 +105,7 @@ public abstract class Slot extends RBuiltinNode.Arg2 {
return RCallNode.createDeferredMemberAccess(object, name); return RCallNode.createDeferredMemberAccess(object, name);
} }
@Specialization @Specialization(guards = "!isLhsOfForeignCall(object)")
protected Object getSlot(Object object, Object nameObj, protected Object getSlot(Object object, Object nameObj,
@Cached("createClassProfile()") ValueProfile nameObjProfile) { @Cached("createClassProfile()") ValueProfile nameObjProfile) {
String name = getName(nameObjProfile.profile(nameObj)); String name = getName(nameObjProfile.profile(nameObj));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment